From 4b288bd347a185e125ea890d1b6f9ca5378b5206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 4 May 2018 14:26:11 +0200 Subject: [PATCH] When pip is run outside of venv, don't show the upgrade warning This is a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1573755 1. We put "rpm" inside pip's INSTALLER instead of "pip" 2. From pip, we check what's in INSTALLER and only show the warning if it's "pip". When a venv is cearted, pip is installed from wheel (trough rewheel), INSTALLER contains "pip". When virtualenv is used, pip is installed from the Interwebz via pip, so INSTALLER contains "pip". Upstream issue https://github.com/pypa/pip/issues/5346 --- pip-nowarn-upgrade.patch | 36 ++++++++++++++++++++++++++++++++++++ python-pip.spec | 17 +++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 pip-nowarn-upgrade.patch diff --git a/pip-nowarn-upgrade.patch b/pip-nowarn-upgrade.patch new file mode 100644 index 0000000..9e314a5 --- /dev/null +++ b/pip-nowarn-upgrade.patch @@ -0,0 +1,36 @@ +diff --git a/pip/utils/outdated.py b/pip/utils/outdated.py +index 2164cc3..c71539f 100644 +--- a/pip/utils/outdated.py ++++ b/pip/utils/outdated.py +@@ -92,6 +92,21 @@ def load_selfcheck_statefile(): + return GlobalSelfCheckState() + + ++def pip_installed_by_pip(): ++ """Checks whether pip was installed by pip ++ ++ This is used not to display the upgrade message when pip is in fact ++ installed by system package manager, such as dnf on Fedora. ++ """ ++ import pkg_resources ++ try: ++ dist = pkg_resources.get_distribution('pip') ++ return (dist.has_metadata('INSTALLER') and ++ 'pip' in dist.get_metadata_lines('INSTALLER')) ++ except pkg_resources.DistributionNotFound: ++ return False ++ ++ + def pip_version_check(session): + """Check for an update for pip. + +@@ -141,7 +156,8 @@ def pip_version_check(session): + + # Determine if our pypi_version is older + if (pip_version < remote_version and +- pip_version.base_version != remote_version.base_version): ++ pip_version.base_version != remote_version.base_version and ++ pip_installed_by_pip()): + # Advise "python -m pip" on Windows to avoid issues + # with overwriting pip.exe. + if WINDOWS: diff --git a/python-pip.spec b/python-pip.spec index 791ccb7..cc65ebc 100644 --- a/python-pip.spec +++ b/python-pip.spec @@ -61,6 +61,11 @@ Patch0: allow-stripping-given-prefix-from-wheel-RECORD-files.patch # Issue upstream: https://github.com/pypa/pip/issues/4288 Patch1: emit-a-warning-when-running-with-root-privileges.patch + +# WIP upstream patch https://github.com/pypa/pip/issues/5346 +# https://bugzilla.redhat.com/show_bug.cgi?id=1573755 +Patch2: pip-nowarn-upgrade.patch + # Downstream only patch # Users are upgrading pip9 to pip10 by various manners, # one of them is `pip install --user --upgrade pip`. @@ -223,6 +228,7 @@ tar -xf %{SOURCE1} %patch0 -p1 %patch1 -p1 +%patch2 -p1 sed -i '1d' pip/__init__.py @@ -348,6 +354,15 @@ ln -s ./pip-%{python3_version} %{buildroot}%{_bindir}/pip-3 %endif +# Make sure the INSTALLER is not pip, otherwise Patch2 won't work +# TODO Maybe we should make all our python packages have this? +%if %{with python2} +echo rpm > %{buildroot}%{python2_sitelib}/pip-%{version}.dist-info/INSTALLER +%endif +%if %{with python3} +echo rpm > %{buildroot}%{python3_sitelib}/pip-%{version}.dist-info/INSTALLER +%endif + %if %{with tests} %check %if %{with python2} @@ -410,8 +425,10 @@ py.test-%{python3_version} -m 'not network' %changelog * Fri May 04 2018 Miro HronĨok - 9.0.3-2 - Allow to import pip10's main from pip9's /usr/bin/pip +- Do not show the "new version of pip" warning outside of venv Resolves: rhbz#1569488 Resolves: rhbz#1571650 +Resolves: rhbz#1573755 * Thu Mar 29 2018 Charalampos Stratakis - 9.0.3-1 - Update to 9.0.3