2020-07-20 19:52:13 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2021-10-05 09:53:19 +00:00
|
|
|
From: Lumir Balhar <lbalhar@redhat.com>
|
|
|
|
Date: Mon, 15 Feb 2021 12:19:27 +0100
|
2019-07-29 22:48:16 +00:00
|
|
|
Subject: [PATCH] 00251: Change user install location
|
2021-10-06 14:40:28 +00:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
2019-05-07 15:13:12 +00:00
|
|
|
|
2021-10-05 09:53:19 +00:00
|
|
|
Change the values of sysconfig's "posix_prefix" install scheme to /usr/local
|
|
|
|
when RPM build or venv/virtualenv is not detected,
|
|
|
|
to make pip, sysconfig and distutils install into an isolated location.
|
|
|
|
|
|
|
|
The original values are saved as an additional "rpm_prefix" install scheme.
|
|
|
|
|
|
|
|
The site module adds the /usr/local paths to sys.path when site packages are
|
|
|
|
enabled and RPM build is not detected.
|
2019-05-07 15:13:12 +00:00
|
|
|
|
|
|
|
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
|
2021-10-05 09:53:19 +00:00
|
|
|
|
|
|
|
Rewrote in Fedora 36+ to patch sysconfig instead of distutils,
|
|
|
|
see https://discuss.python.org/t/pep-632-deprecate-distutils-module/5134/104
|
|
|
|
|
|
|
|
Downstream only for now, waiting for https://bugs.python.org/issue43976
|
|
|
|
|
|
|
|
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
|
|
|
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
|
|
|
|
Co-authored-by: Michal Cyprian <m.cyprian@gmail.com>
|
2021-11-08 07:25:56 +00:00
|
|
|
Co-authored-by: Lumír Balhar <frenzy.madness@gmail.com>
|
2019-05-07 15:13:12 +00:00
|
|
|
---
|
2021-10-05 09:53:19 +00:00
|
|
|
Lib/site.py | 9 ++++++++-
|
2022-04-06 09:36:00 +00:00
|
|
|
Lib/sysconfig.py | 19 +++++++++++++++++++
|
2021-10-05 09:53:19 +00:00
|
|
|
Lib/test/test_sysconfig.py | 4 +++-
|
2022-04-06 09:36:00 +00:00
|
|
|
3 files changed, 30 insertions(+), 2 deletions(-)
|
2021-10-05 09:53:19 +00:00
|
|
|
|
2017-06-26 14:32:56 +00:00
|
|
|
diff --git a/Lib/site.py b/Lib/site.py
|
2021-12-10 08:58:04 +00:00
|
|
|
index b11cd48e69..63ddd5b21b 100644
|
2017-06-26 14:32:56 +00:00
|
|
|
--- a/Lib/site.py
|
|
|
|
+++ b/Lib/site.py
|
2021-12-10 08:58:04 +00:00
|
|
|
@@ -377,8 +377,15 @@ def getsitepackages(prefixes=None):
|
2017-06-26 14:32:56 +00:00
|
|
|
return sitepackages
|
2019-05-07 15:13:12 +00:00
|
|
|
|
2017-06-26 14:32:56 +00:00
|
|
|
def addsitepackages(known_paths, prefixes=None):
|
|
|
|
- """Add site-packages to sys.path"""
|
2018-02-02 11:27:49 +00:00
|
|
|
+ """Add site-packages to sys.path
|
2017-06-26 14:32:56 +00:00
|
|
|
+
|
2018-02-02 11:27:49 +00:00
|
|
|
+ '/usr/local' is included in PREFIXES if RPM build is not detected
|
|
|
|
+ to make packages installed into this location visible.
|
2017-06-26 14:32:56 +00:00
|
|
|
+
|
|
|
|
+ """
|
2020-10-09 10:25:22 +00:00
|
|
|
_trace("Processing global site-packages")
|
2018-02-02 11:27:49 +00:00
|
|
|
+ if ENABLE_USER_SITE and 'RPM_BUILD_ROOT' not in os.environ:
|
2017-06-26 14:32:56 +00:00
|
|
|
+ PREFIXES.insert(0, "/usr/local")
|
|
|
|
for sitedir in getsitepackages(prefixes):
|
|
|
|
if os.path.isdir(sitedir):
|
|
|
|
addsitedir(sitedir, known_paths)
|
2021-10-05 09:53:19 +00:00
|
|
|
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
|
2022-05-08 07:44:42 +00:00
|
|
|
index e21b7303fe..37b04452bc 100644
|
2021-10-05 09:53:19 +00:00
|
|
|
--- a/Lib/sysconfig.py
|
|
|
|
+++ b/Lib/sysconfig.py
|
2022-04-06 09:36:00 +00:00
|
|
|
@@ -103,6 +103,25 @@
|
|
|
|
else:
|
|
|
|
_INSTALL_SCHEMES['venv'] = _INSTALL_SCHEMES['posix_venv']
|
2021-10-05 09:53:19 +00:00
|
|
|
|
|
|
|
+# backup the original posix_prefix as rpm_prefix
|
|
|
|
+# RPM packages use it and we need to be able to read it even when changed
|
|
|
|
+_INSTALL_SCHEMES['rpm_prefix'] = _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.
|
|
|
|
# Sync it when modify this function.
|
|
|
|
diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
|
2022-05-08 07:44:42 +00:00
|
|
|
index f2b93706b2..cc58f47cdb 100644
|
2021-10-05 09:53:19 +00:00
|
|
|
--- a/Lib/test/test_sysconfig.py
|
|
|
|
+++ b/Lib/test/test_sysconfig.py
|
2022-04-06 09:36:00 +00:00
|
|
|
@@ -333,7 +333,7 @@ def test_get_config_h_filename(self):
|
2021-10-05 09:53:19 +00:00
|
|
|
self.assertTrue(os.path.isfile(config_h), config_h)
|
|
|
|
|
|
|
|
def test_get_scheme_names(self):
|
2022-04-06 09:36:00 +00:00
|
|
|
- wanted = ['nt', 'posix_home', 'posix_prefix', 'posix_venv', 'nt_venv', 'venv']
|
|
|
|
+ wanted = ['nt', 'posix_home', 'posix_prefix', 'posix_venv', 'nt_venv', 'venv', 'rpm_prefix']
|
2021-10-05 09:53:19 +00:00
|
|
|
if HAS_USER_BASE:
|
|
|
|
wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
|
|
|
|
self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
|
2022-04-06 09:36:00 +00:00
|
|
|
@@ -345,6 +345,8 @@ def test_symlink(self): # Issue 7880
|
2021-10-05 09:53:19 +00:00
|
|
|
cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
|
|
|
|
self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
|
|
|
|
|
|
|
|
+ @unittest.skipIf('RPM_BUILD_ROOT' not in os.environ,
|
|
|
|
+ "Test doesn't expect Fedora's paths")
|
|
|
|
def test_user_similar(self):
|
|
|
|
# Issue #8759: make sure the posix scheme for the users
|
|
|
|
# is similar to the global posix_prefix one
|