forked from paylogic/pip-accel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract requirement_is_installed() from setuptools_supports_wheels()
- Loading branch information
Showing
2 changed files
with
28 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Utility functions for the pip accelerator. | ||
# | ||
# Author: Peter Odding <[email protected]> | ||
# Last Change: December 28, 2015 | ||
# Last Change: January 10, 2016 | ||
# URL: https://github.com/paylogic/pip-accel | ||
|
||
""" | ||
|
@@ -26,7 +26,12 @@ | |
# External dependencies. | ||
from humanfriendly import parse_path | ||
from pip.commands.uninstall import UninstallCommand | ||
from pkg_resources import WorkingSet | ||
from pip._vendor.pkg_resources import ( | ||
DistributionNotFound, | ||
WorkingSet, | ||
get_distribution, | ||
parse_requirements, | ||
) | ||
|
||
# Initialize a logger for this module. | ||
logger = logging.getLogger(__name__) | ||
|
@@ -254,6 +259,23 @@ def __exit__(self, exc_type=None, exc_value=None, traceback=None): | |
replace_file(self.temporary_file, self.filename) | ||
|
||
|
||
def requirement_is_installed(expr): | ||
""" | ||
Check whether a requirement is installed. | ||
:param expr: A requirement specification similar to those used in pip | ||
requirement files (a string). | ||
:returns: :data:`True` if the requirement is available (installed), | ||
:data:`False` otherwise. | ||
""" | ||
required_dist = next(parse_requirements(expr)) | ||
try: | ||
installed_dist = get_distribution(required_dist.key) | ||
return installed_dist in required_dist | ||
except DistributionNotFound: | ||
return False | ||
|
||
|
||
def is_installed(package_name): | ||
""" | ||
Check whether a package is installed in the current environment. | ||
|