#5 When pip is run outside of venv, don't show the upgrade warning
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/python-pip pip-nowarn-upgrade  into  master

@@ -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:

file modified
+17
@@ -61,6 +61,11 @@ 

  # 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 @@ 

  

  %patch0 -p1

  %patch1 -p1

+ %patch2 -p1

  

  sed -i '1d' pip/__init__.py

  
@@ -348,6 +354,15 @@ 

  %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 @@ 

  %changelog

  * Fri May 04 2018 Miro Hrončok <mhroncok@redhat.com> - 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 <cstratak@redhat.com> - 9.0.3-1

  - Update to 9.0.3

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

rebased onto 4b288bd

3 years ago

Fixed INSATLLER typo in the commit message.

LGTM.

Ideally, pip install should have a switch to to set what will go into the INSTALLER file and then we can use this in python-rpm-macros.

Ideally, pip install should have a switch to to set what will go into the INSTALLER file and then we can use this in python-rpm-macros.

This is of course out of scope of this PR, but while we are at it: Note that we mostly use python setup.py install, not pip.

@ncoghlan Please let me know if you see anything utterly catastrophic with this approach. If not, let's ship it on Monday.

This approach looks good to me as a near term solution to avoiding the warning.

As far as a longer term answer to "How to reliably set INSTALLER appropriately?" goes, I think it would be better if there was an RPM file trigger in the base Python package that overwrote the INSTALLER files for anything installed via RPM at install time. That way it would automatically do the right thing for all RPM managed Python packages with dist-info and egg-info directories, whether those packages are old or new, Fedora built, or third party.

(Such a file trigger could potentially even synthesise dist-info directories for packages that don't have them, but doing that would require defining an upstream convention for reserving a suitable namesspace - pursuing such an idea would be a lot more feasible now that legacy PyPI has been shutdown).

Thanks. That sounds reasonable. Let me open a bug for that so we don't forget once this is merged.

https://bugzilla.redhat.com/show_bug.cgi?id=1575270

Before i merge this, it seems to me that the patch is not applied to the package itself. At least when i install form the CI build. Something is weird.

Ok, so if i download and install the package, it's fine. However if I try to mock -r fedora-rawhide-x86_64 --install https://kojipkgs.fedoraproject.org//work/tasks/6639/26766639/python3-pip-9.0.3-2.fc29.noarch.rpm I and up with some different package, maybe a cache thing.

Pull-Request has been merged by churchyard

3 years ago