Skip to content

Poetry v1.2.2 does not work with packaging==20.4 due to a bad cherry-pick #6807

@aloisklink

Description

@aloisklink
  • Poetry version: v1.2.2
  • Python version: 3.8.10
  • OS version and name: Ubuntu 20.04
  • pyproject.toml: Any pyproject.toml (you can create a blank one with poetry init and it has the same error, so does poetry run pytest)
  • I am on the latest stable Poetry version, installed using a recommended method.
    • I'm on v1.2.2 (current latest), but I installed via pip3 install poetry.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

It looks like the 1.2 branch has a bad cherry-pick, 04c5cbf

This line was not in the original commit and is not in the master branch:

from packaging.utils import NormalizedName

On v20.4 of packaging, this import is only available if typing.TYPE_CHECKING, which is correct on the Poetry master branch:

if TYPE_CHECKING:
from collections.abc import Iterable
from cleo.io.io import IO
from packaging.utils import NormalizedName

This causes the following error when running poetry install:

  ImportError

  cannot import name 'NormalizedName' from 'packaging.utils' (/home/user/.local/lib/python3.8/site-packages/packaging/utils.py)

  at ~/.local/lib/python3.8/site-packages/poetry/installation/installer.py:6 in <module>
        2│ 
        3│ from typing import TYPE_CHECKING
        4│ 
        5│ from cleo.io.null_io import NullIO
    →   6│ from packaging.utils import NormalizedName
        7│ from packaging.utils import canonicalize_name
        8│ 
        9│ from poetry.installation.executor import Executor
       10│ from poetry.installation.operations import Install

Reproducing error in Poetry repo

On master branch, this works fine!

poetry add packaging==20.4
poetry run pytest

On 1.2 branch, this fails:

user@computer:~/Documents/poetry (master)$ git switch 1.2 --discard-changes
Switched to branch '1.2'
Your branch is up-to-date with 'origin/1.2'.
user@computer:~/Documents/poetry (1.2)$ poetry add packaging==20.4

Updating dependencies
Resolving dependencies... (0.3s)

Writing lock file

Package operations: 0 installs, 7 updates, 0 removals

  • Updating zipp (3.9.0 -> 3.8.1)
  • Updating identify (2.5.6 -> 2.5.5)
  • Updating importlib-resources (5.10.0 -> 5.9.0)
  • Updating typing-extensions (4.4.0 -> 4.3.0)
  • Updating mypy (0.982 -> 0.981)
  • Updating pytest-mock (3.10.0 -> 3.9.0)
  • Updating types-requests (2.28.11.2 -> 2.28.11)
user@computer:~/Documents/poetry (1.2)$ poetry run pytest
ImportError while loading conftest '/home/user/Documents/poetry/tests/conftest.py'.
tests/conftest.py:33: in <module>
    from tests.helpers import MOCK_DEFAULT_GIT_REVISION
tests/helpers.py:22: in <module>
    from poetry.installation.executor import Executor
src/poetry/installation/__init__.py:3: in <module>
    from poetry.installation.installer import Installer
src/poetry/installation/installer.py:6: in <module>
    from packaging.utils import NormalizedName
E   ImportError: cannot import name 'NormalizedName' from 'packaging.utils' (/home/user/Documents/poetry/.venv/lib/python3.8/site-packages/packaging/utils.py)

How to fix

  • Drop packaging v20.4 support
  • Move from packaging.utils import NormalizedName behind an if typing.TYPE_CHECKING: check (this will match the behaviour on the master branch)
  • Ignore if there's not going to be another v1.2.x release, since the master branch isn't affected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions