Skip to content

Commit

Permalink
Improve PEP 753 compliance
Browse files Browse the repository at this point in the history
When generating metadata 1.2 or later, producers SHOULD emit only Project-URL, and SHOULD NOT emit Home-page or Download-URL fields.
  • Loading branch information
dimbleby authored Jan 11, 2025
1 parent 6243e3f commit 4a1ab8b
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
18 changes: 12 additions & 6 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 0 additions & 4 deletions src/poetry/core/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 3 additions & 10 deletions src/poetry/core/masonry/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion tests/masonry/builders/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == [
Expand Down Expand Up @@ -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",
]
Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/builders/test_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/masonry/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4a1ab8b

Please sign in to comment.