pypa / pypa/setuptools

[FR] Environment variables substitution for dynamic dependencies

Open
#4,765 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement Needs Triage
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

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
  • I agree to follow the PSF Code of Conduct

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how setuptools reads [tool.setuptools.dynamic] dependencies from requirements.txt during pip install .. Check the pip requirements-file environment-variable syntax described in the issue and verify the PAT-based example works in a non-interactive installation; done means variables are substituted when parsing dynamic dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.