aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/__init__.py15
-rw-r--r--setuptools/command/build_ext.py2
-rwxr-xr-xsetuptools/command/easy_install.py21
-rw-r--r--setuptools/command/upload_docs.py5
-rw-r--r--setuptools/dist.py146
-rw-r--r--setuptools/extension.py17
-rw-r--r--setuptools/monkey.py175
-rw-r--r--setuptools/msvc.py98
-rwxr-xr-xsetuptools/package_index.py17
-rw-r--r--setuptools/py26compat.py7
-rw-r--r--setuptools/tests/test_msvc.py2
11 files changed, 293 insertions, 212 deletions
diff --git a/setuptools/__init__.py b/setuptools/__init__.py
index cf0c39f2..41b590d7 100644
--- a/setuptools/__init__.py
+++ b/setuptools/__init__.py
@@ -4,7 +4,6 @@ import os
import functools
import distutils.core
import distutils.filelist
-from distutils.core import Command as _Command
from distutils.util import convert_path
from fnmatch import fnmatchcase
@@ -12,12 +11,13 @@ from setuptools.extern.six.moves import filterfalse, map
import setuptools.version
from setuptools.extension import Extension
-from setuptools.dist import Distribution, Feature, _get_unpatched
+from setuptools.dist import Distribution, Feature
from setuptools.depends import Require
+from . import monkey
__all__ = [
'setup', 'Distribution', 'Feature', 'Command', 'Extension', 'Require',
- 'find_packages'
+ 'find_packages',
]
__version__ = setuptools.version.__version__
@@ -121,7 +121,7 @@ find_packages = PackageFinder.find
setup = distutils.core.setup
-_Command = _get_unpatched(_Command)
+_Command = monkey.get_unpatched(distutils.core.Command)
class Command(_Command):
@@ -143,10 +143,6 @@ class Command(_Command):
return cmd
-# we can't patch distutils.cmd, alas
-distutils.core.Command = Command
-
-
def _find_all_simple(path):
"""
Find all files under 'path'
@@ -171,5 +167,4 @@ def findall(dir=os.curdir):
return list(files)
-# fix findall bug in distutils (http://bugs.python.org/issue12885)
-distutils.filelist.findall = findall
+monkey.patch_all()
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py
index f994b626..454c91fb 100644
--- a/setuptools/command/build_ext.py
+++ b/setuptools/command/build_ext.py
@@ -111,7 +111,7 @@ class build_ext(_build_ext):
and get_abi3_suffix()
)
if use_abi3:
- so_ext = get_config_var('SO')
+ so_ext = get_config_var('EXT_SUFFIX')
filename = filename[:-len(so_ext)]
filename = filename + get_abi3_suffix()
if isinstance(ext, Library):
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py
index 5065661f..a3792ce2 100755
--- a/setuptools/command/easy_install.py
+++ b/setuptools/command/easy_install.py
@@ -8,7 +8,7 @@ A tool for doing automatic download/extract/build of distutils-based Python
packages. For detailed documentation, see the accompanying EasyInstall.txt
file, or visit the `EasyInstall home page`__.
-__ https://pythonhosted.org/setuptools/easy_install.html
+__ https://setuptools.readthedocs.io/en/latest/easy_install.html
"""
@@ -49,8 +49,9 @@ from setuptools.sandbox import run_setup
from setuptools.py31compat import get_path, get_config_vars
from setuptools.command import setopt
from setuptools.archive_util import unpack_archive
-from setuptools.package_index import PackageIndex
-from setuptools.package_index import URL_SCHEME
+from setuptools.package_index import (
+ PackageIndex, parse_requirement_arg, URL_SCHEME,
+)
from setuptools.command import bdist_egg, egg_info
from pkg_resources import (
yield_lines, normalize_path, resource_string, ensure_directory,
@@ -512,7 +513,7 @@ class easy_install(Command):
For information on other options, you may wish to consult the
documentation at:
- https://pythonhosted.org/setuptools/easy_install.html
+ https://setuptools.readthedocs.io/en/latest/easy_install.html
Please make the appropriate changes for your system and try again.
""").lstrip()
@@ -1256,7 +1257,8 @@ class easy_install(Command):
* You can set up the installation directory to support ".pth" files by
using one of the approaches described here:
- https://pythonhosted.org/setuptools/easy_install.html#custom-installation-locations
+ https://setuptools.readthedocs.io/en/latest/easy_install.html#custom-installation-locations
+
Please make the appropriate changes for your system and try again.""").lstrip()
@@ -1521,15 +1523,6 @@ def get_exe_prefixes(exe_filename):
return prefixes
-def parse_requirement_arg(spec):
- try:
- return Requirement.parse(spec)
- except ValueError:
- raise DistutilsError(
- "Not a URL, existing file, or requirement spec: %r" % (spec,)
- )
-
-
class PthDistributions(Environment):
"""A .pth file with Distribution paths in it"""
diff --git a/setuptools/command/upload_docs.py b/setuptools/command/upload_docs.py
index ccc1c76f..269dc2d5 100644
--- a/setuptools/command/upload_docs.py
+++ b/setuptools/command/upload_docs.py
@@ -29,6 +29,10 @@ def _encode(s):
class upload_docs(upload):
+ # override the default repository as upload_docs isn't
+ # supported by Warehouse (and won't be).
+ DEFAULT_REPOSITORY = 'https://pypi.python.org/pypi/'
+
description = 'Upload documentation to PyPI'
user_options = [
@@ -53,6 +57,7 @@ class upload_docs(upload):
self.target_dir = None
def finalize_options(self):
+ log.warn("Upload_docs command is deprecated. Use RTD instead.")
upload.finalize_options(self)
if self.upload_dir is None:
if self.has_sphinx():
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 820df6d5..b004f928 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -2,14 +2,12 @@ __all__ = ['Distribution']
import re
import os
-import sys
import warnings
import numbers
import distutils.log
import distutils.core
import distutils.cmd
import distutils.dist
-from distutils.core import Distribution as _Distribution
from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
DistutilsSetupError)
from distutils.util import rfc822_escape
@@ -20,100 +18,66 @@ from pkg_resources.extern import packaging
from setuptools.depends import Require
from setuptools import windows_support
+from setuptools.monkey import get_unpatched
import pkg_resources
def _get_unpatched(cls):
- """Protect against re-patching the distutils if reloaded
+ warnings.warn("Do not call this function", DeprecationWarning)
+ return get_unpatched(cls)
- Also ensures that no other distutils extension monkeypatched the distutils
- first.
- """
- while cls.__module__.startswith('setuptools'):
- cls, = cls.__bases__
- if not cls.__module__.startswith('distutils'):
- raise AssertionError(
- "distutils has already been patched by %r" % cls
- )
- return cls
-
-
-_Distribution = _get_unpatched(_Distribution)
-
-
-def _patch_distribution_metadata_write_pkg_file():
- """Patch write_pkg_file to also write Requires-Python/Requires-External"""
-
- # Based on Python 3.5 version
- def write_pkg_file(self, file):
- """Write the PKG-INFO format data to a file object.
- """
- version = '1.0'
- if (self.provides or self.requires or self.obsoletes or
- self.classifiers or self.download_url):
- version = '1.1'
- # Setuptools specific for PEP 345
- if hasattr(self, 'python_requires'):
- version = '1.2'
-
- file.write('Metadata-Version: %s\n' % version)
- file.write('Name: %s\n' % self.get_name())
- file.write('Version: %s\n' % self.get_version())
- file.write('Summary: %s\n' % self.get_description())
- file.write('Home-page: %s\n' % self.get_url())
- file.write('Author: %s\n' % self.get_contact())
- file.write('Author-email: %s\n' % self.get_contact_email())
- file.write('License: %s\n' % self.get_license())
- if self.download_url:
- file.write('Download-URL: %s\n' % self.download_url)
-
- long_desc = rfc822_escape(self.get_long_description())
- file.write('Description: %s\n' % long_desc)
-
- keywords = ','.join(self.get_keywords())
- if keywords:
- file.write('Keywords: %s\n' % keywords)
-
- self._write_list(file, 'Platform', self.get_platforms())
- self._write_list(file, 'Classifier', self.get_classifiers())
-
- # PEP 314
- self._write_list(file, 'Requires', self.get_requires())
- self._write_list(file, 'Provides', self.get_provides())
- self._write_list(file, 'Obsoletes', self.get_obsoletes())
- # Setuptools specific for PEP 345
- 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():
+# Based on Python 3.5 version
+def write_pkg_file(self, file):
+ """Write the PKG-INFO format data to a file object.
"""
- Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local
- encoding to save the pkg_info. Monkey-patch its write_pkg_info method to
- correct this undesirable behavior.
+ version = '1.0'
+ if (self.provides or self.requires or self.obsoletes or
+ self.classifiers or self.download_url):
+ version = '1.1'
+ # Setuptools specific for PEP 345
+ if hasattr(self, 'python_requires'):
+ version = '1.2'
+
+ file.write('Metadata-Version: %s\n' % version)
+ file.write('Name: %s\n' % self.get_name())
+ file.write('Version: %s\n' % self.get_version())
+ file.write('Summary: %s\n' % self.get_description())
+ file.write('Home-page: %s\n' % self.get_url())
+ file.write('Author: %s\n' % self.get_contact())
+ file.write('Author-email: %s\n' % self.get_contact_email())
+ file.write('License: %s\n' % self.get_license())
+ if self.download_url:
+ file.write('Download-URL: %s\n' % self.download_url)
+
+ long_desc = rfc822_escape(self.get_long_description())
+ file.write('Description: %s\n' % long_desc)
+
+ keywords = ','.join(self.get_keywords())
+ if keywords:
+ file.write('Keywords: %s\n' % keywords)
+
+ self._write_list(file, 'Platform', self.get_platforms())
+ self._write_list(file, 'Classifier', self.get_classifiers())
+
+ # PEP 314
+ self._write_list(file, 'Requires', self.get_requires())
+ self._write_list(file, 'Provides', self.get_provides())
+ self._write_list(file, 'Obsoletes', self.get_obsoletes())
+
+ # Setuptools specific for PEP 345
+ if hasattr(self, 'python_requires'):
+ file.write('Requires-Python: %s\n' % self.python_requires)
+
+
+# from Python 3.4
+def write_pkg_info(self, base_dir):
+ """Write the PKG-INFO file into the release tree.
"""
- environment_local = (3,) <= sys.version_info[:3] < (3, 2, 2)
- if not environment_local:
- return
-
- # from Python 3.4
- def write_pkg_info(self, base_dir):
- """Write the PKG-INFO file into the release tree.
- """
- with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
- encoding='UTF-8') as pkg_info:
- self.write_pkg_file(pkg_info)
+ with open(os.path.join(base_dir, 'PKG-INFO'), 'w',
+ encoding='UTF-8') as pkg_info:
+ self.write_pkg_file(pkg_info)
- distutils.dist.DistributionMetadata.write_pkg_info = write_pkg_info
-
-
-_patch_distribution_metadata_write_pkg_info()
sequence = tuple, list
@@ -245,6 +209,9 @@ def check_packages(dist, attr, value):
)
+_Distribution = get_unpatched(distutils.core.Distribution)
+
+
class Distribution(_Distribution):
"""Distribution with support for features, tests, and package data
@@ -792,11 +759,6 @@ class Distribution(_Distribution):
sys.stdout.detach(), encoding, errors, newline, line_buffering)
-# Install it throughout the distutils
-for module in distutils.dist, distutils.core, distutils.cmd:
- module.Distribution = Distribution
-
-
class Feature:
"""
**deprecated** -- The `Feature` facility was never completely implemented
diff --git a/setuptools/extension.py b/setuptools/extension.py
index f8058b72..03068d35 100644
--- a/setuptools/extension.py
+++ b/setuptools/extension.py
@@ -1,4 +1,3 @@
-import sys
import re
import functools
import distutils.core
@@ -7,12 +6,7 @@ import distutils.extension
from setuptools.extern.six.moves import map
-from .dist import _get_unpatched
-from . import msvc
-
-_Extension = _get_unpatched(distutils.core.Extension)
-
-msvc.patch_for_specialized_compiler()
+from .monkey import get_unpatched
def _have_cython():
@@ -33,6 +27,9 @@ def _have_cython():
have_pyrex = _have_cython
+_Extension = get_unpatched(distutils.core.Extension)
+
+
class Extension(_Extension):
"""Extension that uses '.c' files in place of '.pyx' files"""
@@ -59,9 +56,3 @@ class Extension(_Extension):
class Library(Extension):
"""Just like a regular Extension, but built as a library instead"""
-
-
-distutils.core.Extension = Extension
-distutils.extension.Extension = Extension
-if 'distutils.command.build_ext' in sys.modules:
- sys.modules['distutils.command.build_ext'].Extension = Extension
diff --git a/setuptools/monkey.py b/setuptools/monkey.py
new file mode 100644
index 00000000..c4289762
--- /dev/null
+++ b/setuptools/monkey.py
@@ -0,0 +1,175 @@
+"""
+Monkey patching of distutils.
+"""
+
+import sys
+import distutils.filelist
+import platform
+import types
+
+from .py26compat import import_module
+from setuptools.extern import six
+
+import setuptools
+
+
+__all__ = []
+"""
+Everything is private. Contact the project team
+if you think you need this functionality.
+"""
+
+
+def get_unpatched(item):
+ lookup = (
+ get_unpatched_class if isinstance(item, six.class_types) else
+ get_unpatched_function if isinstance(item, types.FunctionType) else
+ lambda item: None
+ )
+ return lookup(item)
+
+
+def get_unpatched_class(cls):
+ """Protect against re-patching the distutils if reloaded
+
+ Also ensures that no other distutils extension monkeypatched the distutils
+ first.
+ """
+ while cls.__module__.startswith('setuptools'):
+ cls, = cls.__bases__
+ if not cls.__module__.startswith('distutils'):
+ msg = "distutils has already been patched by %r" % cls
+ raise AssertionError(msg)
+ return cls
+
+
+def patch_all():
+ # we can't patch distutils.cmd, alas
+ distutils.core.Command = setuptools.Command
+
+ has_issue_12885 = (
+ sys.version_info < (3, 4, 6)
+ or
+ (3, 5) < sys.version_info <= (3, 5, 3)
+ or
+ (3, 6) < sys.version_info
+ )
+
+ if has_issue_12885:
+ # fix findall bug in distutils (http://bugs.python.org/issue12885)
+ distutils.filelist.findall = setuptools.findall
+
+ needs_warehouse = (
+ sys.version_info < (2, 7, 13)
+ or
+ (3, 0) < sys.version_info < (3, 3, 7)
+ or
+ (3, 4) < sys.version_info < (3, 4, 6)
+ or
+ (3, 5) < sys.version_info <= (3, 5, 3)
+ or
+ (3, 6) < sys.version_info
+ )
+
+ if needs_warehouse:
+ warehouse = 'https://upload.pypi.org/legacy/'
+ distutils.config.PyPIRCCommand.DEFAULT_REPOSITORY = warehouse
+
+ _patch_distribution_metadata_write_pkg_file()
+ _patch_distribution_metadata_write_pkg_info()
+
+ # Install Distribution throughout the distutils
+ for module in distutils.dist, distutils.core, distutils.cmd:
+ module.Distribution = setuptools.dist.Distribution
+
+ # Install the patched Extension
+ distutils.core.Extension = setuptools.extension.Extension
+ distutils.extension.Extension = setuptools.extension.Extension
+ if 'distutils.command.build_ext' in sys.modules:
+ sys.modules['distutils.command.build_ext'].Extension = (
+ setuptools.extension.Extension
+ )
+
+ 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_write_pkg_info():
+ """
+ Workaround issue #197 - Python 3 prior to 3.2.2 uses an environment-local
+ encoding to save the pkg_info. Monkey-patch its write_pkg_info method to
+ correct this undesirable behavior.
+ """
+ environment_local = (3,) <= sys.version_info[:3] < (3, 2, 2)
+ if not environment_local:
+ return
+
+ distutils.dist.DistributionMetadata.write_pkg_info = (
+ setuptools.dist.write_pkg_info
+ )
+
+
+def patch_func(replacement, original):
+ # first set the 'unpatched' attribute on the replacement to
+ # point to the original.
+ vars(replacement).setdefault('unpatched', original)
+
+ # next resolve the module in which the original func resides
+ target_mod = import_module(original.__module__)
+
+ # finally replace the function in the original module
+ setattr(target_mod, original.__name__, replacement)
+
+
+def get_unpatched_function(candidate):
+ return getattr(candidate, 'unpatched')
+
+
+def patch_for_msvc_specialized_compiler():
+ """
+ Patch functions in distutils to use standalone Microsoft Visual C++
+ compilers.
+ """
+ # import late to avoid circular imports on Python < 3.5
+ msvc = import_module('setuptools.msvc')
+
+ try:
+ # Distutil file for MSVC++ 9.0 and upper (Python 2.7 to 3.4)
+ import distutils.msvc9compiler as msvc9compiler
+ except ImportError:
+ pass
+
+ try:
+ # Distutil file for MSVC++ 14.0 and upper (Python 3.5+)
+ import distutils._msvccompiler as msvc14compiler
+ except ImportError:
+ pass
+
+ if platform.system() != 'Windows':
+ # Compilers only availables on Microsoft Windows
+ return
+
+ try:
+ # Patch distutils.msvc9compiler
+ patch_func(msvc.msvc9_find_vcvarsall, msvc9compiler.find_vcvarsall)
+ patch_func(msvc.msvc9_query_vcvarsall, msvc9compiler.query_vcvarsall)
+ except NameError:
+ pass
+
+ try:
+ # Patch distutils._msvccompiler._get_vc_env
+ patch_func(msvc.msvc14_get_vc_env, msvc14compiler._get_vc_env)
+ except NameError:
+ pass
+
+ try:
+ # Patch distutils._msvccompiler.gen_lib_options for Numpy
+ patch_func(msvc.msvc14_gen_lib_options, msvc14compiler.gen_lib_options)
+ except NameError:
+ pass
diff --git a/setuptools/msvc.py b/setuptools/msvc.py
index 26e399cc..e9665e10 100644
--- a/setuptools/msvc.py
+++ b/setuptools/msvc.py
@@ -1,15 +1,31 @@
"""
-This module adds improved support for Microsoft Visual C++ compilers.
+Improved support for Microsoft Visual C++ compilers.
+
+Known supported compilers:
+--------------------------
+Microsoft Visual C++ 9.0:
+ Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64);
+ Microsoft Windows SDK 7.0 (x86, x64, ia64);
+ Microsoft Windows SDK 6.1 (x86, x64, ia64)
+
+Microsoft Visual C++ 10.0:
+ Microsoft Windows SDK 7.1 (x86, x64, ia64)
+
+Microsoft Visual C++ 14.0:
+ Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
"""
+
import os
import sys
import platform
import itertools
import distutils.errors
-from distutils.version import StrictVersion
+from pkg_resources.extern.packaging.version import LegacyVersion
from setuptools.extern.six.moves import filterfalse
+from .monkey import get_unpatched
+
if platform.system() == 'Windows':
from setuptools.extern.six.moves import winreg
safe_env = os.environ
@@ -26,74 +42,10 @@ else:
safe_env = dict()
try:
- # Distutil file for MSVC++ 9.0 and upper (Python 2.7 to 3.4)
- import distutils.msvc9compiler as msvc9compiler
+ from distutils.msvc9compiler import Reg
except ImportError:
pass
-try:
- # Distutil file for MSVC++ 14.0 and upper (Python 3.5+)
- import distutils._msvccompiler as msvc14compiler
-except ImportError:
- pass
-
-
-unpatched = dict()
-
-
-def patch_for_specialized_compiler():
- """
- Patch functions in distutils to use standalone Microsoft Visual C++
- compilers.
-
- Known supported compilers:
- --------------------------
- Microsoft Visual C++ 9.0:
- Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64);
- Microsoft Windows SDK 7.0 (x86, x64, ia64);
- Microsoft Windows SDK 6.1 (x86, x64, ia64)
-
- Microsoft Visual C++ 10.0:
- Microsoft Windows SDK 7.1 (x86, x64, ia64)
-
- Microsoft Visual C++ 14.0:
- Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
- """
- if platform.system() != 'Windows':
- # Compilers only availables on Microsoft Windows
- return
-
- if 'distutils' not in globals():
- # The module isn't available to be patched
- return
-
- if unpatched:
- # Already patched
- return
-
- try:
- # Patch distutils.msvc9compiler
- unpatched['msvc9_find_vcvarsall'] = msvc9compiler.find_vcvarsall
- msvc9compiler.find_vcvarsall = msvc9_find_vcvarsall
- unpatched['msvc9_query_vcvarsall'] = msvc9compiler.query_vcvarsall
- msvc9compiler.query_vcvarsall = msvc9_query_vcvarsall
- except NameError:
- pass
-
- try:
- # Patch distutils._msvccompiler._get_vc_env
- unpatched['msvc14_get_vc_env'] = msvc14compiler._get_vc_env
- msvc14compiler._get_vc_env = msvc14_get_vc_env
- except NameError:
- pass
-
- try:
- # Patch distutils._msvccompiler.gen_lib_options for Numpy
- unpatched['msvc14_gen_lib_options'] = msvc14compiler.gen_lib_options
- msvc14compiler.gen_lib_options = msvc14_gen_lib_options
- except NameError:
- pass
-
def msvc9_find_vcvarsall(version):
"""
@@ -117,7 +69,6 @@ def msvc9_find_vcvarsall(version):
------
vcvarsall.bat path: str
"""
- Reg = msvc9compiler.Reg
VC_BASE = r'Software\%sMicrosoft\DevDiv\VCForPython\%0.1f'
key = VC_BASE % ('', version)
try:
@@ -136,7 +87,7 @@ def msvc9_find_vcvarsall(version):
if os.path.isfile(vcvarsall):
return vcvarsall
- return unpatched['msvc9_find_vcvarsall'](version)
+ return get_unpatched(msvc9_find_vcvarsall)(version)
def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
@@ -169,7 +120,8 @@ def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
"""
# Try to get environement from vcvarsall.bat (Classical way)
try:
- return unpatched['msvc9_query_vcvarsall'](ver, arch, *args, **kwargs)
+ orig = get_unpatched(msvc9_query_vcvarsall)
+ return orig(ver, arch, *args, **kwargs)
except distutils.errors.DistutilsPlatformError:
# Pass error if Vcvarsall.bat is missing
pass
@@ -208,7 +160,7 @@ def msvc14_get_vc_env(plat_spec):
"""
# Try to get environment from vcvarsall.bat (Classical way)
try:
- return unpatched['msvc14_get_vc_env'](plat_spec)
+ return get_unpatched(msvc14_get_vc_env)(plat_spec)
except distutils.errors.DistutilsPlatformError:
# Pass error Vcvarsall.bat is missing
pass
@@ -229,9 +181,9 @@ def msvc14_gen_lib_options(*args, **kwargs):
"""
if "numpy.distutils" in sys.modules:
import numpy as np
- if StrictVersion(np.__version__) < StrictVersion('1.11.2'):
+ if LegacyVersion(np.__version__) < LegacyVersion('1.11.2'):
return np.distutils.ccompiler.gen_lib_options(*args, **kwargs)
- return unpatched['msvc14_gen_lib_options'](*args, **kwargs)
+ return get_unpatched(msvc14_gen_lib_options)(*args, **kwargs)
def _augment_exception(exc, version, arch=''):
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 82cd608f..3fb39269 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -52,6 +52,15 @@ _tmpl = "setuptools/{setuptools.__version__} Python-urllib/{py_major}"
user_agent = _tmpl.format(py_major=sys.version[:3], **globals())
+def parse_requirement_arg(spec):
+ try:
+ return Requirement.parse(spec)
+ except ValueError:
+ raise DistutilsError(
+ "Not a URL, existing file, or requirement spec: %r" % (spec,)
+ )
+
+
def parse_bdist_wininst(name):
"""Return (base,pyversion) or (None,None) for possible .exe name"""
@@ -561,13 +570,7 @@ class PackageIndex(Environment):
# Existing file or directory, just return it
return spec
else:
- try:
- spec = Requirement.parse(spec)
- except ValueError:
- raise DistutilsError(
- "Not a URL, existing file, or requirement spec: %r" %
- (spec,)
- )
+ spec = parse_requirement_arg(spec)
return getattr(self.fetch_distribution(spec, tmpdir), 'location', None)
def fetch_distribution(
diff --git a/setuptools/py26compat.py b/setuptools/py26compat.py
index 90cd695a..5778cdf1 100644
--- a/setuptools/py26compat.py
+++ b/setuptools/py26compat.py
@@ -22,3 +22,10 @@ def strip_fragment(url):
if sys.version_info >= (2, 7):
strip_fragment = lambda x: x
+
+
+try:
+ from importlib import import_module
+except ImportError:
+ def import_module(module_name):
+ return __import__(module_name, fromlist=['__name__'])
diff --git a/setuptools/tests/test_msvc.py b/setuptools/tests/test_msvc.py
index 14e0f208..a0c76ea0 100644
--- a/setuptools/tests/test_msvc.py
+++ b/setuptools/tests/test_msvc.py
@@ -6,8 +6,6 @@ import os
import contextlib
import distutils.errors
-from setuptools.extern import six
-
import pytest
try:
from unittest import mock