Skip to content

Install dependencies from pyproject.toml like from requirements.txt with -r, (again) #13449

@tim-win

Description

@tim-win

What's the problem this feature will solve?

If you don't want to install a package but you do want to install dependencies, we don't have options outside of adding a second dependencies list (a requirements.txt), when all the dependencies are already listed in pyproject.toml. This means people working on a library need to duplicate dependency lists (common) or create on-demand requirements.txt files that aren't checked in (also common), when we really just need a pip install -r ./pyproject.toml that works like pip install ./requirements.txt.

Currently, repos are shipping with pyproject.toml files instead of requirements.txt files. The problem is that without a requirements.txt, there's no way to just install the requirements for these libraries as you work on them. We are seeing that several repos have brutish systems trying to both-ways it, or to simply force developers to write their own requirements.txt files if they want to develop the library. Examples:

And then you have other repos that bend over backwards to support pip and pyproject.toml. FastAPI has one pyproject.toml file, and 7 requirements.txt files in its root directory. Yikes!

Describe the solution you'd like

Expected interface:

pip install -r ./pyproject.toml
pip install -r ./pyproject.toml[dev]

Result:

install the dependencies defined in pyproject.toml
install the dependencies defined in pyproject.toml, plus dev dependencies

The advantage here is that we don't need a separate requirements.txt file, or several, and we can as a community standardize on one place to have dependencies listed.

Alternative Solutions

--deps-only doesn't seem to work in this case

The original recommendation, adding an additional dep in pip tools, is not what we want either. The whole point is a working tool chain with batteries included:

$ pip install pip-tools
$ python -m piptools compile \
    -o requirements.txt \
    pyproject.toml
$ pip install -r requirements.txt 

Don't forget the chatgpt oneliners:

python -c "import tomllib; deps = tomllib.load(open('pyproject.toml', 'rb'))['project']['dependencies']; open('requirements.txt', 'w').write('\n'.join(deps))"

Additional context

pyproject.toml is gaining traction as as both a sane and popular way to define a python library, a rare gem in any large community. However, with its popularity we're seeing standardization, and the new standard is to include pyproject.toml and to skip requirements.txt.

The issue I found on this subject, Support installing requirements from arbitrary keys in pyproject.toml #8049, is not what we're talking about, as pip install -r pyproject.toml --key tool.enscons.install_requires was already rejected, and anyway the interface is not the greatest.

#11584 was opened, but closed in favor of #8049. #8049 was closed for reasons described in the thread.

We still have plenty of python repos with only a pyproject.toml file, and we need to either generate our own requirements.txt files or we need

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions