Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: handle npm.cmd correctly on Windows

Pietro280d14bc0c33
diff --git a/scripts/start_tour.py b/scripts/start_tour.py
index f9d6eee71..7596c8e69 100644
--- a/scripts/start_tour.py
+++ b/scripts/start_tour.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""DeepTutor Setup Tour — minimal terminal-first guided installer."""
+
from __future__ import annotations
import json
@@ -163,6 +164,7 @@ MATH_ANIMATOR_REQUIREMENTS = "requirements/math-animator.txt"
# Cache helpers
# ---------------------------------------------------------------------------
+
def _save_cache(data: dict[str, Any]) -> None:
data["updated_at"] = time.strftime("%Y-%m-%dT%H:%M:%S")
CACHE_PATH.parent.mkdir(parents=True, exist_ok=True)
@@ -187,6 +189,7 @@ def _cleanup_cache() -> None:
# Environment detection
# ---------------------------------------------------------------------------
+
def _python_strategy() -> str:
if os.environ.get("CONDA_DEFAULT_ENV"):
return f"conda:{os.environ['CONDA_DEFAULT_ENV']}"
@@ -331,10 +334,7 @@ def _ensure_math_animator_system_deps() -> None:
for dep in still_missing:
cmd = _math_animator_install_cmd(dep)
commands.append(" ".join(cmd) if cmd else f"install {dep} manually")
- log_warn(
- "Math animator may fail until these are installed: "
- + " | ".join(commands)
- )
+ log_warn("Math animator may fail until these are installed: " + " | ".join(commands))
# ---------------------------------------------------------------------------
@@ -342,7 +342,17 @@ def _ensure_math_animator_system_deps() -> None:
# ---------------------------------------------------------------------------
_NATIVE_BINDINGS = frozenset(
- {"anthropic", "azure_openai", "dashscope", "perplexity", "exa", "tavily", "serper", "jina", "baidu"}
+ {
+ "anthropic",
+ "azure_openai",
+ "dashscope",
+ "perplexity",
+ "exa",
+ "tavily",
+ "serper",
+ "jina",
+ "baidu",
+ }
)
@@ -362,6 +372,22 @@ def _needs_providers(catalog: dict[str, Any]) -> bool:
# Dependency installation
# ---------------------------------------------------------------------------
+
+def _get_npm_command() -> str:
+ """Return the correct npm command for the current platform.
+
+ With shell=True on Windows, we can just use "npm" and let the shell resolve it.
+ """
+ if platform.system().lower() == "windows":
+ return "npm"
+ else:
+ # On Unix-like systems, npm should be found directly
+ npm = shutil.which("npm")
+ if npm:
+ return npm
+ return "npm"
+
+
def _install_commands(
profile: str,
catalog: dict[str, Any],
@@ -376,17 +402,22 @@ def _install_commands(
for req in PROFILE_COMMANDS[profile]:
cmds.append(([_PYTHON, "-m", "pip", "install", "-r", req], PROJECT_ROOT))
if include_math_animator:
- cmds.append(([_PYTHON, "-m", "pip", "install", "-r", MATH_ANIMATOR_REQUIREMENTS], PROJECT_ROOT))
+ cmds.append(
+ ([_PYTHON, "-m", "pip", "install", "-r", MATH_ANIMATOR_REQUIREMENTS], PROJECT_ROOT)
+ )
cmds.append(([_PYTHON, "-m", "pip", "install", "-e", ".", "--no-deps"], PROJECT_ROOT))
if profile.startswith("web"):
- cmds.append((["npm", "install"], PROJECT_ROOT / "web"))
+ npm_cmd = _get_npm_command()
+ cmds.append(([npm_cmd, "install"], PROJECT_ROOT / "web"))
# Provider SDKs are now bundled in cli.txt, no separate install needed.
return cmds
def _run_cmd(cmd: list[str], cwd: Path) -> None:
log_info(f"{dim(str(cwd))} {' '.join(cmd)}")
- result = subprocess.run(cmd, cwd=str(cwd), check=False)
+ # On Windows, use shell=True to handle .cmd files properly
+ use_shell = platform.system().lower() == "windows"
+ result = subprocess.run(cmd, cwd=str(cwd), check=False, shell=use_shell)
if result.returncode != 0:
raise RuntimeError(f"Command failed (exit {result.returncode}): {' '.join(cmd)}")
@@ -395,7 +426,10 @@ def _run_cmd(cmd: list[str], cwd: Path) -> None:
# Model catalog helpers
# ---------------------------------------------------------------------------
-def _ensure_service(catalog: dict[str, Any], svc: str) -> tuple[dict[str, Any], dict[str, Any] | None]:
+
+def _ensure_service(
+ catalog: dict[str, Any], svc: str
+) -> tuple[dict[str, Any], dict[str, Any] | None]:
services = catalog.setdefault("services", {})
service = services.setdefault(svc, {"active_profile_id": None, "profiles": []})
profiles = service.setdefault("profiles", [])
@@ -451,6 +485,7 @@ def _ensure_service(catalog: dict[str, Any], svc: str) -> tuple[dict[str, Any],
# Configure a single service interactively (CLI path only)
# ---------------------------------------------------------------------------
+
def _configure_service(catalog: dict[str, Any], svc: str) -> None:
profile, model = _ensure_service(catalog, svc)
@@ -479,6 +514,7 @@ def _configure_service(catalog: dict[str, Any], svc: str) -> None:
# Live connectivity test (CLI path only)
# ---------------------------------------------------------------------------
+
def _stream_test(svc: str, catalog: dict[str, Any]) -> bool:
run = get_config_test_runner().start(svc, catalog)
seen = 0
@@ -494,7 +530,9 @@ def _stream_test(svc: str, catalog: dict[str, Any]) -> bool:
log_info(dim(msg))
elif kind == "config":
p = ev.get("profile", {})
- log_info(dim(f"{p.get('name', '')} {p.get('binding', '')} {p.get('base_url', '')}"))
+ log_info(
+ dim(f"{p.get('name', '')} {p.get('binding', '')} {p.get('base_url', '')}")
+ )
elif kind == "response":
snippet = ev.get("snippet", "")
d_actual = ev.get("actual_dimension")
@@ -519,6 +557,7 @@ def _stream_test(svc: str, catalog: dict[str, Any]) -> bool:
# Build final .env dict
# ---------------------------------------------------------------------------
+
def _build_env(ports: dict[str, int], catalog: dict[str, Any]) -> dict[str, str]:
rendered = get_env_store().render_from_catalog(catalog)
rendered["BACKEND_PORT"] = str(ports["backend"])
@@ -530,6 +569,7 @@ def _build_env(ports: dict[str, int], catalog: dict[str, Any]) -> dict[str, str]
# Tour banner
# ---------------------------------------------------------------------------
+
def _tour_banner() -> None:
banner(
"DeepTutor Setup Tour",
@@ -544,6 +584,7 @@ def _tour_banner() -> None:
# Web path — install deps, start temp server, wait for browser config
# ===================================================================
+
def _stream_text_kwargs() -> dict[str, object]:
"""Best-effort text decoding for background process output."""
# Some Windows child processes emit locale-specific bytes even when Python
@@ -561,7 +602,11 @@ def _stream_text_kwargs() -> dict[str, object]:
def _spawn_process(
- cmd: list[str], *, cwd: Path, env: dict[str, str], name: str,
+ cmd: list[str],
+ *,
+ cwd: Path,
+ env: dict[str, str],
+ name: str,
) -> subprocess.Popen[str]:
import threading
@@ -661,13 +706,21 @@ def _run_web_tour() -> None:
get_env_store().write(_build_env(ports, catalog))
# Mark cache as waiting (the backend reads this)
- _save_cache({
- "step": 4, "mode": "web", "profile": profile,
- "ports": ports, "status": "waiting",
- })
+ _save_cache(
+ {
+ "step": 4,
+ "mode": "web",
+ "profile": profile,
+ "ports": ports,
+ "status": "waiting",
+ }
+ )
- npm = shutil.which("npm")
- if not npm:
+ npm = _get_npm_command()
+ # Verify npm is actually available and works
+ try:
+ subprocess.run([npm, "--version"], capture_output=True, check=True)
+ except (subprocess.CalledProcessError, FileNotFoundError):
log_error("npm not found. Cannot start frontend.")
raise SystemExit(1)
@@ -683,7 +736,9 @@ def _run_web_tour() -> None:
log_info("Starting temporary server ...")
backend = _spawn_process(backend_cmd, cwd=PROJECT_ROOT, env=backend_env, name="backend")
time.sleep(2)
- frontend = _spawn_process(frontend_cmd, cwd=PROJECT_ROOT / "web", env=frontend_env, name="frontend")
+ frontend = _spawn_process(
+ frontend_cmd, cwd=PROJECT_ROOT / "web", env=frontend_env, name="frontend"
+ )
time.sleep(3)
settings_url = f"http://localhost:{ports['frontend']}/settings?tour=true"
@@ -745,6 +800,7 @@ def _run_web_tour() -> None:
# CLI path — full interactive configuration in the terminal
# ===================================================================
+
def _run_cli_tour() -> None:
total = 6
@@ -821,8 +877,12 @@ def _run_cli_tour() -> None:
log_info(f"Profile {bold(profile)}")
log_info(f"Backend {bold(str(ports['backend']))}")
- log_info(f"LLM {bold((llm_p or {}).get('name', '?'))} {dim((llm_m or {}).get('model', '?'))}")
- log_info(f"Embedding {bold((emb_p or {}).get('name', '?'))} {dim((emb_m or {}).get('model', '?'))}")
+ log_info(
+ f"LLM {bold((llm_p or {}).get('name', '?'))} {dim((llm_m or {}).get('model', '?'))}"
+ )
+ log_info(
+ f"Embedding {bold((emb_p or {}).get('name', '?'))} {dim((emb_m or {}).get('model', '?'))}"
+ )
if search_enabled:
log_info(f"Search {bold((search_p or {}).get('name', '?'))}")
else:
@@ -853,6 +913,7 @@ def _run_cli_tour() -> None:
# Entry
# ===================================================================
+
def run_tour() -> None:
_tour_banner()