utils
utils
¶
Small cross-platform utilities used by the CLI, OAuth flow, and evals.
Kept dependency-free so importing this module is cheap (the public re-export
from openjarvis.core must not pull in heavy modules at package init).
Functions¶
get_python_executable
¶
Return the best python interpreter name on PATH.
Prefers python3 (Linux/macOS convention); falls back to python
(Windows / some minimal Linux distros that ship only python). Returns
the literal string "python3" when neither is found, so callers still
get a usable command that will fail with a clear "command not found"
rather than an empty string.
The result is a command name or absolute path that callers can hand to
:mod:subprocess directly when shell=False, and must be shell-quoted
(:func:shlex.quote) before being interpolated into a shell=True
command string — paths on Windows often contain spaces.
Source code in src/openjarvis/core/utils.py
open_browser
¶
Open url in the user's default browser, with a Windows fast-path.
:func:webbrowser.open is the cross-platform default, but on Windows it
sometimes blocks or fails inside a console host. cmd /c start "" "URL"
is the canonical Windows incantation that hands the URL to the OS shell
and returns immediately. We try that first on Windows and fall back to
:func:webbrowser.open if the subprocess spawn fails.
Source code in src/openjarvis/core/utils.py
process_alive
¶
Return True if a process with pid is currently running.
Cross-platform and non-destructive. The common POSIX idiom
os.kill(pid, 0) must NOT be used on Windows: there os.kill maps any
signal to TerminateProcess, so a "liveness probe" would actually kill
the process. On Windows we inspect a process handle instead.
Source code in src/openjarvis/core/utils.py
terminate_process
¶
Terminate pid gracefully, escalating to a forced kill (cross-platform).
POSIX sends SIGTERM then, after grace_seconds, SIGKILL. Windows
has neither; it uses taskkill (graceful) then taskkill /F /T (force,
whole tree). signal.SIGKILL does not exist on Windows, so it is only
referenced inside the POSIX branch.