Sync patch 251 with Python 3.10+ on Fedora < 36

Instruct pip to use distutils
-----------------------------

The current version of pip uses distutils on Python < 3.10,
so this should change nothing,
but future versions of pip may theoretically change that.

Instruct pypa/distutils to add /local/ addition to prefix
---------------------------------------------------------

Needed for setuptools 60+ installed/upgraded by pip or when we update it in rawhide.
Setuptools 60+ uses bundled pypa/distutils instead of the standard library distutils.

Resolves: rhbz#2040656
This commit is contained in:
Miro Hrončok 2022-01-14 11:31:45 +00:00
parent e5bcc23d18
commit f879788604
2 changed files with 79 additions and 21 deletions

View File

@ -2,41 +2,61 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Michal Cyprian <m.cyprian@gmail.com>
Date: Mon, 26 Jun 2017 16:32:56 +0200
Subject: [PATCH] 00251: Change user install location
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Set values of prefix and exec_prefix in distutils install command
to /usr/local if executable is /usr/bin/python* and RPM build
is not detected to make pip and distutils install into separate location.
Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
Downstream only: Awaiting resources to work on upstream PEP
Downstream only: Reworked in Fedora 36+/Python 3.10+ to follow https://bugs.python.org/issue43976
pypa/distutils integration: https://github.com/pypa/distutils/pull/70
Also set sysconfig._PIP_USE_SYSCONFIG = False, to force pip-upgraded-pip
to respect this patched distutils install command.
See https://bugzilla.redhat.com/show_bug.cgi?id=2014513
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
---
Lib/distutils/command/install.py | 15 +++++++++++++--
Lib/distutils/command/install.py | 9 +++++++--
Lib/site.py | 9 ++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
Lib/sysconfig.py | 17 +++++++++++++++++
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index aaa300efa9..f8d453912a 100644
index aaa300efa9..18f01f10d4 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -419,8 +419,19 @@ class install(Command):
@@ -3,6 +3,7 @@
Implements the Distutils 'install' command."""
import sys
+import sysconfig
import os
from distutils import log
@@ -142,6 +143,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."""
@@ -419,8 +422,10 @@ class install(Command):
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 is set to sys.prefix + /local/
+ # if neither RPM build nor virtual environment is
+ # detected to make pip and distutils install packages
+ # into the separate location.
+ if (not (hasattr(sys, 'real_prefix') or
+ sys.prefix != sys.base_prefix) and
+ 'RPM_BUILD_ROOT' not in os.environ):
+ addition = "/local"
+ else:
+ addition = ""
+
+ self.prefix = os.path.normpath(sys.prefix) + addition
+ self.exec_prefix = os.path.normpath(sys.exec_prefix) + addition
+ 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:
@ -60,3 +80,31 @@ index 9e617afb00..db14f715f9 100644
for sitedir in getsitepackages(prefixes):
if os.path.isdir(sitedir):
addsitedir(sitedir, known_paths)
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index e3f79bfde5..e124104876 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -86,6 +86,23 @@ _INSTALL_SCHEMES = {
},
}
+# Force pip to use distutils paths instead of sysconfig
+# https://github.com/pypa/pip/issues/10647
+_PIP_USE_SYSCONFIG = False
+
+# 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')

View File

@ -17,7 +17,7 @@ URL: https://www.python.org/
#global prerel ...
%global upstream_version %{general_version}%{?prerel}
Version: %{general_version}%{?prerel:~%{prerel}}
Release: 2%{?dist}
Release: 4%{?dist}
License: Python
@ -328,7 +328,7 @@ Patch189: 00189-use-rpm-wheels.patch
%global pip_version 21.2.4
%global setuptools_version 58.1.0
# 00251 # 2eabd04356402d488060bc8fe316ad13fc8a3356
# 00251 # 1b1047c14ff98eae6d355b4aac4df3e388813f62
# Change user install location
#
# Set values of prefix and exec_prefix in distutils install command
@ -336,7 +336,13 @@ Patch189: 00189-use-rpm-wheels.patch
# is not detected to make pip and distutils install into separate location.
#
# Fedora Change: https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
# Downstream only: Awaiting resources to work on upstream PEP
# Downstream only: Reworked in Fedora 36+/Python 3.10+ to follow https://bugs.python.org/issue43976
#
# pypa/distutils integration: https://github.com/pypa/distutils/pull/70
#
# Also set sysconfig._PIP_USE_SYSCONFIG = False, to force pip-upgraded-pip
# to respect this patched distutils install command.
# See https://bugzilla.redhat.com/show_bug.cgi?id=2014513
Patch251: 00251-change-user-install-location.patch
# 00328 # 367fdcb5a075f083aea83ac174999272a8faf75c
@ -1793,6 +1799,10 @@ CheckPython optimized
# ======================================================
%changelog
* Sat Jan 08 2022 Miro Hrončok <mhroncok@redhat.com> - 3.9.9-4
- Instruct pip to use distutils
- Instruct pypa/distutils to add /local/ addition to prefix
* Mon Nov 22 2021 Tomas Orsava <torsava@redhat.com> - 3.9.9-2
- Read pre-packaged Python wheels from a newly versioned directory
/usr/share/python3-wheels