1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
Description: Debian: Add a distutils option --install-layout=deb
This option:
- installs into $prefix/dist-packages instead of $prefix/site-packages.
- doesn't encode the python version into the egg name.
.
We install modules into dist-packages so that a local admin can build their
own cpython from source, and they won't see each others' installed modules.
This keeps Debian packaged applications working correctly, isolated from the
local cpython.
.
Customize site.py to import from Debian's dist-packages layout.
Forwarded: not-needed
--- a/3.11/Lib/distutils/command/install_egg_info.py
+++ b/3.11/Lib/distutils/command/install_egg_info.py
@@ -14,18 +14,38 @@ class install_egg_info(Command):
description = "Install package's PKG-INFO metadata as an .egg-info file"
user_options = [
('install-dir=', 'd', "directory to install to"),
+ ('install-layout', None, "custom installation layout"),
]
def initialize_options(self):
self.install_dir = None
+ self.install_layout = None
+ self.prefix_option = None
def finalize_options(self):
self.set_undefined_options('install_lib',('install_dir','install_dir'))
- basename = "%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.set_undefined_options('install',('install_layout','install_layout'))
+ self.set_undefined_options('install',('prefix_option','prefix_option'))
+ if self.install_layout:
+ if not self.install_layout.lower() in ['deb', 'unix']:
+ raise DistutilsOptionError(
+ "unknown value for --install-layout")
+ no_pyver = (self.install_layout.lower() == 'deb')
+ elif self.prefix_option:
+ no_pyver = False
+ else:
+ no_pyver = True
+ if no_pyver:
+ basename = "%s-%s.egg-info" % (
+ to_filename(safe_name(self.distribution.get_name())),
+ to_filename(safe_version(self.distribution.get_version()))
+ )
+ else:
+ basename = "%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)
self.outputs = [self.target]
--- a/3.11/Lib/distutils/command/install.py
+++ b/3.11/Lib/distutils/command/install.py
@@ -10,7 +10,7 @@
from distutils import log
from distutils.core import Command
from distutils.debug import DEBUG
-from distutils.sysconfig import get_config_vars
+from distutils.sysconfig import get_config_vars, is_virtual_environment
from distutils.errors import DistutilsPlatformError
from distutils.file_util import write_file
from distutils.util import convert_path, subst_vars, change_root
@@ -35,6 +35,30 @@
# of this information should switch to using sysconfig directly.
INSTALL_SCHEMES = {"unix_prefix": {}, "unix_home": {}, "nt": {}}
+# add the Debian install schemes here until they are added to sysconfig
+INSTALL_SCHEMES['unix_local'] = {
+ 'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
+ 'platstdlib': '{platbase}/{platlibdir}/python{py_version_short}',
+ 'purelib': '{base}/local/lib/python{py_version_short}/dist-packages',
+ 'platlib': '{platbase}/local/{platlibdir}/python{py_version_short}/dist-packages',
+ 'include': '{installed_base}/include/python{py_version_short}{abiflags}',
+ 'headers': '{base}/local/include/python{py_version_short}{abiflags}',
+ 'platinclude': '{installed_platbase}/include/python{py_version_short}{abiflags}',
+ 'scripts': '{base}/local/bin',
+ 'data': '{base}/local',
+}
+INSTALL_SCHEMES['deb_system'] = {
+ 'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
+ 'platstdlib': '{platbase}/{platlibdir}/python{py_version_short}',
+ 'purelib': '{base}/lib/python3/dist-packages',
+ 'platlib': '{platbase}/{platlibdir}/python3/dist-packages',
+ 'include': '{installed_base}/include/python{py_version_short}{abiflags}',
+ 'headers': '{installed_base}/include/python{py_version_short}{abiflags}',
+ 'platinclude': '{installed_platbase}/include/python{py_version_short}{abiflags}',
+ 'scripts': '{base}/bin',
+ 'data': '{base}',
+}
+
# Copy from sysconfig._INSTALL_SCHEMES
for key in SCHEME_KEYS:
for distutils_scheme_name, sys_scheme_name in (
@@ -148,6 +172,9 @@ class install(Command):
('record=', None,
"filename in which to record list of installed files"),
+
+ ('install-layout=', None,
+ "installation layout to choose (known values: deb, unix)"),
]
boolean_options = ['compile', 'force', 'skip-build']
@@ -168,6 +195,7 @@ class install(Command):
self.exec_prefix = None
self.home = None
self.user = 0
+ self.prefix_option = None
# These select only the installation base; it's up to the user to
# specify the installation scheme (currently, that means supplying
@@ -190,6 +218,9 @@ class install(Command):
self.install_userbase = USER_BASE
self.install_usersite = USER_SITE
+ # enable custom installation, known values: deb
+ self.install_layout = None
+
self.compile = None
self.optimize = None
@@ -436,6 +467,7 @@ class install(Command):
self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home")
else:
+ self.prefix_option = self.prefix
if self.prefix is None:
if self.exec_prefix is not None:
raise DistutilsOptionError(
@@ -450,7 +482,23 @@
self.install_base = self.prefix
self.install_platbase = self.exec_prefix
- self.select_scheme("unix_prefix")
+ if self.install_layout:
+ if self.install_layout.lower() in ['deb']:
+ self.select_scheme("deb_system")
+ elif self.install_layout.lower() in ['unix']:
+ self.select_scheme("unix_prefix")
+ else:
+ raise DistutilsOptionError(
+ "unknown value for --install-layout")
+ elif ((self.prefix_option and
+ os.path.normpath(self.prefix) != '/usr/local')
+ or is_virtual_environment()):
+ self.select_scheme("unix_prefix")
+ else:
+ if os.path.normpath(self.prefix) == '/usr/local':
+ self.prefix = self.exec_prefix = '/usr'
+ self.install_base = self.install_platbase = '/usr'
+ self.select_scheme("unix_local")
def finalize_other(self):
"""Finalizes options for non-posix platforms"""
--- a/3.11/Lib/distutils/sysconfig.py
+++ b/3.11/Lib/distutils/sysconfig.py
@@ -266,6 +266,10 @@
compiler.shared_lib_extension = shlib_suffix
+def is_virtual_environment():
+ return sys.base_prefix != sys.prefix or hasattr(sys, "real_prefix")
+
+
def get_python_inc(plat_specific=0, prefix=None):
"""Return the directory containing installed Python header files.
@@ -320,6 +324,7 @@
If 'prefix' is supplied, use it instead of sys.base_prefix or
sys.base_exec_prefix -- i.e., ignore 'plat_specific'.
"""
+ is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
if prefix is None:
if standard_lib:
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
@@ -338,6 +343,8 @@
"python" + get_python_version())
if standard_lib:
return libpython
+ elif is_default_prefix and not is_virtual_environment():
+ return os.path.join(prefix, "lib", "python3", "dist-packages")
else:
return os.path.join(libpython, "site-packages")
elif os.name == "nt":
|