mirror of
https://github.com/Bing-su/adetailer.git
synced 2026-03-10 07:50:01 +00:00
fix: update install script
There was an attack on the ultralytics package
This commit is contained in:
18
install.py
18
install.py
@@ -8,12 +8,17 @@ from importlib.metadata import version # python >= 3.8
|
||||
from packaging.version import parse
|
||||
|
||||
import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"}
|
||||
custom_requirements = {"ultralytics": "ultralytics>=8.3.0,!=8.3.41,!=8.3.42"}
|
||||
excluded_versions = {"ultralytics": ("8.3.41", "8.3.42")}
|
||||
|
||||
|
||||
def is_installed(
|
||||
package: str, min_version: str | None = None, max_version: str | None = None
|
||||
package: str,
|
||||
min_version: str | None = None,
|
||||
max_version: str | None = None,
|
||||
):
|
||||
name = import_name.get(package, package)
|
||||
excluded = excluded_versions.get(package, ())
|
||||
try:
|
||||
spec = importlib.util.find_spec(name)
|
||||
except ModuleNotFoundError:
|
||||
@@ -32,7 +37,10 @@ def is_installed(
|
||||
|
||||
try:
|
||||
pkg_version = version(package)
|
||||
return parse(min_version) <= parse(pkg_version) <= parse(max_version)
|
||||
return (
|
||||
parse(min_version) <= parse(pkg_version) <= parse(max_version)
|
||||
and pkg_version not in excluded
|
||||
)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@@ -44,7 +52,7 @@ def run_pip(*args):
|
||||
def install():
|
||||
deps = [
|
||||
# requirements
|
||||
("ultralytics", "8.2.0", None),
|
||||
("ultralytics", "8.3.0", None),
|
||||
("mediapipe", "0.10.13", "0.10.15"),
|
||||
("rich", "13.0.0", None),
|
||||
]
|
||||
@@ -52,7 +60,9 @@ def install():
|
||||
pkgs = []
|
||||
for pkg, low, high in deps:
|
||||
if not is_installed(pkg, low, high):
|
||||
if low and high:
|
||||
if pkg in custom_requirements:
|
||||
cmd = custom_requirements[pkg]
|
||||
elif low and high:
|
||||
cmd = f"{pkg}>={low},<={high}"
|
||||
elif low:
|
||||
cmd = f"{pkg}>={low}"
|
||||
|
||||
Reference in New Issue
Block a user