Uh oh!
There was an error while loading. Please reload this page.
fix(poetry plugin): activate the in-project virtualenv so scripts land on PATH - #2958
Open
mikeland73 wants to merge 1 commit into
Open
fix(poetry plugin): activate the in-project virtualenv so scripts land on PATH#2958mikeland73 wants to merge 1 commit into
mikeland73 wants to merge 1 commit into
Conversation
…d on PATH Since Poetry 2.0.0 removed the bundled `poetry shell` command, the poetry plugin relies on `poetry env use` (in initHook.sh) to point Poetry at the Devbox-provided Python. That selects the virtualenv but never activates it, so console scripts and entry points installed by `poetry install` live in `<project>/.venv/bin` and are not on the Devbox shell's PATH. Users are forced to prefix everything with `poetry run`. The plugin already sets POETRY_VIRTUALENVS_IN_PROJECT=true, so the virtualenv is always created at `<pyproject-dir>/.venv`. Activate it from the init_hook (which runs in the sourced shellrc context, unlike the executed initHook.sh) by exporting VIRTUAL_ENV and prepending its `bin` to PATH once the directory exists. Plugin init hooks run before the user's hooks, and `poetry env use` creates `.venv`, so the guard passes by the time the user's `poetry install` populates `.venv/bin`. The path templates are env-var based and fully double-quoted, so project directories containing spaces are handled correctly. Bump the plugin version so existing environments pick up the new hook. Fixes#2676
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 freeto 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.
Summary
Fixes#2676.
Since Poetry 2.0.0 removed the bundled
poetry shellcommand, the poetry plugin relies onpoetry env use(ininitHook.sh) to point Poetry at the Devbox-provided Python. That selects the virtualenv but never activates it, so console scripts and entry points installed bypoetry installlive in<project>/.venv/binand are not on the Devbox shell's PATH. Users are forced to prefix everything withpoetry run, which is the regression reported in the issue:Fix
The plugin already sets
POETRY_VIRTUALENVS_IN_PROJECT=true, so the virtualenv is always created at<pyproject-dir>/.venv. I activate it from the plugin'sinit_hook— which runs in the sourced shellrc context, unlike the executedinitHook.sh, so it can actually modify the shell'sPATH:Ordering makes this robust:
Config.InitHook()appends included-plugin hooks ahead of the root config's hooks).poetry env useinsideinitHook.shcreates.venv, so the[ -d … ]guard already passes when the activation line runs.poetry installexecutes,.venv/binis already onPATH, so the freshly installed scripts resolve by name.The path is derived from env vars and every expansion is double-quoted, so project directories containing spaces are handled correctly. The plugin
versionis bumped0.0.5→0.0.6so existing environments regenerate with the new hook, matching the convention used by prior plugin behavior changes.How was it tested?
go test ./plugins/ ./internal/plugin/passes, includingplugins/init_hook_quoting_test.go(the new line uses no{{ }}templates, and all path expansions are quoted).bash -nsyntax-checked the rendered activation line.DEVBOX_DEFAULT_PYPROJECT_DIR="/tmp/pdir with space", placed an executable at.venv/bin/myscript, ran the activation line, and confirmedVIRTUAL_ENVwas set correctly andmyscriptresolved and ran by name fromPATH.cc @tlelson — thanks for the clear root-cause analysis and reproduction in the issue.
Community Contribution License
All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.
By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.
Generated by Claude Code