How does one pip install
with all extras? I'm aware that doing something like:
pip install -e .[docs,tests,others]
is an option. But, is it possible to do something like:
pip install -e .[all]
This question is similar to setup.py/setup.cfg install all extras. However, the answer there requires that the setup.cfg
file be edited. Is it possible to do it without modifying setup.py
or setup.cfg
?
pip
has a --report=
option which we can use:
--report <file> Generate a JSON file describing what pip did to
install the provided requirements. Can be used in
combination with --dry-run and --ignore-installed to
'resolve' the requirements. When - is used as file
name it writes to stdout. When writing to stdout,
please combine with the --quiet option to avoid mixing
pip logging output with JSON output.
So let's install the package once without extras and with the --report=-
option to get JSON on standard output.
Pipe the JSON to jq
, digging out the extras defined for the package.
Then install the package again with all extras if any exist.
(You could also --dry-run
the first step to postpone actual installation until the last step).
EXTRAS=$(\
pip install --quiet --report=- --editable="." \
| jq --raw-output '.install[0].metadata.provides_extra|join(",")' 2> /dev/null \
)
[ -n "${EXTRAS}" ] && pip install --editable=".[${EXTRAS}]"