Blob Blame History Raw
# As of 2021-08-11, mkdocs and many of its dependencies are orphaned.
%bcond_with mkdocs

Name:           pipx
Version:        0.16.3
Release:        %autorelease
Summary:        Install and run Python applications in isolated environments

License:        MIT
URL:            https://pypa.github.io/pipx/
Source0:        https://github.com/pypa/pipx/archive/%{version}/pipx-%{version}.tar.gz

Source10:       pipx.1
Source11:       pipx-install.1
Source12:       pipx-inject.1
Source13:       pipx-upgrade.1
Source14:       pipx-upgrade-all.1
Source15:       pipx-uninstall.1
Source16:       pipx-uninstall-all.1
Source17:       pipx-reinstall.1
Source18:       pipx-reinstall-all.1
Source19:       pipx-list.1
Source20:       pipx-run.1
Source21:       pipx-runpip.1
Source22:       pipx-ensurepath.1
Source23:       pipx-completions.1

BuildArch:      noarch

BuildRequires:  python3-devel

BuildRequires:  pkgconfig(bash-completion)
%global bashcompdir %(pkg-config --variable=completionsdir bash-completion 2>/dev/null)
%global bashcomproot %(dirname %{bashcompdir} 2>/dev/null)
BuildRequires:  pkgconfig(fish)
%global fishcompdir %(pkg-config --variable=completionsdir fish 2>/dev/null)
%global fishcomproot %(dirname %{fishcompdir} 2>/dev/null)
BuildRequires:  /usr/bin/register-python-argcomplete

%description
pipx is a tool to help you install and run end-user applications written in
Python. It’s roughly similar to macOS’s brew, JavaScript’s npx, and Linux’s
apt.

It’s closely related to pip. In fact, it uses pip, but is focused on installing
and managing Python packages that can be run from the command line directly as
applications.


%package doc
Summary:        Documentation for pipx

%if %{with mkdocs}
# See noxfile.py
BuildRequires:  python3dist(jinja2)
BuildRequires:  python3dist(mkdocs)
%endif

%description doc
Documentation for pipx.


%prep
%autosetup
%if %{with mkdocs}
# Drop dependency on mkdocs-material. See
# https://bugzilla.redhat.com/show_bug.cgi?id=1960274#c3. The result doesn’t
# look as nice but is still usable.
sed -r -i 's/"material"/"mkdocs"/' mkdocs.yml
%endif


%generate_buildrequires
# We do not run the tests; but we add the runtime requirements as BR’s anyway
# so that the build will fail if some are not available in the distribution.
%pyproject_buildrequires -r


%build
%pyproject_wheel

(
  # Temporary local install
  PYTEMP="${PWD}/%{_vpath_builddir}/pytemp"
  if [ -n "${PYTHONPATH-}" ]; then PYTHONPATH="${PYTHONPATH}:"; fi
  export PYTHONPATH="${PYTHONPATH-}${PYTEMP}"
  if [ -n "${PATH-}" ]; then PATH="${PATH}:"; fi
  export PATH="${PATH}:${PYTEMP}/bin"
  %{__python3} -m pip install --target="${PYTEMP}" \
      --no-deps --use-pep517 --no-build-isolation \
      --disable-pip-version-check --no-clean --progress-bar off --verbose \
      %{_pyproject_wheeldir}/*.whl

%if %{with mkdocs}
  # Build the documentation
  %{__python3} scripts/generate_docs.py
  mkdocs build
%endif

  # Generate shell completions. “pipx completions” says:
  # Add the appropriate command to your shell's config file
  # so that it is run on startup. You will likely have to restart
  # or re-login for the autocompletion to start working.
  #
  # bash:
  #     eval "$(register-python-argcomplete pipx)"
  #
  # zsh:
  #     To activate completions for zsh you need to have
  #     bashcompinit enabled in zsh:
  #
  #     autoload -U bashcompinit
  #     bashcompinit
  #
  #     Afterwards you can enable completion for pipx:
  #
  #     eval "$(register-python-argcomplete pipx)"
  #
  # tcsh:
  #     eval `register-python-argcomplete --shell tcsh pipx`
  #
  # fish:
  #     register-python-argcomplete --shell fish pipx | source
  for sh in bash tcsh fish
  do
    register-python-argcomplete --shell "${sh}" pipx > "pipx.${sh}"
  done

  rm -rf "${PYTEMP}"
)


%install
%pyproject_install
%pyproject_save_files pipx

install -p -m 0644 -D -t %{buildroot}%{bashcompdir} pipx.bash
install -p -m 0644 -D -t %{buildroot}%{fishcompdir} pipx.fish
# It seems that there is not a reasonable way to install tcsh completions
# system-wide, so we just make the completions file available for interested
# users.
install -p -m 0644 -D pipx.tcsh \
    %{buildroot}%{_datadir}/pipx/pipx-completion.tcsh
# Note that there are no “native” zsh completions, so we do not attempt to
# install anything. This could change if an actual zsh user recommends a
# different plan.

install -p -m 0644 -D -t '%{buildroot}/%{_mandir}/man1' \
    %{SOURCE10} %{SOURCE11} %{SOURCE12} %{SOURCE13} %{SOURCE14} %{SOURCE15} \
    %{SOURCE16} %{SOURCE17} %{SOURCE18} %{SOURCE19} %{SOURCE20} %{SOURCE21} \
    %{SOURCE22} %{SOURCE23}


# It’s just not practical to run the tests. For most of them, we need either
# (by default) a bundle of sample wheels from PyPI–which is arch-specific, as
# some of them have compiled extensions—or network access. Previously, we tried
# to disentangle the tests that did not require PyPI packages, but this has
# become onerous.


%files -f %{pyproject_files}
%{_bindir}/pipx

%{_mandir}/man1/pipx.1*
%{_mandir}/man1/pipx-*.1*

# Note that it is standard in Fedora for packages providing shell completions
# to co-own the completions directory in lieu of having a runtime dependency on
# the relevant shell completions package. Note that we do not *have* to own the
# bash completions directory, as it is now (co-)owned by the filesystem
# package. We still co-own it for symmetry with other supported shells.
%{bashcomproot}
%{fishcomproot}
%{_datadir}/pipx


%files doc
%license LICENSE
%doc README.md
# Markdown
%doc docs
%if %{with mkdocs}
%doc site
%endif


%changelog
%autochangelog