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

MAINT: bump minimum required pyproject-metadata version to 0.8.0 #613

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
26 changes: 2 additions & 24 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,12 @@ class MesonBuilderError(Error):

class Metadata(pyproject_metadata.StandardMetadata):
def __init__(self, name: str, *args: Any, **kwargs: Any):
super().__init__(name, *args, **kwargs)
# Local fix for https:/FFY00/python-pyproject-metadata/issues/60
self.name = self._validate_name(name)

@staticmethod
def _validate_name(name: str) -> str:
# See https://packaging.python.org/en/latest/specifications/core-metadata/#name
if not re.match(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', name, re.IGNORECASE):
raise pyproject_metadata.ConfigurationError(
f'Invalid project name "{name}". A valid name consists only of ASCII letters and '
f'numbers, period, underscore and hyphen. It must start and end with a letter or number')
return name
super().__init__(name, *args, **kwargs)

@classmethod
def from_pyproject(
Expand All @@ -252,12 +246,7 @@ def from_pyproject(
project_dir: Path = os.path.curdir,
metadata_version: Optional[str] = None
) -> Self:
metadata = super().from_pyproject(data, project_dir)

# Check for missing version field.
if not metadata.version and 'version' not in metadata.dynamic:
raise pyproject_metadata.ConfigurationError(
'Required "project.version" field is missing and not declared as dynamic')
metadata = super().from_pyproject(data, project_dir, metadata_version)

# Check for unsupported dynamic fields.
unsupported_dynamic = set(metadata.dynamic) - {'version', }
Expand All @@ -267,17 +256,6 @@ def from_pyproject(

return metadata

# Local fix for a bug in pyproject-metadata. See
# https:/mesonbuild/meson-python/issues/454
def _update_dynamic(self, value: Any) -> None:
if value and 'version' in self.dynamic:
self.dynamic.remove('version')

@property
def canonical_name(self) -> str:
# See https://packaging.python.org/en/latest/specifications/name-normalization/#normalization
return packaging.utils.canonicalize_name(self.name)

@property
def distribution_name(self) -> str:
"""Name to be used in wheel and sdist file names."""
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ requires = [
'meson >= 0.63.3; python_version < "3.12"',
'meson >= 1.2.3; python_version >= "3.12"',
'packaging >= 19.0',
'pyproject-metadata >= 0.7.1',
'pyproject-metadata >= 0.8.0',
'tomli >= 1.0.0; python_version < "3.11"',
]

Expand All @@ -36,7 +36,7 @@ dependencies = [
'meson >= 0.63.3; python_version < "3.12"',
'meson >= 1.2.3; python_version >= "3.12"',
'packaging >= 19.0',
'pyproject-metadata >= 0.7.1',
'pyproject-metadata >= 0.8.0',
'tomli >= 1.0.0; python_version < "3.11"',
]

Expand Down
2 changes: 1 addition & 1 deletion tests/packages/full-metadata/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = 'Some package with all of the PEP 621 metadata'
readme = 'README.md'
requires-python = '>=3.7'
license = {file = 'LICENSE'}
keywords = ['full', 'metadata']
keywords = ['full', 'metadata', 'keyword with spaces']
authors = [
{email = '[email protected]'},
{name = 'Jane Doe'}
Expand Down
8 changes: 1 addition & 7 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# SPDX-License-Identifier: MIT

import pathlib
import re

import packaging.version
import pyproject_metadata
Expand Down Expand Up @@ -49,10 +48,5 @@ def test_missing_version(package_missing_version):
pyproject = {'project': {
'name': 'missing-version',
}}
match = '|'.join((
re.escape('Required "project.version" field is missing'),
# pyproject-metatadata 0.8.0 and later
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
))
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'):
Metadata.from_pyproject(pyproject, pathlib.Path())
11 changes: 4 additions & 7 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import pathlib
import re
import stat
import sys
import tarfile
Expand Down Expand Up @@ -33,12 +32,12 @@ def test_pep621(sdist_full_metadata):
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()

metadata = re.escape(textwrap.dedent('''\
metadata = textwrap.dedent('''\
Metadata-Version: 2.1
Name: full-metadata
Version: 1.2.3
Summary: Some package with all of the PEP 621 metadata
Keywords: full metadata
Keywords: full,metadata,keyword with spaces
Home-page: https://example.com
Author: Jane Doe
Author-Email: Unknown <[email protected]>
Expand Down Expand Up @@ -68,11 +67,9 @@ def test_pep621(sdist_full_metadata):
# full-metadata

An example package with all of the PEP 621 metadata!
'''))
''')

# pyproject-metadata 0.8.0 and later uses a comma to separate keywords
expr = metadata.replace(r'Keywords:\ full\ metadata', r'Keywords:\ full[ ,]metadata')
assert re.fullmatch(expr, sdist_pkg_info)
assert sdist_pkg_info == metadata


def test_dynamic_version(sdist_dynamic_version):
Expand Down
Loading