For selective dependencies installing, the only way is indeed to grep/filter the requirements.txt
file according to your criteria. However, there are few ready solutions that might be of use:
If you have a virtualenv and only need to quickly upgrade it to the new requirements or version restrictions, but do not upgrade if the existing packages meet the criteria, you can use
pip install -U --upgrade-strategy=only-if-needed ...
As the manual says:
--upgrade-strategy <upgrade_strategy>
Determines how dependency upgrading should be handled. "eager" - dependencies are upgraded
regardless of whether the currently installed version satisfies the
requirements of the upgraded package(s). "only-if-needed" - are
upgraded only when they do not satisfy the requirements of the
upgraded package(s).
For the optional dependencies, the typical solution is the setuptools' extra requirements. For example, I use it for the development & doc-building requirements:
# setup.py
setup(
...,
extras_require={
'dev': ["pdbpp", "ipython"],
'doc': ["sphinx"],
},
)
Then you can install it as follows, both from the PyPI/DevPI repos, and locally (as an editable library):
pip install mylib[dev]
pip install mylib[doc]
pip install -e .[doc,dev]
You can define any names for the "extra modes" with optional dependencies.