summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-05-09 10:59:59 -0400
committerGitHub <noreply@github.com>2021-05-09 10:59:59 -0400
commitfb377585d680cde6d1832ba7b6d90cfcdb463ee5 (patch)
treec179a84903294afa78089aa23aa604cc0ec5d0b5
parenta41b6d9c50ada747cf45708be8e9b24437b5f6a3 (diff)
parent417b02b79d8b29c6af85cbaedcab05c47c159e30 (diff)
downloadpython-setuptools-git-fb377585d680cde6d1832ba7b6d90cfcdb463ee5.tar.gz
Merge pull request #2641 from cdce8p/mv-version
Always use latest metadata version for PKG-INFO
-rw-r--r--changelog.d/2641.change.rst2
-rw-r--r--setuptools/dist.py48
-rw-r--r--setuptools/tests/test_dist.py6
-rw-r--r--setuptools/tests/test_egg_info.py24
4 files changed, 37 insertions, 43 deletions
diff --git a/changelog.d/2641.change.rst b/changelog.d/2641.change.rst
new file mode 100644
index 00000000..95b8a03e
--- /dev/null
+++ b/changelog.d/2641.change.rst
@@ -0,0 +1,2 @@
+Setuptools will now always try to use the latest supported
+metadata version for ``PKG-INFO``. - by :user:`cdce8p`
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 49501263..24aef1bb 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -52,23 +52,9 @@ def _get_unpatched(cls):
def get_metadata_version(self):
mv = getattr(self, 'metadata_version', None)
-
if mv is None:
- if self.long_description_content_type or self.provides_extras:
- mv = StrictVersion('2.1')
- elif (self.maintainer is not None or
- self.maintainer_email is not None or
- getattr(self, 'python_requires', None) is not None or
- self.project_urls):
- mv = StrictVersion('1.2')
- elif (self.provides or self.requires or self.obsoletes or
- self.classifiers or self.download_url):
- mv = StrictVersion('1.1')
- else:
- mv = StrictVersion('1.0')
-
+ mv = StrictVersion('2.1')
self.metadata_version = mv
-
return mv
@@ -171,22 +157,17 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
write_field('Summary', single_line(self.get_description()))
write_field('Home-page', self.get_url())
- if version < StrictVersion('1.2'):
- write_field('Author', self.get_contact())
- write_field('Author-email', self.get_contact_email())
- else:
- optional_fields = (
- ('Author', 'author'),
- ('Author-email', 'author_email'),
- ('Maintainer', 'maintainer'),
- ('Maintainer-email', 'maintainer_email'),
- )
+ optional_fields = (
+ ('Author', 'author'),
+ ('Author-email', 'author_email'),
+ ('Maintainer', 'maintainer'),
+ ('Maintainer-email', 'maintainer_email'),
+ )
- for field, attr in optional_fields:
- attr_val = getattr(self, attr)
-
- if attr_val is not None:
- write_field(field, attr_val)
+ for field, attr in optional_fields:
+ attr_val = getattr(self, attr, None)
+ if attr_val is not None:
+ write_field(field, attr_val)
license = rfc822_escape(self.get_license())
write_field('License', license)
@@ -202,11 +183,8 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME
if keywords:
write_field('Keywords', keywords)
- if version >= StrictVersion('1.2'):
- for platform in self.get_platforms():
- write_field('Platform', platform)
- else:
- self._write_list(file, 'Platform', self.get_platforms())
+ for platform in self.get_platforms():
+ write_field('Platform', platform)
self._write_list(file, 'Classifier', self.get_classifiers())
diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py
index e09ed4cb..6378caef 100644
--- a/setuptools/tests/test_dist.py
+++ b/setuptools/tests/test_dist.py
@@ -84,15 +84,9 @@ def __read_test_cases():
test_cases = [
('Metadata version 1.0', params()),
- ('Metadata version 1.1: Provides', params(
- provides=['package'],
- )),
('Metadata Version 1.0: Short long description', params(
long_description='Short long description',
)),
- ('Metadata version 1.1: Obsoletes', params(
- obsoletes=['foo'],
- )),
('Metadata version 1.1: Classifiers', params(
classifiers=[
'Programming Language :: Python :: 3',
diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py
index 5283954b..750193dd 100644
--- a/setuptools/tests/test_egg_info.py
+++ b/setuptools/tests/test_egg_info.py
@@ -5,6 +5,7 @@ import glob
import re
import stat
import time
+from typing import List, Tuple
import pytest
from jaraco import path
@@ -45,6 +46,11 @@ class TestEggInfo:
""")
})
+ @staticmethod
+ def _extract_mv_version(pkg_info_lines: List[str]) -> Tuple[int, int]:
+ version_str = pkg_info_lines[0].split(' ')[1]
+ return tuple(map(int, version_str.split('.')[:2]))
+
@pytest.fixture
def env(self):
with contexts.tempdir(prefix='setuptools-test.') as env_dir:
@@ -829,6 +835,20 @@ class TestEggInfo:
for lf in excl_licenses:
assert sources_lines.count(lf) == 0
+ def test_metadata_version(self, tmpdir_cwd, env):
+ """Make sure latest metadata version is used by default."""
+ self._setup_script_with_requires("")
+ code, data = environment.run_setup_py(
+ cmd=['egg_info'],
+ pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
+ data_stream=1,
+ )
+ egg_info_dir = os.path.join('.', 'foo.egg-info')
+ with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
+ pkg_info_lines = pkginfo_file.read().split('\n')
+ # Update metadata version if changed
+ assert self._extract_mv_version(pkg_info_lines) == (2, 1)
+
def test_long_description_content_type(self, tmpdir_cwd, env):
# Test that specifying a `long_description_content_type` keyword arg to
# the `setup` function results in writing a `Description-Content-Type`
@@ -884,7 +904,7 @@ class TestEggInfo:
assert expected_line in pkg_info_lines
expected_line = 'Project-URL: Link Two, https://example.com/two/'
assert expected_line in pkg_info_lines
- assert 'Metadata-Version: 1.2' in pkg_info_lines
+ assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
def test_license(self, tmpdir_cwd, env):
"""Test single line license."""
@@ -933,7 +953,7 @@ class TestEggInfo:
with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
pkg_info_lines = pkginfo_file.read().split('\n')
assert 'Requires-Python: >=2.7.12' in pkg_info_lines
- assert 'Metadata-Version: 1.2' in pkg_info_lines
+ assert self._extract_mv_version(pkg_info_lines) >= (1, 2)
def test_manifest_maker_warning_suppression(self):
fixtures = [