Make the unversioned %__python macro error
See https://fedoraproject.org/wiki/Changes/PythonMacroError While doing it, make %python macros more consistent with %python3 macros, mostly wrt whitespace but also to use python -m pip over plain pip etc. One significant change is the removal of sleeps from python macros, this could affect packages that use python macros to build for Python 2 while also using python3 macros to build for Python 3. In reality, I consider that unlikely. The sleep in python2 macros stays. The --strip-file-prefix option was already removed from %pyX_install_wheel but we forgot to remove it from %py_install_wheel.
This commit is contained in:
parent
59abe832d4
commit
69b1b30d53
@ -16,19 +16,16 @@
|
||||
%py_build() %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
%{__python} %{py_setup} %{?py_setup_args} build --executable="%{__python} %{py_shbang_opts}" %{?*}
|
||||
sleep 1
|
||||
}
|
||||
|
||||
%py_build_egg() %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
%{__python} %{py_setup} %{?py_setup_args} bdist_egg %{?*}
|
||||
sleep 1
|
||||
}
|
||||
|
||||
%py_build_wheel() %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
%{__python} %{py_setup} %{?py_setup_args} bdist_wheel %{?*}
|
||||
sleep 1
|
||||
}
|
||||
|
||||
%py_install() %{expand:\\\
|
||||
@ -39,12 +36,12 @@
|
||||
|
||||
%py_install_egg() %{expand:\\\
|
||||
mkdir -p %{buildroot}%{python_sitelib}
|
||||
easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python_version}.egg %{?*}
|
||||
%{__python} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python_version}.egg %{?*}
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
}
|
||||
|
||||
%py_install_wheel() %{expand:\\\
|
||||
pip install -I dist/%{1} --root %{buildroot} --strip-file-prefix %{buildroot} --no-deps
|
||||
%{__python} -m pip install -I dist/%{1} --root %{buildroot} --no-deps
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
for distinfo in %{buildroot}%{python_sitelib}/*.dist-info %{buildroot}%{python_sitearch}/*.dist-info; do
|
||||
if [ -f ${distinfo}/direct_url.json ]; then
|
||||
|
@ -11,19 +11,11 @@
|
||||
%python2 %__python2
|
||||
%python3 %__python3
|
||||
|
||||
# For backwards compatibility only
|
||||
# See the comments in https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/22
|
||||
%__python /usr/bin/python
|
||||
# See https://fedoraproject.org/wiki/Changes/PythonMacroError
|
||||
%__python %{error:attempt to use unversioned python, define %%__python to %{__python2} or %{__python3} explicitly}
|
||||
|
||||
# Users can use %%python only if they redefined %%__python (e.g. to %%__python3)
|
||||
%python() %{lua:\
|
||||
__python = rpm.expand("%__python")\
|
||||
if __python == "/usr/bin/python" then\
|
||||
rpm.expand("%{error:Cannot use %%python if %%__python wasn't redefined to something other than /usr/bin/python.}")\
|
||||
else\
|
||||
print(__python)\
|
||||
end\
|
||||
}
|
||||
%python %__python
|
||||
|
||||
# There are multiple Python 3 versions packaged, but only one can be the "main" version
|
||||
# That means that it owns the "python3" namespace:
|
||||
|
@ -41,12 +41,12 @@
|
||||
|
||||
%py2_install_egg() %{expand:\\\
|
||||
mkdir -p %{buildroot}%{python2_sitelib}
|
||||
easy_install-%{python2_version} -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python2_version}.egg %{?*}
|
||||
%{__python2} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python2_version}.egg %{?*}
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
}
|
||||
|
||||
%py2_install_wheel() %{expand:\\\
|
||||
pip%{python2_version} install -I dist/%{1} --root %{buildroot} --no-deps
|
||||
%{__python2} -m pip install -I dist/%{1} --root %{buildroot} --no-deps
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
for distinfo in %{buildroot}%{python2_sitelib}/*.dist-info %{buildroot}%{python2_sitearch}/*.dist-info; do
|
||||
if [ -f ${distinfo}/direct_url.json ]; then
|
||||
|
@ -30,17 +30,17 @@
|
||||
%py3_install() %{expand:\\\
|
||||
CFLAGS="${CFLAGS:-${RPM_OPT_FLAGS}}" LDFLAGS="${LDFLAGS:-${RPM_LD_FLAGS}}"\\\
|
||||
%{__python3} %{py_setup} %{?py_setup_args} install -O1 --skip-build --root %{buildroot} %{?*}
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
}
|
||||
|
||||
%py3_install_egg() %{expand:\\\
|
||||
mkdir -p %{buildroot}%{python3_sitelib}
|
||||
easy_install-%{python3_version} -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
|
||||
%{__python3} -m easy_install -m --prefix %{buildroot}%{_prefix} -Z dist/*-py%{python3_version}.egg %{?*}
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
}
|
||||
|
||||
%py3_install_wheel() %{expand:\\\
|
||||
pip%{python3_version} install -I dist/%{1} --root %{buildroot} --no-deps
|
||||
%{__python3} -m pip install -I dist/%{1} --root %{buildroot} --no-deps
|
||||
rm -rfv %{buildroot}%{_bindir}/__pycache__
|
||||
for distinfo in %{buildroot}%{python3_sitelib}/*.dist-info %{buildroot}%{python3_sitearch}/*.dist-info; do
|
||||
if [ -f ${distinfo}/direct_url.json ]; then
|
||||
|
@ -1,6 +1,6 @@
|
||||
Name: python-rpm-macros
|
||||
Version: 3.9
|
||||
Release: 5%{?dist}
|
||||
Release: 6%{?dist}
|
||||
Summary: The common Python RPM macros
|
||||
|
||||
# macros and lua: MIT, compileall2.py: PSFv2
|
||||
@ -107,6 +107,11 @@ install -m 644 compileall2.py %{buildroot}%{_rpmconfigdir}/redhat/
|
||||
|
||||
|
||||
%changelog
|
||||
* Thu Jul 16 2020 Miro Hrončok <mhroncok@redhat.com> - 3.9-6
|
||||
- Make the unversioned %%__python macro error
|
||||
- https://fedoraproject.org/wiki/Changes/PythonMacroError
|
||||
- Make %%python macros more consistent with %%python3 macros
|
||||
|
||||
* Wed Jul 08 2020 Miro Hrončok <mhroncok@redhat.com> - 3.9-5
|
||||
- Introduce %%python_extras_subpkg
|
||||
- Adapt %%py_dist_name to keep square brackets
|
||||
|
@ -362,3 +362,33 @@ def test_python_extras_subpkg_F():
|
||||
It contains no code, just makes sure the dependencies are installed.
|
||||
""").lstrip().splitlines()
|
||||
assert lines == expected
|
||||
|
||||
|
||||
unversioned_macros = pytest.mark.parametrize('macro', [
|
||||
'%__python',
|
||||
'%python',
|
||||
'%python_version',
|
||||
'%python_version_nodots',
|
||||
'%python_sitelib',
|
||||
'%python_sitearch',
|
||||
'%py_shebang_fix',
|
||||
'%py_build',
|
||||
'%py_build_egg',
|
||||
'%py_build_wheel',
|
||||
'%py_install',
|
||||
'%py_install_egg',
|
||||
'%py_install_wheel',
|
||||
])
|
||||
|
||||
|
||||
@unversioned_macros
|
||||
def test_unversioned_python_errors(macro):
|
||||
lines = rpm_eval(macro, fails=True)
|
||||
assert lines[0] == ('error: attempt to use unversioned python, '
|
||||
'define %__python to /usr/bin/python2 or /usr/bin/python3 explicitly')
|
||||
|
||||
|
||||
@unversioned_macros
|
||||
def test_unversioned_python_works_when_defined(macro):
|
||||
macro3 = macro.replace('python', 'python3').replace('py_', 'py3_')
|
||||
assert rpm_eval(macro, __python='/usr/bin/python3') == rpm_eval(macro3)
|
||||
|
Loading…
Reference in New Issue
Block a user