Skip to content

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

Open
Devilthelegend wants to merge 1 commit intotirth8205:mainfrom
Devilthelegend:fix/installer-detect-python-env
Open

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

Conversation

@Devilthelegend
Copy link
Copy Markdown

…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
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

1 participant