-
Notifications
You must be signed in to change notification settings - Fork 67
/
_distutils_system_mod.py
121 lines (102 loc) · 4.21 KB
/
_distutils_system_mod.py
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
"""
Apply Debian-specific patches to distutils commands and sysconfig.
Extracts the customized behavior from patches as reported
in pypa/distutils#2 and applies those customizations (except
for scheme definitions) to those commands.
Place this module somewhere in sys.path to take effect.
"""
import os
import sys
import distutils.sysconfig
import distutils.command.install as orig_install
import distutils.command.install_egg_info as orig_install_egg_info
from distutils.command.install_egg_info import (
to_filename,
safe_name,
safe_version,
)
from distutils.errors import DistutilsOptionError
class install(orig_install.install):
user_options = list(orig_install.install.user_options) + [
('install-layout=', None,
"installation layout to choose (known values: deb, unix)"),
]
def initialize_options(self):
super().initialize_options()
self.prefix_option = None
self.install_layout = None
def finalize_unix(self):
self.prefix_option = self.prefix
super().finalize_unix()
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("posix_prefix")
else:
raise DistutilsOptionError(
"unknown value for --install-layout")
elif ((self.prefix_option and
os.path.normpath(self.prefix) != '/usr/local')
or sys.base_prefix != sys.prefix
or 'PYTHONUSERBASE' in os.environ
or 'VIRTUAL_ENV' in os.environ
or 'real_prefix' in sys.__dict__):
self.select_scheme("posix_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("posix_local")
class install_egg_info(orig_install_egg_info.install_egg_info):
user_options = list(orig_install_egg_info.install_egg_info.user_options) + [
('install-layout', None, "custom installation layout"),
]
def initialize_options(self):
super().initialize_options()
self.prefix_option = None
self.install_layout = None
def finalize_options(self):
self.set_undefined_options('install',('install_layout','install_layout'))
self.set_undefined_options('install',('prefix_option','prefix_option'))
super().finalize_options()
@property
def basename(self):
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]
)
return basename
def _posix_lib(standard_lib, libpython, early_prefix, prefix):
is_default_prefix = not early_prefix or os.path.normpath(early_prefix) in ('/usr', '/usr/local')
if standard_lib:
return libpython
elif (is_default_prefix and
'PYTHONUSERBASE' not in os.environ and
'VIRTUAL_ENV' not in os.environ and
'real_prefix' not in sys.__dict__ and
sys.prefix == sys.base_prefix):
return os.path.join(prefix, "lib", "python3", "dist-packages")
else:
return os.path.join(libpython, "site-packages")
def apply_customizations():
orig_install.install = install
orig_install_egg_info.install_egg_info = install_egg_info
distutils.sysconfig._posix_lib = _posix_lib
apply_customizations()