summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-01-23 16:11:37 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-01-23 16:11:37 -0500
commitf1eb1d26a45dd02bb1bb06b2d979596a5ef5a92f (patch)
treefcc6de2e91e475ae150f9d878b16d25cf5b3a311
parent35e1c9d4d788094c254485dfdefa0c24cd5820ee (diff)
downloadpython-setuptools-git-f1eb1d26a45dd02bb1bb06b2d979596a5ef5a92f.tar.gz
Allow sysconfig to override install schemes and provide some compatibility overrides for debian and fedora until they patch sysconfig.
-rw-r--r--distutils/command/install.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/distutils/command/install.py b/distutils/command/install.py
index 13feeb89..f3dce84b 100644
--- a/distutils/command/install.py
+++ b/distutils/command/install.py
@@ -35,6 +35,13 @@ INSTALL_SCHEMES = {
'scripts': '$base/bin',
'data' : '$base',
},
+ 'unix_local': {
+ 'purelib': '$base/local/lib/python$py_version_short/site-packages',
+ 'platlib': '$platbase/local/$platlibdir/python$py_version_short/site-packages',
+ 'headers': '$base/local/include/python$py_version_short$abiflags/$dist_name',
+ 'scripts': '$base/local/bin',
+ 'data' : '$base/local',
+ },
'unix_home': {
'purelib': '$base/lib/python',
'platlib': '$base/$platlibdir/python',
@@ -282,6 +289,7 @@ class install(Command):
self.dump_dirs("pre-finalize_{unix,other}")
+ self._load_schemes()
if os.name == 'posix':
self.finalize_unix()
else:
@@ -404,6 +412,48 @@ class install(Command):
val = getattr(self, opt_name)
log.debug(" %s: %s", opt_name, val)
+ def _load_schemes(self):
+ """
+ Allow sysconfig and runtime behaviors to alter schemes.
+ """
+
+ try:
+ import sysconfig
+ INSTALL_SCHEMES.update(sysconfig.INSTALL_SCHEMES)
+ return
+ except Exception:
+ pass
+
+ def is_virtualenv():
+ return (
+ hasattr(sys, 'real_prefix') or
+ sys.prefix != sys.base_prefix or
+ 'VIRTUAL_ENV' in os.environ
+ )
+
+ # fedora:
+ def is_rpm_build():
+ return 'RPM_BUILD_ROOT' in os.environ
+
+ if not is_virtualenv() and not is_rpm_build():
+ INSTALL_SCHEMES['unix_prefix'] = INSTALL_SCHEMES['unix_local']
+
+ # debian:
+ def is_deb_system():
+ # TODO: how to solicit without an additional parameter to build?
+ return self.install_layout.lower() == 'deb'
+
+ if is_deb_system():
+ INSTALL_SCHEMES['unix_prefix'] = {
+ 'purelib': '$base/lib/python3/dist-packages',
+ 'platlib': '$platbase/lib/python3/dist-packages',
+ 'headers': '$base/include/python$py_version_short/$dist_name',
+ 'scripts': '$base/bin',
+ 'data' : '$base',
+ }
+ if not is_virtualenv():
+ INSTALL_SCHEMES['unix_prefix'] = INSTALL_SCHEMES['unix_local']
+
def finalize_unix(self):
"""Finalizes options for posix platforms."""
if self.install_base is not None or self.install_platbase is not None: