Don't use custom installation schemes
This commit is contained in:
parent
f5d6ae420d
commit
38f9dd1590
|
@ -1,37 +1,65 @@
|
||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: Lumir Balhar <lbalhar@redhat.com>
|
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||||||
Date: Mon, 15 Feb 2021 12:19:27 +0100
|
Date: Mon, 15 Feb 2021 12:19:27 +0100
|
||||||
Subject: [PATCH] 00251: Change user install location
|
Subject: [PATCH] 00251: Change user install location
|
||||||
MIME-Version: 1.0
|
MIME-Version: 1.0
|
||||||
Content-Type: text/plain; charset=UTF-8
|
Content-Type: text/plain; charset=UTF-8
|
||||||
Content-Transfer-Encoding: 8bit
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
Change the values of sysconfig's "posix_prefix" install scheme to /usr/local
|
Set values of base and platbase in sysconfig from /usr
|
||||||
when RPM build or venv/virtualenv is not detected,
|
to /usr/local when RPM build is not detected
|
||||||
to make pip, sysconfig and distutils install into an isolated location.
|
to make pip and similar tools install into separate location.
|
||||||
|
|
||||||
The original values are saved as an additional "rpm_prefix" install scheme.
|
Set values of prefix and exec_prefix in distutils install command
|
||||||
|
to /usr/local if executable is /usr/bin/python* and RPM build
|
||||||
The site module adds the /usr/local paths to sys.path when site packages are
|
is not detected to make distutils and pypa/distutils install into separate location.
|
||||||
enabled and RPM build is not detected.
|
|
||||||
|
|
||||||
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
Downstream only.
|
||||||
|
|
||||||
Rewrote in Fedora 36+ to patch sysconfig instead of distutils,
|
We've tried to rework in Fedora 36/Python 3.10 to follow https://bugs.python.org/issue43976
|
||||||
see https://discuss.python.org/t/pep-632-deprecate-distutils-module/5134/104
|
but we have identified serious problems with that approach,
|
||||||
|
see https://bugzilla.redhat.com/2026979 or https://bugzilla.redhat.com/2097183
|
||||||
|
|
||||||
Downstream only for now, waiting for https://bugs.python.org/issue43976
|
pypa/distutils integration: https://github.com/pypa/distutils/pull/70
|
||||||
|
|
||||||
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
||||||
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
|
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
|
||||||
Co-authored-by: Michal Cyprian <m.cyprian@gmail.com>
|
Co-authored-by: Michal Cyprian <m.cyprian@gmail.com>
|
||||||
Co-authored-by: Lumír Balhar <frenzy.madness@gmail.com>
|
Co-authored-by: Lumír Balhar <frenzy.madness@gmail.com>
|
||||||
---
|
---
|
||||||
Lib/site.py | 9 ++++++++-
|
Lib/distutils/command/install.py | 8 +++--
|
||||||
Lib/sysconfig.py | 25 +++++++++++++++++++++++++
|
Lib/site.py | 9 +++++-
|
||||||
Lib/test/test_sysconfig.py | 4 +++-
|
Lib/sysconfig.py | 53 +++++++++++++++++++++++++++++++-
|
||||||
3 files changed, 36 insertions(+), 2 deletions(-)
|
Lib/test/test_sysconfig.py | 17 ++++++++--
|
||||||
|
4 files changed, 81 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
|
||||||
|
index 01d5331a63..79f70f0de4 100644
|
||||||
|
--- a/Lib/distutils/command/install.py
|
||||||
|
+++ b/Lib/distutils/command/install.py
|
||||||
|
@@ -159,6 +159,8 @@ class install(Command):
|
||||||
|
|
||||||
|
negative_opt = {'no-compile' : 'compile'}
|
||||||
|
|
||||||
|
+ # Allow Fedora to add components to the prefix
|
||||||
|
+ _prefix_addition = getattr(sysconfig, '_prefix_addition', '')
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
"""Initializes options."""
|
||||||
|
@@ -441,8 +443,10 @@ def finalize_unix(self):
|
||||||
|
raise DistutilsOptionError(
|
||||||
|
"must not supply exec-prefix without prefix")
|
||||||
|
|
||||||
|
- self.prefix = os.path.normpath(sys.prefix)
|
||||||
|
- self.exec_prefix = os.path.normpath(sys.exec_prefix)
|
||||||
|
+ self.prefix = (
|
||||||
|
+ os.path.normpath(sys.prefix) + self._prefix_addition)
|
||||||
|
+ self.exec_prefix = (
|
||||||
|
+ os.path.normpath(sys.exec_prefix) + self._prefix_addition)
|
||||||
|
|
||||||
|
else:
|
||||||
|
if self.exec_prefix is None:
|
||||||
diff --git a/Lib/site.py b/Lib/site.py
|
diff --git a/Lib/site.py b/Lib/site.py
|
||||||
index 939893eb5e..d1316c3355 100644
|
index 939893eb5e..d1316c3355 100644
|
||||||
--- a/Lib/site.py
|
--- a/Lib/site.py
|
||||||
|
@ -54,46 +82,113 @@ index 939893eb5e..d1316c3355 100644
|
||||||
if os.path.isdir(sitedir):
|
if os.path.isdir(sitedir):
|
||||||
addsitedir(sitedir, known_paths)
|
addsitedir(sitedir, known_paths)
|
||||||
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
|
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
|
||||||
index daf9f00006..40e4edf0ae 100644
|
index daf9f00006..10368c92a7 100644
|
||||||
--- a/Lib/sysconfig.py
|
--- a/Lib/sysconfig.py
|
||||||
+++ b/Lib/sysconfig.py
|
+++ b/Lib/sysconfig.py
|
||||||
@@ -58,6 +58,31 @@
|
@@ -58,6 +58,16 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
+# backup the original posix_prefix as rpm_prefix
|
+# For a brief period of time in the Fedora 36 life cycle,
|
||||||
+# RPM packages use it and we need to be able to read it even when changed
|
+# this installation scheme existed and was documented in the release notes.
|
||||||
|
+# For backwards compatibility, we keep it here (at least on 3.10 and 3.11).
|
||||||
+_INSTALL_SCHEMES['rpm_prefix'] = _INSTALL_SCHEMES['posix_prefix']
|
+_INSTALL_SCHEMES['rpm_prefix'] = _INSTALL_SCHEMES['posix_prefix']
|
||||||
+# Virtualenv >= 20.10.0 favors the "venv" scheme over the defaults when creating virtual environments.
|
+# Virtualenv >= 20.10.0 favors the "venv" scheme over the defaults when creating virtual environments.
|
||||||
+# See: https://github.com/pypa/virtualenv/commit/8da79db86d8a5c74d03667a40e64ff832076445e
|
+# See: https://github.com/pypa/virtualenv/commit/8da79db86d8a5c74d03667a40e64ff832076445e
|
||||||
+# See: https://bugs.python.org/issue45413
|
+# See: https://bugs.python.org/issue45413
|
||||||
+# "venv" should be the same as the unpatched posix_prefix for us,
|
+# "venv" should be the same as the posix_prefix for us,
|
||||||
+# so new virtual environments aren't created with paths like venv/local/bin/python.
|
+# so new virtual environments aren't created with paths like venv/local/bin/python.
|
||||||
+_INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_prefix']
|
+_INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_prefix']
|
||||||
+
|
|
||||||
+if (not (hasattr(sys, 'real_prefix') or
|
|
||||||
+ sys.prefix != sys.base_prefix) and
|
|
||||||
+ 'RPM_BUILD_ROOT' not in os.environ):
|
|
||||||
+ _INSTALL_SCHEMES['posix_prefix'] = {
|
|
||||||
+ 'stdlib': '{installed_base}/{platlibdir}/python{py_version_short}',
|
|
||||||
+ 'platstdlib': '{platbase}/{platlibdir}/python{py_version_short}',
|
|
||||||
+ 'purelib': '{base}/local/lib/python{py_version_short}/site-packages',
|
|
||||||
+ 'platlib': '{platbase}/local/{platlibdir}/python{py_version_short}/site-packages',
|
|
||||||
+ 'include':
|
|
||||||
+ '{installed_base}/include/python{py_version_short}{abiflags}',
|
|
||||||
+ 'platinclude':
|
|
||||||
+ '{installed_platbase}/include/python{py_version_short}{abiflags}',
|
|
||||||
+ 'scripts': '{base}/local/bin',
|
|
||||||
+ 'data': '{base}/local',
|
|
||||||
+ }
|
|
||||||
|
|
||||||
# NOTE: site.py has copy of this function.
|
# NOTE: site.py has copy of this function.
|
||||||
# Sync it when modify this function.
|
# Sync it when modify this function.
|
||||||
|
@@ -117,6 +127,19 @@ def joinuser(*args):
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
+# This is used by distutils.command.install in the stdlib
|
||||||
|
+# as well as pypa/distutils (e.g. bundled in setuptools).
|
||||||
|
+# The self.prefix value is set to sys.prefix + /local/
|
||||||
|
+# if neither RPM build nor virtual environment is
|
||||||
|
+# detected to make distutils install packages
|
||||||
|
+# into the separate location.
|
||||||
|
+# https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
+if (not (hasattr(sys, 'real_prefix') or
|
||||||
|
+ sys.prefix != sys.base_prefix) and
|
||||||
|
+ 'RPM_BUILD_ROOT' not in os.environ):
|
||||||
|
+ _prefix_addition = '/local'
|
||||||
|
+
|
||||||
|
+
|
||||||
|
_SCHEME_KEYS = ('stdlib', 'platstdlib', 'purelib', 'platlib', 'include',
|
||||||
|
'scripts', 'data')
|
||||||
|
|
||||||
|
@@ -211,11 +234,39 @@ def _extend_dict(target_dict, other_dict):
|
||||||
|
target_dict[key] = value
|
||||||
|
|
||||||
|
|
||||||
|
+_CONFIG_VARS_LOCAL = None
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+def _config_vars_local():
|
||||||
|
+ # This function returns the config vars with prefixes amended to /usr/local
|
||||||
|
+ # https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
+ global _CONFIG_VARS_LOCAL
|
||||||
|
+ if _CONFIG_VARS_LOCAL is None:
|
||||||
|
+ _CONFIG_VARS_LOCAL = dict(get_config_vars())
|
||||||
|
+ _CONFIG_VARS_LOCAL['base'] = '/usr/local'
|
||||||
|
+ _CONFIG_VARS_LOCAL['platbase'] = '/usr/local'
|
||||||
|
+ return _CONFIG_VARS_LOCAL
|
||||||
|
+
|
||||||
|
+
|
||||||
|
def _expand_vars(scheme, vars):
|
||||||
|
res = {}
|
||||||
|
if vars is None:
|
||||||
|
vars = {}
|
||||||
|
- _extend_dict(vars, get_config_vars())
|
||||||
|
+
|
||||||
|
+ # when we are not in a virtual environment or an RPM build
|
||||||
|
+ # we change '/usr' to '/usr/local'
|
||||||
|
+ # to avoid surprises, we explicitly check for the /usr/ prefix
|
||||||
|
+ # Python virtual environments have different prefixes
|
||||||
|
+ # we only do this for posix_prefix, not to mangle the venv scheme
|
||||||
|
+ # posix_prefix is used by sudo pip install
|
||||||
|
+ # we only change the defaults here, so explicit --prefix will take precedence
|
||||||
|
+ # https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
+ if (scheme == 'posix_prefix' and
|
||||||
|
+ _PREFIX == '/usr' and
|
||||||
|
+ 'RPM_BUILD_ROOT' not in os.environ):
|
||||||
|
+ _extend_dict(vars, _config_vars_local())
|
||||||
|
+ else:
|
||||||
|
+ _extend_dict(vars, get_config_vars())
|
||||||
|
|
||||||
|
for key, value in _INSTALL_SCHEMES[scheme].items():
|
||||||
|
if os.name in ('posix', 'nt'):
|
||||||
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
|
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
|
||||||
index 5ee9839c04..4cc7b13719 100644
|
index 5ee9839c04..16e92ca86f 100644
|
||||||
--- a/Lib/test/test_sysconfig.py
|
--- a/Lib/test/test_sysconfig.py
|
||||||
+++ b/Lib/test/test_sysconfig.py
|
+++ b/Lib/test/test_sysconfig.py
|
||||||
@@ -263,7 +263,7 @@ def test_get_config_h_filename(self):
|
@@ -105,8 +105,19 @@ def test_get_path(self):
|
||||||
|
for scheme in _INSTALL_SCHEMES:
|
||||||
|
for name in _INSTALL_SCHEMES[scheme]:
|
||||||
|
expected = _INSTALL_SCHEMES[scheme][name].format(**config_vars)
|
||||||
|
+ tested = get_path(name, scheme)
|
||||||
|
+ # https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
+ if tested.startswith('/usr/local'):
|
||||||
|
+ # /usr/local should only be used in posix_prefix
|
||||||
|
+ self.assertEqual(scheme, 'posix_prefix')
|
||||||
|
+ # Fedora CI runs tests for venv and virtualenv that check for other prefixes
|
||||||
|
+ self.assertEqual(sys.prefix, '/usr')
|
||||||
|
+ # When building the RPM of Python, %check runs this with RPM_BUILD_ROOT set
|
||||||
|
+ # Fedora CI runs this with RPM_BUILD_ROOT unset
|
||||||
|
+ self.assertNotIn('RPM_BUILD_ROOT', os.environ)
|
||||||
|
+ tested = tested.replace('/usr/local', '/usr')
|
||||||
|
self.assertEqual(
|
||||||
|
- os.path.normpath(get_path(name, scheme)),
|
||||||
|
+ os.path.normpath(tested),
|
||||||
|
os.path.normpath(expected),
|
||||||
|
)
|
||||||
|
|
||||||
|
@@ -263,7 +274,7 @@ def test_get_config_h_filename(self):
|
||||||
self.assertTrue(os.path.isfile(config_h), config_h)
|
self.assertTrue(os.path.isfile(config_h), config_h)
|
||||||
|
|
||||||
def test_get_scheme_names(self):
|
def test_get_scheme_names(self):
|
||||||
|
@ -102,7 +197,7 @@ index 5ee9839c04..4cc7b13719 100644
|
||||||
if HAS_USER_BASE:
|
if HAS_USER_BASE:
|
||||||
wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
|
wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
|
||||||
self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
|
self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
|
||||||
@@ -274,6 +274,8 @@ def test_symlink(self): # Issue 7880
|
@@ -274,6 +285,8 @@ def test_symlink(self): # Issue 7880
|
||||||
cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
|
cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
|
||||||
self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
|
self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ URL: https://www.python.org/
|
||||||
#global prerel ...
|
#global prerel ...
|
||||||
%global upstream_version %{general_version}%{?prerel}
|
%global upstream_version %{general_version}%{?prerel}
|
||||||
Version: %{general_version}%{?prerel:~%{prerel}}
|
Version: %{general_version}%{?prerel:~%{prerel}}
|
||||||
Release: 1%{?dist}
|
Release: 2%{?dist}
|
||||||
License: Python
|
License: Python
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,24 +276,25 @@ Source11: idle3.appdata.xml
|
||||||
# Was Patch0 in ivazquez' python3000 specfile
|
# Was Patch0 in ivazquez' python3000 specfile
|
||||||
Patch1: 00001-rpath.patch
|
Patch1: 00001-rpath.patch
|
||||||
|
|
||||||
# 00251 # 531494a5ded29dad59f617304dab4eb8b7f80b0b
|
# 00251 # 8448a0d6edd44d0818b8c02dc603b769b5363e5b
|
||||||
# Change user install location
|
# Change user install location
|
||||||
#
|
#
|
||||||
# Change the values of sysconfig's "posix_prefix" install scheme to /usr/local
|
# Set values of base and platbase in sysconfig from /usr
|
||||||
# when RPM build or venv/virtualenv is not detected,
|
# to /usr/local when RPM build is not detected
|
||||||
# to make pip, sysconfig and distutils install into an isolated location.
|
# to make pip and similar tools install into separate location.
|
||||||
#
|
#
|
||||||
# The original values are saved as an additional "rpm_prefix" install scheme.
|
# Set values of prefix and exec_prefix in distutils install command
|
||||||
#
|
# to /usr/local if executable is /usr/bin/python* and RPM build
|
||||||
# The site module adds the /usr/local paths to sys.path when site packages are
|
# is not detected to make distutils and pypa/distutils install into separate location.
|
||||||
# enabled and RPM build is not detected.
|
|
||||||
#
|
#
|
||||||
# Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
# Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
||||||
|
# Downstream only.
|
||||||
#
|
#
|
||||||
# Rewrote in Fedora 36+ to patch sysconfig instead of distutils,
|
# We've tried to rework in Fedora 36/Python 3.10 to follow https://bugs.python.org/issue43976
|
||||||
# see https://discuss.python.org/t/pep-632-deprecate-distutils-module/5134/104
|
# but we have identified serious problems with that approach,
|
||||||
|
# see https://bugzilla.redhat.com/2026979 or https://bugzilla.redhat.com/2097183
|
||||||
#
|
#
|
||||||
# Downstream only for now, waiting for https://bugs.python.org/issue43976
|
# pypa/distutils integration: https://github.com/pypa/distutils/pull/70
|
||||||
Patch251: 00251-change-user-install-location.patch
|
Patch251: 00251-change-user-install-location.patch
|
||||||
|
|
||||||
# 00328 # 318e500c98f5e59eb1f23e0fcd32db69b9bd17e1
|
# 00328 # 318e500c98f5e59eb1f23e0fcd32db69b9bd17e1
|
||||||
|
@ -1588,6 +1589,11 @@ CheckPython optimized
|
||||||
# ======================================================
|
# ======================================================
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Aug 22 2022 Miro Hrončok <mhroncok@redhat.com> - 3.10.6-2
|
||||||
|
- Don't use custom installation schemes
|
||||||
|
- Fixes rhbz#2026979
|
||||||
|
- Fixes rhbz#2097183
|
||||||
|
|
||||||
* Tue Aug 02 2022 Tomáš Hrnčiar <thrnciar@redhat.com> - 3.10.6-1
|
* Tue Aug 02 2022 Tomáš Hrnčiar <thrnciar@redhat.com> - 3.10.6-1
|
||||||
- Update to 3.10.6
|
- Update to 3.10.6
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue