Simplify was_installed_by_pip() (#6616)

This uses `get_installer()` to reduce code duplication.
This commit is contained in:
Pradyun Gedam 2019-06-16 21:25:53 +05:30 committed by GitHub
commit 82284073e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

1
news/6533.trivial Normal file
View File

@ -0,0 +1 @@
Override the definition of the function was_installed_by_pip (src\pip\_internal\utils\outdated.py) too specific with a more general alternative

View File

@ -13,6 +13,7 @@ from pip._internal.index import PackageFinder
from pip._internal.utils.compat import WINDOWS
from pip._internal.utils.filesystem import check_path_owner
from pip._internal.utils.misc import ensure_dir, get_installed_version
from pip._internal.utils.packaging import get_installer
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
@ -85,8 +86,7 @@ def was_installed_by_pip(pkg):
"""
try:
dist = pkg_resources.get_distribution(pkg)
return (dist.has_metadata('INSTALLER') and
'pip' in dist.get_metadata_lines('INSTALLER'))
return "pip" == get_installer(dist)
except pkg_resources.DistributionNotFound:
return False