Skip to content

Bump core metadata version to 2.4 #4830

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

Merged
merged 1 commit into from
Feb 17, 2025
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
1 change: 1 addition & 0 deletions newsfragments/4830.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump core metadata version to ``2.4``. -- by :user:`cdce8p`
7 changes: 4 additions & 3 deletions setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
def get_metadata_version(self):
mv = getattr(self, 'metadata_version', None)
if mv is None:
mv = Version('2.2')
mv = Version('2.4')
self.metadata_version = mv
return mv

Expand Down Expand Up @@ -176,8 +176,9 @@ def write_field(key, value):
if attr_val is not None:
write_field(field, attr_val)

license = self.license_expression or self.get_license()
if license:
if license_expression := self.license_expression:
write_field('License-Expression', license_expression)
elif license := self.get_license():
write_field('License', rfc822_escape(license))

for label, url in self.project_urls.items():
Expand Down
15 changes: 13 additions & 2 deletions setuptools/tests/config/test_apply_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,28 @@ def test_utf8_maintainer_in_metadata( # issue-3663


@pytest.mark.parametrize(
('pyproject_text', 'license', 'license_expression', 'content_str'),
(
'pyproject_text',
'license',
'license_expression',
'content_str',
'not_content_str',
),
(
pytest.param(
PEP639_LICENSE_TEXT,
'MIT',
None,
'License: MIT',
'License-Expression: ',
id='license-text',
),
pytest.param(
PEP639_LICENSE_EXPRESSION,
None,
'MIT OR Apache-2.0',
'License: MIT OR Apache-2.0', # TODO Metadata version '2.4'
'License-Expression: MIT OR Apache-2.0',
'License: ',
id='license-expression',
),
),
Expand All @@ -302,6 +310,7 @@ def test_license_in_metadata(
license,
license_expression,
content_str,
not_content_str,
pyproject_text,
tmp_path,
):
Expand All @@ -317,7 +326,9 @@ def test_license_in_metadata(
with open(pkg_file, "w", encoding="utf-8") as fh:
dist.metadata.write_pkg_file(fh)
content = pkg_file.read_text(encoding="utf-8")
assert "Metadata-Version: 2.4" in content
assert content_str in content
assert not_content_str not in content


def test_license_expression_with_bad_classifier(tmp_path):
Expand Down
8 changes: 4 additions & 4 deletions setuptools/tests/test_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_provides_extra(self, tmpdir_cwd, env):
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
pkg_info_lines = fp.read().split('\n')
assert 'Provides-Extra: foobar' in pkg_info_lines
assert 'Metadata-Version: 2.2' in pkg_info_lines
assert 'Metadata-Version: 2.4' in pkg_info_lines

def test_doesnt_provides_extra(self, tmpdir_cwd, env):
self._setup_script_with_requires(
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def test_metadata_version(self, tmpdir_cwd, env):
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
pkg_info_lines = fp.read().split('\n')
# Update metadata version if changed
assert self._extract_mv_version(pkg_info_lines) == (2, 2)
assert self._extract_mv_version(pkg_info_lines) == (2, 4)

def test_long_description_content_type(self, tmpdir_cwd, env):
# Test that specifying a `long_description_content_type` keyword arg to
Expand All @@ -1116,7 +1116,7 @@ def test_long_description_content_type(self, tmpdir_cwd, env):
pkg_info_lines = fp.read().split('\n')
expected_line = 'Description-Content-Type: text/markdown'
assert expected_line in pkg_info_lines
assert 'Metadata-Version: 2.2' in pkg_info_lines
assert 'Metadata-Version: 2.4' in pkg_info_lines

def test_long_description(self, tmpdir_cwd, env):
# Test that specifying `long_description` and `long_description_content_type`
Expand All @@ -1135,7 +1135,7 @@ def test_long_description(self, tmpdir_cwd, env):
egg_info_dir = os.path.join('.', 'foo.egg-info')
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
pkg_info_lines = fp.read().split('\n')
assert 'Metadata-Version: 2.2' in pkg_info_lines
assert 'Metadata-Version: 2.4' in pkg_info_lines
assert '' == pkg_info_lines[-1] # last line should be empty
long_desc_lines = pkg_info_lines[pkg_info_lines.index('') :]
assert 'This is a long description' in long_desc_lines
Expand Down
Loading