setuptools icon indicating copy to clipboard operation
setuptools copied to clipboard

[FR] Environment variables substitution for dynamic dependencies

Open sondalex opened this issue 1 year ago • 1 comments

What's the problem this feature will solve?

Setuptools supports dynamically specifying dependencies through pyproject.toml using the following syntax:

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }

The requirements.txt format, as described in the pip documentation, includes a proposal for environment variable substitution. However, this functionality is not currently implemented in setuptools.

Describe the solution you'd like

Introduce support in setuptools for substituting environment variables when parsing dependencies from a requirements.txt file. This would enable use cases like the following:

  1. Define a private dependency in requirements.txt:

    mypackage@https://${PAT}@<pypi-feed>/<path>
    
  2. Specify dynamic dependencies in pyproject.toml:

    [project]
    # Other project metadata
    dynamic = ["dependencies"]
    
    [tool.setuptools.dynamic]
    dependencies = { file = ["requirements.txt"] }
    
  3. Set the necessary environment variables before installation:

    export PAT=...
    export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring # To avoid interactive prompts
    
  4. Run the installation:

    pip install .
    

This feature would be especially beneficial for non-interactive sessions, such as CI/CD pipelines.

Alternative Solutions

No response

Additional context

No response

Code of Conduct

  • [X] I agree to follow the PSF Code of Conduct

sondalex avatar Dec 10 '24 13:12 sondalex

Any advance on this? This feature is desperately needed in many situations.

javier-wf avatar Jan 13 '25 08:01 javier-wf