From c8fcf4d2e3aaf543f065971dcf78451be35adcc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 19 Nov 2021 16:50:31 +0100 Subject: [PATCH 1/6] Incorporate Fedora's distutil patch See https://github.com/pypa/setuptools/pull/2896#issuecomment-973983395 --- distutils/command/install.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index c756b6db..dbc83fce 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -471,8 +471,24 @@ 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) + # Fedora (and Fedora derived distros) used to patch distutils + # until Fedora 36 and/or Python 3.11. + # Here, we preserve that behavior conditionally on a special + # _distutils_mangle_rpm_prefix attribute of sysconfig + # that Fedora sets on their older Pythons to support this check. + # When it is set and true-ish, + # self.prefix is set to sys.prefix + /local/ + # if neither RPM build nor virtual environment is + # detected to make pip and distutils install packages to /usr/local. + addition = "" + if (getattr(sysconfig, "_distutils_mangle_rpm_prefix", False) and + not (hasattr(sys, 'real_prefix') or + sys.prefix != sys.base_prefix) and + 'RPM_BUILD_ROOT' not in os.environ): + addition = "/local" + + self.prefix = os.path.normpath(sys.prefix) + addition + self.exec_prefix = os.path.normpath(sys.exec_prefix) + addition else: if self.exec_prefix is None: From 22e1669edc3ed00a87e59a2f6c5918aa67ae731e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 20 Nov 2021 12:18:15 -0500 Subject: [PATCH 2/6] Expose _prefix_addition as a class property on install. --- distutils/command/install.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index dbc83fce..583b1713 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -190,6 +190,8 @@ class install(Command): negative_opt = {'no-compile' : 'compile'} + # Allow Fedora to add components to the prefix + _prefix_addition = "" def initialize_options(self): """Initializes options.""" @@ -471,24 +473,10 @@ def finalize_unix(self): raise DistutilsOptionError( "must not supply exec-prefix without prefix") - # Fedora (and Fedora derived distros) used to patch distutils - # until Fedora 36 and/or Python 3.11. - # Here, we preserve that behavior conditionally on a special - # _distutils_mangle_rpm_prefix attribute of sysconfig - # that Fedora sets on their older Pythons to support this check. - # When it is set and true-ish, - # self.prefix is set to sys.prefix + /local/ - # if neither RPM build nor virtual environment is - # detected to make pip and distutils install packages to /usr/local. - addition = "" - if (getattr(sysconfig, "_distutils_mangle_rpm_prefix", False) and - not (hasattr(sys, 'real_prefix') or - sys.prefix != sys.base_prefix) and - 'RPM_BUILD_ROOT' not in os.environ): - addition = "/local" - - 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: From 8c64fdc8560d9f7b7d3926350bba7702b0906329 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 20 Nov 2021 12:47:02 -0500 Subject: [PATCH 3/6] Update comment for _distutils_system_mod. --- distutils/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/distutils/__init__.py b/distutils/__init__.py index 8fd493b4..ba337639 100644 --- a/distutils/__init__.py +++ b/distutils/__init__.py @@ -15,8 +15,10 @@ try: - # Allow Debian and pkgsrc (only) to customize system - # behavior. Ref pypa/distutils#2 and pypa/distutils#16. + # Allow Debian and pkgsrc and Fedora (only) to customize + # system + # behavior. Ref pypa/distutils#2 and pypa/distutils#16 + # and pypa/distutils#70. # This hook is deprecated and no other environments # should use it. importlib.import_module('_distutils_system_mod') From 81d6300d60c59cea05a6dfe9a513ced61b901f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 24 Nov 2021 13:28:58 +0100 Subject: [PATCH 4/6] Load _prefix_addition attribute directly from sysconfig Co-authored-by: Jason R. Coombs --- distutils/command/install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index 583b1713..d648dd18 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -191,7 +191,7 @@ class install(Command): negative_opt = {'no-compile' : 'compile'} # Allow Fedora to add components to the prefix - _prefix_addition = "" + _prefix_addition = getattr(sysconfig, '_prefix_addition', "") def initialize_options(self): """Initializes options.""" From f76901831084c11ec633eb96c310860d15199edd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Wed, 24 Nov 2021 11:57:52 -0500 Subject: [PATCH 5/6] Revert "Update comment for _distutils_system_mod." as Fedora is not using that hook. This reverts commit 8c64fdc8560d9f7b7d3926350bba7702b0906329. --- distutils/__init__.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/distutils/__init__.py b/distutils/__init__.py index ba337639..8fd493b4 100644 --- a/distutils/__init__.py +++ b/distutils/__init__.py @@ -15,10 +15,8 @@ try: - # Allow Debian and pkgsrc and Fedora (only) to customize - # system - # behavior. Ref pypa/distutils#2 and pypa/distutils#16 - # and pypa/distutils#70. + # Allow Debian and pkgsrc (only) to customize system + # behavior. Ref pypa/distutils#2 and pypa/distutils#16. # This hook is deprecated and no other environments # should use it. importlib.import_module('_distutils_system_mod') From 58ccfa53b00b8de5d56295cc9825c6efd2e3581f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 27 Nov 2021 22:50:34 -0500 Subject: [PATCH 6/6] Move _prefix_addition inline, so it's only configurable through sysconfig. --- distutils/command/install.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/distutils/command/install.py b/distutils/command/install.py index d648dd18..18b352fa 100644 --- a/distutils/command/install.py +++ b/distutils/command/install.py @@ -190,8 +190,6 @@ 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.""" @@ -473,10 +471,13 @@ def finalize_unix(self): raise DistutilsOptionError( "must not supply exec-prefix without prefix") + # Allow Fedora to add components to the prefix + _prefix_addition = getattr(sysconfig, '_prefix_addition', "") + self.prefix = ( - os.path.normpath(sys.prefix) + self._prefix_addition) + os.path.normpath(sys.prefix) + _prefix_addition) self.exec_prefix = ( - os.path.normpath(sys.exec_prefix) + self._prefix_addition) + os.path.normpath(sys.exec_prefix) + _prefix_addition) else: if self.exec_prefix is None: