From 5802dc6818d2387677ad31f3f51c52835836df23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 20 Jun 2025 19:12:08 +0200 Subject: [PATCH] Handle alternate executable names for cases this isn't the main Python This is based on work in https://gitlab.com/redhat/centos-stream/rpms/python3.12-pip/-/commit/f1b86318fc6f21d5514fb7933172798cb4ea3db4 and https://src.fedoraproject.org/rpms/python-pip/pull-request/71 (not merged) With one notable difference: The Bash completion function has no dot in it now. I believe that having a dot in it breaks it: https://issues.redhat.com/browse/RHEL-99083 [skip changelog] --- python-pip.spec | 59 ++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/python-pip.spec b/python-pip.spec index ec68d37..055999d 100644 --- a/python-pip.spec +++ b/python-pip.spec @@ -249,13 +249,28 @@ export PYTHONPATH=./src/ %pyproject_install %pyproject_save_files -l pip +# We'll install pip as pip3.X +# Later we'll provide symbolic links, manpage links and bashcompletion fixes for alternative names +%if "%{python3_pkgversion}" == "3" +%global alternate_names pip-%{python3_version} pip-3 pip3 pip +%else +%global alternate_names pip-%{python3_version} +%endif + +# Provide symlinks to executables +mv %{buildroot}%{_bindir}/pip %{buildroot}%{_bindir}/pip%{python3_version} +rm %{buildroot}%{_bindir}/pip3 +for pip in %{alternate_names}; do +ln -s ./pip%{python3_version} %{buildroot}%{_bindir}/$pip +done + %if %{with man} pushd docs/build/man install -d %{buildroot}%{_mandir}/man1 for MAN in *1; do -install -pm0644 $MAN %{buildroot}%{_mandir}/man1/$MAN -for pip in "pip3" "pip-3" "pip%{python3_version}" "pip-%{python3_version}"; do -echo ".so $MAN" > %{buildroot}%{_mandir}/man1/${MAN/pip/$pip} +install -pm0644 $MAN %{buildroot}%{_mandir}/man1/${MAN/pip/pip%{python3_version}} +for pip in %{alternate_names}; do +echo ".so ${MAN/pip/pip%{python3_version}}" > %{buildroot}%{_mandir}/man1/${MAN/pip/$pip} done done popd @@ -263,19 +278,13 @@ popd mkdir -p %{buildroot}%{bash_completions_dir} PYTHONPATH=%{buildroot}%{python3_sitelib} \ - %{buildroot}%{_bindir}/pip completion --bash \ - > %{buildroot}%{bash_completions_dir}/pip3 - -# Make bash completion apply to all the 5 symlinks we install -sed -i -e "s/^\\(complete.*\\) pip\$/\\1 pip pip{,-}{3,%{python3_version}}/" \ - -e s/_pip_completion/_pip3_completion/ \ - %{buildroot}%{bash_completions_dir}/pip3 - - -# Provide symlinks to executables to comply with Fedora guidelines for Python -ln -s ./pip%{python3_version} %{buildroot}%{_bindir}/pip-%{python3_version} -ln -s ./pip-%{python3_version} %{buildroot}%{_bindir}/pip-3 + %{buildroot}%{_bindir}/pip%{python3_version} completion --bash \ + > %{buildroot}%{bash_completions_dir}/pip%{python3_version} +# Make bash completion apply to all alternate names symlinks we install +sed -i -e "s/^\\(complete.*\\) pip%{python3_version}\$/\\1 pip%{python3_version} %{alternate_names}/" \ + -e s/_pip_completion/_pip%{python3_version_nodots}_completion/ \ + %{buildroot}%{bash_completions_dir}/pip%{python3_version} mkdir -p %{buildroot}%{python_wheel_dir} install -p %{_pyproject_wheeldir}/%{python_wheel_name} -t %{buildroot}%{python_wheel_dir} @@ -290,9 +299,9 @@ grep "exe$" %{pyproject_files} && exit 1 || true grep "pem$" %{pyproject_files} && exit 1 || true # Verify we can at least run basic commands without crashing -%{py3_test_envvars} %{buildroot}%{_bindir}/pip --help -%{py3_test_envvars} %{buildroot}%{_bindir}/pip list -%{py3_test_envvars} %{buildroot}%{_bindir}/pip show pip +%{py3_test_envvars} %{buildroot}%{_bindir}/pip%{python3_version} --help +%{py3_test_envvars} %{buildroot}%{_bindir}/pip%{python3_version} list +%{py3_test_envvars} %{buildroot}%{_bindir}/pip%{python3_version} show pip %if %{with tests} # Upstream tests @@ -318,18 +327,22 @@ pytest_k="$pytest_k and not test_check_unsupported" %files -n python%{python3_pkgversion}-%{srcname} -f %{pyproject_files} %doc README.rst %if %{with man} -%{_mandir}/man1/pip.* -%{_mandir}/man1/pip-*.* -%{_mandir}/man1/pip3.* -%{_mandir}/man1/pip3-*.* +%if "%{python3_pkgversion}" == "3" +%{_mandir}/man1/pip{,3,-3}.1.* +%{_mandir}/man1/pip{,3,-3}-[^3]*.1.* %endif +%{_mandir}/man1/pip{,-}%{python3_version}.1.* +%{_mandir}/man1/pip{,-}%{python3_version}-*.1.* +%endif +%if "%{python3_pkgversion}" == "3" %{_bindir}/pip %{_bindir}/pip3 %{_bindir}/pip-3 +%endif %{_bindir}/pip%{python3_version} %{_bindir}/pip-%{python3_version} %dir %{bash_completions_dir} -%{bash_completions_dir}/pip3 +%{bash_completions_dir}/pip%{python3_version} %files -n %{python_wheel_pkg_prefix}-%{srcname}-wheel