|
106 | 106 | else:
|
107 | 107 | _INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_venv']
|
108 | 108 |
|
| 109 | +# For a brief period of time in the Fedora 36 life cycle, |
| 110 | +# this installation scheme existed and was documented in the release notes. |
| 111 | +# For backwards compatibility, we keep it here (at least on 3.10 and 3.11). |
| 112 | +_INSTALL_SCHEMES['rpm_prefix'] = _INSTALL_SCHEMES['posix_prefix'] |
| 113 | + |
| 114 | + |
109 | 115 | def _get_implementation():
|
110 | 116 | return 'Python'
|
111 | 117 |
|
@@ -167,6 +173,19 @@ def joinuser(*args):
|
167 | 173 | },
|
168 | 174 | }
|
169 | 175 |
|
| 176 | +# This is used by distutils.command.install in the stdlib |
| 177 | +# as well as pypa/distutils (e.g. bundled in setuptools). |
| 178 | +# The self.prefix value is set to sys.prefix + /local/ |
| 179 | +# if neither RPM build nor virtual environment is |
| 180 | +# detected to make distutils install packages |
| 181 | +# into the separate location. |
| 182 | +# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe |
| 183 | +if (not (hasattr(sys, 'real_prefix') or |
| 184 | + sys.prefix != sys.base_prefix) and |
| 185 | + 'RPM_BUILD_ROOT' not in os.environ): |
| 186 | + _prefix_addition = '/local' |
| 187 | + |
| 188 | + |
170 | 189 | _SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
|
171 | 190 | 'scripts', 'data')
|
172 | 191 |
|
@@ -261,11 +280,40 @@ def _extend_dict(target_dict, other_dict):
|
261 | 280 | target_dict[key] = value
|
262 | 281 |
|
263 | 282 |
|
| 283 | +_CONFIG_VARS_LOCAL = None |
| 284 | + |
| 285 | + |
| 286 | +def _config_vars_local(): |
| 287 | + # This function returns the config vars with prefixes amended to /usr/local |
| 288 | + # https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe |
| 289 | + global _CONFIG_VARS_LOCAL |
| 290 | + if _CONFIG_VARS_LOCAL is None: |
| 291 | + _CONFIG_VARS_LOCAL = dict(get_config_vars()) |
| 292 | + _CONFIG_VARS_LOCAL['base'] = '/usr/local' |
| 293 | + _CONFIG_VARS_LOCAL['platbase'] = '/usr/local' |
| 294 | + return _CONFIG_VARS_LOCAL |
| 295 | + |
| 296 | + |
264 | 297 | def _expand_vars(scheme, vars):
|
265 | 298 | res = {}
|
266 | 299 | if vars is None:
|
267 | 300 | vars = {}
|
268 |
| - _extend_dict(vars, get_config_vars()) |
| 301 | + |
| 302 | + # when we are not in a virtual environment or an RPM build |
| 303 | + # we change '/usr' to '/usr/local' |
| 304 | + # to avoid surprises, we explicitly check for the /usr/ prefix |
| 305 | + # Python virtual environments have different prefixes |
| 306 | + # we only do this for posix_prefix, not to mangle the venv scheme |
| 307 | + # posix_prefix is used by sudo pip install |
| 308 | + # we only change the defaults here, so explicit --prefix will take precedence |
| 309 | + # https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe |
| 310 | + if (scheme == 'posix_prefix' and |
| 311 | + _PREFIX == '/usr' and |
| 312 | + 'RPM_BUILD_ROOT' not in os.environ): |
| 313 | + _extend_dict(vars, _config_vars_local()) |
| 314 | + else: |
| 315 | + _extend_dict(vars, get_config_vars()) |
| 316 | + |
269 | 317 | if os.name == 'nt':
|
270 | 318 | # On Windows we want to substitute 'lib' for schemes rather
|
271 | 319 | # than the native value (without modifying vars, in case it
|
|
0 commit comments