Skip to content

fix(install): detect Poetry/uv environment and generate correct MCP serve command#287

Merged
tirth8205 merged 1 commit intotirth8205:mainfrom
Devilthelegend:fix/installer-detect-python-env
Apr 18, 2026
Merged

fix(install): detect Poetry/uv environment and generate correct MCP serve command#287
tirth8205 merged 1 commit intotirth8205:mainfrom
Devilthelegend:fix/installer-detect-python-env

Conversation

@Devilthelegend
Copy link
Copy Markdown
Contributor

…erve command

When the package is installed inside a Poetry or uv virtual environment, the previous implementation hardcoded either uvx code-review-graph serve (if uvx was on PATH) or code-review-graph serve, neither of which works when the MCP client starts the server in a fresh shell where the virtualenv is not activated.

Root causes fixed:

  1. POETRY_ACTIVE=1 is only set by poetry shell, NOT by poetry run. Added VIRTUAL_ENV pattern matching (pypoetry) to detect both cases.

  2. The code-review-graph serve fallback assumed the binary is on the global PATH, which is never true inside a virtualenv.

Changes:

  • Add _in_poetry_project(): checks POETRY_ACTIVE=1 OR VIRTUAL_ENV contains pypoetry (covers both poetry shell and poetry run)

  • Add _in_uv_project(): walks uv.lock up from sys.executable to detect uv-managed projects activated without UV_PROJECT_ENVIRONMENT

  • Add _detect_serve_command(): priority chain: poetry, uv, uvx (original behaviour preserved), sys.executable fallback

  • Replace hardcoded logic in _build_server_entry() with _detect_serve_command()

  • Add 15 targeted tests covering all detection paths and edge cases

Closes #256

…erve command

When the package is installed inside a Poetry or uv virtual environment, the previous implementation hardcoded either `uvx code-review-graph serve` (if uvx was on PATH) or `code-review-graph serve`, neither of which works when the MCP client starts the server in a fresh shell where the virtualenv is not activated.

Root causes fixed:

1. POETRY_ACTIVE=1 is only set by poetry shell, NOT by poetry run. Added VIRTUAL_ENV pattern matching (pypoetry) to detect both cases.

2. The code-review-graph serve fallback assumed the binary is on the global PATH, which is never true inside a virtualenv.

Changes:

- Add _in_poetry_project(): checks POETRY_ACTIVE=1 OR VIRTUAL_ENV contains pypoetry (covers both poetry shell and poetry run)

- Add _in_uv_project(): walks uv.lock up from sys.executable to detect uv-managed projects activated without UV_PROJECT_ENVIRONMENT

- Add _detect_serve_command(): priority chain: poetry, uv, uvx (original behaviour preserved), sys.executable fallback

- Replace hardcoded logic in _build_server_entry() with _detect_serve_command()

- Add 15 targeted tests covering all detection paths and edge cases

Closes tirth8205#256
@tirth8205 tirth8205 merged commit 72ce6f3 into tirth8205:main Apr 18, 2026
1 check passed
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.

Installer should check python environment

2 participants