Skip to content

fix: keep VIRTUAL_ENV on the versions symlink path - #529

Open
r3wretrhy wants to merge 1 commit into
pyenv:masterfrom
r3wretrhy:fix/virtual-env-symlink-path-494
Open

r3wretrhy wants to merge 1 commit into
pyenv:masterfrom
r3wretrhy:fix/virtual-env-symlink-path-494

Conversation

@r3wretrhy

@r3wretrhy r3wretrhy commented Oct 3, 2026 •

Copy link
Copy Markdown

pyenv activate resolves $PYENV_ROOT/versions/<name> through the symlink into .../versions/<base>/envs/<name> before exporting VIRTUAL_ENV. Shims keep the symlink path on PATH, so tools that compare the two (Neovim, for example) warn that they disagree.

Stop resolving that symlink on activate so VIRTUAL_ENV matches the path on PATH.

Fixes #494.


Summary by cubic

Fixes pyenv activate so VIRTUAL_ENV matches the symlink path that shims put on PATH, eliminating tool warnings (e.g. Neovim) about the two disagreeing.

  • Stops resolving the $PYENV_ROOT/versions/<name> symlink before exporting VIRTUAL_ENV; the prefix is now left as pyenv-prefix returned it.
  • Adds a regression test for $VIRTUAL_ENV and $PATH don't agree #494.

Written for commit 390b7ca. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

@native-api native-api left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As per the problem statement, we should rather be testing that VIRTUAL_ENV is in agreement with PATH. Symlink resolution and stuff are but implementation details that are subject to change.

@r3wretrhy

Copy link
Copy Markdown
Author

Thanks @native-api — updated the regression test to assert the #494 property directly: after activate, VIRTUAL_ENV/bin/python matches the python that PATH yields (with the shim-facing versions/<name>/bin on PATH). Dropped the symlink-resolution assertion as an implementation detail.

@r3wretrhy
r3wretrhy force-pushed the fix/virtual-env-symlink-path-494 branch from 5c0e99c to 8893cb8 Compare October 4, 2026 07:01
Comment thread test/activate.bats
Comment on lines +519 to +537
assert_success
assert_output <<EOS
deactivated
export PYENV_VIRTUAL_ENV="${PYENV_ROOT}/versions/myenv";
export VIRTUAL_ENV="${PYENV_ROOT}/versions/myenv";
export _OLD_VIRTUAL_PS1="\${PS1:-}";
export PS1="(myenv) \${PS1:-}";
EOS

# Per #494: VIRTUAL_ENV must agree with the python PATH yields.
eval "$(printf '%s\n' "$output" | grep '^export ')"
path_python="$(command -v python)"
assert_equal "${VIRTUAL_ENV}/bin/python" "${path_python}"

unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
unstub pyenv-sh-deactivate
}

@native-api native-api Oct 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are we just checking equality or enforcing some specific value? If the latter then the latter check is redundant. If the former then the former check is redundant.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Kept the equality check (assert_equal of VIRTUAL_ENV/bin/python vs command -v python) and dropped the redundant specific-value assert_output for VIRTUAL_ENV.

pyenv-virtualenv installs $PYENV_ROOT/versions/<name> as a symlink to
.../versions/<base>/envs/<name>, and shims put that symlink path on PATH.
Resolving the symlink when activating made VIRTUAL_ENV disagree with PATH,
which tools like Neovim warn about.

Leave the prefix as pyenv-prefix returned it so VIRTUAL_ENV matches PATH.
Adds a regression test for pyenv#494.
@r3wretrhy
r3wretrhy force-pushed the fix/virtual-env-symlink-path-494 branch from 8893cb8 to 390b7ca Compare October 5, 2026 14:32
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.

$VIRTUAL_ENV and $PATH don't agree

2 participants