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

View File

@@ -52,7 +52,7 @@ def install_crowsnest() -> None:
git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master") git_clone_wrapper(CROWSNEST_REPO, CROWSNEST_DIR, "master")
# Step 2: Install dependencies # Step 2: Install dependencies
check_install_dependencies(["make"]) check_install_dependencies({"make"})
# Step 3: Check for Multi Instance # Step 3: Check for Multi Instance
im = InstanceManager(Klipper) im = InstanceManager(Klipper)
@@ -139,7 +139,7 @@ def update_crowsnest() -> None:
git_pull_wrapper(CROWSNEST_REPO, CROWSNEST_DIR) git_pull_wrapper(CROWSNEST_REPO, CROWSNEST_DIR)
deps = parse_packages_from_file(CROWSNEST_INSTALL_SCRIPT) deps = parse_packages_from_file(CROWSNEST_INSTALL_SCRIPT)
check_install_dependencies(deps) check_install_dependencies({*deps})
cmd_sysctl_service(CROWSNEST_SERVICE_NAME, "restart") cmd_sysctl_service(CROWSNEST_SERVICE_NAME, "restart")

View File

@@ -169,7 +169,7 @@ def install_klipper_packages() -> None:
if Path("/boot/dietpi/.version").exists(): if Path("/boot/dietpi/.version").exists():
packages.append("dbus") packages.append("dbus")
check_install_dependencies(packages) check_install_dependencies({*packages})
def update_klipper() -> None: def update_klipper() -> None:

View File

@@ -78,8 +78,7 @@ def install_klipperscreen() -> None:
): ):
return return
package_list = ["git", "wget", "curl", "unzip", "dfu-util"] check_install_dependencies()
check_install_dependencies(package_list)
git_clone_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR) git_clone_wrapper(KLIPPERSCREEN_REPO, KLIPPERSCREEN_DIR)

View File

@@ -167,7 +167,7 @@ def install_moonraker_packages() -> None:
if not moonraker_deps: if not moonraker_deps:
raise ValueError("Error reading Moonraker dependencies!") raise ValueError("Error reading Moonraker dependencies!")
check_install_dependencies(moonraker_deps) check_install_dependencies({*moonraker_deps})
def install_moonraker_polkit() -> None: def install_moonraker_polkit() -> None:

View File

@@ -168,7 +168,7 @@ def install_oe_dependencies() -> None:
if not oe_deps: if not oe_deps:
raise ValueError("Error reading OctoEverywhere dependencies!") 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) install_python_requirements(OE_ENV_DIR, OE_REQ_FILE)

View File

@@ -112,7 +112,7 @@ def install_client(client: BaseWebClient) -> None:
) )
valid_port = is_valid_port(port, ports_in_use) valid_port = is_valid_port(port, ports_in_use)
check_install_dependencies(["nginx"]) check_install_dependencies({"nginx"})
try: try:
download_client(client) download_client(client)

View File

@@ -236,7 +236,7 @@ class ObicoExtension(BaseExtension):
# install dependencies # install dependencies
script = OBICO_DIR.joinpath("install.sh") script = OBICO_DIR.joinpath("install.sh")
package_list = parse_packages_from_file(script) package_list = parse_packages_from_file(script)
check_install_dependencies(package_list) check_install_dependencies({*package_list})
# create virtualenv # create virtualenv
create_python_venv(OBICO_ENV_DIR) create_python_venv(OBICO_ENV_DIR)

View File

@@ -48,7 +48,7 @@ class PrettyGcodeExtension(BaseExtension):
allow_go_back=True, allow_go_back=True,
) )
check_install_dependencies(["nginx"]) check_install_dependencies({"nginx"})
try: try:
# remove any existing pgc dir # remove any existing pgc dir

View File

@@ -158,7 +158,7 @@ class TelegramBotExtension(BaseExtension):
# install dependencies # install dependencies
script = TG_BOT_DIR.joinpath("scripts/install.sh") script = TG_BOT_DIR.joinpath("scripts/install.sh")
package_list = parse_packages_from_file(script) package_list = parse_packages_from_file(script)
check_install_dependencies(package_list) check_install_dependencies({*package_list})
# create virtualenv # create virtualenv
create_python_venv(TG_BOT_ENV) create_python_venv(TG_BOT_ENV)

View File

@@ -11,7 +11,7 @@ from __future__ import annotations
import re import re
from datetime import datetime from datetime import datetime
from pathlib import Path 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 components.klipper.klipper import Klipper
from core.constants import ( from core.constants import (
@@ -47,17 +47,23 @@ def get_current_date() -> Dict[Literal["date", "time"], str]:
return {"date": date, "time": time} 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 Common helper method to check if dependencies are installed
and if not, install them automatically | 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 :param deps: List of strings of package names to check if installed
:return: None :return: None
""" """
if deps is 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: if requirements:
Logger.print_status("Installing dependencies ...") Logger.print_status("Installing dependencies ...")
Logger.print_info("The following packages need installation:") Logger.print_info("The following packages need installation:")