refactor(KIAUH): use pythons own venv module to create a venv
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -114,10 +114,9 @@ def setup_klipper_prerequesites() -> None:
|
|||||||
repo_manager.clone_repo()
|
repo_manager.clone_repo()
|
||||||
|
|
||||||
# install klipper dependencies and create python virtualenv
|
# install klipper dependencies and create python virtualenv
|
||||||
install_klipper_packages(Path(KLIPPER_DIR))
|
install_klipper_packages(KLIPPER_DIR)
|
||||||
create_python_venv(Path(KLIPPER_ENV_DIR))
|
create_python_venv(KLIPPER_ENV_DIR)
|
||||||
klipper_py_req = Path(KLIPPER_REQUIREMENTS_TXT)
|
install_python_requirements(KLIPPER_ENV_DIR, KLIPPER_REQUIREMENTS_TXT)
|
||||||
install_python_requirements(Path(KLIPPER_ENV_DIR), klipper_py_req)
|
|
||||||
|
|
||||||
|
|
||||||
def install_klipper_packages(klipper_dir: Path) -> None:
|
def install_klipper_packages(klipper_dir: Path) -> None:
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import sys
|
|||||||
import time
|
import time
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import venv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Literal
|
from typing import List, Literal
|
||||||
|
|
||||||
@@ -68,14 +69,10 @@ def create_python_venv(target: Path) -> None:
|
|||||||
Logger.print_status("Set up Python virtual environment ...")
|
Logger.print_status("Set up Python virtual environment ...")
|
||||||
if not target.exists():
|
if not target.exists():
|
||||||
try:
|
try:
|
||||||
command = ["python3", "-m", "venv", f"{target}"]
|
venv.create(target, with_pip=True)
|
||||||
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
|
|
||||||
|
|
||||||
Logger.print_ok("Setup of virtualenv successfull!")
|
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:
|
except subprocess.CalledProcessError as e:
|
||||||
Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}")
|
Logger.print_error(f"Error setting up virtualenv:\n{e.output.decode()}")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user