Skip to content

pip check does not check extra requirements #4204

Closed
@augurar

Description

@augurar
  • Pip version: 9.0.1
  • Python version: Python 2.7.3
  • Operating System: Ubuntu 12.04.5 LTS

Description:

Based on the description pip check is intended to check for unsatisfied dependencies in installed packages. However, this does not seem to catch dependency issues related to extras.

Reproducing the issue:

Create packages a, b, c, and d.

.
├── a
│   ├── a
│   └── __init__.py
│   └── setup.py
├── b
│   ├── b
│   │   └── __init__.py
│   └── setup.py
├── c
│   ├── c
│   │   └── __init__.py
│   └── setup.py
└── d
    ├── d
    │   └── __init__.py
    └── setup.py
from setuptools import setup, find_packages

setup(
    name="a",
    version="1.0",
    packages=find_packages(),
)
from setuptools import setup, find_packages

setup(
    name="b",
    version='1.0',
    packages=find_packages(),
    extras_require={
        'a': ['a'],
    },
)
from setuptools import setup, find_packages

setup(
    name="c",
    version="1.0",
    packages=find_packages(),
    install_requires=[
        'b',
    ],
)
from setuptools import setup, find_packages

setup(
    name="d",
    version="1.0",
    packages=find_packages(),
    install_requires=[
        'b[a]',
    ],
)

Create dists for all four packages and install to a local pypi. Then (assuming the local pypi is running on localhost port 8080):

$ pip install -i http://localhost:8080 c d
$ pip uninstall a

Now we have an issue, since c --> b[a] --> a, but a is not installed. However, pip check does not catch this issue.

$ pip check
No broken requirements found.

The following script detects the problem:

import pip
import pkg_resources

pkg_resources.require(str(dep.as_requirement())
                      for dep in pip.get_installed_distributions())
$ python check_dependencies.py 
Traceback (most recent call last):
  File "check_dependencies.py", line 5, in <module>
    for dep in pip.get_installed_distributions())
  File ".../venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 963, in require
    needed = self.resolve(parse_requirements(requirements))
  File ".../venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 849, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'a; extra == "a"' distribution was not found and is required by b

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-lockedOutdated issues that have been locked by automation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions