Update public source
This commit is contained in:
@@ -21,6 +21,7 @@ if str(PROJECT_ROOT) not in sys.path:
|
|||||||
sys.path.insert(0, str(PROJECT_ROOT))
|
sys.path.insert(0, str(PROJECT_ROOT))
|
||||||
|
|
||||||
from tileserver_config import load_tileserver_config
|
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)
|
TILESERVER_CONFIG_DATA = load_tileserver_config(PROJECT_ROOT)
|
||||||
|
|
||||||
@@ -129,12 +130,12 @@ def start_tileserver():
|
|||||||
"Чужой процесс не будет остановлен."
|
"Чужой процесс не будет остановлен."
|
||||||
)
|
)
|
||||||
|
|
||||||
node = shutil.which("node")
|
try:
|
||||||
|
node = str(get_node_path())
|
||||||
if node is None:
|
except FileNotFoundError as error:
|
||||||
raise LifecycleError(
|
raise LifecycleError(
|
||||||
"Node.js не найден в PATH."
|
"Локальный Node.js не найден."
|
||||||
)
|
) from error
|
||||||
|
|
||||||
if not TILESERVER_ENTRY.is_file():
|
if not TILESERVER_ENTRY.is_file():
|
||||||
raise LifecycleError(
|
raise LifecycleError(
|
||||||
@@ -165,7 +166,8 @@ def start_tileserver():
|
|||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
cwd=TILESERVER_DIR,
|
cwd=TILESERVER_DIR,
|
||||||
stdin=subprocess.DEVNULL
|
stdin=subprocess.DEVNULL,
|
||||||
|
env=get_runtime_env()
|
||||||
)
|
)
|
||||||
|
|
||||||
deadline = time.monotonic() + STARTUP_TIMEOUT
|
deadline = time.monotonic() + STARTUP_TIMEOUT
|
||||||
@@ -873,8 +875,12 @@ def install():
|
|||||||
if shutil.which("sudo") is None:
|
if shutil.which("sudo") is None:
|
||||||
raise LifecycleError("Не найден sudo.")
|
raise LifecycleError("Не найден sudo.")
|
||||||
|
|
||||||
if shutil.which("node") is None:
|
try:
|
||||||
raise LifecycleError("Не найден Node.js.")
|
get_node_path()
|
||||||
|
except FileNotFoundError as error:
|
||||||
|
raise LifecycleError(
|
||||||
|
"Локальный Node.js не найден."
|
||||||
|
) from error
|
||||||
|
|
||||||
if not TILESERVER_ENTRY.is_file():
|
if not TILESERVER_ENTRY.is_file():
|
||||||
raise LifecycleError(
|
raise LifecycleError(
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user