From 51eb4dedcaa798fddb418c7133371726f9e993d6 Mon Sep 17 00:00:00 2001 From: John Sirois Date: Wed, 6 Feb 2019 13:37:21 -0700 Subject: [PATCH] Support de-vendoring for installs. Now that pex vendors setuptools and wheel, we build / install sdists with potentially fragile import semantics for these two distributions. In particular, we trip up against this when trying to build cryptography. Robustify installs by de-vendoring setuptools and wheel when used in an install context. In order to support de-vendoring make the method of import conditional on an environment variable instead of attempting to re-write vendored imports at runtime. Fixes #661 --- pex/base.py | 6 +- pex/environment.py | 18 ++- pex/finders.py | 5 +- pex/installer.py | 37 ++++--- pex/interpreter.py | 6 +- pex/package.py | 6 +- pex/pex.py | 12 +- pex/pex_builder.py | 12 +- pex/resolvable.py | 6 +- pex/resolver.py | 12 +- pex/resolver_options.py | 6 +- pex/third_party/__init__.py | 47 ++++++-- pex/util.py | 13 ++- pex/vendor/__init__.py | 6 +- pex/vendor/__main__.py | 18 +++ .../setuptools/pkg_resources/__init__.py | 48 ++++++-- .../_vendor/packaging/markers.py | 18 ++- .../_vendor/packaging/requirements.py | 24 +++- .../setuptools/setuptools/__init__.py | 36 +++++- .../setuptools/_vendor/packaging/markers.py | 18 ++- .../_vendor/packaging/requirements.py | 24 +++- .../setuptools/setuptools/archive_util.py | 6 +- .../setuptools/setuptools/build_meta.py | 6 +- .../setuptools/setuptools/command/__init__.py | 6 +- .../setuptools/setuptools/command/alias.py | 12 +- .../setuptools/command/bdist_egg.py | 30 ++++- .../setuptools/command/build_clib.py | 6 +- .../setuptools/command/build_ext.py | 12 +- .../setuptools/setuptools/command/build_py.py | 18 ++- .../setuptools/setuptools/command/develop.py | 30 ++++- .../setuptools/command/easy_install.py | 103 +++++++++++++++--- .../setuptools/setuptools/command/egg_info.py | 76 ++++++++++--- .../setuptools/setuptools/command/install.py | 6 +- .../setuptools/command/install_egg_info.py | 24 +++- .../setuptools/command/install_lib.py | 6 +- .../setuptools/command/install_scripts.py | 18 ++- .../setuptools/command/py36compat.py | 6 +- .../setuptools/setuptools/command/rotate.py | 12 +- .../setuptools/setuptools/command/saveopts.py | 6 +- .../setuptools/setuptools/command/sdist.py | 12 +- .../setuptools/setuptools/command/setopt.py | 12 +- .../setuptools/setuptools/command/test.py | 26 ++++- .../setuptools/setuptools/command/upload.py | 18 ++- .../setuptools/command/upload_docs.py | 18 ++- .../_vendored/setuptools/setuptools/config.py | 30 ++++- .../_vendored/setuptools/setuptools/dist.py | 66 +++++++++-- .../setuptools/setuptools/extension.py | 6 +- .../setuptools/setuptools/lib2to3_ex.py | 6 +- .../_vendored/setuptools/setuptools/monkey.py | 12 +- .../_vendored/setuptools/setuptools/msvc.py | 18 ++- .../setuptools/setuptools/namespaces.py | 6 +- .../setuptools/setuptools/package_index.py | 58 ++++++++-- .../setuptools/setuptools/py27compat.py | 6 +- .../setuptools/setuptools/py33compat.py | 12 +- .../setuptools/setuptools/sandbox.py | 42 +++++-- .../setuptools/setuptools/ssl_support.py | 12 +- .../setuptools/setuptools/unicode_utils.py | 6 +- .../setuptools/setuptools/version.py | 6 +- .../_vendored/setuptools/setuptools/wheel.py | 36 +++++- pex/vendor/_vendored/wheel/wheel/__main__.py | 6 +- .../_vendored/wheel/wheel/bdist_wheel.py | 6 +- pex/vendor/_vendored/wheel/wheel/egg2wheel.py | 18 ++- pex/vendor/_vendored/wheel/wheel/install.py | 6 +- pex/vendor/_vendored/wheel/wheel/metadata.py | 6 +- .../_vendored/wheel/wheel/tool/__init__.py | 18 ++- pex/vendor/_vendored/wheel/wheel/util.py | 6 +- .../_vendored/wheel/wheel/wininst2wheel.py | 12 +- tests/test_bdist_pex.py | 2 +- 68 files changed, 1028 insertions(+), 221 deletions(-) diff --git a/pex/base.py b/pex/base.py index 8208d15c4..0448e2305 100644 --- a/pex/base.py +++ b/pex/base.py @@ -5,7 +5,11 @@ from pex.compatibility import Iterable from pex.compatibility import string as compatibility_string -from pex.third_party.pkg_resources import Requirement + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Requirement # vendor:skip +else: + from pex.third_party.pkg_resources import Requirement REQUIRED_ATTRIBUTES = ( 'extras', diff --git a/pex/environment.py b/pex/environment.py index bde20e602..316dc9091 100644 --- a/pex/environment.py +++ b/pex/environment.py @@ -19,15 +19,25 @@ from pex.package import distribution_compatible from pex.pex_info import PexInfo from pex.platforms import Platform -from pex.third_party.pkg_resources import ( +from pex.tracer import TRACER +from pex.util import CacheHelper, DistributionHelper + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ( DistributionNotFound, Environment, Requirement, WorkingSet, find_distributions -) -from pex.tracer import TRACER -from pex.util import CacheHelper, DistributionHelper + ) # vendor:skip +else: + from pex.third_party.pkg_resources import ( + DistributionNotFound, + Environment, + Requirement, + WorkingSet, + find_distributions + ) def _import_pkg_resources(): diff --git a/pex/finders.py b/pex/finders.py index a2b8aa568..f9f74accc 100644 --- a/pex/finders.py +++ b/pex/finders.py @@ -22,7 +22,10 @@ import sys import zipimport -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources if sys.version_info >= (3, 3) and sys.implementation.name == "cpython": import importlib.machinery as importlib_machinery diff --git a/pex/installer.py b/pex/installer.py index 3ae8e98e5..a663a30ba 100644 --- a/pex/installer.py +++ b/pex/installer.py @@ -36,15 +36,9 @@ def __init__(self, source_dir, interpreter=None, install_dir=None): """Create an installer from an unpacked source distribution in source_dir.""" self._source_dir = source_dir self._install_tmp = install_dir or safe_mkdtemp() + self._interpreter = interpreter or PythonInterpreter.get() self._installed = None - from pex import vendor - self._interpreter = vendor.setup_interpreter(distributions=self.mixins, - interpreter=interpreter or PythonInterpreter.get()) - if not self._interpreter.satisfies(self.mixins): - raise self.IncapableInterpreter('Interpreter %s not capable of running %s' % ( - self._interpreter.binary, self.__class__.__name__)) - @property def mixins(self): """Return a list of requirements to load into the setup script prior to invocation.""" @@ -59,34 +53,41 @@ def _setup_command(self): raise NotImplementedError @property - def bootstrap_script(self): + def setup_py_wrapper(self): + # NB: It would be more direct to just over-write setup.py by pre-pending the setuptools import. + # We cannot do this however because we would then run afoul of setup.py file in the wild with + # from __future__ imports. This mode of injecting the import works around that issue. return """ -import sys -sys.path.insert(0, {root!r}) - -# Expose vendored mixin path_items (setuptools, wheel, etc.) directly to the package's setup.py. -from pex import third_party -third_party.install(root={root!r}, expose={mixins!r}) +# We need to allow setuptools to monkeypatch distutils in case the underlying setup.py uses +# distutils; otherwise, we won't have access to distutils commands installed vi the +# `distutils.commands` `entrypoints` setup metadata (which is only supported by setuptools). +# The prime example here is `bdist_wheel` offered by the wheel dist. +import setuptools # Now execute the package's setup.py such that it sees itself as a setup.py executed via # `python setup.py ...` +import sys __file__ = 'setup.py' sys.argv[0] = __file__ with open(__file__, 'rb') as fp: exec(fp.read()) -""".format(root=third_party.isolated(), mixins=self.mixins) +""" def run(self): if self._installed is not None: return self._installed with TRACER.timed('Installing %s' % self._install_tmp, V=2): - command = [self._interpreter.binary, '-sE', '-'] + self._setup_command() + env = self._interpreter.sanitized_environment() + env['PYTHONPATH'] = os.pathsep.join(third_party.expose(self.mixins)) + env['__PEX_UNVENDORED__'] = '1' + + command = [self._interpreter.binary, '-s', '-'] + self._setup_command() try: Executor.execute(command, - env=self._interpreter.sanitized_environment(), + env=env, cwd=self._source_dir, - stdin_payload=self.bootstrap_script.encode('ascii')) + stdin_payload=self.setup_py_wrapper.encode('ascii')) self._installed = True except Executor.NonZeroExit as e: self._installed = False diff --git a/pex/interpreter.py b/pex/interpreter.py index 8518a99b7..883f3abff 100644 --- a/pex/interpreter.py +++ b/pex/interpreter.py @@ -22,9 +22,13 @@ get_impl_ver, get_impl_version_info ) -from pex.third_party.pkg_resources import Distribution, Requirement from pex.tracer import TRACER +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Distribution, Requirement # vendor:skip +else: + from pex.third_party.pkg_resources import Distribution, Requirement + try: from numbers import Integral except ImportError: diff --git a/pex/package.py b/pex/package.py index cc90537c5..ba34fd532 100644 --- a/pex/package.py +++ b/pex/package.py @@ -9,9 +9,13 @@ from pex.base import maybe_requirement from pex.link import Link from pex.pep425tags import get_supported -from pex.third_party.pkg_resources import EGG_NAME, parse_version, safe_name, safe_version from pex.util import Memoizer +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import EGG_NAME, parse_version, safe_name, safe_version # vendor:skip +else: + from pex.third_party.pkg_resources import EGG_NAME, parse_version, safe_name, safe_version + class Package(Link): """Base class for named Python binary packages (e.g. source, egg, wheel).""" diff --git a/pex/pex.py b/pex/pex.py index da65134f8..d52e3495e 100644 --- a/pex/pex.py +++ b/pex/pex.py @@ -8,7 +8,6 @@ from distutils import sysconfig from site import USER_SITE -import pex.third_party.pkg_resources as pkg_resources from pex import third_party from pex.bootstrap import Bootstrap from pex.common import die @@ -22,11 +21,20 @@ from pex.interpreter import PythonInterpreter from pex.orderedset import OrderedSet from pex.pex_info import PexInfo -from pex.third_party.pkg_resources import EntryPoint, WorkingSet, find_distributions from pex.tracer import TRACER from pex.util import iter_pth_paths, merge_split, named_temporary_file from pex.variables import ENV +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import EntryPoint, WorkingSet, find_distributions # vendor:skip +else: + from pex.third_party.pkg_resources import EntryPoint, WorkingSet, find_distributions + class DevNull(object): def __init__(self): diff --git a/pex/pex_builder.py b/pex/pex_builder.py index f39fe4434..4ddb01719 100644 --- a/pex/pex_builder.py +++ b/pex/pex_builder.py @@ -12,10 +12,14 @@ from pex.finders import get_entry_point_from_console_script, get_script_from_distributions from pex.interpreter import PythonInterpreter from pex.pex_info import PexInfo -from pex.third_party.pkg_resources import DefaultProvider, ZipProvider, get_provider from pex.tracer import TRACER from pex.util import CacheHelper, DistributionHelper +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import DefaultProvider, ZipProvider, get_provider # vendor:skip +else: + from pex.third_party.pkg_resources import DefaultProvider, ZipProvider, get_provider + BOOTSTRAP_DIR = '.bootstrap' LEGACY_BOOSTRAP_PKG = '_pex' @@ -293,7 +297,11 @@ def _add_dist_zip(self, path, dist_name): # into an importable shape. We can do that by installing it into its own # wheel dir. if dist_name.endswith("whl"): - from pex.third_party.wheel.install import WheelFile + if "__PEX_UNVENDORED__" in __import__("os").environ: + from wheel.install import WheelFile # vendor:skip + else: + from pex.third_party.wheel.install import WheelFile + tmp = safe_mkdtemp() whltmp = os.path.join(tmp, dist_name) os.mkdir(whltmp) diff --git a/pex/resolvable.py b/pex/resolvable.py index 31f68a9e6..345472514 100644 --- a/pex/resolvable.py +++ b/pex/resolvable.py @@ -13,7 +13,11 @@ from pex.installer import InstallerBase, Packager from pex.package import Package from pex.resolver_options import ResolverOptionsBuilder, ResolverOptionsInterface -from pex.third_party.pkg_resources import Requirement, safe_extra + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Requirement, safe_extra # vendor:skip +else: + from pex.third_party.pkg_resources import Requirement, safe_extra # Extract extras as specified per "declaring extras": # https://pythonhosted.org/setuptools/setuptools.html diff --git a/pex/resolver.py b/pex/resolver.py index 3fd9a764d..5ebcd55d1 100644 --- a/pex/resolver.py +++ b/pex/resolver.py @@ -10,7 +10,6 @@ from collections import namedtuple from contextlib import contextmanager -import pex.third_party.pkg_resources as pkg_resources from pex.common import safe_mkdir from pex.fetcher import Fetcher from pex.interpreter import PythonInterpreter @@ -20,10 +19,19 @@ from pex.platforms import Platform from pex.resolvable import ResolvableRequirement, resolvables_from_iterable from pex.resolver_options import ResolverOptionsBuilder -from pex.third_party.pkg_resources import safe_name from pex.tracer import TRACER from pex.util import DistributionHelper +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import safe_name # vendor:skip +else: + from pex.third_party.pkg_resources import safe_name + @contextmanager def patched_packing_env(env): diff --git a/pex/resolver_options.py b/pex/resolver_options.py index 4de803f20..58bbdb75f 100644 --- a/pex/resolver_options.py +++ b/pex/resolver_options.py @@ -10,9 +10,13 @@ from pex.iterator import Iterator from pex.package import EggPackage, SourcePackage, WheelPackage from pex.sorter import Sorter -from pex.third_party.pkg_resources import safe_name from pex.translator import ChainedTranslator, EggTranslator, SourceTranslator, WheelTranslator +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import safe_name # vendor:skip +else: + from pex.third_party.pkg_resources import safe_name + class ResolverOptionsInterface(object): def get_context(self): diff --git a/pex/third_party/__init__.py b/pex/third_party/__init__.py index e845b13a8..c7f39efd8 100644 --- a/pex/third_party/__init__.py +++ b/pex/third_party/__init__.py @@ -208,20 +208,35 @@ def install_vendored(cls, prefix, root=None, expose=None): if expose: # But only expose the bits needed. - path_by_key = OrderedDict((spec.key, spec.relpath) for spec in vendor.iter_vendor_specs() - if spec.key in expose) - path_by_key['pex'] = root # The pex distribution itself is trivially available to expose. - - unexposed = set(expose) - set(path_by_key.keys()) - if unexposed: - raise ValueError('The following vendored dists are not available to expose: {}' - .format(', '.join(sorted(unexposed)))) - - exposed_paths = path_by_key.values() - for exposed_path in exposed_paths: - sys.path.insert(0, os.path.join(root, exposed_path)) + exposed_paths = [] + for path in cls.expose(expose, root): + sys.path.insert(0, path) + exposed_paths.append(os.path.relpath(path, root)) + vendor_importer._expose(exposed_paths) + @classmethod + def expose(cls, dists, root=None): + from pex import vendor + + root = cls._abs_root(root) + + def iter_available(): + yield 'pex', root # The pex distribution itself is trivially available to expose. + for spec in vendor.iter_vendor_specs(): + yield spec.key, spec.relpath + + path_by_key = OrderedDict((key, relpath) for key, relpath in iter_available() if key in dists) + + unexposed = set(dists) - set(path_by_key.keys()) + if unexposed: + raise ValueError('The following vendored dists are not available to expose: {}' + .format(', '.join(sorted(unexposed)))) + + exposed_paths = path_by_key.values() + for exposed_path in exposed_paths: + yield os.path.join(root, exposed_path) + @classmethod def install(cls, uninstallable, prefix, path_items, root=None, warning=None): """Install an importer for modules found under ``path_items`` at the given import ``prefix``. @@ -396,5 +411,13 @@ def install(root=None, expose=None): VendorImporter.install_vendored(prefix=import_prefix(), root=root, expose=expose) +def expose(dists): + from pex.common import safe_delete + + for path in VendorImporter.expose(dists, root=isolated()): + safe_delete(os.path.join(path, '__init__.py')) + yield path + + # Implicitly install an importer for vendored code on the first import of pex.third_party. install() diff --git a/pex/util.py b/pex/util.py index 160ad514b..84e60d12a 100644 --- a/pex/util.py +++ b/pex/util.py @@ -15,12 +15,21 @@ from pex.common import rename_if_empty, safe_mkdir, safe_mkdtemp, safe_open from pex.compatibility import exec_function from pex.finders import register_finders -from pex.third_party.pkg_resources import ( + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ( + find_distributions, + resource_isdir, + resource_listdir, + resource_string + ) # vendor:skip +else: + from pex.third_party.pkg_resources import ( find_distributions, resource_isdir, resource_listdir, resource_string -) + ) class DistributionHelper(object): diff --git a/pex/vendor/__init__.py b/pex/vendor/__init__.py index c80f6a58b..d331e1d16 100644 --- a/pex/vendor/__init__.py +++ b/pex/vendor/__init__.py @@ -143,7 +143,11 @@ def vendor_runtime(chroot, dest_basedir, label, root_module_names): pkg_file = os.path.join(pkg_path, '__init__.py') src = os.path.join(VendorSpec.ROOT, pkg_file) dest = os.path.join(dest_basedir, pkg_file) - chroot.copy(src, dest, label) + if os.path.exists(src): + chroot.copy(src, dest, label) + else: + # We delete `pex/vendor/_vendored//__init__.py` when isolating third_party. + chroot.touch(dest, label) for name in vendored_names: vendor_module_names[name] = True TRACER.log('Vendoring {} from {} @ {}'.format(name, spec, spec.target_dir), V=3) diff --git a/pex/vendor/__main__.py b/pex/vendor/__main__.py index 1bda990a4..b06f8b680 100644 --- a/pex/vendor/__main__.py +++ b/pex/vendor/__main__.py @@ -61,6 +61,16 @@ def _find_literal_node(statement, call_argument): elif isinstance(call_argument.value, LiteralyEvaluable): return call_argument.value + @staticmethod + def _modify_import(original, modified): + indent = ' ' * (modified.absolute_bounding_box.top_left.column - 1) + return os.linesep.join(indent + line for line in ( + 'if "__PEX_UNVENDORED__" in __import__("os").environ:', + ' {} # vendor:skip'.format(original), + 'else:', + ' {}'.format(modified), + )) + @classmethod def for_path_items(cls, prefix, path_items): pkg_names = frozenset(pkg_name for _, pkg_name, _ in pkgutil.iter_modules(path=path_items)) @@ -98,10 +108,13 @@ def _modify__import__calls(self, red_baron): # noqa: We want __import__ as part root_package = value.split('.')[0] if root_package in self._packages: raw_value.replace('{!r}'.format(self._prefix + '.' + value)) + + parent.replace(self._modify_import(original, parent)) yield original, parent def _modify_import_statements(self, red_baron): for import_node in red_baron.find_all('ImportNode'): + modified = False if self._skip(import_node): continue @@ -129,6 +142,7 @@ def _modify_import_statements(self, red_baron): # imported). This ensures the code can traverse from the re-named root - `a` in this # example, through middle nodes (`a.b`) all the way to the leaf target (`a.b.c`). + modified = True def prefixed_fullname(): return '{prefix}.{module}'.format(prefix=self._prefix, module='.'.join(map(str, import_module))) @@ -144,6 +158,8 @@ def prefixed_fullname(): root=root_package.value) import_module.target = root_package.value + if modified: + import_node.replace(self._modify_import(original, import_node)) yield original, import_node def _modify_from_import_statements(self, red_baron): @@ -161,6 +177,8 @@ def _modify_from_import_statements(self, red_baron): if root_package.value in self._packages: root_package.replace('{prefix}.{root}'.format(prefix=self._prefix, root=root_package.value)) + + from_import_node.replace(self._modify_import(original, from_import_node)) yield original, from_import_node diff --git a/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py b/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py index 986a863e2..e31218395 100644 --- a/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py +++ b/pex/vendor/_vendored/setuptools/pkg_resources/__init__.py @@ -52,8 +52,16 @@ except NameError: FileExistsError = OSError -from pex.third_party.pkg_resources.extern import six -from pex.third_party.pkg_resources.extern.six.moves import urllib, map, filter +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern import six # vendor:skip +else: + from pex.third_party.pkg_resources.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.six.moves import urllib, map, filter # vendor:skip +else: + from pex.third_party.pkg_resources.extern.six.moves import urllib, map, filter + # capture these to bypass sandboxing from os import utime @@ -75,12 +83,36 @@ importlib_machinery = None from . import py31compat -from pex.third_party.pkg_resources.extern import appdirs -from pex.third_party.pkg_resources.extern import packaging -__import__('pex.third_party.pkg_resources.extern.packaging.version') -__import__('pex.third_party.pkg_resources.extern.packaging.specifiers') -__import__('pex.third_party.pkg_resources.extern.packaging.requirements') -__import__('pex.third_party.pkg_resources.extern.packaging.markers') +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern import appdirs # vendor:skip +else: + from pex.third_party.pkg_resources.extern import appdirs + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern import packaging # vendor:skip +else: + from pex.third_party.pkg_resources.extern import packaging + +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('pkg_resources.extern.packaging.version') # vendor:skip +else: + __import__('pex.third_party.pkg_resources.extern.packaging.version') + +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('pkg_resources.extern.packaging.specifiers') # vendor:skip +else: + __import__('pex.third_party.pkg_resources.extern.packaging.specifiers') + +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('pkg_resources.extern.packaging.requirements') # vendor:skip +else: + __import__('pex.third_party.pkg_resources.extern.packaging.requirements') + +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('pkg_resources.extern.packaging.markers') # vendor:skip +else: + __import__('pex.third_party.pkg_resources.extern.packaging.markers') + __metaclass__ = type diff --git a/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/markers.py b/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/markers.py index fc27edf4a..953d408af 100644 --- a/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/markers.py +++ b/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/markers.py @@ -8,9 +8,21 @@ import platform import sys -from pex.third_party.pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd -from pex.third_party.pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString -from pex.third_party.pkg_resources.extern.pyparsing import Literal as L # noqa +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import Literal as L # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import Literal as L + # noqa from ._compat import string_types from .specifiers import Specifier, InvalidSpecifier diff --git a/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/requirements.py b/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/requirements.py index 3a138e5ae..fb42a954a 100644 --- a/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/requirements.py +++ b/pex/vendor/_vendored/setuptools/pkg_resources/_vendor/packaging/requirements.py @@ -6,10 +6,26 @@ import string import re -from pex.third_party.pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException -from pex.third_party.pkg_resources.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine -from pex.third_party.pkg_resources.extern.pyparsing import Literal as L # noqa -from pex.third_party.pkg_resources.extern.six.moves.urllib import parse as urlparse +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.pyparsing import Literal as L # vendor:skip +else: + from pex.third_party.pkg_resources.extern.pyparsing import Literal as L + # noqa +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources.extern.six.moves.urllib import parse as urlparse # vendor:skip +else: + from pex.third_party.pkg_resources.extern.six.moves.urllib import parse as urlparse + from .markers import MARKER_EXPR, Marker from .specifiers import LegacySpecifier, Specifier, SpecifierSet diff --git a/pex/vendor/_vendored/setuptools/setuptools/__init__.py b/pex/vendor/_vendored/setuptools/setuptools/__init__.py index 47648607b..f613df9c9 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/__init__.py +++ b/pex/vendor/_vendored/setuptools/setuptools/__init__.py @@ -10,13 +10,37 @@ from ._deprecation_warning import SetuptoolsDeprecationWarning -from pex.third_party.setuptools.extern.six import PY3 -from pex.third_party.setuptools.extern.six.moves import filter, map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six import PY3 # vendor:skip +else: + from pex.third_party.setuptools.extern.six import PY3 + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import filter, map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import filter, map + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools.version # vendor:skip +else: + import pex.third_party.setuptools.version, pex.third_party.setuptools as setuptools + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extension import Extension # vendor:skip +else: + from pex.third_party.setuptools.extension import Extension + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.dist import Distribution, Feature # vendor:skip +else: + from pex.third_party.setuptools.dist import Distribution, Feature + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.depends import Require # vendor:skip +else: + from pex.third_party.setuptools.depends import Require -import pex.third_party.setuptools.version, pex.third_party.setuptools as setuptools -from pex.third_party.setuptools.extension import Extension -from pex.third_party.setuptools.dist import Distribution, Feature -from pex.third_party.setuptools.depends import Require from . import monkey __metaclass__ = type diff --git a/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/markers.py b/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/markers.py index 5892bd4ed..d86fb71d7 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/markers.py +++ b/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/markers.py @@ -8,9 +8,21 @@ import platform import sys -from pex.third_party.setuptools.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd -from pex.third_party.setuptools.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString -from pex.third_party.setuptools.extern.pyparsing import Literal as L # noqa +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import ParseException, ParseResults, stringStart, stringEnd + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import ZeroOrMore, Group, Forward, QuotedString + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import Literal as L # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import Literal as L + # noqa from ._compat import string_types from .specifiers import Specifier, InvalidSpecifier diff --git a/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/requirements.py b/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/requirements.py index e0b91ed9c..907fac057 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/requirements.py +++ b/pex/vendor/_vendored/setuptools/setuptools/_vendor/packaging/requirements.py @@ -6,10 +6,26 @@ import string import re -from pex.third_party.setuptools.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException -from pex.third_party.setuptools.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine -from pex.third_party.setuptools.extern.pyparsing import Literal as L # noqa -from pex.third_party.setuptools.extern.six.moves.urllib import parse as urlparse +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import ZeroOrMore, Word, Optional, Regex, Combine + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.pyparsing import Literal as L # vendor:skip +else: + from pex.third_party.setuptools.extern.pyparsing import Literal as L + # noqa +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves.urllib import parse as urlparse # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves.urllib import parse as urlparse + from .markers import MARKER_EXPR, Marker from .specifiers import LegacySpecifier, Specifier, SpecifierSet diff --git a/pex/vendor/_vendored/setuptools/setuptools/archive_util.py b/pex/vendor/_vendored/setuptools/setuptools/archive_util.py index 63f0608c2..3fccb4819 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/archive_util.py +++ b/pex/vendor/_vendored/setuptools/setuptools/archive_util.py @@ -8,7 +8,11 @@ import contextlib from distutils.errors import DistutilsError -from pex.third_party.pkg_resources import ensure_directory +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ensure_directory # vendor:skip +else: + from pex.third_party.pkg_resources import ensure_directory + __all__ = [ "unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter", diff --git a/pex/vendor/_vendored/setuptools/setuptools/build_meta.py b/pex/vendor/_vendored/setuptools/setuptools/build_meta.py index 93a572489..4f842cdde 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/build_meta.py +++ b/pex/vendor/_vendored/setuptools/setuptools/build_meta.py @@ -32,7 +32,11 @@ import shutil import contextlib -import pex.third_party.setuptools as setuptools +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools + import distutils diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/__init__.py b/pex/vendor/_vendored/setuptools/setuptools/command/__init__.py index 548a80f45..141ba62a3 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/__init__.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/__init__.py @@ -9,7 +9,11 @@ from distutils.command.bdist import bdist import sys -from pex.third_party.setuptools.command import install_scripts +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command import install_scripts # vendor:skip +else: + from pex.third_party.setuptools.command import install_scripts + if 'egg' not in bdist.format_commands: bdist.format_command['egg'] = ('bdist_egg', "Python .egg file") diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/alias.py b/pex/vendor/_vendored/setuptools/setuptools/command/alias.py index 98e5be6b3..cc5438d48 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/alias.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/alias.py @@ -1,8 +1,16 @@ from distutils.errors import DistutilsOptionError -from pex.third_party.setuptools.extern.six.moves import map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.setopt import edit_config, option_base, config_file # vendor:skip +else: + from pex.third_party.setuptools.command.setopt import edit_config, option_base, config_file -from pex.third_party.setuptools.command.setopt import edit_config, option_base, config_file def shquote(arg): diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/bdist_egg.py b/pex/vendor/_vendored/setuptools/setuptools/command/bdist_egg.py index 2f8323fb1..78583b33c 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/bdist_egg.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/bdist_egg.py @@ -12,12 +12,32 @@ import textwrap import marshal -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import get_build_platform, Distribution, ensure_directory # vendor:skip +else: + from pex.third_party.pkg_resources import get_build_platform, Distribution, ensure_directory + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import EntryPoint # vendor:skip +else: + from pex.third_party.pkg_resources import EntryPoint + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extension import Library # vendor:skip +else: + from pex.third_party.setuptools.extension import Library + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command -from pex.third_party.pkg_resources import get_build_platform, Distribution, ensure_directory -from pex.third_party.pkg_resources import EntryPoint -from pex.third_party.setuptools.extension import Library -from pex.third_party.setuptools import Command try: # Python 2.7 or >=3.2 diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/build_clib.py b/pex/vendor/_vendored/setuptools/setuptools/command/build_clib.py index db5fae281..d19c18f09 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/build_clib.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/build_clib.py @@ -1,7 +1,11 @@ import distutils.command.build_clib as orig from distutils.errors import DistutilsSetupError from distutils import log -from pex.third_party.setuptools.dep_util import newer_pairwise_group +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.dep_util import newer_pairwise_group # vendor:skip +else: + from pex.third_party.setuptools.dep_util import newer_pairwise_group + class build_clib(orig.build_clib): diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/build_ext.py b/pex/vendor/_vendored/setuptools/setuptools/command/build_ext.py index 365b43eca..6a43122ef 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/build_ext.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/build_ext.py @@ -9,8 +9,16 @@ from distutils.errors import DistutilsError from distutils import log -from pex.third_party.setuptools.extension import Library -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extension import Library # vendor:skip +else: + from pex.third_party.setuptools.extension import Library + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + try: # Attempt to use Cython for building extensions, if available diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/build_py.py b/pex/vendor/_vendored/setuptools/setuptools/command/build_py.py index 151476a55..86d5f4dae 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/build_py.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/build_py.py @@ -8,11 +8,23 @@ import distutils.errors import itertools -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import map, filter, filterfalse +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map, filter, filterfalse # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map, filter, filterfalse + try: - from pex.third_party.setuptools.lib2to3_ex import Mixin2to3 + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.lib2to3_ex import Mixin2to3 # vendor:skip + else: + from pex.third_party.setuptools.lib2to3_ex import Mixin2to3 + except ImportError: class Mixin2to3: diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/develop.py b/pex/vendor/_vendored/setuptools/setuptools/command/develop.py index 50dc10782..a71a494d6 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/develop.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/develop.py @@ -5,12 +5,32 @@ import glob import io -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Distribution, PathMetadata, normalize_path # vendor:skip +else: + from pex.third_party.pkg_resources import Distribution, PathMetadata, normalize_path + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.easy_install import easy_install # vendor:skip +else: + from pex.third_party.setuptools.command.easy_install import easy_install + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import namespaces # vendor:skip +else: + from pex.third_party.setuptools import namespaces + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools -from pex.third_party.pkg_resources import Distribution, PathMetadata, normalize_path -from pex.third_party.setuptools.command.easy_install import easy_install -from pex.third_party.setuptools import namespaces -import pex.third_party.setuptools as setuptools __metaclass__ = type diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/easy_install.py b/pex/vendor/_vendored/setuptools/setuptools/command/easy_install.py index cfd61cfcc..365c4b4cf 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/easy_install.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/easy_install.py @@ -43,28 +43,87 @@ from sysconfig import get_config_vars, get_path -from pex.third_party.setuptools import SetuptoolsDeprecationWarning +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import SetuptoolsDeprecationWarning # vendor:skip +else: + from pex.third_party.setuptools import SetuptoolsDeprecationWarning + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import configparser, map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import configparser, map + -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import configparser, map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.sandbox import run_setup # vendor:skip +else: + from pex.third_party.setuptools.sandbox import run_setup -from pex.third_party.setuptools import Command -from pex.third_party.setuptools.sandbox import run_setup -from pex.third_party.setuptools.py27compat import rmtree_safe -from pex.third_party.setuptools.command import setopt -from pex.third_party.setuptools.archive_util import unpack_archive -from pex.third_party.setuptools.package_index import ( +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.py27compat import rmtree_safe # vendor:skip +else: + from pex.third_party.setuptools.py27compat import rmtree_safe + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command import setopt # vendor:skip +else: + from pex.third_party.setuptools.command import setopt + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.archive_util import unpack_archive # vendor:skip +else: + from pex.third_party.setuptools.archive_util import unpack_archive + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.package_index import ( + PackageIndex, parse_requirement_arg, URL_SCHEME, +) # vendor:skip +else: + from pex.third_party.setuptools.package_index import ( PackageIndex, parse_requirement_arg, URL_SCHEME, ) -from pex.third_party.setuptools.command import bdist_egg, egg_info -from pex.third_party.setuptools.wheel import Wheel -from pex.third_party.pkg_resources import ( + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command import bdist_egg, egg_info # vendor:skip +else: + from pex.third_party.setuptools.command import bdist_egg, egg_info + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.wheel import Wheel # vendor:skip +else: + from pex.third_party.setuptools.wheel import Wheel + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ( + yield_lines, normalize_path, resource_string, ensure_directory, + get_distribution, find_distributions, Environment, Requirement, + Distribution, PathMetadata, EggMetadata, WorkingSet, DistributionNotFound, + VersionConflict, DEVELOP_DIST, +) # vendor:skip +else: + from pex.third_party.pkg_resources import ( yield_lines, normalize_path, resource_string, ensure_directory, get_distribution, find_distributions, Environment, Requirement, Distribution, PathMetadata, EggMetadata, WorkingSet, DistributionNotFound, VersionConflict, DEVELOP_DIST, ) -import pex.third_party.pkg_resources.py31compat, pex.third_party.pkg_resources as pkg_resources + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources.py31compat # vendor:skip +else: + import pex.third_party.pkg_resources.py31compat, pex.third_party.pkg_resources as pkg_resources + __metaclass__ = type @@ -2286,7 +2345,11 @@ def current_umask(): def bootstrap(): # This function is called when setuptools*.egg is run using /bin/sh - import pex.third_party.setuptools as setuptools + if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip + else: + import pex.third_party.setuptools as setuptools + argv0 = os.path.dirname(setuptools.__path__[0]) sys.argv[0] = argv0 @@ -2295,8 +2358,16 @@ def bootstrap(): def main(argv=None, **kw): - from pex.third_party.setuptools import setup - from pex.third_party.setuptools.dist import Distribution + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import setup # vendor:skip + else: + from pex.third_party.setuptools import setup + + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.dist import Distribution # vendor:skip + else: + from pex.third_party.setuptools.dist import Distribution + class DistributionWithoutHelpCommands(Distribution): common_usage = "" diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/egg_info.py b/pex/vendor/_vendored/setuptools/setuptools/command/egg_info.py index d762e3da6..61c756b08 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/egg_info.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/egg_info.py @@ -16,22 +16,72 @@ import time import collections -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import map - -from pex.third_party.setuptools import Command -from pex.third_party.setuptools.command.sdist import sdist -from pex.third_party.setuptools.command.sdist import walk_revctrl -from pex.third_party.setuptools.command.setopt import edit_config -from pex.third_party.setuptools.command import bdist_egg -from pex.third_party.pkg_resources import ( +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.sdist import sdist # vendor:skip +else: + from pex.third_party.setuptools.command.sdist import sdist + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.sdist import walk_revctrl # vendor:skip +else: + from pex.third_party.setuptools.command.sdist import walk_revctrl + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.setopt import edit_config # vendor:skip +else: + from pex.third_party.setuptools.command.setopt import edit_config + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command import bdist_egg # vendor:skip +else: + from pex.third_party.setuptools.command import bdist_egg + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ( + parse_requirements, safe_name, parse_version, + safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename) # vendor:skip +else: + from pex.third_party.pkg_resources import ( parse_requirements, safe_name, parse_version, safe_version, yield_lines, EntryPoint, iter_entry_points, to_filename) -import pex.third_party.setuptools.unicode_utils as unicode_utils -from pex.third_party.setuptools.glob import glob -from pex.third_party.setuptools.extern import packaging -from pex.third_party.setuptools import SetuptoolsDeprecationWarning +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools.unicode_utils as unicode_utils # vendor:skip +else: + import pex.third_party.setuptools.unicode_utils as unicode_utils + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.glob import glob # vendor:skip +else: + from pex.third_party.setuptools.glob import glob + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import packaging # vendor:skip +else: + from pex.third_party.setuptools.extern import packaging + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import SetuptoolsDeprecationWarning # vendor:skip +else: + from pex.third_party.setuptools import SetuptoolsDeprecationWarning + def translate_pattern(glob): """ diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/install.py b/pex/vendor/_vendored/setuptools/setuptools/command/install.py index 2569b932f..acd1c52b7 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/install.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/install.py @@ -5,7 +5,11 @@ import platform import distutils.command.install as orig -import pex.third_party.setuptools as setuptools +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools + # Prior to numpy 1.9, NumPy relies on the '_install' name, so provide it for # now. See https://github.com/pypa/setuptools/issues/199/ diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/install_egg_info.py b/pex/vendor/_vendored/setuptools/setuptools/command/install_egg_info.py index 6358d733d..202d8276a 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/install_egg_info.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/install_egg_info.py @@ -1,10 +1,26 @@ from distutils import log, dir_util import os -from pex.third_party.setuptools import Command -from pex.third_party.setuptools import namespaces -from pex.third_party.setuptools.archive_util import unpack_archive -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import namespaces # vendor:skip +else: + from pex.third_party.setuptools import namespaces + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.archive_util import unpack_archive # vendor:skip +else: + from pex.third_party.setuptools.archive_util import unpack_archive + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + class install_egg_info(namespaces.Installer, Command): diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/install_lib.py b/pex/vendor/_vendored/setuptools/setuptools/command/install_lib.py index 962b0639a..89d7f1472 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/install_lib.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/install_lib.py @@ -95,7 +95,11 @@ def copy_tree( # Exclude namespace package __init__.py* files from the output - from pex.third_party.setuptools.archive_util import unpack_directory + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.archive_util import unpack_directory # vendor:skip + else: + from pex.third_party.setuptools.archive_util import unpack_directory + from distutils import log outfiles = [] diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/install_scripts.py b/pex/vendor/_vendored/setuptools/setuptools/command/install_scripts.py index 2b9f842bf..f42a8ff01 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/install_scripts.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/install_scripts.py @@ -3,7 +3,11 @@ import os import sys -from pex.third_party.pkg_resources import Distribution, PathMetadata, ensure_directory +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Distribution, PathMetadata, ensure_directory # vendor:skip +else: + from pex.third_party.pkg_resources import Distribution, PathMetadata, ensure_directory + class install_scripts(orig.install_scripts): @@ -14,7 +18,11 @@ def initialize_options(self): self.no_ep = False def run(self): - import pex.third_party.setuptools.command.easy_install as ei + if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools.command.easy_install as ei # vendor:skip + else: + import pex.third_party.setuptools.command.easy_install as ei + self.run_command("egg_info") if self.distribution.scripts: @@ -50,7 +58,11 @@ def run(self): def write_script(self, script_name, contents, mode="t", *ignored): """Write an executable file to the scripts directory""" - from pex.third_party.setuptools.command.easy_install import chmod, current_umask + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.easy_install import chmod, current_umask # vendor:skip + else: + from pex.third_party.setuptools.command.easy_install import chmod, current_umask + log.info("Installing %s script to %s", script_name, self.install_dir) target = os.path.join(self.install_dir, script_name) diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/py36compat.py b/pex/vendor/_vendored/setuptools/setuptools/command/py36compat.py index edc8c4d9d..33ff76e9e 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/py36compat.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/py36compat.py @@ -3,7 +3,11 @@ from distutils.util import convert_path from distutils.command import sdist -from pex.third_party.setuptools.extern.six.moves import filter +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import filter # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import filter + class sdist_add_defaults: diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/rotate.py b/pex/vendor/_vendored/setuptools/setuptools/command/rotate.py index dfa2a791d..b263acc27 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/rotate.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/rotate.py @@ -4,9 +4,17 @@ import os import shutil -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command -from pex.third_party.setuptools import Command class rotate(Command): diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/saveopts.py b/pex/vendor/_vendored/setuptools/setuptools/command/saveopts.py index adedf8dea..59ac03db5 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/saveopts.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/saveopts.py @@ -1,4 +1,8 @@ -from pex.third_party.setuptools.command.setopt import edit_config, option_base +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.setopt import edit_config, option_base # vendor:skip +else: + from pex.third_party.setuptools.command.setopt import edit_config, option_base + class saveopts(option_base): diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/sdist.py b/pex/vendor/_vendored/setuptools/setuptools/command/sdist.py index 2fec7deae..d0abb6769 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/sdist.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/sdist.py @@ -5,11 +5,19 @@ import io import contextlib -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + from .py36compat import sdist_add_defaults -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + _default_revctrl = list diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/setopt.py b/pex/vendor/_vendored/setuptools/setuptools/command/setopt.py index 666ba02d4..dcef5b9d4 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/setopt.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/setopt.py @@ -4,9 +4,17 @@ import distutils import os -from pex.third_party.setuptools.extern.six.moves import configparser +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import configparser # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import configparser + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command -from pex.third_party.setuptools import Command __all__ = ['config_file', 'edit_config', 'option_base', 'setopt'] diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/test.py b/pex/vendor/_vendored/setuptools/setuptools/command/test.py index 0150a94a1..191b38f24 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/test.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/test.py @@ -8,13 +8,31 @@ from distutils import log from unittest import TestLoader -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import map, filter +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six -from pex.third_party.pkg_resources import (resource_listdir, resource_exists, normalize_path, +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map, filter # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map, filter + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import (resource_listdir, resource_exists, normalize_path, + working_set, _namespace_packages, evaluate_marker, + add_activation_listener, require, EntryPoint) # vendor:skip +else: + from pex.third_party.pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) -from pex.third_party.setuptools import Command + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Command # vendor:skip +else: + from pex.third_party.setuptools import Command + __metaclass__ = type diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/upload.py b/pex/vendor/_vendored/setuptools/setuptools/command/upload.py index 9358cf598..ff2370639 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/upload.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/upload.py @@ -12,9 +12,21 @@ from distutils.errors import DistutilsError -from pex.third_party.setuptools.extern.six.moves.urllib.request import urlopen, Request -from pex.third_party.setuptools.extern.six.moves.urllib.error import HTTPError -from pex.third_party.setuptools.extern.six.moves.urllib.parse import urlparse +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves.urllib.request import urlopen, Request # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves.urllib.request import urlopen, Request + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves.urllib.error import HTTPError # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves.urllib.error import HTTPError + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves.urllib.parse import urlparse # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves.urllib.parse import urlparse + class upload(orig.upload): """ diff --git a/pex/vendor/_vendored/setuptools/setuptools/command/upload_docs.py b/pex/vendor/_vendored/setuptools/setuptools/command/upload_docs.py index ffba7a893..d5dfd4931 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/command/upload_docs.py +++ b/pex/vendor/_vendored/setuptools/setuptools/command/upload_docs.py @@ -16,10 +16,22 @@ import itertools import functools -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import http_client, urllib +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import http_client, urllib # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import http_client, urllib + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import iter_entry_points # vendor:skip +else: + from pex.third_party.pkg_resources import iter_entry_points -from pex.third_party.pkg_resources import iter_entry_points from .upload import upload diff --git a/pex/vendor/_vendored/setuptools/setuptools/config.py b/pex/vendor/_vendored/setuptools/setuptools/config.py index 9cd5cd64e..f46588fee 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/config.py +++ b/pex/vendor/_vendored/setuptools/setuptools/config.py @@ -11,8 +11,16 @@ from importlib import import_module from distutils.errors import DistutilsOptionError, DistutilsFileError -from pex.third_party.setuptools.extern.packaging.version import LegacyVersion, parse -from pex.third_party.setuptools.extern.six import string_types, PY3 +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.packaging.version import LegacyVersion, parse # vendor:skip +else: + from pex.third_party.setuptools.extern.packaging.version import LegacyVersion, parse + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six import string_types, PY3 # vendor:skip +else: + from pex.third_party.setuptools.extern.six import string_types, PY3 + __metaclass__ = type @@ -35,7 +43,11 @@ def read_configuration( :rtype: dict """ - from pex.third_party.setuptools.dist import Distribution, _Distribution + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.dist import Distribution, _Distribution # vendor:skip + else: + from pex.third_party.setuptools.dist import Distribution, _Distribution + filepath = os.path.abspath(filepath) @@ -557,9 +569,17 @@ def _parse_packages(self, value): self.sections.get('packages.find', {})) if findns: - from pex.third_party.setuptools import find_namespace_packages as find_packages + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import find_namespace_packages as find_packages # vendor:skip + else: + from pex.third_party.setuptools import find_namespace_packages as find_packages + else: - from pex.third_party.setuptools import find_packages + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import find_packages # vendor:skip + else: + from pex.third_party.setuptools import find_packages + return find_packages(**find_kwargs) diff --git a/pex/vendor/_vendored/setuptools/setuptools/dist.py b/pex/vendor/_vendored/setuptools/setuptools/dist.py index ba649a2bd..1364c6c8e 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/dist.py +++ b/pex/vendor/_vendored/setuptools/setuptools/dist.py @@ -21,21 +21,61 @@ from distutils.util import rfc822_escape from distutils.version import StrictVersion -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern import packaging -from pex.third_party.setuptools.extern.six.moves import map, filter, filterfalse +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import packaging # vendor:skip +else: + from pex.third_party.setuptools.extern import packaging + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map, filter, filterfalse # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map, filter, filterfalse + from . import SetuptoolsDeprecationWarning -from pex.third_party.setuptools.depends import Require -from pex.third_party.setuptools import windows_support -from pex.third_party.setuptools.monkey import get_unpatched -from pex.third_party.setuptools.config import parse_configuration -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.depends import Require # vendor:skip +else: + from pex.third_party.setuptools.depends import Require + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import windows_support # vendor:skip +else: + from pex.third_party.setuptools import windows_support + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.monkey import get_unpatched # vendor:skip +else: + from pex.third_party.setuptools.monkey import get_unpatched + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.config import parse_configuration # vendor:skip +else: + from pex.third_party.setuptools.config import parse_configuration + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + from .py36compat import Distribution_parse_config_files -__import__('pex.third_party.setuptools.extern.packaging.specifiers') -__import__('pex.third_party.setuptools.extern.packaging.version') +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('setuptools.extern.packaging.specifiers') # vendor:skip +else: + __import__('pex.third_party.setuptools.extern.packaging.specifiers') + +if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('setuptools.extern.packaging.version') # vendor:skip +else: + __import__('pex.third_party.setuptools.extern.packaging.version') + def _get_unpatched(cls): @@ -625,7 +665,11 @@ def get_egg_cache_dir(self): def fetch_build_egg(self, req): """Fetch an egg needed for building""" - from pex.third_party.setuptools.command.easy_install import easy_install + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.easy_install import easy_install # vendor:skip + else: + from pex.third_party.setuptools.command.easy_install import easy_install + dist = self.__class__({'script_args': ['easy_install']}) opts = dist.get_option_dict('easy_install') opts.clear() diff --git a/pex/vendor/_vendored/setuptools/setuptools/extension.py b/pex/vendor/_vendored/setuptools/setuptools/extension.py index 53cc9cf08..855348136 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/extension.py +++ b/pex/vendor/_vendored/setuptools/setuptools/extension.py @@ -4,7 +4,11 @@ import distutils.errors import distutils.extension -from pex.third_party.setuptools.extern.six.moves import map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map + from .monkey import get_unpatched diff --git a/pex/vendor/_vendored/setuptools/setuptools/lib2to3_ex.py b/pex/vendor/_vendored/setuptools/setuptools/lib2to3_ex.py index 6ddce4a6b..4292ac059 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/lib2to3_ex.py +++ b/pex/vendor/_vendored/setuptools/setuptools/lib2to3_ex.py @@ -11,7 +11,11 @@ from distutils import log from lib2to3.refactor import RefactoringTool, get_fixers_from_package -import pex.third_party.setuptools as setuptools +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools + class DistutilsRefactoringTool(RefactoringTool): diff --git a/pex/vendor/_vendored/setuptools/setuptools/monkey.py b/pex/vendor/_vendored/setuptools/setuptools/monkey.py index 54d511faf..07be46f33 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/monkey.py +++ b/pex/vendor/_vendored/setuptools/setuptools/monkey.py @@ -10,9 +10,17 @@ from importlib import import_module import inspect -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools -import pex.third_party.setuptools as setuptools __all__ = [] """ diff --git a/pex/vendor/_vendored/setuptools/setuptools/msvc.py b/pex/vendor/_vendored/setuptools/setuptools/msvc.py index eb81cab7b..7cb3d5d1f 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/msvc.py +++ b/pex/vendor/_vendored/setuptools/setuptools/msvc.py @@ -22,14 +22,26 @@ import platform import itertools import distutils.errors -from pex.third_party.setuptools.extern.packaging.version import LegacyVersion +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.packaging.version import LegacyVersion # vendor:skip +else: + from pex.third_party.setuptools.extern.packaging.version import LegacyVersion + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import filterfalse # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import filterfalse -from pex.third_party.setuptools.extern.six.moves import filterfalse from .monkey import get_unpatched if platform.system() == 'Windows': - from pex.third_party.setuptools.extern.six.moves import winreg + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import winreg # vendor:skip + else: + from pex.third_party.setuptools.extern.six.moves import winreg + safe_env = os.environ else: """ diff --git a/pex/vendor/_vendored/setuptools/setuptools/namespaces.py b/pex/vendor/_vendored/setuptools/setuptools/namespaces.py index 1dbbd5196..b37013cbf 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/namespaces.py +++ b/pex/vendor/_vendored/setuptools/setuptools/namespaces.py @@ -2,7 +2,11 @@ from distutils import log import itertools -from pex.third_party.setuptools.extern.six.moves import map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import map + flatten = itertools.chain.from_iterable diff --git a/pex/vendor/_vendored/setuptools/setuptools/package_index.py b/pex/vendor/_vendored/setuptools/setuptools/package_index.py index 56ebbd41b..a823883e6 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/package_index.py +++ b/pex/vendor/_vendored/setuptools/setuptools/package_index.py @@ -10,22 +10,58 @@ import warnings from functools import wraps -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import urllib, http_client, configparser, map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six -import pex.third_party.setuptools as setuptools -from pex.third_party.pkg_resources import ( +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import urllib, http_client, configparser, map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import urllib, http_client, configparser, map + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import setuptools # vendor:skip +else: + import pex.third_party.setuptools as setuptools + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ( + CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST, + Environment, find_distributions, safe_name, safe_version, + to_filename, Requirement, DEVELOP_DIST, EGG_DIST, +) # vendor:skip +else: + from pex.third_party.pkg_resources import ( CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST, Environment, find_distributions, safe_name, safe_version, to_filename, Requirement, DEVELOP_DIST, EGG_DIST, ) -from pex.third_party.setuptools import ssl_support + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import ssl_support # vendor:skip +else: + from pex.third_party.setuptools import ssl_support + from distutils import log from distutils.errors import DistutilsError from fnmatch import translate -from pex.third_party.setuptools.py27compat import get_all_headers -from pex.third_party.setuptools.py33compat import unescape -from pex.third_party.setuptools.wheel import Wheel +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.py27compat import get_all_headers # vendor:skip +else: + from pex.third_party.setuptools.py27compat import get_all_headers + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.py33compat import unescape # vendor:skip +else: + from pex.third_party.setuptools.py33compat import unescape + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.wheel import Wheel # vendor:skip +else: + from pex.third_party.setuptools.wheel import Wheel + __metaclass__ = type @@ -690,7 +726,11 @@ def gen_setup(self, filename, fragment, tmpdir): # Make sure the file has been downloaded to the temp dir. if os.path.dirname(filename) != tmpdir: dst = os.path.join(tmpdir, basename) - from pex.third_party.setuptools.command.easy_install import samefile + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.easy_install import samefile # vendor:skip + else: + from pex.third_party.setuptools.command.easy_install import samefile + if not samefile(filename, dst): shutil.copy2(filename, dst) filename = dst diff --git a/pex/vendor/_vendored/setuptools/setuptools/py27compat.py b/pex/vendor/_vendored/setuptools/setuptools/py27compat.py index cf58dd312..ac9eedb1b 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/py27compat.py +++ b/pex/vendor/_vendored/setuptools/setuptools/py27compat.py @@ -4,7 +4,11 @@ import platform -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + def get_all_headers(message, key): diff --git a/pex/vendor/_vendored/setuptools/setuptools/py33compat.py b/pex/vendor/_vendored/setuptools/setuptools/py33compat.py index 83cf2b810..7af7a406c 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/py33compat.py +++ b/pex/vendor/_vendored/setuptools/setuptools/py33compat.py @@ -7,8 +7,16 @@ except ImportError: html = None -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import html_parser +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import html_parser # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import html_parser + __metaclass__ = type diff --git a/pex/vendor/_vendored/setuptools/setuptools/sandbox.py b/pex/vendor/_vendored/setuptools/setuptools/sandbox.py index 1480a3018..29dfde208 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/sandbox.py +++ b/pex/vendor/_vendored/setuptools/setuptools/sandbox.py @@ -9,10 +9,22 @@ import pickle import textwrap -from pex.third_party.setuptools.extern import six -from pex.third_party.setuptools.extern.six.moves import builtins, map +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import builtins, map # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import builtins, map + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources.py31compat # vendor:skip +else: + import pex.third_party.pkg_resources.py31compat, pex.third_party.pkg_resources as pkg_resources -import pex.third_party.pkg_resources.py31compat, pex.third_party.pkg_resources as pkg_resources if sys.platform.startswith('java'): import org.python.modules.posix.PosixModule as _os @@ -24,7 +36,11 @@ _file = None _open = open from distutils.errors import DistutilsError -from pex.third_party.pkg_resources import working_set +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import working_set # vendor:skip +else: + from pex.third_party.pkg_resources import working_set + __all__ = [ @@ -107,7 +123,11 @@ def dump(type, exc): return pickle.dumps(type), pickle.dumps(exc) except Exception: # get UnpickleableException inside the sandbox - from pex.third_party.setuptools.sandbox import UnpickleableException as cls + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.sandbox import UnpickleableException as cls # vendor:skip + else: + from pex.third_party.setuptools.sandbox import UnpickleableException as cls + return cls.dump(cls, cls(repr(exc))) @@ -191,7 +211,11 @@ def setup_context(setup_dir): with override_temp(temp_dir): with pushd(setup_dir): # ensure setuptools commands are available - __import__('pex.third_party.setuptools') + if "__PEX_UNVENDORED__" in __import__("os").environ: + __import__('setuptools') # vendor:skip + else: + __import__('pex.third_party.setuptools') + yield @@ -403,7 +427,11 @@ def __init__(self, sandbox, exceptions=_EXCEPTIONS): AbstractSandbox.__init__(self) def _violation(self, operation, *args, **kw): - from pex.third_party.setuptools.sandbox import SandboxViolation + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.sandbox import SandboxViolation # vendor:skip + else: + from pex.third_party.setuptools.sandbox import SandboxViolation + raise SandboxViolation(operation, args, kw) if _file: diff --git a/pex/vendor/_vendored/setuptools/setuptools/ssl_support.py b/pex/vendor/_vendored/setuptools/setuptools/ssl_support.py index a55f5bfdf..46a0150e5 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/ssl_support.py +++ b/pex/vendor/_vendored/setuptools/setuptools/ssl_support.py @@ -4,9 +4,17 @@ import re import functools -from pex.third_party.setuptools.extern.six.moves import urllib, http_client, map, filter +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six.moves import urllib, http_client, map, filter # vendor:skip +else: + from pex.third_party.setuptools.extern.six.moves import urllib, http_client, map, filter + + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import ResolutionError, ExtractionError # vendor:skip +else: + from pex.third_party.pkg_resources import ResolutionError, ExtractionError -from pex.third_party.pkg_resources import ResolutionError, ExtractionError try: import ssl diff --git a/pex/vendor/_vendored/setuptools/setuptools/unicode_utils.py b/pex/vendor/_vendored/setuptools/setuptools/unicode_utils.py index 11eef1c4a..8a33c4aff 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/unicode_utils.py +++ b/pex/vendor/_vendored/setuptools/setuptools/unicode_utils.py @@ -1,7 +1,11 @@ import unicodedata import sys -from pex.third_party.setuptools.extern import six +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern import six # vendor:skip +else: + from pex.third_party.setuptools.extern import six + # HFS Plus uses decomposed UTF-8 diff --git a/pex/vendor/_vendored/setuptools/setuptools/version.py b/pex/vendor/_vendored/setuptools/setuptools/version.py index 2456ab2c1..bead7cac9 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/version.py +++ b/pex/vendor/_vendored/setuptools/setuptools/version.py @@ -1,4 +1,8 @@ -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + try: __version__ = pkg_resources.get_distribution('setuptools').version diff --git a/pex/vendor/_vendored/setuptools/setuptools/wheel.py b/pex/vendor/_vendored/setuptools/setuptools/wheel.py index 6832f15c5..6b6c5591f 100644 --- a/pex/vendor/_vendored/setuptools/setuptools/wheel.py +++ b/pex/vendor/_vendored/setuptools/setuptools/wheel.py @@ -8,12 +8,36 @@ import re import zipfile -from pex.third_party.pkg_resources import Distribution, PathMetadata, parse_version -from pex.third_party.setuptools.extern.packaging.utils import canonicalize_name -from pex.third_party.setuptools.extern.six import PY3 -from pex.third_party.setuptools import Distribution as SetuptoolsDistribution -from pex.third_party.setuptools import pep425tags -from pex.third_party.setuptools.command.egg_info import write_requirements +if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Distribution, PathMetadata, parse_version # vendor:skip +else: + from pex.third_party.pkg_resources import Distribution, PathMetadata, parse_version + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.packaging.utils import canonicalize_name # vendor:skip +else: + from pex.third_party.setuptools.extern.packaging.utils import canonicalize_name + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.extern.six import PY3 # vendor:skip +else: + from pex.third_party.setuptools.extern.six import PY3 + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import Distribution as SetuptoolsDistribution # vendor:skip +else: + from pex.third_party.setuptools import Distribution as SetuptoolsDistribution + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools import pep425tags # vendor:skip +else: + from pex.third_party.setuptools import pep425tags + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command.egg_info import write_requirements # vendor:skip +else: + from pex.third_party.setuptools.command.egg_info import write_requirements + __metaclass__ = type diff --git a/pex/vendor/_vendored/wheel/wheel/__main__.py b/pex/vendor/_vendored/wheel/wheel/__main__.py index df772e604..9035c6456 100644 --- a/pex/vendor/_vendored/wheel/wheel/__main__.py +++ b/pex/vendor/_vendored/wheel/wheel/__main__.py @@ -11,7 +11,11 @@ def main(): # needed for console script import os.path path = os.path.dirname(os.path.dirname(__file__)) sys.path[0:0] = [path] - import pex.third_party.wheel.tool, pex.third_party.wheel as wheel + if "__PEX_UNVENDORED__" in __import__("os").environ: + import wheel.tool # vendor:skip + else: + import pex.third_party.wheel.tool, pex.third_party.wheel as wheel + sys.exit(wheel.tool.main()) diff --git a/pex/vendor/_vendored/wheel/wheel/bdist_wheel.py b/pex/vendor/_vendored/wheel/wheel/bdist_wheel.py index b98844d24..51aab9595 100644 --- a/pex/vendor/_vendored/wheel/wheel/bdist_wheel.py +++ b/pex/vendor/_vendored/wheel/wheel/bdist_wheel.py @@ -17,7 +17,11 @@ from distutils import log as logger from shutil import rmtree -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + from .pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag, get_platform from .util import native, open_for_csv diff --git a/pex/vendor/_vendored/wheel/wheel/egg2wheel.py b/pex/vendor/_vendored/wheel/wheel/egg2wheel.py index 143cb68ea..765612495 100644 --- a/pex/vendor/_vendored/wheel/wheel/egg2wheel.py +++ b/pex/vendor/_vendored/wheel/wheel/egg2wheel.py @@ -10,9 +10,21 @@ from distutils.archive_util import make_archive from glob import iglob -import pex.third_party.wheel.bdist_wheel, pex.third_party.wheel as wheel -from pex.third_party.wheel.tool import WheelError -from pex.third_party.wheel.wininst2wheel import _bdist_wheel_tag +if "__PEX_UNVENDORED__" in __import__("os").environ: + import wheel.bdist_wheel # vendor:skip +else: + import pex.third_party.wheel.bdist_wheel, pex.third_party.wheel as wheel + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from wheel.tool import WheelError # vendor:skip +else: + from pex.third_party.wheel.tool import WheelError + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from wheel.wininst2wheel import _bdist_wheel_tag # vendor:skip +else: + from pex.third_party.wheel.wininst2wheel import _bdist_wheel_tag + egg_info_re = re.compile(r''' (?P.+?)-(?P.+?) diff --git a/pex/vendor/_vendored/wheel/wheel/install.py b/pex/vendor/_vendored/wheel/wheel/install.py index def783ab6..9203208dd 100644 --- a/pex/vendor/_vendored/wheel/wheel/install.py +++ b/pex/vendor/_vendored/wheel/wheel/install.py @@ -41,7 +41,11 @@ def parse_version(version): """Use parse_version from pkg_resources or distutils as available.""" global parse_version try: - from pex.third_party.pkg_resources import parse_version + if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import parse_version # vendor:skip + else: + from pex.third_party.pkg_resources import parse_version + except ImportError: from distutils.version import LooseVersion as parse_version return parse_version(version) diff --git a/pex/vendor/_vendored/wheel/wheel/metadata.py b/pex/vendor/_vendored/wheel/wheel/metadata.py index eca49bc09..afaab60a6 100644 --- a/pex/vendor/_vendored/wheel/wheel/metadata.py +++ b/pex/vendor/_vendored/wheel/wheel/metadata.py @@ -7,7 +7,11 @@ import textwrap from collections import namedtuple -import pex.third_party.pkg_resources as pkg_resources +if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip +else: + import pex.third_party.pkg_resources as pkg_resources + from .pkginfo import read_pkg_info diff --git a/pex/vendor/_vendored/wheel/wheel/tool/__init__.py b/pex/vendor/_vendored/wheel/wheel/tool/__init__.py index ceacb8e4f..66b5426cd 100644 --- a/pex/vendor/_vendored/wheel/wheel/tool/__init__.py +++ b/pex/vendor/_vendored/wheel/wheel/tool/__init__.py @@ -19,7 +19,11 @@ def require_pkgresources(name): try: - import pex.third_party.pkg_resources as pkg_resources # noqa: F401 + if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip + else: + import pex.third_party.pkg_resources as pkg_resources + # noqa: F401 except ImportError: raise RuntimeError("'{0}' needs pkg_resources (part of setuptools).".format(name)) @@ -249,8 +253,16 @@ def install_scripts(distributions): Regenerate the entry_points console_scripts for the named distribution. """ try: - from pex.third_party.setuptools.command import easy_install - import pex.third_party.pkg_resources as pkg_resources + if "__PEX_UNVENDORED__" in __import__("os").environ: + from setuptools.command import easy_install # vendor:skip + else: + from pex.third_party.setuptools.command import easy_install + + if "__PEX_UNVENDORED__" in __import__("os").environ: + import pkg_resources # vendor:skip + else: + import pex.third_party.pkg_resources as pkg_resources + except ImportError: raise RuntimeError("'wheel install_scripts' needs setuptools.") diff --git a/pex/vendor/_vendored/wheel/wheel/util.py b/pex/vendor/_vendored/wheel/wheel/util.py index 96bcbd47f..ad119bd72 100644 --- a/pex/vendor/_vendored/wheel/wheel/util.py +++ b/pex/vendor/_vendored/wheel/wheel/util.py @@ -141,7 +141,11 @@ def matches_requirement(req, wheels): :param wheels: List of wheels to search. """ try: - from pex.third_party.pkg_resources import Distribution, Requirement + if "__PEX_UNVENDORED__" in __import__("os").environ: + from pkg_resources import Distribution, Requirement # vendor:skip + else: + from pex.third_party.pkg_resources import Distribution, Requirement + except ImportError: raise RuntimeError("Cannot use requirements without pkg_resources") diff --git a/pex/vendor/_vendored/wheel/wheel/wininst2wheel.py b/pex/vendor/_vendored/wheel/wheel/wininst2wheel.py index 7a489c5f0..601cca5fa 100644 --- a/pex/vendor/_vendored/wheel/wheel/wininst2wheel.py +++ b/pex/vendor/_vendored/wheel/wheel/wininst2wheel.py @@ -9,8 +9,16 @@ from glob import iglob from shutil import rmtree -import pex.third_party.wheel.bdist_wheel, pex.third_party.wheel as wheel -from pex.third_party.wheel.archive import archive_wheelfile +if "__PEX_UNVENDORED__" in __import__("os").environ: + import wheel.bdist_wheel # vendor:skip +else: + import pex.third_party.wheel.bdist_wheel, pex.third_party.wheel as wheel + +if "__PEX_UNVENDORED__" in __import__("os").environ: + from wheel.archive import archive_wheelfile # vendor:skip +else: + from pex.third_party.wheel.archive import archive_wheelfile + egg_info_re = re.compile(r'''(^|/)(?P[^/]+?)-(?P.+?) (-(?P.+?))?(-(?P.+?))?.egg-info(/|$)''', re.VERBOSE) diff --git a/tests/test_bdist_pex.py b/tests/test_bdist_pex.py index e7449715a..d9946522a 100644 --- a/tests/test_bdist_pex.py +++ b/tests/test_bdist_pex.py @@ -21,7 +21,7 @@ def __init__(self, source_dir, interpreter, bdist_args=None): @property def mixins(self): - return ['setuptools', 'pex'] + return ['setuptools', 'wheel', 'pex'] def _setup_command(self): return ['bdist_pex', '--bdist-dir={}'.format(self._install_tmp)] + self._bdist_args