From 5b578a851f09c93b8e105ab22511f004f6e5c9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 3 Sep 2021 16:06:03 +0200 Subject: [PATCH] Set $RPM_BUILD_ROOT in %{python3_...} macros, for alternate sysconfig install scheme Our Pythons currently patches distutils to install packages to /usr/lib(64)/pythonX.Y/site-packages when the $RPM_BUILD_ROOT environment variable is set (and to /usr/local/lib(64)/pythonX.Y/site-packages otherwise). With the deprecation of distutils [1] we want to change the patch to create and use a different sysconfig install scheme [2]. However, we have realized that macros defined as %(%{__python3} ...) don't "see" the environment variables set by rpmbuild because they are expanded earlier and hence e.g. %{python3_sitelib} evaluates to /usr/local/lib/python3.X/site-packages -- which is not desired. To be able to reliably detect an RPM build environment by checking the presence of the $RPM_BUILD_ROOT environment variable, we manually set it in the macro definitions. Since %{buildroot} in not fully populated (e.g. it can expand literally to /home/anna/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64), we don't use it here. The variable simply needs to present in the environment. See also the analysis of the build failures when this is not done [3]. [1] https://www.python.org/dev/peps/pep-0632/ [2] https://bugs.python.org/issue43976 [3] https://src.fedoraproject.org/rpms/python3.10/pull-request/63#comment-79042 --- macros.python | 16 +++++++++------- macros.python3 | 16 +++++++++------- python-rpm-macros.spec | 6 +++++- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/macros.python b/macros.python index 04c47c5..39b4120 100644 --- a/macros.python +++ b/macros.python @@ -1,12 +1,14 @@ # unversioned macros: used with user defined __python, no longer part of rpm >= 4.15 # __python is defined to error by default in the srpm macros -%python_sitelib %(%{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib'))") -%python_sitearch %(%{__python} -Esc "import sysconfig; print(sysconfig.get_path('platlib'))") -%python_version %(%{__python} -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))") -%python_version_nodots %(%{__python} -Esc "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") -%python_platform %(%{__python} -Esc "import sysconfig; print(sysconfig.get_platform())") -%python_platform_triplet %(%{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))") -%python_ext_suffix %(%{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") +# nb: $RPM_BUILD_ROOT is not set when the macros are expanded (at spec parse time) +# so we set it manually (to empty string), making our Python prefer the correct install scheme location +%python_sitelib %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib'))") +%python_sitearch %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_path('platlib'))") +%python_version %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))") +%python_version_nodots %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") +%python_platform %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_platform())") +%python_platform_triplet %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))") +%python_ext_suffix %(RPM_BUILD_ROOT= %{__python} -Esc "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") %py_setup setup.py %py_shbang_opts -s diff --git a/macros.python3 b/macros.python3 index 93b4199..7db969e 100644 --- a/macros.python3 +++ b/macros.python3 @@ -1,10 +1,12 @@ -%python3_sitelib %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))") -%python3_sitearch %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_path('platlib'))") -%python3_version %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))") -%python3_version_nodots %(%{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") -%python3_platform %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())") -%python3_platform_triplet %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))") -%python3_ext_suffix %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") +# nb: $RPM_BUILD_ROOT is not set when the macros are expanded (at spec parse time) +# so we set it manually (to empty string), making our Python prefer the correct install scheme location +%python3_sitelib %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))") +%python3_sitearch %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_path('platlib'))") +%python3_version %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}.{0.minor}'.format(sys.version_info))") +%python3_version_nodots %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))") +%python3_platform %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())") +%python3_platform_triplet %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('MULTIARCH'))") +%python3_ext_suffix %(RPM_BUILD_ROOT= %{__python3} -Ic "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))") %py3dir %{_builddir}/python3-%{name}-%{version}-%{release} %py3_shbang_opts -s diff --git a/python-rpm-macros.spec b/python-rpm-macros.spec index 624a66e..b0364e2 100644 --- a/python-rpm-macros.spec +++ b/python-rpm-macros.spec @@ -47,7 +47,7 @@ elseif posix.stat('macros.python-srpm') then end } Version: %{__default_python3_version} -Release: 8%{?dist} +Release: 9%{?dist} BuildArch: noarch @@ -141,6 +141,10 @@ install -m 755 brp-* %{buildroot}%{_rpmconfigdir}/redhat/ %changelog +* Thu Sep 09 2021 Miro HronĨok - 3.10-9 +- Set $RPM_BUILD_ROOT in %%{python3_...} macros + to allow selecting alternate sysconfig install scheme based on that variable + * Thu Sep 09 2021 Petr Viktorin - 3.10-8 - Use --hardlink-dupes in %%py_byte_compile and brp-python-bytecompile (for Python 3)