mirror of
https://github.com/open-jarvis/OpenJarvis.git
synced 2026-07-28 14:07:55 +00:00
fix(windows): cross-platform python discovery + browser open helpers (#436)
Reimplements the useful parts of #385 cleanly. Adds two small cross-platform helpers under `openjarvis.core.utils`: - `get_python_executable()` — prefers `python3`, falls back to `python` for Windows / minimal distros that only ship the unversioned name. - `open_browser(url)` — `webbrowser.open` by default; on Windows uses `cmd /c start "" <url>` to avoid console-host edge cases. Swapped at every hardcoded `python3` / `webbrowser.open` site: `connectors/oauth.py`, `evals/scorers/livecodebench.py`, `scripts/oauth_all.py`, `scripts/install/install.sh` (adds `PY_CMD` detection block), `scripts/quickstart.sh` (adds `MINGW*|MSYS*|CYGWIN*) cmd /c start` case), and the two affected test files. Test files wrap `get_python_executable()` in `shlex.quote()` before interpolating into `shell=True` strings — Windows interpreter paths often contain spaces. Deliberately different from #385: `openjarvis.core.__init__` does NOT re-export `DEFAULT_CONFIG_DIR` (would have raised ImportError because it's in `openjarvis.core.config`, not the package `__init__`; re-exporting would also force eager import of the heavy config module at every `import openjarvis.core`). `oauth.py` keeps `from openjarvis.core.config import DEFAULT_CONFIG_DIR` alongside the new `from openjarvis.core import open_browser`. Original API surface and call-site sweep by @sanjayravit in #385 — huge thanks for the careful Windows-compatibility audit. This PR preserves your design while fixing the ImportError edge cases caught during review. Co-Authored-By: sanjayravit <sanjayravit@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
sanjayravit
Claude Opus 4.7
parent
ad7c86495f
commit
caa3adbbce
@@ -90,6 +90,18 @@ EOF
|
||||
need git
|
||||
need curl
|
||||
|
||||
# ---- python command ----
|
||||
# Prefer `python3` (Linux / macOS / WSL convention); fall back to `python`
|
||||
# on minimal distros that only ship the unversioned name. This is used by
|
||||
# the analytics beacon and state-file helpers below — uv installs its own
|
||||
# interpreter into the venv later, so this is only for the bootstrap shims.
|
||||
PY_CMD="python3"
|
||||
if ! command -v python3 >/dev/null 2>&1; then
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
PY_CMD="python"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ---- env ----
|
||||
OPENJARVIS_HOME="${OPENJARVIS_HOME:-$HOME/.openjarvis}"
|
||||
OPENJARVIS_REPO_URL="${OPENJARVIS_REPO_URL:-https://github.com/open-jarvis/OpenJarvis.git}"
|
||||
@@ -148,7 +160,7 @@ get_anon_id() {
|
||||
return
|
||||
fi
|
||||
local new_id
|
||||
new_id="$(python3 -c 'import uuid; print(uuid.uuid4())' 2>/dev/null || echo "")"
|
||||
new_id="$("$PY_CMD" -c 'import uuid; print(uuid.uuid4())' 2>/dev/null || echo "")"
|
||||
if [[ -z "$new_id" ]]; then
|
||||
return
|
||||
fi
|
||||
@@ -189,7 +201,7 @@ beacon() {
|
||||
os="$(detect_os)"
|
||||
arch="$(detect_arch)"
|
||||
|
||||
python3 - "$ANALYTICS_HOST" "$ANALYTICS_KEY" "$event" "$anon_id" \
|
||||
"$PY_CMD" - "$ANALYTICS_HOST" "$ANALYTICS_KEY" "$event" "$anon_id" \
|
||||
"$os" "$arch" "$stage" "$elapsed_ms" "$exit_code" \
|
||||
>/dev/null 2>&1 <<'PYEOF' || true
|
||||
import json
|
||||
@@ -251,7 +263,7 @@ mark_done() {
|
||||
if [[ ! -f "$STATE_FILE" ]]; then
|
||||
echo '{}' > "$STATE_FILE"
|
||||
fi
|
||||
python3 - "$STATE_FILE" "$1" "$WSL" <<'PYEOF'
|
||||
"$PY_CMD" - "$STATE_FILE" "$1" "$WSL" <<'PYEOF'
|
||||
import json, sys
|
||||
path, key, wsl = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
with open(path) as f:
|
||||
|
||||
@@ -11,7 +11,6 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import webbrowser
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List
|
||||
@@ -19,6 +18,8 @@ from urllib.parse import parse_qs, urlencode, urlparse
|
||||
|
||||
import httpx
|
||||
|
||||
from openjarvis.core import open_browser
|
||||
|
||||
CONFIG_DIR = Path.home() / ".openjarvis" / "connectors"
|
||||
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@@ -144,7 +145,7 @@ def do_google() -> None:
|
||||
})
|
||||
)
|
||||
print(" Opening browser...")
|
||||
webbrowser.open(url)
|
||||
open_browser(url)
|
||||
code = _wait_for_code()
|
||||
|
||||
resp = httpx.post(
|
||||
@@ -192,7 +193,7 @@ def do_strava() -> None:
|
||||
})
|
||||
)
|
||||
print(" Opening browser...")
|
||||
webbrowser.open(url)
|
||||
open_browser(url)
|
||||
code = _wait_for_code()
|
||||
|
||||
resp = httpx.post(
|
||||
@@ -303,7 +304,7 @@ def do_spotify() -> None:
|
||||
})
|
||||
)
|
||||
print(" Opening browser...")
|
||||
webbrowser.open(url)
|
||||
open_browser(url)
|
||||
code = _wait_for_code(port=spotify_port)
|
||||
|
||||
import base64
|
||||
|
||||
+14
-8
@@ -47,19 +47,24 @@ echo " └───────────────────────
|
||||
echo -e "${NC}"
|
||||
|
||||
# ── 1. Check Python ──────────────────────────────────────────────────
|
||||
# Prefer python3, fall back to python (Windows / minimal distros that ship
|
||||
# only the unversioned name).
|
||||
info "Checking Python..."
|
||||
if command -v python3 &>/dev/null; then
|
||||
PY_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
|
||||
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
|
||||
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
|
||||
if [ "$PY_MAJOR" -ge 3 ] && [ "$PY_MINOR" -ge 10 ]; then
|
||||
ok "Python $PY_VERSION"
|
||||
else
|
||||
fail "Python 3.10+ required (found $PY_VERSION)"
|
||||
fi
|
||||
PY_CMD="python3"
|
||||
elif command -v python &>/dev/null; then
|
||||
PY_CMD="python"
|
||||
else
|
||||
fail "Python 3 not found. Install from https://python.org"
|
||||
fi
|
||||
PY_VERSION=$("$PY_CMD" -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
|
||||
PY_MAJOR=$(echo "$PY_VERSION" | cut -d. -f1)
|
||||
PY_MINOR=$(echo "$PY_VERSION" | cut -d. -f2)
|
||||
if [ "$PY_MAJOR" -ge 3 ] && [ "$PY_MINOR" -ge 10 ]; then
|
||||
ok "Python $PY_VERSION ($PY_CMD)"
|
||||
else
|
||||
fail "Python 3.10+ required (found $PY_VERSION)"
|
||||
fi
|
||||
|
||||
# ── 2. Check / install uv ───────────────────────────────────────────
|
||||
info "Checking uv..."
|
||||
@@ -182,6 +187,7 @@ info "Opening $URL ..."
|
||||
case "$(uname -s)" in
|
||||
Darwin) open "$URL" ;;
|
||||
Linux) xdg-open "$URL" 2>/dev/null || true ;;
|
||||
MINGW*|MSYS*|CYGWIN*) cmd /c start "" "$URL" 2>/dev/null || true ;;
|
||||
*) true ;;
|
||||
esac
|
||||
|
||||
|
||||
Reference in New Issue
Block a user