refactor: check_install_dependencies expects a set now

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-08-11 12:54:27 +02:00
parent ea4409ee54
commit 13611ccd52
10 changed files with 20 additions and 15 deletions
+2 -2
View File
@@ -52,7 +52,7 @@ def install_crowsnest() -> None:
git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master")
# Step 2: Install dependencies
check_install_dependencies(["make"])
check_install_dependencies({"make"})
# Step 3: Check for Multi Instance
im = InstanceManager(Klipper)
@@ -139,7 +139,7 @@ def update_crowsnest() -> None:
git_pull_wrapper(CROWSNEST_REPO, CROWSNEST_DIR)
deps = parse_packages_from_file(CROWSNEST_INSTALL_SCRIPT)
check_install_dependencies(deps)
check_install_dependencies({*deps})
cmd_sysctl_service(CROWSNEST_SERVICE_NAME, "restart")
+1 -1
View File
@@ -169,7 +169,7 @@ def install_klipper_packages() -> None:
if Path("/boot/dietpi/.version").exists():
packages.append("dbus")
check_install_dependencies(packages)
check_install_dependencies({*packages})
def update_klipper() -> None:
@@ -78,8 +78,7 @@ def install_klipperscreen() -> None:
):
return
package_list = ["git", "wget", "curl", "unzip", "dfu-util"]
check_install_dependencies(package_list)
check_install_dependencies()
git_clone_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR)
@@ -167,7 +167,7 @@ def install_moonraker_packages() -> None:
if not moonraker_deps:
raise ValueError("Error reading Moonraker dependencies!")
check_install_dependencies(moonraker_deps)
check_install_dependencies({*moonraker_deps})
def install_moonraker_polkit() -> None:
@@ -168,7 +168,7 @@ def install_oe_dependencies() -> None:
if not oe_deps:
raise ValueError("Error reading OctoEverywhere dependencies!")
check_install_dependencies(oe_deps)
check_install_dependencies({*oe_deps})
install_python_requirements(OE_ENV_DIR, OE_REQ_FILE)
@@ -112,7 +112,7 @@ def install_client(client: BaseWebClient) -> None:
)
valid_port = is_valid_port(port, ports_in_use)
check_install_dependencies(["nginx"])
check_install_dependencies({"nginx"})
try:
download_client(client)
@@ -236,7 +236,7 @@ class ObicoExtension(BaseExtension):
# install dependencies
script = OBICO_DIR.joinpath("install.sh")
package_list = parse_packages_from_file(script)
check_install_dependencies(package_list)
check_install_dependencies({*package_list})
# create virtualenv
create_python_venv(OBICO_ENV_DIR)
@@ -48,7 +48,7 @@ class PrettyGcodeExtension(BaseExtension):
allow_go_back=True,
)
check_install_dependencies(["nginx"])
check_install_dependencies({"nginx"})
try:
# remove any existing pgc dir
@@ -158,7 +158,7 @@ class TelegramBotExtension(BaseExtension):
# install dependencies
script = TG_BOT_DIR.joinpath("scripts/install.sh")
package_list = parse_packages_from_file(script)
check_install_dependencies(package_list)
check_install_dependencies({*package_list})
# create virtualenv
create_python_venv(TG_BOT_ENV)
+10 -4
View File
@@ -11,7 +11,7 @@ from __future__ import annotations
import re
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Literal, Optional, Type
from typing import Dict, List, Literal, Optional, Set, Type
from components.klipper.klipper import Klipper
from core.constants import (
@@ -47,17 +47,23 @@ def get_current_date() -> Dict[Literal["date", "time"], str]:
return {"date": date, "time": time}
def check_install_dependencies(deps: List[str] | None = None) -> None:
def check_install_dependencies(
deps: Set[str] | None = None, include_global: bool = True
) -> None:
"""
Common helper method to check if dependencies are installed
and if not, install them automatically |
:param include_global: Wether to include the global dependencies or not
:param deps: List of strings of package names to check if installed
:return: None
"""
if deps is None:
deps = []
deps = set()
requirements = check_package_install({*GLOBAL_DEPS, *deps})
if include_global:
deps.update(GLOBAL_DEPS)
requirements = check_package_install(deps)
if requirements:
Logger.print_status("Installing dependencies ...")
Logger.print_info("The following packages need installation:")