Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ jobs:
- os: ubuntu-latest
python: '3.12'
pyproject_metadata: '==0.7.1'
# Tets with pyproject-metadata release candidate
- os: ubuntu-latest
python: '3.12'
pyproject_metadata: '==0.9.0rc1'

steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dynamic = [
[project.optional-dependencies]
test = [
'build',
'packaging >= 23.1',
'pytest >= 6.0',
'pytest-cov[toml]',
'pytest-mock',
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from venv import EnvBuilder

import packaging.metadata
import packaging.version
import pytest

Expand All @@ -24,6 +25,12 @@
from mesonpy._util import chdir


def metadata(data):
meta, other = packaging.metadata.parse_email(data)
assert not other
return meta


def adjust_packaging_platform_tag(platform: str) -> str:
if platform.startswith(('manylinux', 'musllinux')):
# The packaging module generates overly specific platforms tags on
Expand Down
9 changes: 8 additions & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: MIT

import pathlib
import re

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

import mesonpy

from .conftest import in_git_repo_context
from .conftest import in_git_repo_context, metadata


def test_no_pep621(sdist_library):
with tarfile.open(sdist_library, 'r:gz') as sdist:
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read()

assert sdist_pkg_info == textwrap.dedent('''\
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
Metadata-Version: 2.1
Name: library
Version: 1.0.0
''')
'''))


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()
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read()

metadata = textwrap.dedent('''\
meta = metadata(sdist_pkg_info)

# pyproject-metadata prior to 0.9.0 strips trailing newlines
meta['license'] = meta['license'].rstrip()

# pyproject-metadata 0.9.0 and later does not emit Home-Page
meta.pop('home_page', None)
# nor normalizes Project-URL keys
meta['project_urls'] = {k.lower(): v for k, v in meta['project_urls'].items()}

assert meta == 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,keyword with spaces
Home-page: https://example.com
Author: Jane Doe
Author-Email: Unknown <jhon.doe@example.com>
Maintainer-Email: Jane Doe <jane.doe@example.com>
License: some license
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Project-URL: Homepage, https://example.com
Project-URL: Documentation, https://readthedocs.org
Project-URL: Repository, https://github.com/mesonbuild/meson-python
Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
Project-URL: homepage, https://example.com
Project-URL: documentation, https://readthedocs.org
Project-URL: repository, https://github.com/mesonbuild/meson-python
Project-URL: changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
Requires-Python: >=3.7
Requires-Dist: a
Requires-Dist: b>1
Expand All @@ -67,20 +76,18 @@ def test_pep621(sdist_full_metadata):
# full-metadata

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

assert sdist_pkg_info == metadata
'''))


def test_dynamic_version(sdist_dynamic_version):
with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode()
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read()

assert sdist_pkg_info == textwrap.dedent('''\
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
Metadata-Version: 2.1
Name: dynamic-version
Version: 1.0.0
''')
'''))


def test_contents(sdist_library):
Expand Down
Loading