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