File python-pip.spec of Package python-pip.31596

#
# spec file for package python-pip
#
# Copyright (c) 2020 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "test"
%define psuffix -test
%bcond_without test
%bcond_with wheel
%else
%if "%{flavor}" == "wheel"
%define psuffix -wheel
%bcond_without wheel
%bcond_with test
%else
%define psuffix %{nil}
%bcond_with test
%bcond_with wheel
%endif
%endif
Name:           python-pip%{psuffix}
Version:        20.0.2
Release:        0
Summary:        A Python package management system
License:        MIT
Group:          Development/Languages/Python
URL:            http://www.pip-installer.org
Source:         https://github.com/pypa/pip/archive/%{version}.tar.gz
Source1:        setuptools-45.1.0-py3-none-any.whl
Patch0:         pip-shipped-requests-cabundle.patch
Patch1:		pip-bigendian.patch
# PATCH-FIX-UPSTREAM CVE-2021-3572-split-unicode-separators.patch bsc#1186819 mcepl@suse.com
# Don't split git references on unicode separators
Patch2:         CVE-2021-3572-split-unicode-separators.patch
# PATCH-FIX-UPSTREAM CVE-2023-5752-r-param-hg.patch bsc#1217353 mcepl@suse.com
# avoid configurable injection via hg parameter
Patch3:         CVE-2023-5752-r-param-hg.patch
BuildRequires:  %{python_module setuptools}
BuildRequires:  fdupes
BuildRequires:  python-rpm-macros
Requires:       ca-certificates
Requires:       coreutils
Requires:       python-setuptools
Requires:       python-xml
Requires(post): update-alternatives
Requires(postun): update-alternatives
Recommends:     ca-certificates-mozilla
BuildArch:      noarch
%if %{with test}
# Test requirements:
BuildRequires:  %{python_module PyYAML}
BuildRequires:  %{python_module Werkzeug}
BuildRequires:  %{python_module cryptography}
BuildRequires:  %{python_module docutils}
BuildRequires:  %{python_module freezegun}
BuildRequires:  %{python_module mock}
BuildRequires:  %{python_module pip = %{version}}
BuildRequires:  %{python_module pretend}
BuildRequires:  %{python_module pytest}
BuildRequires:  %{python_module scripttest >= 1.3}
BuildRequires:  %{python_module virtualenv >= 1.10}
BuildRequires:  ca-certificates
BuildRequires:  git
BuildRequires:  subversion
%endif
%if %{with wheel}
BuildRequires:  %{python_module wheel}
%endif
%python_subpackages

%description
Pip is a replacement for easy_install. It uses mostly the same techniques for
finding packages, so packages that were made easy_installable should be
pip-installable as well.

%prep
%setup -q -n pip-%{version}
%patch -P0 -p1
if test `uname -m` == "s390x"; then
%patch -P1 -p1
fi
%patch -P2 -p1
%patch -P3 -p1

%if %{with test}
mkdir -p tests/data/common_wheels
cp %{SOURCE1} tests/data/common_wheels/
%endif
# remove shebangs verbosely (if only sed would offer a verbose mode...)
for f in $(find src -name \*.py -exec grep -l '^#!%{_bindir}/env' {} \;); do
    sed -i 's|^#!%{_bindir}/env .*$||g' $f
done
rm src/pip/_vendor/certifi/cacert.pem
# Remove windows executable binaries
# bsc#1212015
rm -v src/pip/_vendor/distlib/*.exe
sed -i '/\.exe/d' setup.py

%build
%if %{without wheel}
%python_build
%else
%python_exec setup.py bdist_wheel --universal
%endif

%if %{without test} && %{without wheel}
%install
%python_install
%prepare_alternative pip
%{python_expand export maj_ver=$(ver=%{$python_version}; echo ${ver:0:1})
%prepare_alternative pip${maj_ver}
%fdupes %{buildroot}%{$python_sitelib}
}
%endif

%if %{with wheel}
%python_expand install -D -m 0644 -t %{buildroot}%{$python_sitelib}/../wheels dist/*.whl
%endif

%if %{with test}
%check
export PYTHONPATH=build/lib
%pytest -k 'not network and not (test_build_env_allow_only_one_install or test_build_env_requirements_check or test_build_env_overlay_prefix_has_priority or test_build_env_isolation or test_should_cache_git_sha)' tests/unit
%endif

%if %{without test} && %{without wheel}
%pre
# Since /usr/bin/pip became ghosted to be used with update-alternatives, we have to get rid
# of the old binary resulting from the non-update-alternatives-ified package:
[ -h %{_bindir}/pip ] || rm -f %{_bindir}/pip

%post
# can't use `python_install_alternative` because it's pipX.Y, not pip-X.Y
PRIO=$(echo %{python_version}|tr -d '.')
MAJVER=$(ver=%{python_version}; echo ${ver:0:1})
update-alternatives --install %{_bindir}/pip          pip \
    %{_bindir}/pip%{python_version} $PRIO
update-alternatives --install %{_bindir}/pip${MAJVER} pip${MAJVER} \
    %{_bindir}/pip%{python_version} $PRIO

%postun
if [ ! -f %{_bindir}/pip%{python_version} ] ; then
   MAJVER=$(ver=%{python_version}; echo ${ver:0:1})
   update-alternatives --remove pip %{_bindir}/pip%{python_version}
   update-alternatives --remove pip${MAJVER} %{_bindir}/pip%{python_version}
fi
%endif

%clean

%files %{python_files}
%if %{without test} && %{without wheel}
%license LICENSE.txt
%doc AUTHORS.txt NEWS.rst README.rst
%{_bindir}/pip
%{_bindir}/pip%{python_version}
%python3_only %{_bindir}/pip3
%python2_only %{_bindir}/pip2
%{python_sitelib}/pip-%{version}-*-info
%{python_sitelib}/pip
%ghost %{_sysconfdir}/alternatives/pip
%python2_only %ghost %{_sysconfdir}/alternatives/pip2
%python3_only %ghost %{_sysconfdir}/alternatives/pip3
%endif

%if %{with wheel}
%dir %{python_sitelib}/../wheels
%{python_sitelib}/../wheels/*
%endif

%changelog
openSUSE Build Service is sponsored by