Simplify bash completion

Bash reads all the completion files at start, so we don't need
additional symlinks.
Register completions for all the pip3 symliks at once.
This commit is contained in:
Petr Viktorin 2019-08-28 16:24:13 +02:00
parent 9a8a1ef98e
commit a0ac853b8c

View File

@ -10,12 +10,7 @@
%global pypa_theme_commit_hash d2e63fbfc62af3b7050f619b2f5bb8658985b931 %global pypa_theme_commit_hash d2e63fbfc62af3b7050f619b2f5bb8658985b931
%endif %endif
# Note that with disabled python3, bashcomp2 will be disabled as well because %global bashcompdir %(pkg-config --variable=completionsdir bash-completion 2>/dev/null)
# bashcompdir will point to a different path than with python3 enabled.
%global bashcompdir %(b=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null); echo ${b:-%{_sysconfdir}/bash_completion.d})
%if "%{bashcompdir}" != "%{_sysconfdir}/bash_completion.d"
%global bashcomp2 1
%endif
Name: python-%{srcname} Name: python-%{srcname}
# When updating, update the bundled libraries versions bellow! # When updating, update the bundled libraries versions bellow!
@ -306,22 +301,12 @@ done
mkdir -p %{buildroot}%{bashcompdir} mkdir -p %{buildroot}%{bashcompdir}
PYTHONPATH=%{buildroot}%{python3_sitelib} \ PYTHONPATH=%{buildroot}%{python3_sitelib} \
%{buildroot}%{_bindir}/pip completion --bash \ %{buildroot}%{_bindir}/pip completion --bash \
> %{buildroot}%{bashcompdir}/pip > %{buildroot}%{bashcompdir}/pip3
pips3=pip
for pip in %{buildroot}%{_bindir}/pip*; do # Make bash completion apply to all the 5 symlinks we install
pip=$(basename $pip) sed -i -e "s/^\\(complete.*\\) pip\$/\\1 pip pip{,-}{3,%{python3_version}}/" \
case $pip in
pip3*)
pips3="$pips3 $pip"
%if 0%{?bashcomp2}
ln -s pip %{buildroot}%{bashcompdir}/$pip
%endif
;;
esac
done
sed -i -e "s/^\\(complete.*\\) pip\$/\\1 $pips3/" \
-e s/_pip_completion/_pip3_completion/ \ -e s/_pip_completion/_pip3_completion/ \
%{buildroot}%{bashcompdir}/pip %{buildroot}%{bashcompdir}/pip3
# Provide symlinks to executables to comply with Fedora guidelines for Python # Provide symlinks to executables to comply with Fedora guidelines for Python
@ -373,11 +358,7 @@ ln -sf %{buildroot}%{_bindir}/pip3 _bin/pip
%{_bindir}/pip-%{python3_version} %{_bindir}/pip-%{python3_version}
%{python3_sitelib}/pip* %{python3_sitelib}/pip*
%dir %{bashcompdir} %dir %{bashcompdir}
%{bashcompdir}/pip %{bashcompdir}/pip3
%{bashcompdir}/pip3*
%if 0%{?bashcomp2}
%dir %(dirname %{bashcompdir})
%endif
%if %{with doc} %if %{with doc}
%files doc %files doc