Use sysconfig.get_path() to define %python_sitelib and %python_sitearch
Distutils which were used to define the macros are deprecated in Python3.10: https://www.python.org/dev/peps/pep-0632/. Sysconfig isn't and it works across our Pythons, making it better choice for the task.
This commit is contained in:
parent
bd4c3de20c
commit
9d2fcef337
@ -1,7 +1,7 @@
|
||||
# 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 "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
|
||||
%python_sitearch %(%{__python} -Esc "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
|
||||
%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())")
|
||||
|
@ -1,5 +1,5 @@
|
||||
%python3_sitelib %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
|
||||
%python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
|
||||
%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())")
|
||||
|
@ -22,7 +22,7 @@ License: MIT and Python
|
||||
# The macro is defined in python-srpm-macros.
|
||||
%{?load:%{SOURCE102}}
|
||||
Version: %{__default_python3_version}
|
||||
Release: 36%{?dist}
|
||||
Release: 37%{?dist}
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
@ -95,6 +95,10 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Apr 07 2021 Karolina Surma <ksurma@redhat.com> - 3.9-37
|
||||
- Use sysconfig.get_path() to get %%python3_sitelib and %%python3_sitearch
|
||||
- Fixes: rhbz#1946972
|
||||
|
||||
* Mon Mar 29 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-36
|
||||
- Allow commas as argument separator for extras names in %%python_extras_subpkg
|
||||
- Fixes: rhbz#1936486
|
||||
|
@ -38,6 +38,17 @@ def rpm_eval(expression, fails=False, **kwargs):
|
||||
return cp.stdout.strip().splitlines()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def lib():
|
||||
lib_eval = rpm_eval("%_lib")[0]
|
||||
if lib_eval == "%_lib" and TESTED_FILES:
|
||||
raise ValueError(
|
||||
"%_lib is not resolved to an actual value. "
|
||||
"You may want to include /usr/lib/rpm/platform/x86_64-linux/macros to TESTED_FILES."
|
||||
)
|
||||
return lib_eval
|
||||
|
||||
|
||||
def shell_stdout(script):
|
||||
return subprocess.check_output(script,
|
||||
env={**os.environ, 'LANG': 'C.utf-8'},
|
||||
@ -290,9 +301,8 @@ def test_pycached_in_sitelib():
|
||||
]
|
||||
|
||||
|
||||
def test_pycached_in_sitearch():
|
||||
def test_pycached_in_sitearch(lib):
|
||||
lines = rpm_eval('%pycached %{python3_sitearch}/foo*.py')
|
||||
lib = rpm_eval('%_lib')[0]
|
||||
assert lines == [
|
||||
f'/usr/{lib}/python{X_Y}/site-packages/foo*.py',
|
||||
f'/usr/{lib}/python{X_Y}/site-packages/__pycache__/foo*.cpython-{XY}{{,.opt-?}}.pyc'
|
||||
@ -532,3 +542,27 @@ def test_platform_triplet():
|
||||
@x86_64_only
|
||||
def test_ext_suffix():
|
||||
assert rpm_eval("%python3_ext_suffix")[0] == f".cpython-{XY}-x86_64-linux-gnu.so"
|
||||
|
||||
|
||||
def test_python_sitelib_value():
|
||||
macro = '%python_sitelib'
|
||||
assert rpm_eval(macro, __python='/usr/bin/python3.6')[0] == f'/usr/lib/python3.6/site-packages'
|
||||
assert rpm_eval(macro, __python='%__python3')[0] == f'/usr/lib/python{X_Y}/site-packages'
|
||||
|
||||
|
||||
def test_python3_sitelib_value():
|
||||
macro = '%python3_sitelib'
|
||||
assert rpm_eval(macro, __python3='/usr/bin/python3.6')[0] == f'/usr/lib/python3.6/site-packages'
|
||||
assert rpm_eval(macro)[0] == f'/usr/lib/python{X_Y}/site-packages'
|
||||
|
||||
|
||||
def test_python_sitearch_value(lib):
|
||||
macro = '%python_sitearch'
|
||||
assert rpm_eval(macro, __python='/usr/bin/python3.6')[0] == f'/usr/{lib}/python3.6/site-packages'
|
||||
assert rpm_eval(macro, __python='%__python3')[0] == f'/usr/{lib}/python{X_Y}/site-packages'
|
||||
|
||||
|
||||
def test_python3_sitearch_value(lib):
|
||||
macro = '%python3_sitearch'
|
||||
assert rpm_eval(macro, __python3='/usr/bin/python3.6')[0] == f'/usr/{lib}/python3.6/site-packages'
|
||||
assert rpm_eval(macro)[0] == f'/usr/{lib}/python{X_Y}/site-packages'
|
||||
|
@ -25,4 +25,5 @@
|
||||
- python3-rpm-macros
|
||||
- python3-devel
|
||||
- python3-pytest
|
||||
- python3.6
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user