Special variable inside requirements.txt which contains path to current requirements.txt
See original GitHub issueFirst of all i’m sorry for my poor English and pip skills What’s the problem this feature will solve? This feature request is based on my stackoverflow question https://stackoverflow.com/questions/57590215/path-to-current-file-inside-requirements-txt
Pip allow to specify path to other packages in requirements.txt. For example -e path/to/some/package
. It allow pip users to reuse local packages between local projects
For example suppose i have following structure of folders:
my_collection_of_packages/
package1/
package1/
some.py
setup.py
requirements.txt
package2/
same_structure_as_package1
requirements.txt
project1/
requirements.txt
package2
depends on package1
, so package2/requirements.txt
contains following string -e ../package1/
. So if my projects depends on package2
i can perform something like pip install -e project2
and it will install package1
too. But unfortunately, it will not work if my project is not at the same folder level with my packages.
For example, if my project is project1
and project1/requirements.txt
contains -e ../my_collection_of_packages/package2/
it’s impossible to install package2/requirements.txt
because it contains relative path ../package1/
which is equal project1/../package1/
if we run package2/requirements.txt
.
Describe the solution you’d like
From my point of view a special variable which contains path to current requirements.txt can be solution for this problem. I have no idea which name is better, but suppose it is ${requirements_pwd}
. So now package2/requirements.txt
can reference package1
by -e ${requirements_pwd}/../package1/
And project1
can reference package2
as -e ${requirements_pwd}/../my_collection_of_packages/package2/
Alternative Solutions It’s possible to achieve same result by using absolute paths, but this makes usage of packages on different machines almost impossible.
For linux another solution is to define environment variable ${package_collection}
and use it inside requirements.txt
. For example package2/requirements.txt
should be ${package_collection}/my_collection_of_packages/package1/
. Have no idea how to make it work on windows and linux simultaneously
Additional context Link to stackoverflow question: https://stackoverflow.com/questions/57590215/path-to-current-file-inside-requirements-txt
Thank in advance. Please let me know if something wrong with my problem statement.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
This might help clarify.
Hi @chrahunt ! Thank you for answer and thank you for suggestions! Actually currently i’m doing something very similar. But i want to avoid
pip install -e package1;pip install -e package2;pip install -r requirements.txt
because i use a lot of local packages with complicated dependencies. I need something likepip install -r local-requirements.txt
which will collect all my local dependencies automatically. So currently i have a script which installs all local packages to project’s venv. But it’s temporal solution. I’m totally agree that hard-coded relative paths is terrible, but i just cannot figure out other solution. Currently manual download is not an issue for me because i keep all packages in monorepository.