Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

packaging dependency is not strict enough #1293

Closed
1 task done
dranjan opened this issue Aug 1, 2022 · 2 comments · Fixed by #1295
Closed
1 task done

packaging dependency is not strict enough #1293

dranjan opened this issue Aug 1, 2022 · 2 comments · Fixed by #1295
Labels
🐛 bug Something isn't working

Comments

@dranjan
Copy link
Contributor

dranjan commented Aug 1, 2022

PDM uses the function packaging.utils.parse_wheel_filename, which was introduced in version 20.9: https://packaging.pypa.io/en/stable/changelog.html#id5 Therefore, I believe PDM should constrain the minimum version of packaging to at least 20.9 in its requirements.

As far as who is affected by this, there's one very specific set of circumstances that I've seen:

  • you're running Ubuntu 20.04, or another distro on which python3-packaging is at version 20.3 at the system level,
  • you like to use pip3 install --user, and
  • you also install PDM using pip3.

In that case, pip will find the system-level version 20.3 of packaging and not install a newer version, which silently breaks PDM.

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

This repro script sort of emulates the situation outlined above using a virtualenv.

#!/usr/bin/env bash

set -euxo pipefail

mkdir -p build/

venv="build/venv"
python3 -m venv "$venv"
"$venv/bin/python3" -m pip install packaging==20.3
"$venv/bin/python3" -m pip install pdm
"$venv/bin/python3" -m pdm -h -v

Actual behavior

% ./repro.sh
+ mkdir -p build/
+ venv=build/venv
+ python3 -m venv build/venv
+ build/venv/bin/python3 -m pip install packaging==20.3
Collecting packaging==20.3
  Downloading packaging-20.3-py2.py3-none-any.whl (37 kB)
Collecting six
  Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Installing collected packages: six, pyparsing, packaging
Successfully installed packaging-20.3 pyparsing-3.0.9 six-1.16.0
+ build/venv/bin/python3 -m pip install pdm

(... pip output ...)

+ build/venv/bin/python3 -m pdm -h -v
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.8/runpy.py", line 144, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/__init__.py", line 7, in <module>
    from pdm.cli.commands.base import BaseCommand as _BaseCommand
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/cli/commands/base.py", line 6, in <module>
    from pdm.cli.utils import PdmFormatter
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/cli/utils.py", line 31, in <module>
    from pdm.formats import FORMATS
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/formats/__init__.py", line 8, in <module>
    from pdm.formats import flit, pipfile, poetry, requirements, setup_py
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/formats/flit.py", line 17, in <module>
    from pdm.project import Project
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/project/__init__.py", line 2, in <module>
    from pdm.project.core import Project  # noqa
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/project/core.py", line 21, in <module>
    from pdm.models.caches import CandidateInfoCache, HashCache, WheelCache
  File "/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/pdm/models/caches.py", line 14, in <module>
    from packaging.utils import canonicalize_name, parse_wheel_filename
ImportError: cannot import name 'parse_wheel_filename' from 'packaging.utils' (/home/darsh/work/ref-6032/build/venv/lib/python3.8/site-packages/packaging/utils.py)

Expected behavior

PDM does not crash.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:

(Those also fail with the same traceback.)

@dranjan dranjan added the 🐛 bug Something isn't working label Aug 1, 2022
@frostming
Copy link
Collaborator

Care to submit a PR for this?

@dranjan
Copy link
Contributor Author

dranjan commented Aug 2, 2022

Sure, seems simple enough...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants