diff --git a/distutils/__init__.py b/distutils/__init__.py index d823d040a1..0ba5e44abf 100644 --- a/distutils/__init__.py +++ b/distutils/__init__.py @@ -9,5 +9,15 @@ """ import sys +import importlib __version__ = sys.version[:sys.version.index(' ')] + + +try: + # Allow Debian (only) to customize system behavior. + # Ref pypa/distutils#2. This hook is deprecated and + # no other environments should use it. + importlib.import_module('_distutils_system_mod') +except ImportError: + pass diff --git a/distutils/command/install_egg_info.py b/distutils/command/install_egg_info.py index 0ddc7367cc..adc0323f98 100644 --- a/distutils/command/install_egg_info.py +++ b/distutils/command/install_egg_info.py @@ -19,14 +19,21 @@ class install_egg_info(Command): def initialize_options(self): self.install_dir = None - def finalize_options(self): - self.set_undefined_options('install_lib',('install_dir','install_dir')) - basename = "%s-%s-py%d.%d.egg-info" % ( + @property + def basename(self): + """ + Allow basename to be overridden by child class. + Ref pypa/distutils#2. + """ + return "%s-%s-py%d.%d.egg-info" % ( to_filename(safe_name(self.distribution.get_name())), to_filename(safe_version(self.distribution.get_version())), *sys.version_info[:2] ) - self.target = os.path.join(self.install_dir, basename) + + def finalize_options(self): + self.set_undefined_options('install_lib',('install_dir','install_dir')) + self.target = os.path.join(self.install_dir, self.basename) self.outputs = [self.target] def run(self): diff --git a/distutils/sysconfig.py b/distutils/sysconfig.py index 8832b3eceb..7bfc67ba7b 100644 --- a/distutils/sysconfig.py +++ b/distutils/sysconfig.py @@ -129,6 +129,14 @@ def get_python_inc(plat_specific=0, prefix=None): "on platform '%s'" % os.name) +# allow this behavior to be monkey-patched. Ref pypa/distutils#2. +def _posix_lib(standard_lib, libpython, early_prefix, prefix): + if standard_lib: + return libpython + else: + return os.path.join(libpython, "site-packages") + + def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): """Return the directory containing the Python library (standard or site additions). @@ -152,6 +160,8 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): return os.path.join(prefix, "lib-python", sys.version[0]) return os.path.join(prefix, 'site-packages') + early_prefix = prefix + if prefix is None: if standard_lib: prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX @@ -169,10 +179,7 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None): implementation = 'pypy' if IS_PYPY else 'python' libpython = os.path.join(prefix, libdir, implementation + get_python_version()) - if standard_lib: - return libpython - else: - return os.path.join(libpython, "site-packages") + return _posix_lib(standard_lib, libpython, early_prefix, prefix) elif os.name == "nt": if standard_lib: return os.path.join(prefix, "Lib")