Define %python3_cache_tag / %python_cache_tag, e.g. cpython-311
When reviewing https://src.fedoraproject.org/rpms/pyproject-rpm-macros/pull-request/291 we have discovered that there is no macronized way to get this part of some paths and that packagers need to hardcode it as cpython-%{python3_version_nodots}. This way, we have a standardized macro packagers (and other macros) can use.
This commit is contained in:
parent
d174f03f62
commit
3cce7271e4
@ -10,6 +10,7 @@
|
||||
%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'))")
|
||||
%python_cache_tag %(RPM_BUILD_ROOT= %{__python} -Esc "import sys; print(sys.implementation.cache_tag)")
|
||||
|
||||
%py_setup setup.py
|
||||
%py_shbang_opts -s
|
||||
|
@ -8,6 +8,7 @@
|
||||
%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'))")
|
||||
%python3_cache_tag %(RPM_BUILD_ROOT= %{__python3} -Ic "import sys; print(sys.implementation.cache_tag)")
|
||||
%py3dir %{_builddir}/python3-%{name}-%{version}-%{release}
|
||||
|
||||
%py3_shbang_opts -s
|
||||
@ -103,6 +104,7 @@
|
||||
pyminor = path:match("/python3.(%d+)/") or "*"
|
||||
dirname = path:match("(.*/)")
|
||||
modulename = path:match(".*/([^/]+).py")
|
||||
-- %%python3_cache_tag is not used here because this macro supports not-installed CPythons
|
||||
print("\\n" .. dirname .. "__pycache__/" .. modulename .. ".cpython-3" .. pyminor .. "{,.opt-?}.pyc")
|
||||
end
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ elseif posix.stat('macros.python-srpm') then
|
||||
end
|
||||
}
|
||||
Version: %{__default_python3_version}
|
||||
Release: 18%{?dist}
|
||||
Release: 19%{?dist}
|
||||
|
||||
BuildArch: noarch
|
||||
|
||||
@ -151,6 +151,9 @@ grep -E '^#[^%%]*%%[^%%]' %{buildroot}%{rpmmacrodir}/macros.* && exit 1 || true
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Jul 19 2022 Miro Hrončok <mhroncok@redhat.com> - 3.10-19
|
||||
- Define %%python3_cache_tag / %%python_cache_tag, e.g. cpython-311
|
||||
|
||||
* Thu May 26 2022 Owen Taylor <otaylor@redhat.com> - 3.10-18
|
||||
- Support installing to %%{_prefix} other than /usr
|
||||
|
||||
|
@ -72,8 +72,17 @@ def get_alt_x_y():
|
||||
raise ValueError(f"${env_name} must be X.Y")
|
||||
return alternate_python_version
|
||||
|
||||
# We don't use the decorator, to be able to call the function itselef
|
||||
|
||||
def get_alt_xy():
|
||||
"""
|
||||
Same as get_alt_x_y() but without a dot
|
||||
"""
|
||||
return get_alt_x_y().replace(".", "")
|
||||
|
||||
|
||||
# We don't use decorators, to be able to call the functions directly
|
||||
alt_x_y = pytest.fixture(scope="session")(get_alt_x_y)
|
||||
alt_xy = pytest.fixture(scope="session")(get_alt_xy)
|
||||
|
||||
|
||||
def shell_stdout(script):
|
||||
@ -638,6 +647,7 @@ unversioned_macros = pytest.mark.parametrize('macro', [
|
||||
'%python_platform',
|
||||
'%python_platform_triplet',
|
||||
'%python_ext_suffix',
|
||||
'%python_cache_tag',
|
||||
'%py_shebang_fix',
|
||||
'%py_build',
|
||||
'%py_build_egg',
|
||||
@ -676,6 +686,18 @@ def test_ext_suffix():
|
||||
assert rpm_eval("%python3_ext_suffix") == [f".cpython-{XY}-x86_64-linux-gnu.so"]
|
||||
|
||||
|
||||
def test_cache_tag():
|
||||
assert rpm_eval("%python3_cache_tag") == [f"cpython-{XY}"]
|
||||
|
||||
|
||||
def test_cache_tag_alternate_python(alt_x_y, alt_xy):
|
||||
assert rpm_eval("%python_cache_tag", __python=f"/usr/bin/python{alt_x_y}") == [f"cpython-{alt_xy}"]
|
||||
|
||||
|
||||
def test_cache_tag_alternate_python3(alt_x_y, alt_xy):
|
||||
assert rpm_eval("%python3_cache_tag", __python3=f"/usr/bin/python{alt_x_y}") == [f"cpython-{alt_xy}"]
|
||||
|
||||
|
||||
def test_python_sitelib_value_python3():
|
||||
macro = '%python_sitelib'
|
||||
assert rpm_eval(macro, __python='%__python3') == [f'/usr/lib/python{X_Y}/site-packages']
|
||||
|
Loading…
Reference in New Issue
Block a user