Skip to content

fix: prepend PowerShell call operator when activating environments#197

Merged
flying-sheep merged 1 commit into
pypa:mainfrom
d-biehl:fix/pwsh-activation-call-operator
Jun 1, 2026
Merged

fix: prepend PowerShell call operator when activating environments#197
flying-sheep merged 1 commit into
pypa:mainfrom
d-biehl:fix/pwsh-activation-call-operator

Conversation

@d-biehl

@d-biehl d-biehl commented May 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #196.

Problem

Activating a Hatch environment in a PowerShell terminal fails with a ParserError when the Hatch executable path contains a space (e.g. the standalone installer's C:\Program Files\Hatch\hatch.EXE). The host quotes the executable, and PowerShell parses a leading quoted string as an expression rather than a command to run:

"C:\Program Files\Hatch\hatch.EXE" --env=devel.py3.14-rf74 shell
ParserError: Unexpected token 'env=devel.py3.14-rf74' in expression or statement.

Invoking a quoted executable in PowerShell requires the call operator &. The ms-python.vscode-python-envs host adds it automatically on its run path (runInTerminal.ts) but not on the activation path (getShellCommandAsString), so the manager has to supply it for PowerShell — which the built-in venv/poetry managers do, but this manager did not.

Fix

Add a pwsh-specific shellActivation entry that prefixes the call operator, matching the built-in managers ({ executable: '&', args: [...] }). A lone & is left unquoted by the host's quoting, producing:

& "C:\Program Files\Hatch\hatch.EXE" --env devel.py3.14-rf74 shell

'pwsh' covers both Windows PowerShell 5.x and PowerShell 7; cmd/bash/zsh/fish keep using the shared 'unknown' entry, where & is neither needed nor valid. The --env flag and its value are now passed as separate args so only the value is quoted when needed.

Testing

Verified manually on Windows with PowerShell — activation now works. tsc --noEmit and biome check pass.

PowerShell parses a leading quoted string as an expression, so when the
Hatch executable path contains a space (e.g. under "C:\Program Files"),
the host-quoted activation command failed with a ParserError and the
environment was not activated.

Add a pwsh-specific shellActivation entry that prefixes the call operator
`&`, matching how the built-in venv/poetry managers handle PowerShell.
cmd/bash/zsh/fish keep using the shared entry, where `&` is neither needed
nor valid.

Fixes pypa#196
Copilot AI review requested due to automatic review settings May 31, 2026 22:57
@flying-sheep flying-sheep merged commit 682a443 into pypa:main Jun 1, 2026
6 checks passed
@flying-sheep

Copy link
Copy Markdown
Member

thanks!

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.

[BUG] Activating a Hatch environment fails in PowerShell when Hatch is installed in a path containing spaces (missing & call operator)

2 participants