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

Follow most recent packaging specification for wheel name normalization #394

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/poetry/core/masonry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def escape_version(version: str) -> str:


def escape_name(name: str) -> str:
"""Escaped wheel name as specified in :pep:`427#escaping-and-unicode`."""
return re.sub(r"[^\w\d.]+", "_", name, flags=re.UNICODE)
"""Escaped wheel name as specified in https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe expand this doc string to indicate that this should only be used for generation of wheels never to canonicalize artifact package names.

return re.sub(r"[-_.]+", "_", name, flags=re.UNICODE).lower()
37 changes: 37 additions & 0 deletions tests/masonry/utils/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from __future__ import annotations

import pytest

from poetry.core.masonry.utils.helpers import escape_name
from poetry.core.masonry.utils.helpers import escape_version


@pytest.mark.parametrize(
"version,expected",
[
("1.2.3", "1.2.3"),
("1.2.3_1", "1.2.3_1"),
("1.2.3-1", "1.2.3_1"),
("1.2.3-1", "1.2.3_1"),
("2022.2", "2022.2"),
("12.20.12-----451---14-1-4-41", "12.20.12_451_14_1_4_41"),
("1.0b2.dev1", "1.0b2.dev1"),
("1.0+abc.7", "1.0+abc.7"),
],
)
def test_escape_version(version: str, expected: str) -> None:
assert escape_version(version) == expected


@pytest.mark.parametrize(
"name,expected",
[
("foo", "foo"),
("foo-bar", "foo_bar"),
("FOO-bAr", "foo_bar"),
("foo.bar", "foo_bar"),
("foo123-ba---.r", "foo123_ba_r"),
],
)
def test_escape_name(name: str, expected: str) -> None:
assert escape_name(name) == expected