From 4a1ab8b3d89e2cc17c8ac583bf6aea94c3f39be6 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sat, 11 Jan 2025 15:09:37 +0000 Subject: [PATCH] Improve PEP 753 compliance When generating metadata 1.2 or later, producers SHOULD emit only Project-URL, and SHOULD NOT emit Home-page or Download-URL fields. --- src/poetry/core/factory.py | 18 ++++++++++++------ src/poetry/core/masonry/builders/builder.py | 4 ---- src/poetry/core/masonry/metadata.py | 13 +++---------- tests/masonry/builders/test_builder.py | 3 ++- tests/masonry/builders/test_complete.py | 2 +- tests/masonry/test_api.py | 2 +- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index 8e12ae5c4..f8fb922f3 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -201,12 +201,18 @@ def _configure_package_metadata( package.dynamic_classifiers = not static_classifiers if urls := project.get("urls"): - package.homepage = urls.get("homepage") or urls.get("Homepage") - package.repository_url = urls.get("repository") or urls.get("Repository") - package.documentation_url = urls.get("documentation") or urls.get( - "Documentation" - ) - package.custom_urls = urls + custom_urls = {} + for name, url in urls.items(): + lower_name = name.lower() + if lower_name == "homepage": + package.homepage = url + elif lower_name == "repository": + package.repository_url = url + elif lower_name == "documentation": + package.documentation_url = url + else: + custom_urls[name] = url + package.custom_urls = custom_urls else: package.homepage = tool_poetry.get("homepage") package.repository_url = tool_poetry.get("repository") diff --git a/src/poetry/core/masonry/builders/builder.py b/src/poetry/core/masonry/builders/builder.py index 2d02330f3..890eca44b 100644 --- a/src/poetry/core/masonry/builders/builder.py +++ b/src/poetry/core/masonry/builders/builder.py @@ -210,10 +210,6 @@ def get_metadata_content(self) -> str: summary=str(self._meta.summary), ) - # Optional fields - if self._meta.home_page: - content += f"Home-page: {self._meta.home_page}\n" - if self._meta.license: license_field = "License: " # Indentation is not only for readability, but required diff --git a/src/poetry/core/masonry/metadata.py b/src/poetry/core/masonry/metadata.py index a64c4df8b..6812a7edb 100644 --- a/src/poetry/core/masonry/metadata.py +++ b/src/poetry/core/masonry/metadata.py @@ -105,15 +105,8 @@ def from_package(cls, package: ProjectPackage) -> Metadata: meta.provides_extra = list(package.extras) - if package.urls: - for name, url in package.urls.items(): - if name.lower() == "homepage" and meta.home_page == url: - continue - if name == "repository" and url == package.urls["Repository"]: - continue - if name == "documentation" and url == package.urls["Documentation"]: - continue - - meta.project_urls += (f"{name}, {url}",) + meta.project_urls = tuple( + f"{name}, {url}" for name, url in package.urls.items() + ) return meta diff --git a/tests/masonry/builders/test_builder.py b/tests/masonry/builders/test_builder.py index c0c00569b..25c124325 100644 --- a/tests/masonry/builders/test_builder.py +++ b/tests/masonry/builders/test_builder.py @@ -98,7 +98,7 @@ def test_get_metadata_content() -> None: assert parsed["Keywords"] == "packaging,dependency,poetry" assert parsed["Requires-Python"] == ">=3.6,<4.0" assert parsed["License"] == "MIT" - assert parsed["Home-page"] == "https://python-poetry.org/" + assert parsed["Home-page"] is None classifiers = parsed.get_all("Classifier") assert classifiers == [ @@ -132,6 +132,7 @@ def test_get_metadata_content() -> None: urls = parsed.get_all("Project-URL") assert urls == [ "Documentation, https://python-poetry.org/docs", + "Homepage, https://python-poetry.org/", "Issue Tracker, https://github.com/python-poetry/poetry/issues", "Repository, https://github.com/python-poetry/poetry", ] diff --git a/tests/masonry/builders/test_complete.py b/tests/masonry/builders/test_complete.py index 4fe4e1523..82fbda353 100644 --- a/tests/masonry/builders/test_complete.py +++ b/tests/masonry/builders/test_complete.py @@ -188,7 +188,6 @@ def test_complete(project: str, no_vcs: bool) -> None: Name: my-package Version: 1.2.3 Summary: Some description. -Home-page: https://python-poetry.org/ License: MIT Keywords: packaging,dependency,poetry Author: Sébastien Eustace @@ -214,6 +213,7 @@ def test_complete(project: str, no_vcs: bool) -> None: Requires-Dist: pendulum (>=1.4,<2.0) ; (python_version ~= "2.7"\ and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time") Project-URL: Documentation, https://python-poetry.org/docs +Project-URL: Homepage, https://python-poetry.org/ Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues Project-URL: Repository, https://github.com/python-poetry/poetry Description-Content-Type: text/x-rst diff --git a/tests/masonry/test_api.py b/tests/masonry/test_api.py index f86418865..ac129958d 100644 --- a/tests/masonry/test_api.py +++ b/tests/masonry/test_api.py @@ -154,7 +154,6 @@ def test_prepare_metadata_for_build_wheel(project: str) -> None: Name: my-package Version: 1.2.3 Summary: Some description. -Home-page: https://python-poetry.org/ License: MIT Keywords: packaging,dependency,poetry Author: Sébastien Eustace @@ -179,6 +178,7 @@ def test_prepare_metadata_for_build_wheel(project: str) -> None: Requires-Dist: cleo (>=0.6,<0.7) Requires-Dist: pendulum (>=1.4,<2.0) ; (python_version ~= "2.7" and sys_platform == "win32" or python_version in "3.4 3.5") and (extra == "time") Project-URL: Documentation, https://python-poetry.org/docs +Project-URL: Homepage, https://python-poetry.org/ Project-URL: Issue Tracker, https://github.com/python-poetry/poetry/issues Project-URL: Repository, https://github.com/python-poetry/poetry Description-Content-Type: text/x-rst