Skip to content

Commit 09cb321

Browse files
release: Prevent virtualenv redirect from occupying .venv (#26168)
## Why Backport of [#26167](#26167) for the 2026.6 release branch. [virtualenv 21.12](https://github.com/pypa/virtualenv/releases/tag/21.12.0) began writing a `.venv` redirect file when creating `.virtualenv` in a project with `pyproject.toml`. The following `python -m venv .venv` then cannot create the separate stdlib venv directory, breaking the release branch's Windows and Linux venv jobs. ## Change Pass `--no-venv-redirect` when creating `.virtualenv` so the existing `.virtualenv` and `.venv` tests continue to use their original, separate paths. Exit immediately if stdlib venv creation fails. ## Windows unit-test investigation The Windows `ts-unit` job also intermittently failed on the first Native Python Finder refresh while the subsequent refresh succeeded. The locator-output diagnostic reproduced the failure: Pet logged `Skipping refresh state sync for stale generation 0 because current generation is 1` and returned no environments. The finder had launched a configure request in its constructor without awaiting it, while its first refresh launched another configure and could start before the first completed. Pet suppresses environment notifications from stale configuration generations. Remove the redundant constructor configure; the first refresh already configures and awaits completion before sending the refresh request. The existing non-empty assertion is unchanged and still includes the locator log on failure. The release branch's Build workflow must pass after this lands before releasing. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7a06e93 commit 09cb321

4 files changed

Lines changed: 15 additions & 12 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ jobs:
311311
if: matrix.test-suite == 'venv'
312312
run: |
313313
python -m pip install virtualenv
314-
python -m virtualenv .virtualenv/
314+
python -m virtualenv --no-venv-redirect .virtualenv/
315315
if ('${{ matrix.os }}' -match 'windows-latest') {
316316
& ".virtualenv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} virtualEnvPath
317317
} else {
@@ -326,10 +326,11 @@ jobs:
326326
if: matrix.test-suite == 'venv' && startsWith(matrix.python, 3.)
327327
run: |
328328
python -m venv .venv
329+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
329330
if ('${{ matrix.os }}' -match 'windows-latest') {
330-
& ".venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
331+
& "./.venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
331332
} else {
332-
& ".venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
333+
& "./.venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
333334
}
334335
335336
- name: Prepare conda for venv tests

‎.github/workflows/pr-check.yml‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ jobs:
304304
if: matrix.test-suite == 'venv'
305305
run: |
306306
python -m pip install virtualenv
307-
python -m virtualenv .virtualenv/
307+
python -m virtualenv --no-venv-redirect .virtualenv/
308308
if ('${{ matrix.os }}' -match 'windows-latest') {
309309
& ".virtualenv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} virtualEnvPath
310310
} else {
@@ -319,10 +319,11 @@ jobs:
319319
if: matrix.test-suite == 'venv' && startsWith(matrix.python, 3.)
320320
run: |
321321
python -m venv .venv
322+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
322323
if ('${{ matrix.os }}' -match 'windows-latest') {
323-
& ".venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
324+
& "./.venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
324325
} else {
325-
& ".venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
326+
& "./.venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
326327
}
327328
328329
- name: Prepare conda for venv tests
@@ -584,7 +585,7 @@ jobs:
584585
shell: pwsh
585586
run: |
586587
python -m pip install virtualenv
587-
python -m virtualenv .virtualenv/
588+
python -m virtualenv --no-venv-redirect .virtualenv/
588589
if ('${{ matrix.os }}' -match 'windows-latest') {
589590
& ".virtualenv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} virtualEnvPath
590591
} else {
@@ -598,10 +599,11 @@ jobs:
598599
shell: pwsh
599600
run: |
600601
python -m venv .venv
602+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
601603
if ('${{ matrix.os }}' -match 'windows-latest') {
602-
& ".venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
604+
& "./.venv/Scripts/python.exe" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
603605
} else {
604-
& ".venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
606+
& "./.venv/bin/python" ./build/ci/addEnvPath.py ${{ env.PYTHON_VIRTUAL_ENVS_LOCATION }} venvPath
605607
}
606608
607609
- name: Prepare conda for venv tests

‎src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class NativePythonFinderImpl extends DisposableBase implements NativePythonFinde
120120
? getGlobalStorage<boolean>(this.context, DONT_SHOW_SPAWN_ERROR_AGAIN, false)
121121
: ({ get: () => false, set: async () => {} } as IPersistentStorage<boolean>);
122122
this.connection = this.start();
123-
void this.configure();
124123
this.firstRefreshResults = this.refreshFirstTime();
125124
}
126125

‎src/test/pythonEnvironments/nativePythonFinder.unit.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ suite('Native Python Finder', () => {
2121
let getConfigurationStub: sinon.SinonStub;
2222
let configMock: typemoq.IMock<WorkspaceConfiguration>;
2323
let getWorkspaceFolderPathsStub: sinon.SinonStub;
24+
const locatorOutput = new MockOutputChannel('locator');
2425

2526
setup(() => {
2627
createLogOutputChannelStub = sinon.stub(windowsApis, 'createLogOutputChannel');
27-
createLogOutputChannelStub.returns(new MockOutputChannel('locator'));
28+
createLogOutputChannelStub.returns(locatorOutput);
2829

2930
getWorkspaceFolderPathsStub = sinon.stub(workspaceApis, 'getWorkspaceFolderPaths');
3031
getWorkspaceFolderPathsStub.returns([]);
@@ -55,7 +56,7 @@ suite('Native Python Finder', () => {
5556
}
5657

5758
// typically all test envs should have at least one environment
58-
assert.isNotEmpty(envs);
59+
assert.isNotEmpty(envs, `Python Locator output:\n${locatorOutput.output || '(none)'}`);
5960
});
6061

6162
test('Resolve should return python environments with version', async () => {

0 commit comments

Comments
 (0)