Skip to content

Commit d638bc8

Browse files
committed
MAINT: remove workarounds for bugs fixed in pyproject-metadata 0.8.0
Update tests to consider only pyproject-metadata 0.8.0 behavior.
1 parent 40a01f0 commit d638bc8

File tree

4 files changed

+8
-39
lines changed

4 files changed

+8
-39
lines changed

mesonpy/__init__.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,12 @@ class MesonBuilderError(Error):
232232

233233
class Metadata(pyproject_metadata.StandardMetadata):
234234
def __init__(self, name: str, *args: Any, **kwargs: Any):
235-
super().__init__(name, *args, **kwargs)
236-
# Local fix for https://github.com/FFY00/python-pyproject-metadata/issues/60
237-
self.name = self._validate_name(name)
238-
239-
@staticmethod
240-
def _validate_name(name: str) -> str:
241235
# See https://packaging.python.org/en/latest/specifications/core-metadata/#name
242236
if not re.match(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', name, re.IGNORECASE):
243237
raise pyproject_metadata.ConfigurationError(
244238
f'Invalid project name "{name}". A valid name consists only of ASCII letters and '
245239
f'numbers, period, underscore and hyphen. It must start and end with a letter or number')
246-
return name
240+
super().__init__(name, *args, **kwargs)
247241

248242
@classmethod
249243
def from_pyproject(
@@ -252,12 +246,7 @@ def from_pyproject(
252246
project_dir: Path = os.path.curdir,
253247
metadata_version: Optional[str] = None
254248
) -> Self:
255-
metadata = super().from_pyproject(data, project_dir)
256-
257-
# Check for missing version field.
258-
if not metadata.version and 'version' not in metadata.dynamic:
259-
raise pyproject_metadata.ConfigurationError(
260-
'Required "project.version" field is missing and not declared as dynamic')
249+
metadata = super().from_pyproject(data, project_dir, metadata_version)
261250

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

268257
return metadata
269258

270-
# Local fix for a bug in pyproject-metadata. See
271-
# https://github.com/mesonbuild/meson-python/issues/454
272-
def _update_dynamic(self, value: Any) -> None:
273-
if value and 'version' in self.dynamic:
274-
self.dynamic.remove('version')
275-
276-
@property
277-
def canonical_name(self) -> str:
278-
# See https://packaging.python.org/en/latest/specifications/name-normalization/#normalization
279-
return packaging.utils.canonicalize_name(self.name)
280-
281259
@property
282260
def distribution_name(self) -> str:
283261
"""Name to be used in wheel and sdist file names."""

tests/packages/full-metadata/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ description = 'Some package with all of the PEP 621 metadata'
1313
readme = 'README.md'
1414
requires-python = '>=3.7'
1515
license = {file = 'LICENSE'}
16-
keywords = ['full', 'metadata']
16+
keywords = ['full', 'metadata', 'keyword with spaces']
1717
authors = [
1818
{email = '[email protected]'},
1919
{name = 'Jane Doe'}

tests/test_metadata.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-License-Identifier: MIT
44

55
import pathlib
6-
import re
76

87
import packaging.version
98
import pyproject_metadata
@@ -49,10 +48,5 @@ def test_missing_version(package_missing_version):
4948
pyproject = {'project': {
5049
'name': 'missing-version',
5150
}}
52-
match = '|'.join((
53-
re.escape('Required "project.version" field is missing'),
54-
# pyproject-metatadata 0.8.0 and later
55-
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
56-
))
57-
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
51+
with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'):
5852
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import os
66
import pathlib
7-
import re
87
import stat
98
import sys
109
import tarfile
@@ -33,12 +32,12 @@ def test_pep621(sdist_full_metadata):
3332
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
3433
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
3534

36-
metadata = re.escape(textwrap.dedent('''\
35+
metadata = textwrap.dedent('''\
3736
Metadata-Version: 2.1
3837
Name: full-metadata
3938
Version: 1.2.3
4039
Summary: Some package with all of the PEP 621 metadata
41-
Keywords: full metadata
40+
Keywords: full,metadata,keyword with spaces
4241
Home-page: https://example.com
4342
Author: Jane Doe
4443
Author-Email: Unknown <[email protected]>
@@ -68,11 +67,9 @@ def test_pep621(sdist_full_metadata):
6867
# full-metadata
6968
7069
An example package with all of the PEP 621 metadata!
71-
'''))
70+
''')
7271

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

7774

7875
def test_dynamic_version(sdist_dynamic_version):

0 commit comments

Comments
 (0)