fix(install): detect Poetry/uv environment and generate correct MCP serve command#287
Open
Devilthelegend wants to merge 1 commit intotirth8205:mainfrom
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…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) orcode-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:
POETRY_ACTIVE=1 is only set by poetry shell, NOT by poetry run. Added VIRTUAL_ENV pattern matching (pypoetry) to detect both cases.
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