Description
Issue
I am opening this issue to discuss if the extras should be kept or removed in the compiled files.
@atugushev made a good summary of the situation:
Currently, we have direct references without extras and pinned packages with extras in requirements.txt, which looks wrong and should be synced in some single way.
We would like to get feedback from the community, do you think we should keep them or remove them and why?
My opinion is that we should remove them, since pip-compile
is already listing all packages needed for a project, it seems redundant to me to specify it twice (one time in the extra and one time as a top-level dependency). Also, it's in theory possible to install more packages than those specified in the requirements.txt via the extras. In my opinion the generated .txt file of pip-compile
should act as a lock file. The only advantage I can see is that we can easily inspect which dependencies are using extras.
@AndydeCleyre said that the order of installation could matter in some cases such as GDAL
which requires numpy
to be installed first. I checked if having the extra (gdal[numpy]
) in the .txt file was making a difference, and I found that it was not working. You can read this gist if you want to have a look at the tests I've done (there's a conclusion at the end if you don't want to read it all).
Links
Some links about the discussion around this:
- PR to remove extras
- PR to add extras in direct references
- PR about the direct reference without extras
Samples from dependency management tools
The goal is to show you the output of different management tools when the project specifies extras. This may help you make a decision on the issue.
For each tool, I installed gdal[numpy]==3.2.2
.
pip
Command: pip freeze > requirements.txt
The file contains:
GDAL==3.2.2
numpy==1.22.3
pip-tools
Command: pip-compile
The file contains:
gdal[numpy]==3.2.2
# via -r requirements.in
numpy==1.22.3
# via gdal
Pipenv
Command: pipenv lock -r > requirements.txt
The file contains:
-i https://pypi.org/simple
gdal[numpy]==3.2.2
numpy==1.22.3
Poetry
Command: poetry export -o requirements.txt
The file contains:
gdal==3.2.2
numpy==1.22.3; python_version >= "3.8"
Pros and cons
I'll try to collect all your feedbacks to update these lists.
Reasons to keep the extras:
- We can clearly see which dependencies are using extras (FlorentJeannot)
- Always remove extras in compiled files #1613 (comment)
Reasons to remove the extras:
- In theory, it's possible that
pip-sync
orpip
could install more packages than what is listed in a .txt file because of extras. I think the output ofpip-compile
should act as a lock file, so it should only install what's specified in the .txt file. (FlorentJeannot) - It's redundant. Packages specified in the extras are also in the top-level dependencies. (FlorentJeannot)
- Always remove extras in compiled files #1613 (comment)