Skip to content

Commit

Permalink
Merge pull request #68 from pypa/feature/debian-compat
Browse files Browse the repository at this point in the history
Add hook to enable monkeypatching in Debian and unblock distutils adoption in Setuptools.
  • Loading branch information
jaraco committed Nov 18, 2021
2 parents 855ef64 + 4e6ed3f commit 46c2e34
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
10 changes: 10 additions & 0 deletions distutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 11 additions & 4 deletions distutils/command/install_egg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 11 additions & 4 deletions distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 46c2e34

Please sign in to comment.