refactor(KIAUH): use pythons own venv module to create a venv

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2023-12-29 19:20:04 +01:00
parent cda6d31a7c
commit c28d5c28b9
2 changed files with 7 additions and 11 deletions

View File

@@ -114,10 +114,9 @@ def setup_klipper_prerequesites() -> None:
repo_manager.clone_repo()
# install klipper dependencies and create python virtualenv
install_klipper_packages(Path(KLIPPER_DIR))
create_python_venv(Path(KLIPPER_ENV_DIR))
klipper_py_req = Path(KLIPPER_REQUIREMENTS_TXT)
install_python_requirements(Path(KLIPPER_ENV_DIR), klipper_py_req)
install_klipper_packages(KLIPPER_DIR)
create_python_venv(KLIPPER_ENV_DIR)
install_python_requirements(KLIPPER_ENV_DIR, KLIPPER_REQUIREMENTS_TXT)
def install_klipper_packages(klipper_dir: Path) -> None:

View File

@@ -17,6 +17,7 @@ import sys
import time
import urllib.error
import urllib.request
import venv
from pathlib import Path
from typing import List, Literal
@@ -68,14 +69,10 @@ def create_python_venv(target: Path) -> None:
Logger.print_status("Set up Python virtual environment ...")
if not target.exists():
try:
command = ["python3", "-m", "venv", f"{target}"]
result = subprocess.run(command, stderr=subprocess.PIPE, text=True)
if result.returncode != 0 or result.stderr:
Logger.print_error(f"{result.stderr}", prefix=False)
Logger.print_error("Setup of virtualenv failed!")
return
venv.create(target, with_pip=True)
Logger.print_ok("Setup of virtualenv successfull!")
except OSError as e:
Logger.print_error(f"Error setting up virtualenv:\n{e}")
except subprocess.CalledProcessError as e:
Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}")
else: