Skip to content

Commit 46c2e34

Browse files
authored
Merge pull request #68 from pypa/feature/debian-compat
Add hook to enable monkeypatching in Debian and unblock distutils adoption in Setuptools.
2 parents 855ef64 + 4e6ed3f commit 46c2e34

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

distutils/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@
99
"""
1010

1111
import sys
12+
import importlib
1213

1314
__version__ = sys.version[:sys.version.index(' ')]
15+
16+
17+
try:
18+
# Allow Debian (only) to customize system behavior.
19+
# Ref pypa/distutils#2. This hook is deprecated and
20+
# no other environments should use it.
21+
importlib.import_module('_distutils_system_mod')
22+
except ImportError:
23+
pass

distutils/command/install_egg_info.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,21 @@ class install_egg_info(Command):
1919
def initialize_options(self):
2020
self.install_dir = None
2121

22-
def finalize_options(self):
23-
self.set_undefined_options('install_lib',('install_dir','install_dir'))
24-
basename = "%s-%s-py%d.%d.egg-info" % (
22+
@property
23+
def basename(self):
24+
"""
25+
Allow basename to be overridden by child class.
26+
Ref pypa/distutils#2.
27+
"""
28+
return "%s-%s-py%d.%d.egg-info" % (
2529
to_filename(safe_name(self.distribution.get_name())),
2630
to_filename(safe_version(self.distribution.get_version())),
2731
*sys.version_info[:2]
2832
)
29-
self.target = os.path.join(self.install_dir, basename)
33+
34+
def finalize_options(self):
35+
self.set_undefined_options('install_lib',('install_dir','install_dir'))
36+
self.target = os.path.join(self.install_dir, self.basename)
3037
self.outputs = [self.target]
3138

3239
def run(self):

distutils/sysconfig.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ def get_python_inc(plat_specific=0, prefix=None):
129129
"on platform '%s'" % os.name)
130130

131131

132+
# allow this behavior to be monkey-patched. Ref pypa/distutils#2.
133+
def _posix_lib(standard_lib, libpython, early_prefix, prefix):
134+
if standard_lib:
135+
return libpython
136+
else:
137+
return os.path.join(libpython, "site-packages")
138+
139+
132140
def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
133141
"""Return the directory containing the Python library (standard or
134142
site additions).
@@ -152,6 +160,8 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
152160
return os.path.join(prefix, "lib-python", sys.version[0])
153161
return os.path.join(prefix, 'site-packages')
154162

163+
early_prefix = prefix
164+
155165
if prefix is None:
156166
if standard_lib:
157167
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):
169179
implementation = 'pypy' if IS_PYPY else 'python'
170180
libpython = os.path.join(prefix, libdir,
171181
implementation + get_python_version())
172-
if standard_lib:
173-
return libpython
174-
else:
175-
return os.path.join(libpython, "site-packages")
182+
return _posix_lib(standard_lib, libpython, early_prefix, prefix)
176183
elif os.name == "nt":
177184
if standard_lib:
178185
return os.path.join(prefix, "Lib")

0 commit comments

Comments
 (0)