aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2018-11-05 10:23:15 -0500
committerPaul Ganssle <paul@ganssle.io>2018-11-07 17:38:41 -0500
commit386fcdbe02c4170a560d67742f2ac1319430ff43 (patch)
treeceb7f45963660ee9e9fd8e60598f57071cc0bf10 /setuptools
parente5d362d3736bc5972835a55bcb165d8c55913547 (diff)
downloadexternal_python_setuptools-386fcdbe02c4170a560d67742f2ac1319430ff43.tar.gz
external_python_setuptools-386fcdbe02c4170a560d67742f2ac1319430ff43.tar.bz2
external_python_setuptools-386fcdbe02c4170a560d67742f2ac1319430ff43.zip
Start patching DistributionMetadata.read_pkg_file
This turns get_metadata_version into a method on DistributionMetadata, populated either by inferrence (in the case of package metadata specified in `setup`) or from the data in a specified PKG-INFO file. To populate metadata_version from PKG-INFO, we need to monkey patch read_pkg_file in addition to write_pkg_file.
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/dist.py33
-rw-r--r--setuptools/monkey.py12
2 files changed, 26 insertions, 19 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 5b750b62..ae9816fd 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -43,18 +43,25 @@ def _get_unpatched(cls):
return get_unpatched(cls)
-def get_metadata_version(dist_md):
- if dist_md.long_description_content_type or dist_md.provides_extras:
- return StrictVersion('2.1')
- elif (dist_md.maintainer is not None or
- dist_md.maintainer_email is not None or
- getattr(dist_md, 'python_requires', None) is not None):
- return StrictVersion('1.2')
- elif (dist_md.provides or dist_md.requires or dist_md.obsoletes or
- dist_md.classifiers or dist_md.download_url):
- return StrictVersion('1.1')
+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):
+ 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')
+
+ self.metadata_version = mv
- return StrictVersion('1.0')
+ return mv
def read_pkg_file(self, file):
@@ -100,7 +107,7 @@ def read_pkg_file(self, file):
self.classifiers = _read_list('classifier')
# PEP 314 - these fields only exist in 1.1
- if metadata_version == StrictVersion('1.1'):
+ if self.metadata_version == StrictVersion('1.1'):
self.requires = _read_list('requires')
self.provides = _read_list('provides')
self.obsoletes = _read_list('obsoletes')
@@ -114,7 +121,7 @@ def read_pkg_file(self, file):
def write_pkg_file(self, file):
"""Write the PKG-INFO format data to a file object.
"""
- version = get_metadata_version(self)
+ version = self.get_metadata_version()
file.write('Metadata-Version: %s\n' % version)
file.write('Name: %s\n' % self.get_name())
diff --git a/setuptools/monkey.py b/setuptools/monkey.py
index 05a738b0..3c77f8cf 100644
--- a/setuptools/monkey.py
+++ b/setuptools/monkey.py
@@ -84,7 +84,7 @@ def patch_all():
warehouse = 'https://upload.pypi.org/legacy/'
distutils.config.PyPIRCCommand.DEFAULT_REPOSITORY = warehouse
- _patch_distribution_metadata_write_pkg_file()
+ _patch_distribution_metadata()
# Install Distribution throughout the distutils
for module in distutils.dist, distutils.core, distutils.cmd:
@@ -101,11 +101,11 @@ def patch_all():
patch_for_msvc_specialized_compiler()
-def _patch_distribution_metadata_write_pkg_file():
- """Patch write_pkg_file to also write Requires-Python/Requires-External"""
- distutils.dist.DistributionMetadata.write_pkg_file = (
- setuptools.dist.write_pkg_file
- )
+def _patch_distribution_metadata():
+ """Patch write_pkg_file and read_pkg_file for higher metadata standards"""
+ for attr in ('write_pkg_file', 'read_pkg_file', 'get_metadata_version'):
+ new_val = getattr(setuptools.dist, attr)
+ setattr(distutils.dist.DistributionMetadata, attr, new_val)
def patch_func(replacement, target_mod, func_name):