Skip to content

Commit

Permalink
feat: support PEP 753
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 11, 2024
1 parent bd15fbf commit 054d2e2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ homepage = "https://github.com/pypa/pyproject-metadata"
[tool.flit.sdist]
include = ["LICENSE", "tests/**", "docs/**", ".gitignore"]

[tool.uv]
dev-dependencies = ["pyproject-metadata[test]"]
environments = [
"python_version >= '3.10'",
]


[tool.pytest.ini_options]
minversion = "6.0"
Expand Down Expand Up @@ -93,7 +99,8 @@ extend-select = [
]
ignore = [
"ISC001", # conflicts with formatter
"PLR09", # Design related (too many X)
"PLR09", # Design related (too many X)
"PLR2004", # Magic value in comparison
]

[tool.ruff.format]
Expand Down
11 changes: 8 additions & 3 deletions pyproject_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def validate(self, *, warn: bool = True) -> None: # noqa: C901
- License classifiers deprecated for metadata_version >= 2.4 (warning)
- ``license`` is an SPDX license expression if metadata_version >= 2.4
- ``license_files`` is supported only for metadata_version >= 2.4
- ``project_url`` can't contain keys over 32 characters
"""
errors = ErrorCollector(collect_errors=self.all_errors)

Expand Down Expand Up @@ -544,6 +545,11 @@ def validate(self, *, warn: bool = True) -> None: # noqa: C901
msg = "{key} is supported only when emitting metadata version >= 2.4"
errors.config_error(msg, key="project.license-files")

for name in self.urls:
if len(name) > 32:
msg = "{key} names cannot be more than 32 characters long"
errors.config_error(msg, key="project.urls", got=name)

errors.finalize("Metadata validation failed")

def _write_metadata( # noqa: C901
Expand All @@ -565,8 +571,7 @@ def _write_metadata( # noqa: C901
if self.description:
smart_message["Summary"] = self.description
smart_message["Keywords"] = ",".join(self.keywords) or None
if "homepage" in self.urls:
smart_message["Home-page"] = self.urls["homepage"]
# skip 'Home-page'
# skip 'Download-URL'
smart_message["Author"] = _name_list(self.authors)
smart_message["Author-Email"] = _email_list(self.authors)
Expand All @@ -588,7 +593,7 @@ def _write_metadata( # noqa: C901
# skip 'Obsoletes-Dist'
# skip 'Requires-External'
for name, url in self.urls.items():
smart_message["Project-URL"] = f"{name.capitalize()}, {url}"
smart_message["Project-URL"] = f"{name}, {url}"
if self.requires_python:
smart_message["Requires-Python"] = str(self.requires_python)
for dep in self.dependencies:
Expand Down
4 changes: 2 additions & 2 deletions pyproject_metadata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def __dir__() -> list[str]:
"classifier",
"description",
"description-content-type",
"download-url", # Not specified via pyproject standards
"download-url", # Not specified via pyproject standards, deprecated by PEP 753
"dynamic", # Can't be in dynamic
"home-page", # Not specified via pyproject standards
"home-page", # Not specified via pyproject standards, deprecated by PEP 753
"keywords",
"license",
"license-expression",
Expand Down
33 changes: 21 additions & 12 deletions tests/test_standard_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,9 @@ def all_errors(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch)
name = "test"
version = "0.1.0"
[project.urls]
documentation = true
Documentation = true
""",
'Field "project.urls.documentation" has an invalid type, expecting a string (got bool)',
'Field "project.urls.Documentation" has an invalid type, expecting a string (got bool)',
id="Invalid urls documentation type",
),
pytest.param(
Expand All @@ -606,6 +606,17 @@ def all_errors(request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch)
'Field "project.urls.repository" has an invalid type, expecting a string (got bool)',
id="Invalid urls repository type",
),
pytest.param(
"""
[project]
name = "test"
version = "0.1.0"
[project.urls]
"I am really really too long for this place" = "url"
""",
"\"project.urls\" names cannot be more than 32 characters long (got 'I am really really too long for this place')",
id="URL name too long",
),
pytest.param(
"""
[project]
Expand Down Expand Up @@ -1097,17 +1108,16 @@ def test_as_json(monkeypatch: pytest.MonkeyPatch) -> None:
],
"description": "some readme 👋\n",
"description_content_type": "text/markdown",
"home_page": "example.com",
"keywords": ["trampolim", "is", "interesting"],
"license": "some license text",
"maintainer_email": "Other Example <[email protected]>",
"metadata_version": "2.1",
"name": "full_metadata",
"project_url": [
"Homepage, example.com",
"Documentation, readthedocs.org",
"Repository, github.com/some/repo",
"Changelog, github.com/some/repo/blob/master/CHANGELOG.rst",
"homepage, example.com",
"documentation, readthedocs.org",
"repository, github.com/some/repo",
"changelog, github.com/some/repo/blob/master/CHANGELOG.rst",
],
"provides_extra": ["test"],
"requires_dist": [
Expand Down Expand Up @@ -1138,17 +1148,16 @@ def test_as_rfc822(monkeypatch: pytest.MonkeyPatch) -> None:
("Version", "3.2.1"),
("Summary", "A package with all the metadata :)"),
("Keywords", "trampolim,is,interesting"),
("Home-page", "example.com"),
("Author", "Example!"),
("Author-Email", "Unknown <[email protected]>"),
("Maintainer-Email", "Other Example <[email protected]>"),
("License", "some license text"),
("Classifier", "Development Status :: 4 - Beta"),
("Classifier", "Programming Language :: Python"),
("Project-URL", "Homepage, example.com"),
("Project-URL", "Documentation, readthedocs.org"),
("Project-URL", "Repository, github.com/some/repo"),
("Project-URL", "Changelog, github.com/some/repo/blob/master/CHANGELOG.rst"),
("Project-URL", "homepage, example.com"),
("Project-URL", "documentation, readthedocs.org"),
("Project-URL", "repository, github.com/some/repo"),
("Project-URL", "changelog, github.com/some/repo/blob/master/CHANGELOG.rst"),
("Requires-Python", ">=3.8"),
("Requires-Dist", "dependency1"),
("Requires-Dist", "dependency2>1.0.0"),
Expand Down

0 comments on commit 054d2e2

Please sign in to comment.