You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say we have a project called A in a Github repository from an organization, that has a requirements.txt file with the following dependencies:
B @ git+https://${PAT_TOKEN}@github.com/MY_ORGANIZATION/[email protected]
Then we have the project B also in a Github repository from the same organization, with his own requirements.txt file. For example:
C @ git+https://${PAT_TOKEN}@github.com/MY_ORGANIZATION/[email protected]
As said, all projects belong to the same Github organization (also C), so we can create a Personal Access Token (PAT) that can be used for authenticating in all projects. We export the PAT_TOKEN and set it as an environment variable in a terminal.
If we do pip install -r requirements.txt for project B everything works fine. The C project is installed as a dependency of B and the ${PAT_TOKEN} is correctly read from the environment variables, resolving the url, doing the checkout, etc.
However, if we do the same for project A it fails. Initially, it correctly resolves the B dependency, injecting the ${PAT_TOKEN} from env vars, but now B requires to install C, and in that case the ${PAT_TOKEN} is not replaced by the env variable, but passed literally to the checkout, then failing.
Expected behavior
The value of ${PAT_TOKEN} environment variable must be passed recursively to all dependencies and dependencies of dependencies.
pip version
24.3.1
Python version
3.11
OS
linux
How to Reproduce
Create a private repository A in GitHub inside an organization O, and commit some random code that imports package B.
Create a private repository B in GitHub inside an organization O, and commit some random code that imports package C.
Create a private repository C in GitHub inside an organization O, and commit some random code.
Create a requirements.txt file for project Aand add the following line: B @ git+https://${PAT_TOKEN}@github.com/O/[email protected]
Create a requirements.txt file for project Band add the following line: C @ git+https://${PAT_TOKEN}@github.com/O/[email protected]
In your account settings, create a personal access token that can be used for all the respositories within the organization.
Run pip install -r requirements.txt for A project.
Output
...
Collecting B@ git+https://****@github.com/O/B (from -r requirements.txt (line 1))
Cloning https://****@github.com/O/B (to revision v0.1.0) to /tmp/pip-install-l1b_8yth/B_afff0d9438154e0bbd86cc84bd9a6408
Running command git clone --filter=blob:none --quiet 'https://****@github.com/O/B' /tmp/pip-install-l1b_8yth/B_afff0d9438154e0bbd86cc84bd9a6408
Resolved https://****@github.com/O/B to commit 04060492b1907ca817366f20be6a87a32680bf04
Installing build dependencies: started
...
Collecting C@ git+https://****@github.com/O/[email protected] (from B@ git+https://***@github.com/O/[email protected]>-r requirements.txt (line 1))
Cloning https://****@github.com/O/C (to revision v0.1.0) to /tmp/pip-install-l1b_8yth/C_66e1729f35a1430fa58d589084f2aacd
Running command git clone --filter=blob:none --quiet 'https://****@github.com/O/C' /tmp/pip-install-l1b_8yth/C_66e1729f35a1430fa58d589084f2aacd
fatal: could not read Password for 'https://${PAT_TOKEN}@github.com': No such device or address
error: subprocess-exited-with-error
× git clone --filter=blob:none --quiet 'https://****@github.com/O/C' /tmp/pip-install-l1b_8yth/C_66e1729f35a1430fa58d589084f2aacd did not run successfully.
│ exit code: 128
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
note: This error originates from a subprocess, and is likely not a problem with pip
For pip install -r requirements.txt will read those requirements and substitute any environmental variables.
But when you pass a source tree, like a file path or a git link, pip invokes the defined build backend (setuptools, hatchling, poetry.core, flit, etc.) to build the package, it then receives that packages dependency metadata from the build backend, pip does not try to read any requirements.txt from that project, that's up to how the build backend is set up.
You've not provided a reproducible example of how you've set these projects up, but if you have a setup.py that reads and passes the dependencies from a requirements.txt then you need to check setuptools and see if it supports environmental substitution, I'm not very familiar myself sorry.
Description
Let's say we have a project called
A
in a Github repository from an organization, that has arequirements.txt
file with the following dependencies:B @ git+https://${PAT_TOKEN}@github.com/MY_ORGANIZATION/[email protected]
Then we have the project
B
also in a Github repository from the same organization, with his ownrequirements.txt
file. For example:C @ git+https://${PAT_TOKEN}@github.com/MY_ORGANIZATION/[email protected]
As said, all projects belong to the same Github organization (also
C
), so we can create a Personal Access Token (PAT) that can be used for authenticating in all projects. We export the PAT_TOKEN and set it as an environment variable in a terminal.If we do
pip install -r requirements.txt
for projectB
everything works fine. TheC
project is installed as a dependency ofB
and the${PAT_TOKEN}
is correctly read from the environment variables, resolving the url, doing the checkout, etc.However, if we do the same for project
A
it fails. Initially, it correctly resolves theB
dependency, injecting the${PAT_TOKEN}
from env vars, but nowB
requires to installC
, and in that case the${PAT_TOKEN}
is not replaced by the env variable, but passed literally to the checkout, then failing.Expected behavior
The value of ${PAT_TOKEN} environment variable must be passed recursively to all dependencies and dependencies of dependencies.
pip version
24.3.1
Python version
3.11
OS
linux
How to Reproduce
A
in GitHub inside an organizationO
, and commit some random code that imports packageB
.B
in GitHub inside an organizationO
, and commit some random code that imports packageC
.C
in GitHub inside an organizationO
, and commit some random code.requirements.txt
file for projectA
and add the following line:B @ git+https://${PAT_TOKEN}@github.com/O/[email protected]
requirements.txt
file for projectB
and add the following line:C @ git+https://${PAT_TOKEN}@github.com/O/[email protected]
pip install -r requirements.txt
forA
project.Output
Code of Conduct
The text was updated successfully, but these errors were encountered: