Commit 98477464 authored by Xavier Fernandez's avatar Xavier Fernandez

Add python/external_requires keywords to setup

This should allow setuptools to write the metadata Requires-Python and
Requires-External from PEP345 to the PKGINFO file
parent 8e80ee74
...@@ -95,6 +95,8 @@ setup_params = dict( ...@@ -95,6 +95,8 @@ setup_params = dict(
"install_requires = setuptools.dist:check_requirements", "install_requires = setuptools.dist:check_requirements",
"tests_require = setuptools.dist:check_requirements", "tests_require = setuptools.dist:check_requirements",
"setup_requires = setuptools.dist:check_requirements", "setup_requires = setuptools.dist:check_requirements",
"python_requires = setuptools.dist:check_specifier",
"external_requires = setuptools.dist:assert_string_list",
"entry_points = setuptools.dist:check_entry_points", "entry_points = setuptools.dist:check_entry_points",
"test_suite = setuptools.dist:check_test_suite", "test_suite = setuptools.dist:check_test_suite",
"zip_safe = setuptools.dist:assert_bool", "zip_safe = setuptools.dist:assert_bool",
......
...@@ -39,6 +39,22 @@ def _get_unpatched(cls): ...@@ -39,6 +39,22 @@ def _get_unpatched(cls):
_Distribution = _get_unpatched(_Distribution) _Distribution = _get_unpatched(_Distribution)
def _patch_distribution_metadata_write_pkg_file():
"""Patch write_pkg_file to also write Requires-Python/Requires-External"""
original_write = distutils.dist.DistributionMetadata.write_pkg_file
def write_pkg_file(self, file):
"""Write the PKG-INFO format data to a file object.
"""
original_write(self, file)
if hasattr(self, 'python_requires'):
file.write('Requires-Python: %s\n' % self.python_requires)
if getattr(self, 'external_requires', []):
self._write_list(file, 'Requires-External', self.external_requires)
distutils.dist.DistributionMetadata.write_pkg_file = write_pkg_file
_patch_distribution_metadata_write_pkg_file()
def _patch_distribution_metadata_write_pkg_info(): def _patch_distribution_metadata_write_pkg_info():
""" """
Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local
...@@ -138,6 +154,18 @@ def check_requirements(dist, attr, value): ...@@ -138,6 +154,18 @@ def check_requirements(dist, attr, value):
raise DistutilsSetupError(tmpl.format(attr=attr, error=error)) raise DistutilsSetupError(tmpl.format(attr=attr, error=error))
def check_specifier(dist, attr, value):
"""Verify that value is a valid version specifier"""
try:
packaging.specifiers.SpecifierSet(value)
except packaging.specifiers.InvalidSpecifier as error:
tmpl = (
"{attr!r} must be a string or list of strings "
"containing valid version specifiers; {error}"
)
raise DistutilsSetupError(tmpl.format(attr=attr, error=error))
def check_entry_points(dist, attr, value): def check_entry_points(dist, attr, value):
"""Verify that entry_points map is parseable""" """Verify that entry_points map is parseable"""
try: try:
...@@ -303,6 +331,10 @@ class Distribution(_Distribution): ...@@ -303,6 +331,10 @@ class Distribution(_Distribution):
"setuptools, pip, and PyPI. Please see PEP 440 for more " "setuptools, pip, and PyPI. Please see PEP 440 for more "
"details." % self.metadata.version "details." % self.metadata.version
) )
if getattr(self, 'python_requires', None):
self.metadata.python_requires = self.python_requires
if getattr(self, 'external_requires', None):
self.metadata.external_requires = self.external_requires
def parse_command_line(self): def parse_command_line(self):
"""Process features after parsing command line options""" """Process features after parsing command line options"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment