Skip to content

fix(gateway): detect virtualenv path instead of hardcoding venv/#2493

Closed
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:fix/gateway-venv-path-detection
Closed

fix(gateway): detect virtualenv path instead of hardcoding venv/#2493
Mibayy wants to merge 1 commit into
NousResearch:mainfrom
Mibayy:fix/gateway-venv-path-detection

Conversation

@Mibayy

@Mibayy Mibayy commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #2492.

Problem

generate_systemd_unit() and get_python_path() in hermes_cli/gateway.py hardcode venv as the virtualenv directory name. When the virtualenv is created as .venv (which setup-hermes.sh and .gitignore both reference), the generated systemd unit has incorrect VIRTUAL_ENV and PATH environment variables pointing to a nonexistent venv/ directory.

Solution

Introduce _detect_venv_dir() which:

  1. Checks sys.prefix vs sys.base_prefix to detect the active virtualenv (works regardless of directory name)
  2. Falls back to probing .venv then venv under PROJECT_ROOT
  3. Returns None when no virtualenv is found

Both get_python_path() and generate_systemd_unit() now use this detection instead of hardcoded paths.

Tests

Added tests for:

  • _detect_venv_dir(): sys.prefix detection, .venv fallback, venv fallback, .venv preferred over venv, no venv returns None
  • generate_systemd_unit(): verifies the unit file uses the detected venv path

Fixes NousResearch#2492.

`generate_systemd_unit()` and `get_python_path()` hardcoded `venv`
as the virtualenv directory name. When the virtualenv is `.venv`
(which `setup-hermes.sh` and `.gitignore` both reference), the
generated systemd unit had incorrect VIRTUAL_ENV and PATH variables.

Introduce `_detect_venv_dir()` which:
1. Checks `sys.prefix` vs `sys.base_prefix` to detect the active venv
2. Falls back to probing `.venv` then `venv` under PROJECT_ROOT

Both `get_python_path()` and `generate_systemd_unit()` now use
this detection instead of hardcoded paths.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #2797. Your implementation was cherry-picked onto current main with authorship preserved — yours was the cleanest approach and submitted first. Thanks @Mibayy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(gateway): systemd service unit hardcodes venv/ path, breaks when virtualenv is .venv

2 participants