tox-dev / pipdeptree

A command line utility to display dependency tree of the installed Python packages
https://pypi.python.org/pypi/pipdeptree
MIT License
2.73k stars 147 forks source link

List pip as dependency #336

Closed pawamoy closed 3 months ago

pawamoy commented 3 months ago

We ran the test suite with a decreasing version of pip until it failed at 18.0.

#!/usr/bin/env bash

pip_version=100  # very high on purpose
install_pip() {
    pip_version=$(uv pip install "pip<${pip_version}" 2>&1 | grep -F '+ pip==' | cut -d= -f3)
    echo -en "Testing with pip version ${pip_version}: "
}

main() {
    echo "Setup"
    {
        uv venv
        . .venv/bin/activate
        uv pip install -e .[test,graphviz]
        uv pip uninstall pip
    } &>/dev/null
    install_pip
    while :; do
        if pytest tests &>/dev/null; then
            echo "OK"
            install_pip
        else
            echo "Failed"
            break
        fi
    done
}

main

The above text is the commit message. Feel free to reword it by squashing the PR.

Output of the script:

% bash testpip.sh
Setup
Testing with pip version 24.0: OK
Testing with pip version 23.3.2: OK
Testing with pip version 23.3.1: OK
Testing with pip version 23.3: OK
Testing with pip version 23.2.1: OK
Testing with pip version 23.2: OK
Testing with pip version 23.1.2: OK
Testing with pip version 23.1.1: OK
Testing with pip version 23.1: OK
Testing with pip version 23.0.1: OK
Testing with pip version 23.0: OK
Testing with pip version 22.3.1: OK
Testing with pip version 22.3: OK
Testing with pip version 22.2.2: OK
Testing with pip version 22.2.1: OK
Testing with pip version 22.2: OK
Testing with pip version 22.1.2: OK
Testing with pip version 22.1.1: OK
Testing with pip version 22.1: OK
Testing with pip version 22.0.4: OK
Testing with pip version 22.0.3: OK
Testing with pip version 22.0.2: OK
Testing with pip version 22.0.1: OK
Testing with pip version 22.0: OK
Testing with pip version 21.3.1: OK
Testing with pip version 21.3: OK
Testing with pip version 21.2.4: OK
Testing with pip version 21.2.3: OK
Testing with pip version 21.2.2: OK
Testing with pip version 21.2.1: OK
Testing with pip version 21.1.3: OK
Testing with pip version 21.1.2: OK
Testing with pip version 21.1.1: OK
Testing with pip version 21.1: OK
Testing with pip version 21.0.1: OK
Testing with pip version 21.0: OK
Testing with pip version 20.3.4: OK
Testing with pip version 20.3.3: OK
Testing with pip version 20.3.1: OK
Testing with pip version 20.3: OK
Testing with pip version 20.2.4: OK
Testing with pip version 20.2.3: OK
Testing with pip version 20.2.2: OK
Testing with pip version 20.2.1: OK
Testing with pip version 20.2: OK
Testing with pip version 20.1.1: OK
Testing with pip version 20.1: OK
Testing with pip version 20.0.2: OK
Testing with pip version 20.0.1: OK
Testing with pip version 19.3.1: OK
Testing with pip version 19.3: OK
Testing with pip version 19.2.3: OK
Testing with pip version 19.2.2: OK
Testing with pip version 19.2.1: OK
Testing with pip version 19.2: OK
Testing with pip version 19.1.1: OK
Testing with pip version 19.1: OK
Testing with pip version 19.0.3: OK
Testing with pip version 19.0.2: OK
Testing with pip version 19.0.1: OK
Testing with pip version 19.0: OK
Testing with pip version 18.1: OK
Testing with pip version 18.0: Failed

It's possible that lower versions would work, and only 18.0 failed because of some bug in it. However I feel like v18.1 is old enough and we don't have to support even lower versions. Happy to test further down if you disagree!

IMPORTANT: I consider this PR a quick fix for #335, waiting for a better solution such as #333. Feel free to close this PR if you don't plan on merging it and quickly releasing a new version with pip as a dependency before merging and releasing #333.

Closes #335.

pawamoy commented 3 months ago

As to why the test suite failed with pip 18.0:

% pytest tests
ImportError while loading conftest '/media/data/dev/pipdeptree/tests/conftest.py'.
tests/conftest.py:9: in <module>
    from pipdeptree._models import PackageDAG
src/pipdeptree/_models/__init__.py:3: in <module>
    from .dag import PackageDAG, ReversedPackageDAG
src/pipdeptree/_models/dag.py:12: in <module>
    from .package import DistPackage, ReqPackage, pep503_normalize
src/pipdeptree/_models/package.py:10: in <module>
    from pip._vendor.pkg_resources import Requirement  # noqa: PLC2701
.venv/lib/python3.11/site-packages/pip/_vendor/pkg_resources/__init__.py:77: in <module>
    __import__('pip._vendor.packaging.requirements')
.venv/lib/python3.11/site-packages/pip/_vendor/packaging/requirements.py:9: in <module>
    from pip._vendor.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
.venv/lib/python3.11/site-packages/pip/_vendor/pyparsing.py:943: in <module>
    collections.MutableMapping.register(ParseResults)
E   AttributeError: module 'collections' has no attribute 'MutableMapping'
pawamoy commented 3 months ago

I'll run the same script on other supported Python versions to make sure 18.1 is the lowest.

pawamoy commented 3 months ago

Failed with pip 23.1.1 on Python 3.12:

% pytest tests 
ImportError while loading conftest '/media/data/dev/pipdeptree/tests/conftest.py'.
tests/conftest.py:9: in <module>
    from pipdeptree._models import PackageDAG
src/pipdeptree/_models/__init__.py:3: in <module>
    from .dag import PackageDAG, ReversedPackageDAG
src/pipdeptree/_models/dag.py:12: in <module>
    from .package import DistPackage, ReqPackage, pep503_normalize
src/pipdeptree/_models/package.py:10: in <module>
    from pip._vendor.pkg_resources import Requirement  # noqa: PLC2701
.venv/lib/python3.12/site-packages/pip/_vendor/pkg_resources/__init__.py:2191: in <module>
    register_finder(pkgutil.ImpImporter, find_on_path)
E   AttributeError: module 'pkgutil' has no attribute 'ImpImporter'. Did you mean: 'zipimporter'?
pawamoy commented 3 months ago

Yeah I notice pip>=23.3.1 is used in the optional test dependencies :thinking:

pawamoy commented 3 months ago

OK, tested on all supported Python versions:

Dependencies updated accordingly.