Skip to content

Commit fb37758

Browse files
authored
Merge pull request #2641 from cdce8p/mv-version
Always use latest metadata version for PKG-INFO
2 parents a41b6d9 + 417b02b commit fb37758

File tree

4 files changed

+37
-43
lines changed

4 files changed

+37
-43
lines changed

changelog.d/2641.change.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Setuptools will now always try to use the latest supported
2+
metadata version for ``PKG-INFO``. - by :user:`cdce8p`

setuptools/dist.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,9 @@ def _get_unpatched(cls):
5252

5353
def get_metadata_version(self):
5454
mv = getattr(self, 'metadata_version', None)
55-
5655
if mv is None:
57-
if self.long_description_content_type or self.provides_extras:
58-
mv = StrictVersion('2.1')
59-
elif (self.maintainer is not None or
60-
self.maintainer_email is not None or
61-
getattr(self, 'python_requires', None) is not None or
62-
self.project_urls):
63-
mv = StrictVersion('1.2')
64-
elif (self.provides or self.requires or self.obsoletes or
65-
self.classifiers or self.download_url):
66-
mv = StrictVersion('1.1')
67-
else:
68-
mv = StrictVersion('1.0')
69-
56+
mv = StrictVersion('2.1')
7057
self.metadata_version = mv
71-
7258
return mv
7359

7460

@@ -171,22 +157,17 @@ def write_field(key, value):
171157
write_field('Summary', single_line(self.get_description()))
172158
write_field('Home-page', self.get_url())
173159

174-
if version < StrictVersion('1.2'):
175-
write_field('Author', self.get_contact())
176-
write_field('Author-email', self.get_contact_email())
177-
else:
178-
optional_fields = (
179-
('Author', 'author'),
180-
('Author-email', 'author_email'),
181-
('Maintainer', 'maintainer'),
182-
('Maintainer-email', 'maintainer_email'),
183-
)
160+
optional_fields = (
161+
('Author', 'author'),
162+
('Author-email', 'author_email'),
163+
('Maintainer', 'maintainer'),
164+
('Maintainer-email', 'maintainer_email'),
165+
)
184166

185-
for field, attr in optional_fields:
186-
attr_val = getattr(self, attr)
187-
188-
if attr_val is not None:
189-
write_field(field, attr_val)
167+
for field, attr in optional_fields:
168+
attr_val = getattr(self, attr, None)
169+
if attr_val is not None:
170+
write_field(field, attr_val)
190171

191172
license = rfc822_escape(self.get_license())
192173
write_field('License', license)
@@ -202,11 +183,8 @@ def write_field(key, value):
202183
if keywords:
203184
write_field('Keywords', keywords)
204185

205-
if version >= StrictVersion('1.2'):
206-
for platform in self.get_platforms():
207-
write_field('Platform', platform)
208-
else:
209-
self._write_list(file, 'Platform', self.get_platforms())
186+
for platform in self.get_platforms():
187+
write_field('Platform', platform)
210188

211189
self._write_list(file, 'Classifier', self.get_classifiers())
212190

setuptools/tests/test_dist.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,9 @@ def __read_test_cases():
8484

8585
test_cases = [
8686
('Metadata version 1.0', params()),
87-
('Metadata version 1.1: Provides', params(
88-
provides=['package'],
89-
)),
9087
('Metadata Version 1.0: Short long description', params(
9188
long_description='Short long description',
9289
)),
93-
('Metadata version 1.1: Obsoletes', params(
94-
obsoletes=['foo'],
95-
)),
9690
('Metadata version 1.1: Classifiers', params(
9791
classifiers=[
9892
'Programming Language :: Python :: 3',

setuptools/tests/test_egg_info.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import re
66
import stat
77
import time
8+
from typing import List, Tuple
89

910
import pytest
1011
from jaraco import path
@@ -45,6 +46,11 @@ def run():
4546
""")
4647
})
4748

49+
@staticmethod
50+
def _extract_mv_version(pkg_info_lines: List[str]) -> Tuple[int, int]:
51+
version_str = pkg_info_lines[0].split(' ')[1]
52+
return tuple(map(int, version_str.split('.')[:2]))
53+
4854
@pytest.fixture
4955
def env(self):
5056
with contexts.tempdir(prefix='setuptools-test.') as env_dir:
@@ -829,6 +835,20 @@ def test_setup_cfg_license_file_license_files(
829835
for lf in excl_licenses:
830836
assert sources_lines.count(lf) == 0
831837

838+
def test_metadata_version(self, tmpdir_cwd, env):
839+
"""Make sure latest metadata version is used by default."""
840+
self._setup_script_with_requires("")
841+
code, data = environment.run_setup_py(
842+
cmd=['egg_info'],
843+
pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
844+
data_stream=1,
845+
)
846+
egg_info_dir = os.path.join('.', 'foo.egg-info')
847+
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
848+
pkg_info_lines = pkginfo_file.read().split('\n')
849+
# Update metadata version if changed
850+
assert self._extract_mv_version(pkg_info_lines) == (2, 1)
851+
832852
def test_long_description_content_type(self, tmpdir_cwd, env):
833853
# Test that specifying a `long_description_content_type` keyword arg to
834854
# the `setup` function results in writing a `Description-Content-Type`
@@ -884,7 +904,7 @@ def test_project_urls(self, tmpdir_cwd, env):
884904
assert expected_line in pkg_info_lines
885905
expected_line = 'Project-URL: Link Two, https://example.com/two/'
886906
assert expected_line in pkg_info_lines
887-
assert 'Metadata-Version: 1.2' in pkg_info_lines
907+
assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
888908

889909
def test_license(self, tmpdir_cwd, env):
890910
"""Test single line license."""
@@ -933,7 +953,7 @@ def test_python_requires_egg_info(self, tmpdir_cwd, env):
933953
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
934954
pkg_info_lines = pkginfo_file.read().split('\n')
935955
assert 'Requires-Python: >=2.7.12' in pkg_info_lines
936-
assert 'Metadata-Version: 1.2' in pkg_info_lines
956+
assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
937957

938958
def test_manifest_maker_warning_suppression(self):
939959
fixtures = [

0 commit comments

Comments
 (0)