Make pip_installed_by_pip() more generic

This commit is contained in:
Nehal J Wani 2018-07-15 21:24:12 +05:30
parent 067dd8c2c4
commit 96f9fcc4a0
No known key found for this signature in database
GPG Key ID: 87F40C1A586E6978
2 changed files with 4 additions and 4 deletions

View File

@ -58,14 +58,14 @@ class SelfCheckState(object):
separators=(",", ":"))
def pip_installed_by_pip():
"""Checks whether pip was installed by pip
def was_installed_by_pip(pkg):
"""Checks whether pkg 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.
"""
try:
dist = pkg_resources.get_distribution('pip')
dist = pkg_resources.get_distribution(pkg)
return (dist.has_metadata('INSTALLER') and
'pip' in dist.get_metadata_lines('INSTALLER'))
except pkg_resources.DistributionNotFound:
@ -125,7 +125,7 @@ def pip_version_check(session, options):
# Determine if our pypi_version is older
if (pip_version < remote_version and
pip_version.base_version != remote_version.base_version and
pip_installed_by_pip()):
was_installed_by_pip('pip')):
# Advise "python -m pip" on Windows to avoid issues
# with overwriting pip.exe.
if WINDOWS: