[python] Fix incorrect VIRTUAL_ENV in pyenv-mode-set-local-version#17246
Merged
bcc32 merged 1 commit intosyl20bnr:developfrom Mar 15, 2026
Merged
Conversation
Remove the erroneous `(setenv "VIRTUAL_ENV" version)` call from `spacemacs//pyenv-mode-set-local-version`. This line was introduced in commit e699763 to help Python LSP servers detect pyenv version changes. However, the implementation was incorrect: it set `VIRTUAL_ENV` to a bare version string (e.g. "3.13.2") instead of a filesystem path. The `VIRTUAL_ENV` environment variable, by convention, should contain the absolute path to a virtualenv directory. This causes issues in pyenv + Poetry workflows: Poetry reads `VIRTUAL_ENV` and interprets the version string as a virtualenv path, leading to errors. The severity depends on hook execution order — if `spacemacs//python-setup-backend` (which calls `poetry-venv-workon` → `pyvenv-activate`) runs after the pyenv hook, the bogus value gets overwritten and the bug is masked; otherwise Poetry breaks. The `setenv` call is also unnecessary. `pyenv-mode-set` already handles all required environment setup internally: - calls `pythonic-activate` with the full path from `pyenv-mode-full-path` to set `python-shell-virtualenv-root` - sets `PYENV_VERSION` to the version string Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
bcc32
approved these changes
Mar 15, 2026
Collaborator
|
Thanks for your contribution. |
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.
Summary
(setenv "VIRTUAL_ENV" version)fromspacemacs//pyenv-mode-set-local-versionVIRTUAL_ENVto a bare version string (e.g."3.13.2")instead of a filesystem path, breaking tools like Poetry that expect
VIRTUAL_ENVto be a valid virtualenv directory pathpyenv-mode-setalready handlesenvironment setup internally via
pythonic-activateandPYENV_VERSIONContext
Introduced in e699763 to help LSP detect pyenv changes, but the value
was always wrong (version name instead of path). In pyenv + Poetry
workflows, Poetry reads
VIRTUAL_ENVand interprets the version stringas a path, causing errors. Whether the bug manifests depends on hook
execution order — if Poetry's
pyvenv-activateruns after the pyenvhook, it overwrites the bad value and masks the issue.
What I tested
VIRTUAL_ENVwas beingset to a bare version string (e.g. "3.13.2") by this function
poetry env infoin the Spacemacs shelloutputs the correct virtualenv path
pyenv-mode-setalreadycorrectly handles environment setup (
PYENV_VERSIONviasetenv,python-shell-virtualenv-rootviapythonic-activate)Not tested
pyenv-mode-setstill sets
PYENV_VERSIONandpython-shell-virtualenv-root, whichLSP servers should use
incorrect for those users (setting a name string, not a path)