Skip to content

Commit d1da1af

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 78ed330 commit d1da1af

File tree

4 files changed

+8
-37
lines changed

4 files changed

+8
-37
lines changed

mesonpy/__init__.py

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

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

250244
@classmethod
251245
def from_pyproject(
@@ -254,12 +248,7 @@ def from_pyproject(
254248
project_dir: Path = os.path.curdir,
255249
metadata_version: Optional[str] = None
256250
) -> Self:
257-
metadata = super().from_pyproject(data, project_dir)
258-
259-
# Check for missing version field.
260-
if not metadata.version and 'version' not in metadata.dynamic:
261-
raise pyproject_metadata.ConfigurationError(
262-
'Required "project.version" field is missing and not declared as dynamic')
251+
metadata = super().from_pyproject(data, project_dir, metadata_version)
263252

264253
# Check for unsupported dynamic fields.
265254
unsupported_dynamic = set(metadata.dynamic) - {'version', }
@@ -269,17 +258,6 @@ def from_pyproject(
269258

270259
return metadata
271260

272-
# Local fix for a bug in pyproject-metadata. See
273-
# https://github.com/mesonbuild/meson-python/issues/454
274-
def _update_dynamic(self, value: Any) -> None:
275-
if value and 'version' in self.dynamic:
276-
self.dynamic.remove('version')
277-
278-
@property
279-
def canonical_name(self) -> str:
280-
# See https://packaging.python.org/en/latest/specifications/name-normalization/#normalization
281-
return packaging.utils.canonicalize_name(self.name)
282-
283261
@property
284262
def distribution_name(self) -> str:
285263
"""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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,5 @@ def test_missing_version(package_missing_version):
4949
pyproject = {'project': {
5050
'name': 'missing-version',
5151
}}
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):
52+
with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'):
5853
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def test_pep621(sdist_full_metadata):
3131
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
3232
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
3333

34-
metadata = re.escape(textwrap.dedent('''\
34+
metadata = textwrap.dedent('''\
3535
Metadata-Version: 2.1
3636
Name: full-metadata
3737
Version: 1.2.3
3838
Summary: Some package with all of the PEP 621 metadata
39-
Keywords: full metadata
39+
Keywords: full,metadata,keyword with spaces
4040
Home-page: https://example.com
4141
Author: Jane Doe
4242
Author-Email: Unknown <[email protected]>
@@ -66,11 +66,9 @@ def test_pep621(sdist_full_metadata):
6666
# full-metadata
6767
6868
An example package with all of the PEP 621 metadata!
69-
'''))
69+
''')
7070

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

7573

7674
def test_dynamic_version(sdist_dynamic_version):

0 commit comments

Comments
 (0)