mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Check global installed packages
This commit is contained in:
parent
fda65a4934
commit
4fb301b7a9
@ -32,8 +32,8 @@ def install_package(package, upgrade=True, target=None):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def check_package_exists(package, target):
|
def check_package_exists(package, lib_dir):
|
||||||
"""Check if a package exists.
|
"""Check if a package is installed globally or in lib_dir.
|
||||||
Returns True when the requirement is met.
|
Returns True when the requirement is met.
|
||||||
Returns False when the package is not installed or doesn't meet req."""
|
Returns False when the package is not installed or doesn't meet req."""
|
||||||
try:
|
try:
|
||||||
@ -42,5 +42,11 @@ def check_package_exists(package, target):
|
|||||||
# This is a zip file
|
# This is a zip file
|
||||||
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
|
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
|
||||||
|
|
||||||
return any(dist in req for dist in
|
# Check packages from lib dir
|
||||||
pkg_resources.find_distributions(target))
|
if lib_dir is not None:
|
||||||
|
if any(dist in req for dist in
|
||||||
|
pkg_resources.find_distributions(lib_dir)):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# Check packages from global + virtual environment
|
||||||
|
return any(dist in req for dist in pkg_resources.working_set)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user