Skip to content

gh-159498: Fix PowerShell venv activation for paths containing brackets - #159499

Open
repzakske wants to merge 2 commits into
python:mainfrom
repzakske:fix/venv-powershell-literal-paths
Open

repzakske wants to merge 2 commits into
python:mainfrom
repzakske:fix/venv-powershell-literal-paths

Conversation

@repzakske

@repzakske repzakske commented Oct 15, 2026 •

Copy link
Copy Markdown

Fixes #159498.

PowerShell interprets square brackets in the activation script's path and config path as wildcard syntax. This can prevent activation under project [2026]/.venv, or make venv[1] select a sibling directory named venv1.

Use literal lookups for the script directory and pyvenv.cfg, constructing the config path without wildcard resolution.

The regression test activates an environment named venv[1] in each available PowerShell implementation and checks the active environment, configured prompt, and selected interpreter using the existing subprocess helper.

Validation

  • The regression test fails against the original script and when each corrected lookup is independently reverted, in both shells.
  • Built CPython main locally and ran python -m test -v -u cpu test_venv: 54 tests, 9 platform skips, no failures.
  • Tested with PowerShell 7.6.5 and Windows PowerShell 5.1 on Windows.
  • Applicable pre-commit hooks and patchcheck passed.
  • Full CPython test-suite and upstream CI results remain pending.

Please consider backports to 3.14 and 3.15.

@python-cla-bot

python-cla-bot Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell venv activation treats square brackets in paths as wildcards

1 participant