diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2016-07-20 19:28:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-20 19:28:05 -0400 |
| commit | b2f50d5ddf0be280d0b0106f178437a4aad1b306 (patch) | |
| tree | 507b2701d1ba2bf13233d5670509d042af4e863a /setuptools | |
| parent | 18f760aa07da104d7ed156b7f085bd05fb0c964d (diff) | |
| parent | 020771f5e631741de31255283aa81adc05a26a9d (diff) | |
| download | external_python_setuptools-b2f50d5ddf0be280d0b0106f178437a4aad1b306.tar.gz external_python_setuptools-b2f50d5ddf0be280d0b0106f178437a4aad1b306.tar.bz2 external_python_setuptools-b2f50d5ddf0be280d0b0106f178437a4aad1b306.zip | |
Merge pull request #631 from xavfernandez/xfernandez/python_requires
Add python_requires keywords to setup
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/dist.py | 28 | ||||
| -rw-r--r-- | setuptools/tests/test_egg_info.py | 24 |
2 files changed, 52 insertions, 0 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index b8ada9b9..bfdbb3b5 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -39,6 +39,20 @@ def _get_unpatched(cls): _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) + + distutils.dist.DistributionMetadata.write_pkg_file = write_pkg_file +_patch_distribution_metadata_write_pkg_file() + + def _patch_distribution_metadata_write_pkg_info(): """ Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local @@ -138,6 +152,18 @@ def check_requirements(dist, attr, value): 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): """Verify that entry_points map is parseable""" try: @@ -305,6 +331,8 @@ class Distribution(_Distribution): "setuptools, pip, and PyPI. Please see PEP 440 for more " "details." % self.metadata.version ) + if getattr(self, 'python_requires', None): + self.metadata.python_requires = self.python_requires def parse_command_line(self): """Process features after parsing command line options""" diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index dea7f992..0b9da538 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -210,6 +210,30 @@ class TestEggInfo(object): self._run_install_command(tmpdir_cwd, env) assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == [] + def test_python_requires_egg_info(self, tmpdir_cwd, env): + self._setup_script_with_requires( + """python_requires='>=2.7.12',""") + environ = os.environ.copy().update( + HOME=env.paths['home'], + ) + code, data = environment.run_setup_py( + cmd=['egg_info'], + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + env=environ, + ) + egg_info_dir = os.path.join('.', 'foo.egg-info') + pkginfo = os.path.join(egg_info_dir, 'PKG-INFO') + assert 'Requires-Python: >=2.7.12' in open(pkginfo).read().split('\n') + + def test_python_requires_install(self, tmpdir_cwd, env): + self._setup_script_with_requires( + """python_requires='>=1.2.3',""") + self._run_install_command(tmpdir_cwd, env) + egg_info_dir = self._find_egg_info_files(env.paths['lib']).base + pkginfo = os.path.join(egg_info_dir, 'PKG-INFO') + assert 'Requires-Python: >=1.2.3' in open(pkginfo).read().split('\n') + def _run_install_command(self, tmpdir_cwd, env, cmd=None, output=None): environ = os.environ.copy().update( HOME=env.paths['home'], |
