File saltbundlepy-pip.spec of Package saltbundlepy-pip

#
# spec file for package saltbundlepy-pip
#
# Copyright (c) 2022 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/
#


%{?!saltbundlepy_module:%define saltbundlepy_module() saltbundlepy-%{**}}
%define pythons saltbundlepy


%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
%else
%define psuffix %{nil}
%bcond_with test
%bcond_with wheel
%endif
%endif
Name:           saltbundlepy-pip%{psuffix}
Version:        20.2.4
Release:        0
Summary:        A Python package management system
License:        MIT
URL:            http://www.pip-installer.org
# The PyPI archive lacks the tests
Source:         https://github.com/pypa/pip/archive/%{version}.tar.gz#/pip-%{version}-gh.tar.gz
# PATCH-FIX-OPENSUSE return-CA-bundle-for-distro.patch -- adapted patch from saltbundlepy-certifi package
Patch0:         return-CA-bundle-for-distro.patch
# PATCH-FIX-UPSTREAM remove_mock.patch gh#pypa/pip#9266 mcepl@suse.com
# remove dependency on the external module mock
Patch1:         remove_mock.patch
BuildRequires:  saltbundlepy-base
BuildRequires:  saltbundlepy-setuptools >= 40.8.0
BuildRequires:  fdupes
BuildRequires:  saltbundlepy-rpm-macros
Requires:       ca-certificates
Requires:       coreutils
Requires:       saltbundlepy-setuptools
Requires:       saltbundlepy-xml
Requires(post): update-alternatives
Requires(postun): update-alternatives
BuildArch:      noarch
%if %{with test}
# Test requirements:
BuildRequires:  %{saltbundlepy_module PyYAML}
BuildRequires:  %{saltbundlepy_module Werkzeug}
BuildRequires:  %{saltbundlepy_module cryptography}
BuildRequires:  %{saltbundlepy_module csv23}
BuildRequires:  %{saltbundlepy_module docutils}
BuildRequires:  %{saltbundlepy_module freezegun}
BuildRequires:  %{saltbundlepy_module pretend}
BuildRequires:  %{saltbundlepy_module pytest}
BuildRequires:  %{saltbundlepy_module scripttest}
BuildRequires:  %{saltbundlepy_module setuptools-wheel}
BuildRequires:  %{saltbundlepy_module virtualenv >= 1.10}
BuildRequires:  %{saltbundlepy_module wheel}
%if 0%{?suse_version} <= 1500
BuildRequires:  %{saltbundlepy_module mock}
%endif
BuildRequires:  ca-certificates
BuildRequires:  git
BuildRequires:  subversion
%endif
%if %{with wheel}
BuildRequires:  %{saltbundlepy_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
# Unbundling is not advised by upstream. See src/pip/_vendor/README.rst
# Exception: Use our own cabundle. Adapted patch from python-certifi package
%autosetup -p1 -n pip-%{version}

%if 0%{?suse_version}
export CA_BUNDLE_PATH=/etc/ssl/ca-bundle.pem
%endif
%if 0%{?rhel_version} || 0%{?centos_version} || 0%{?fedora_version} || 0%{?almalinux_version} || 0%{?rocky_version}
export CA_BUNDLE_PATH=/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
%endif
%if 0%{?debian_version} || 0%{?ubuntu_version}
export CA_BUNDLE_PATH=/etc/ssl/certs/ca-certificates.crt
%endif
if [ -z "${CA_BUNDLE_PATH}" ]; then
    echo "Error: Unable to define CA bundle path!"
    exit 1
fi
sed -i "s#++CA_BUNDLE_PATH++#${CA_BUNDLE_PATH}#" src/pip/_vendor/certifi/core.py

rm src/pip/_vendor/certifi/cacert.pem

%if %{with test}
mkdir -p tests/data/common_wheels
%python_expand cp %{$python_sitelib}/../wheels/setuptools*.whl 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

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

%if !%{with test} && !%{with wheel}
%install
%python_install
%python_clone -a %{buildroot}%{_bindir}/pip
%python_clone -a %{buildroot}%{_bindir}/pip3
# if we just cloned to pip3-2.7 delete it
rm -f %{buildroot}%{_bindir}/pip3-2*
%python_expand %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=$(pwd)/build/lib
# no network on OBS
donttest="test_network or test_remote_reqs_parse"
# incompatible virtualenv version
donttest+=" or test_build_env_allow_only_one_install"
donttest+=" or test_build_env_isolation"
donttest+=" or test_build_env_requirements_check"
donttest+=" or test_build_env_overlay_prefix_has_priority"
donttest+=" or test_should_cache_git_sha"
# incompatible virtualenv version and no coverage wheel in common_wheels
donttest+=" or test_from_link_vcs_with_source_dir_obtains_commit_id"
donttest+=" or test_from_link_vcs_without_source_dir"
%pytest -k "not ($donttest)" tests/unit
%endif

%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
[ -h %{_bindir}/pip3 ] || rm -f %{_bindir}/pip3
# If libalternatives is used: Removing old update-alternatives entries.
%python_libalternatives_reset_alternative pip

%if !%{with test} && !%{with wheel}
%post
# keep the alternative groups separate. Users could decide to let pip and pip3 point to
# different flavors
%python_install_alternative pip
%python_install_alternative pip3

%postun
%python_uninstall_alternative pip
%python_uninstall_alternative pip3
%endif

%files %{python_files}
%if !%{with test} && !%{with wheel}
%license LICENSE.txt
%doc AUTHORS.txt NEWS.rst README.rst
%python_alternative %{_bindir}/pip
%if "%{python_flavor}" == "python2"
%{_bindir}/pip2
%else
%python_alternative %{_bindir}/pip3
%endif
%{_bindir}/pip%{python_bin_suffix}
%{python_sitelib}/pip-%{version}*-info
%{python_sitelib}/pip
%endif

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

%changelog
openSUSE Build Service is sponsored by