aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorilltellyoulater <3078931+illtellyoulater@users.noreply.github.com>2023-12-04 02:35:35 +0000
committerGitHub <noreply@github.com>2023-12-04 02:35:35 +0000
commit639ccf254bd4d072f33333abb1ada3d08aaab470 (patch)
tree0f7b8f2382eda790ba652fb1aa8f21894c32bb50
parent4afaaf8a020c1df457bcf7250cb1c7f609699fa7 (diff)
Update launch_utils.py to fix wrong dep. checks and reinstalls
Fixes failing dependency checks for extensions having a different package name and import name (for example ffmpeg-python / ffmpeg), which currently is causing the unneeded reinstall of packages at runtime. In fact with current code, the same string is used when installing a package and when checking for its presence, as you can see in the following example: > launch_utils.run_pip("install ffmpeg-python", "required package") [ Installing required package: "ffmpeg-python" ... ] [ Installed ] > launch_utils.is_installed("ffmpeg-python") False ... which would actually return true with: > launch_utils.is_installed("ffmpeg") True
-rw-r--r--modules/launch_utils.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/modules/launch_utils.py b/modules/launch_utils.py
index 6e54d063..6664c5e0 100644
--- a/modules/launch_utils.py
+++ b/modules/launch_utils.py
@@ -6,6 +6,7 @@ import os
import shutil
import sys
import importlib.util
+import importlib.metadata
import platform
import json
from functools import lru_cache
@@ -119,11 +120,16 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_
def is_installed(package):
try:
- spec = importlib.util.find_spec(package)
- except ModuleNotFoundError:
- return False
+ dist = importlib.metadata.distribution(package)
+ except importlib.metadata.PackageNotFoundError:
+ try:
+ spec = importlib.util.find_spec(package)
+ except ModuleNotFoundError:
+ return False
- return spec is not None
+ return spec is not None
+
+ return dist is not None
def repo_dir(name):