From 012f209303a0276aa0a7d26b6f498487bd0e2999 Mon Sep 17 00:00:00 2001 From: WildSoft Date: Thu, 19 Nov 2026 00:39:35 +0300 Subject: [PATCH] Update public source --- src/lifecycle_manager.py | 22 +++++++++++++-------- src/runtime_paths.py | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 src/runtime_paths.py diff --git a/src/lifecycle_manager.py b/src/lifecycle_manager.py index d31ea16..a2a83be 100644 --- a/src/lifecycle_manager.py +++ b/src/lifecycle_manager.py @@ -21,6 +21,7 @@ if str(PROJECT_ROOT) not in sys.path: sys.path.insert(0, str(PROJECT_ROOT)) from tileserver_config import load_tileserver_config +from runtime_paths import get_node_path, get_runtime_env TILESERVER_CONFIG_DATA = load_tileserver_config(PROJECT_ROOT) @@ -129,12 +130,12 @@ def start_tileserver(): "Чужой процесс не будет остановлен." ) - node = shutil.which("node") - - if node is None: + try: + node = str(get_node_path()) + except FileNotFoundError as error: raise LifecycleError( - "Node.js не найден в PATH." - ) + "Локальный Node.js не найден." + ) from error if not TILESERVER_ENTRY.is_file(): raise LifecycleError( @@ -165,7 +166,8 @@ def start_tileserver(): process = subprocess.Popen( command, cwd=TILESERVER_DIR, - stdin=subprocess.DEVNULL + stdin=subprocess.DEVNULL, + env=get_runtime_env() ) deadline = time.monotonic() + STARTUP_TIMEOUT @@ -873,8 +875,12 @@ def install(): if shutil.which("sudo") is None: raise LifecycleError("Не найден sudo.") - if shutil.which("node") is None: - raise LifecycleError("Не найден Node.js.") + try: + get_node_path() + except FileNotFoundError as error: + raise LifecycleError( + "Локальный Node.js не найден." + ) from error if not TILESERVER_ENTRY.is_file(): raise LifecycleError( diff --git a/src/runtime_paths.py b/src/runtime_paths.py new file mode 100644 index 0000000..314058f --- /dev/null +++ b/src/runtime_paths.py @@ -0,0 +1,42 @@ +import os +from pathlib import Path + + +PROJECT_ROOT = Path(__file__).resolve().parent.parent +NODE_BIN_DIR = PROJECT_ROOT / "runtime" / "node" / "bin" + + +def _runtime_executable(name): + executable = NODE_BIN_DIR / name + + if not executable.is_file() or not os.access(executable, os.X_OK): + raise FileNotFoundError( + f"Локальный исполняемый файл {name} не найден: {executable}" + ) + + return executable + + +def get_node_path(): + return _runtime_executable("node") + + +def get_npm_path(): + return _runtime_executable("npm") + + +def get_npx_path(): + return _runtime_executable("npx") + + +def get_runtime_env(): + environment = os.environ.copy() + current_path = environment.get("PATH", "") + + environment["PATH"] = ( + f"{NODE_BIN_DIR}{os.pathsep}{current_path}" + if current_path + else str(NODE_BIN_DIR) + ) + + return environment