Skip to content

Commit 0a4eb8b

Browse files
authored
Bump core metadata version to 2.4 (#4830)
2 parents 016d24a + 9bf4bb9 commit 0a4eb8b

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

newsfragments/4830.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump core metadata version to ``2.4``. -- by :user:`cdce8p`

setuptools/_core_metadata.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
def get_metadata_version(self):
2929
mv = getattr(self, 'metadata_version', None)
3030
if mv is None:
31-
mv = Version('2.2')
31+
mv = Version('2.4')
3232
self.metadata_version = mv
3333
return mv
3434

@@ -176,8 +176,9 @@ def write_field(key, value):
176176
if attr_val is not None:
177177
write_field(field, attr_val)
178178

179-
license = self.license_expression or self.get_license()
180-
if license:
179+
if license_expression := self.license_expression:
180+
write_field('License-Expression', license_expression)
181+
elif license := self.get_license():
181182
write_field('License', rfc822_escape(license))
182183

183184
for label, url in self.project_urls.items():

setuptools/tests/config/test_apply_pyprojecttoml.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,28 @@ def test_utf8_maintainer_in_metadata( # issue-3663
280280

281281

282282
@pytest.mark.parametrize(
283-
('pyproject_text', 'license', 'license_expression', 'content_str'),
283+
(
284+
'pyproject_text',
285+
'license',
286+
'license_expression',
287+
'content_str',
288+
'not_content_str',
289+
),
284290
(
285291
pytest.param(
286292
PEP639_LICENSE_TEXT,
287293
'MIT',
288294
None,
289295
'License: MIT',
296+
'License-Expression: ',
290297
id='license-text',
291298
),
292299
pytest.param(
293300
PEP639_LICENSE_EXPRESSION,
294301
None,
295302
'MIT OR Apache-2.0',
296-
'License: MIT OR Apache-2.0', # TODO Metadata version '2.4'
303+
'License-Expression: MIT OR Apache-2.0',
304+
'License: ',
297305
id='license-expression',
298306
),
299307
),
@@ -302,6 +310,7 @@ def test_license_in_metadata(
302310
license,
303311
license_expression,
304312
content_str,
313+
not_content_str,
305314
pyproject_text,
306315
tmp_path,
307316
):
@@ -317,7 +326,9 @@ def test_license_in_metadata(
317326
with open(pkg_file, "w", encoding="utf-8") as fh:
318327
dist.metadata.write_pkg_file(fh)
319328
content = pkg_file.read_text(encoding="utf-8")
329+
assert "Metadata-Version: 2.4" in content
320330
assert content_str in content
331+
assert not_content_str not in content
321332

322333

323334
def test_license_expression_with_bad_classifier(tmp_path):

setuptools/tests/test_egg_info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ def test_provides_extra(self, tmpdir_cwd, env):
522522
with open(os.path.join(egg_info_dir, 'PKG-INFO'), encoding="utf-8") as fp:
523523
pkg_info_lines = fp.read().split('\n')
524524
assert 'Provides-Extra: foobar' in pkg_info_lines
525-
assert 'Metadata-Version: 2.2' in pkg_info_lines
525+
assert 'Metadata-Version: 2.4' in pkg_info_lines
526526

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

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

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

0 commit comments

Comments
 (0)