Skip to content

fix(poetry plugin): activate the in-project virtualenv so scripts land on PATH - #2958

Open
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-s11hj2
Open

fix(poetry plugin): activate the in-project virtualenv so scripts land on PATH#2958
mikeland73 wants to merge 1 commit into
mainfrom
claude/focused-goldberg-s11hj2

Conversation

@mikeland73

Copy link
Copy Markdown
Contributor

Summary

Fixes#2676.

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, which is the regression reported in the issue:

Scripts from the python package are not available on the path of the devbox shell since updating from 1.7.1.

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's init_hook — which runs in the sourced shellrc context, unlike the executedinitHook.sh, so it can actually modify the shell's PATH:

"init_hook": [
"\"{{ .Virtenv }}/bin/initHook.sh\"",
"if [ -d \"${DEVBOX_PYPROJECT_DIR:-$DEVBOX_DEFAULT_PYPROJECT_DIR}/.venv\" ]; then export VIRTUAL_ENV=\"${DEVBOX_PYPROJECT_DIR:-$DEVBOX_DEFAULT_PYPROJECT_DIR}/.venv\"; export PATH=\"$VIRTUAL_ENV/bin:$PATH\"; fi"
]

Ordering makes this robust:

  • Plugin init hooks run before the user's own hooks (Config.InitHook() appends included-plugin hooks ahead of the root config's hooks).
  • poetry env use inside initHook.sh creates .venv, so the [ -d … ] guard already passes when the activation line runs.
  • By the time the user's poetry install executes, .venv/bin is already on PATH, 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 version is bumped 0.0.50.0.6 so 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, including plugins/init_hook_quoting_test.go (the new line uses no {{ }} templates, and all path expansions are quoted).
  • Validated the JSON parses and bash -n syntax-checked the rendered activation line.
  • Simulated a spaced project dir end-to-end: exported DEVBOX_DEFAULT_PYPROJECT_DIR="/tmp/pdir with space", placed an executable at .venv/bin/myscript, ran the activation line, and confirmed VIRTUAL_ENV was set correctly and myscript resolved and ran by name from PATH.

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

…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
CopilotAI lite review requested due to automatic review settings August 17, 2026 14:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Poetry shell missing scripts

3 participants

@mikeland73@claude