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. Related: rhbz#1950291
This commit is contained in:
parent
019f8b973d
commit
20a3073f02
@ -1,7 +1,7 @@
|
|||||||
# unversioned macros: used with user defined __python, no longer part of rpm >= 4.15
|
# 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 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_sitelib %(%{__python} -Esc "import sysconfig; print(sysconfig.get_path('purelib'))")
|
||||||
%python_sitearch %(%{__python} -Esc "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
|
%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 %(%{__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_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 %(%{__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_sitelib %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_path('purelib'))")
|
||||||
%python3_sitearch %(%{__python3} -Ic "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
|
%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 %(%{__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_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 %(%{__python3} -Ic "import sysconfig; print(sysconfig.get_platform())")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Name: python-rpm-macros
|
Name: python-rpm-macros
|
||||||
Version: 3.9
|
Version: 3.9
|
||||||
Release: 36.1%{?dist}
|
Release: 37%{?dist}
|
||||||
Summary: The common Python RPM macros
|
Summary: The common Python RPM macros
|
||||||
|
|
||||||
# macros and lua: MIT, compileall2.py: PSFv2
|
# macros and lua: MIT, compileall2.py: PSFv2
|
||||||
@ -90,6 +90,10 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Apr 16 2021 Karolina Surma <ksurma@redhat.com> - 3.9-37
|
||||||
|
- Use sysconfig.get_path() to get %%python3_sitelib and %%python3_sitearch
|
||||||
|
- Fixes: rhbz#1947468
|
||||||
|
|
||||||
* Fri Apr 16 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-36.1
|
* Fri Apr 16 2021 Miro Hrončok <mhroncok@redhat.com> - 3.9-36.1
|
||||||
- Allow commas as argument separator for extras names in %%python_extras_subpkg
|
- Allow commas as argument separator for extras names in %%python_extras_subpkg
|
||||||
- Fixes: rhbz#1936486
|
- Fixes: rhbz#1936486
|
||||||
|
@ -38,6 +38,17 @@ def rpm_eval(expression, fails=False, **kwargs):
|
|||||||
return cp.stdout.strip().splitlines()
|
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):
|
def shell_stdout(script):
|
||||||
return subprocess.check_output(script,
|
return subprocess.check_output(script,
|
||||||
env={**os.environ, 'LANG': 'C.utf-8'},
|
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')
|
lines = rpm_eval('%pycached %{python3_sitearch}/foo*.py')
|
||||||
lib = rpm_eval('%_lib')[0]
|
|
||||||
assert lines == [
|
assert lines == [
|
||||||
f'/usr/{lib}/python{X_Y}/site-packages/foo*.py',
|
f'/usr/{lib}/python{X_Y}/site-packages/foo*.py',
|
||||||
f'/usr/{lib}/python{X_Y}/site-packages/__pycache__/foo*.cpython-{XY}{{,.opt-?}}.pyc'
|
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
|
@x86_64_only
|
||||||
def test_ext_suffix():
|
def test_ext_suffix():
|
||||||
assert rpm_eval("%python3_ext_suffix")[0] == f".cpython-{XY}-x86_64-linux-gnu.so"
|
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-rpm-macros
|
||||||
- python3-devel
|
- python3-devel
|
||||||
- python3-pytest
|
- python3-pytest
|
||||||
|
- python3.6
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user