Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to ONLY install extras from pyproject.toml #2052

Closed
jordantshaw opened this issue Jan 27, 2024 · 4 comments
Closed

Option to ONLY install extras from pyproject.toml #2052

jordantshaw opened this issue Jan 27, 2024 · 4 comments
Labels
awaiting response Awaiting response from a contributor extras Handling optional dependencies question User question

Comments

@jordantshaw
Copy link

What's the problem this feature will solve?

Being able to produce requirement files which only contain the extra dependencies in the pyproject.toml file.

Describe the solution you'd like

For a few of my python applications (not installable libraries) I am using pyproject.toml files to define the top-level dependencies. I like being able to define all of the dependencies within the pyproject.toml file, rather than using requirements.in files.

I would like to be able to create a requirements-dev.txt file based off the optional-dependencies in the pyproject.toml, but only the extra dependencies should be in the requirements-dev.txt file.

@webknjaz
Copy link
Member

Extras have a different purpose/semantics. And no installers would install them separately from the mandatory runtime deps. They are exposed to the end-users and are essentially a feature-flag like API. Also, pip-tools is not an installer but a constraint file generator.
What you want is defined as "dependency groups" in PEP 735, which is not yet finalized. I mentioned it in passing in my comment about the locking/pinning misconceptions: #1326 (comment).

@chrysle chrysle added question User question awaiting response Awaiting response from a contributor extras Handling optional dependencies labels Jan 27, 2024
@jordantshaw
Copy link
Author

@webknjaz I understand what you are saying. I think I solved my problem using using the constraint arg (-c). Basically I am trying to generate a requirements-dev.txt file, but I want to make sure that the pinned dependencies from the requirements.txt file are used. This does what Im looking for.

pip-compile --upgrade -o requirements/main.txt
pip-compile --upgrade -c requirements/main.txt -o requirements/dev.txt --extra=dev

As per your comment about using extras in a pyproject.toml file to define dev dependencies. I think you are right, that should not be done in a installable library type project. However, in an application project, where code is simply being deployed, I dont see why you shouldn't define dev dependencies in the extra-dependencies section. As there really is no "end-user" of the application.

@webknjaz
Copy link
Member

I'd like to emphasize that extras are only defined in the context of distribution metadata. Any other use implies a distribution anyway. To address this separate use case, PEP 735 defines dependency groups that aren't going to end up in the distribution metadata and are tailored specifically to the use case you're describing.

Meanwhile, keep having separate requirements files — they're made for this too, the difference is that they are pip-specific and PEP 735 is going to solve this in a generic cross-compatible tool-agnostic manner.

@WhyNotHugo
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Awaiting response from a contributor extras Handling optional dependencies question User question
Projects
None yet
Development

No branches or pull requests

4 participants