-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Feature: Adding dependencies through CLI #1730
Comments
Another question -- it also seems like this functionality could be added to |
You can see the discussions about this behavior at #759 and #1550, but the upshot is that |
Thanks for the clarification. Looking at #759, thinking of That makes me more on-board to use a new |
This feature would also enable something like this in tox:
Today you are basically forced to have a requirements-x.in file since you can't do something like |
What's the problem this feature will solve?
Some libraries allow many backing modules for the same functionality. Two very popular examples are OpenCv and Qt. The python module
cv2
is provided byopencv-python-headless
,opencv-python-contrib
,opencv-python
, and a few more pypi packages. Similarly, Qt APIs are available viaPySide5
,PySide6
, etc.Often, rather than adding an
extra
argument to pip installs, developers will simply check if one of many compatible libraries is available and raise an error otherwise.qtpy
andpyqtgraph
are popular examples of this: Qt is not specified in their requirements file; the user is expected to install this separately and the import fails if it isn't found.pip-compile
doesn't handle these cases well -- currently, the only way requirements can be specified is through a requirements file.TLDR: It is cumbersome to install packages that should exist in the user's environment, but did not come from
requirements.txt
.Describe the solution you'd like
Ideally,
pip-compile
can support cli dependencies in itspip-args
flag, since according to the docs:This would allow
pip-compile
to handle these cases without forcing arequirements-tmp.txt
for dependencies not managed or specified by the library at hand, and fits within thepip-args
capabilities of adding cli dependencies.Alternative Solutions
Devs can make an additional requirements file that specifies these needs, i.e.:
which holds the relevant information. However, this leads to quite a bit of repo bloat if a separate additional requirements file must be specified for each similar (single) dependency. This is why e.g. packages like
qtpy
don't have an explicitrequirements.txt
file indicating this information.Additional context
I would be happy to work on the PR if this idea is positively received.
The solution should be quite easy to implement using
pip-compile
's existing logic, by simply extendingreqs
to include these additional options. It has the nice benefit of still printing in the "autogenerated" message, so reproducibility will not be lost.As a side note, the CLI already has an (undocumented) ability to accept requirements from stdin, so non-
requirements.txt
dependencies are already considered appropriate with existing logic.As another side note, stdin dependencies are lost in the "autogeneration" comment! This solution has the added benefit of retaining those dependencies on multiple runs of
pip-compile
since stdin can simply be directed as ainline-requirements
arg.I.e. run
echo pyside6 | pip-compile - -o requirements.txt
and you will get a file with this comment at the top:Note! The original stdin text,
pyside6
, is lost. This would not happen if it was stored as a CLI option.The text was updated successfully, but these errors were encountered: