Hey, all. I previously ran into what I thought was a bug with pip’s handling of package extras. When you install a package with extras, pip doesn’t remember the dependency relations of the extras after installation. I initially filed an issue with pip, which has since been closed. Here’s the gist:
As an example, create example-package
with an extra dependency. Using setuptools, the setup.cfg
file would look something like this:
[metadata]
name = example-package
version = 1.0
...
[options]
install_requires =
psycopg[binary] >=3.0
Here, psycopg[binary]
adds a psycopg-binary
package dependency.
Then, install example-package
. It will install psycopg-binary
, psycopg
, and example-package
. The first package here is an extra dependency.
Now, pip show example-package
will list psycopg
as example-package
's only requirement. Additionally, pip show psycopg-binary
will state that psycopg-binary
is not required by any other package. If you pip uninstall psycopg-binary
, pip check
will not state that there are broken dependencies.
I was under the impression that all dependencies fall into one of two categories: build dependencies (specified in a pyproject.toml file per PEP 517/518) and everything else (tool-dependent, but typically specified in a setup.py/setup.cfg file using setuptools). Build dependencies need not persist after build-time, and all other dependencies persist as long as the packages requiring them are installed. In my example, example-project
's metadata states that it requires psycopg[binary]
. After initial installation, this metadata persists; the package still has this requirement.
What are people’s thoughts on this? PEP 508 states how to specify package dependencies. Is there a similar PEP that states what dependencies really “mean”? If not, how do you all think that extras should be handled?