Skip to content

Commit

Permalink
Use vendored packaging to canonicalize requirements (#614)
Browse files Browse the repository at this point in the history
This makes the METADATA file from bdist_wheel and the PKG-INFO file from setuptools render the same way (see pypa/setuptools#4336 for more info).

Closes #395.
  • Loading branch information
wimglenn committed May 1, 2024
1 parent 754a238 commit 4ec2ae3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release Notes
=============

**UNRELEASED**

- Canonicalize requirements in METADATA file (PR by Wim Jeantine-Glenn)

**0.43.0 (2024-03-11)**

- Dropped support for Python 3.7
Expand Down
1 change: 0 additions & 1 deletion src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,6 @@ def adios(p: str) -> None:

if os.path.isfile(egginfo_path):
# .egg-info is a single file
pkginfo_path = egginfo_path
pkg_info = pkginfo_to_metadata(egginfo_path, egginfo_path)
os.mkdir(distinfo_path)
else:
Expand Down
3 changes: 2 additions & 1 deletion src/wheel/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def generate_requirements(
condition = " ; " + condition

for new_req in convert_requirements(depends):
yield "Requires-Dist", new_req + condition
canonical_req = str(Requirement(new_req + condition))
yield "Requires-Dist", canonical_req


def pkginfo_to_metadata(egg_info_path: str, pkginfo_path: str) -> Message:
Expand Down
22 changes: 11 additions & 11 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ def test_pkginfo_to_metadata(tmp_path):
("Metadata-Version", "2.1"),
("Name", "spam"),
("Version", "0.1"),
("Requires-Dist", "pip @ https://github.com/pypa/pip/archive/1.3.1.zip"),
("Requires-Dist", 'pywin32 ; sys_platform=="win32"'),
("Requires-Dist", 'foo @ http://host/foo.zip ; sys_platform=="win32"'),
("Requires-Dist", "pip@ https://github.com/pypa/pip/archive/1.3.1.zip"),
("Requires-Dist", 'pywin32; sys_platform == "win32"'),
("Requires-Dist", 'foo@ http://host/foo.zip ; sys_platform == "win32"'),
("Provides-Extra", "signatures"),
(
"Requires-Dist",
"pyxdg ; (sys_platform!=\"win32\") and extra == 'signatures'",
'pyxdg; sys_platform != "win32" and extra == "signatures"',
),
("Provides-Extra", "empty_extra"),
("Provides-Extra", "extra"),
("Requires-Dist", "bar @ http://host/bar.zip ; extra == 'extra'"),
("Requires-Dist", 'bar@ http://host/bar.zip ; extra == "extra"'),
("Provides-Extra", "faster-signatures"),
("Requires-Dist", "ed25519ll ; extra == 'faster-signatures'"),
("Requires-Dist", 'ed25519ll; extra == "faster-signatures"'),
("Provides-Extra", "rest"),
("Requires-Dist", "docutils >=0.8 ; extra == 'rest'"),
("Requires-Dist", "keyring ; extra == 'signatures'"),
("Requires-Dist", "keyrings.alt ; extra == 'signatures'"),
("Requires-Dist", 'docutils>=0.8; extra == "rest"'),
("Requires-Dist", 'keyring; extra == "signatures"'),
("Requires-Dist", 'keyrings.alt; extra == "signatures"'),
("Provides-Extra", "test"),
("Requires-Dist", "pytest >=3.0.0 ; extra == 'test'"),
("Requires-Dist", "pytest-cov ; extra == 'test'"),
("Requires-Dist", 'pytest>=3.0.0; extra == "test"'),
("Requires-Dist", 'pytest-cov; extra == "test"'),
]

pkg_info = tmp_path.joinpath("PKG-INFO")
Expand Down

0 comments on commit 4ec2ae3

Please sign in to comment.