Skip to content

fix: skip terminal activation when there is no activate script - #1801

Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
microsoft:mainfrom
Shubham-Padkonde:fix-activation-without-activate-script
Open

Shubham Padkonde (Shubham-Padkonde) wants to merge 1 commit into
microsoft:mainfrom
Shubham-Padkonde:fix-activation-without-activate-script

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Fixes #1775

Problem

When an interpreter's bin/ has no activate script, getShellActivationCommands(binDir) still emitted source <bin>/activate for sh, bash, zsh, Git Bash, ksh and the unknown fallback. uv python install toolchains are an example: they're base interpreters, not virtual environments. Every new terminal then ran a failing command:

source: no such file or directory: ~/.local/share/uv/python/cpython-3.13.9-macos-aarch64-none/bin/activate

The other shells (csh, fish, xonsh, nu, pwsh, cmd) were already gated on their script existing.

Fix

  • getShellActivationCommands only adds the activate-based entries (unknown, sh, bash, Git Bash, zsh, ksh) when <binDir>/activate exists. This matches how the other shells are handled. Real venvs, pipenv and poetry environments always ship activate, so they're unaffected.
  • isActivatableEnvironment now requires a non-empty shellActivation map. It used to check only that the map existed, so an environment with no activation commands was still offered for activation (the terminal activate button and command-based auto-activation).

Tests

  • New tests in utils.getShellActivationCommands.unit.test.ts:
    • no POSIX or unknown activation without an activate script, on non-Windows and on Windows;
    • activation is still emitted when the script exists.
  • New src/test/features/common/activation.unit.test.ts covers isActivatableEnvironment, including the empty-map case.
  • Two existing tests ("Bash activation does not include Set-ExecutionPolicy" and "Windows unknown shell uses activate…") now create the activate file they rely on.
  • Unit tests (tsc + mocha, Node 22):
    • with the change: 2411 passing;
    • without it: the 3 new tests covering the bug fail.
  • eslint and prettier --check are clean on the changed files.

I did not test this manually in VS Code with a real uv toolchain. The fix is covered by the unit tests above.

This change was written with help from an AI coding assistant (Claude Code). I reviewed and tested it as described above.

🤖 Generated with Claude Code

getShellActivationCommands() emitted `source <bin>/activate` for sh,
bash, zsh, Git Bash, ksh and the "unknown" shell without checking that
the script exists, unlike the other shells. For base interpreters that
share the layout but are not virtual environments (for example
`uv python install` toolchains), every new terminal then ran a failing
`source` command. Only add these entries when `activate` exists, and
treat an environment with an empty shell activation map as not
activatable.

Fixes microsoft#1775

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

Terminal activation emits source <prefix>/bin/activate for uv-managed toolchains that have no activate script

1 participant