Skip to content

fix: support uv venv backend under MSYS2/MinGW (#1088)#1117

Open
henryiii wants to merge 1 commit into
wntrblm:mainfrom
henryiii:fix/uv-mingw-venv
Open

fix: support uv venv backend under MSYS2/MinGW (#1088)#1117
henryiii wants to merge 1 commit into
wntrblm:mainfrom
henryiii:fix/uv-mingw-venv

Conversation

@henryiii

@henryiii henryiii commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Okay, I think this is a valid fix for #1088. @Tiphereth-A, would be good if you could take a look to be sure. :)

🤖 AI text below 🤖

Fixes #1088.

Problem

Under MSYS2/MinGW, uv cannot inspect the native interpreter — it reports an unknown operating system (e.g. mingw_x86_64_ucrt_gnu). Because script mode runs uv venv -p <sys.executable> ..., venv creation failed even though a bare uv venv works fine.

Fix

  • In VirtualEnv.create, skip -p for the uv backend on MinGW when no interpreter is explicitly requested, letting uv pick the default (which works). An explicit interpreter is still passed through, and non-MinGW behavior is unchanged.
  • uv builds a Windows-style venv (Scripts/python.exe) even under MinGW, whereas the native interpreter and virtualenv/venv use a POSIX layout (bin/python). A new _windows_layout property centralizes this so bin_paths and the environment-reuse check select the right directory per backend.

Based on the patch from @Tiphereth-A in msys2/MINGW-packages#28759.

Tests

Added tests for the MinGW uv layout, the MinGW no--p command, and the explicit-interpreter uv path. nox/virtualenv.py and tests/test_virtualenv.py pass lint and the full test_virtualenv.py suite.

@henryiii henryiii marked this pull request as draft June 17, 2026 19:54
@henryiii henryiii marked this pull request as ready for review June 18, 2026 14:53
henryiii added a commit to henryiii/nox that referenced this pull request Jun 26, 2026
…MinGW

Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii

Copy link
Copy Markdown
Collaborator Author

🤖 AI text below 🤖

Pushed one commit adding MinGW-host test corrections (test_bin_paths, test_bin_windows, test_create): on a real MSYS2/MinGW host sys.platform == "win32" but the native venv uses a POSIX bin/ layout with .exe executables, so the Windows-layout assertions must exclude MinGW. These are no-ops off MinGW (the existing matrix stays green) and only matter under the experimental MSYS2 job in #1122.

For context: #1122 stands up that MSYS2 job and acts as a real-host demonstration of this PR. Without this PR, #1122 shows the #1088 symptom directly — uv venv -p .../bin/python.EXE → Failed to inspect Python interpreter — across test_uv_creation, test_create_reuse_uv_environment, test_stale_environment[uv-virtualenv-False], and the test_noxfile_script_mode* trio. With this PR merged, that job goes fully green (726 passed). The two PRs are independent diffs and can land in either order.

@Tiphereth-A Tiphereth-A 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.

LGTM

@henryiii henryiii force-pushed the fix/uv-mingw-venv branch from e31b38e to 82cef5a Compare June 29, 2026 15:30
@henryiii

Copy link
Copy Markdown
Collaborator Author

🤖 AI text below 🤖

Correction to my earlier comment: the MinGW-host test corrections (test_bin_paths, test_bin_windows, test_create) have been moved to #1122 instead — they cover the native bin/ layout that predates this PR (#901), so they belong with the CI job that exercises them. This PR now contains only the uv-backend fix and its own tests.

The relationship is unchanged: #1122 stands up the MSYS2 job and demonstrates this PR on a real host. With its own corrections in place, #1122's only remaining red is the uv path — uv venv -p .../bin/python.EXE → Failed to inspect Python interpreter (the #1088 symptom) — which this PR fixes. The two PRs share no commits and can land in either order.

henryiii added a commit to henryiii/nox that referenced this pull request Jun 29, 2026
uv can't inspect the MinGW interpreter, so creating a uv venv from it fails
(wntrblm#1088). Mark the affected uv/script-mode tests xfail on MinGW (non-strict, so
they xpass once wntrblm#1117 lands) to keep the experimental MSYS2 job green.

Assisted-by: ClaudeCode:claude-opus-4.8
henryiii added a commit that referenced this pull request Jun 29, 2026
* ci: skip uv install on MinGW in tests session

uv ships no MinGW wheel and fails to build from source there; the uv tests
already skip via @has_uv when the command is absent.

Assisted-by: ClaudeCode:claude-opus-4.8

* ci: add experimental MSYS2/MinGW test run

Runs the suite under a real MSYS2/MINGW64 Python to exercise the
nox.virtualenv._IS_MINGW code paths, previously only covered by mocked unit
tests. Non-blocking (continue-on-error) until proven stable; feeds coverage
into the cover job. uv comes from setup-uv (no uv CLI exists in MSYS2 repos),
and the session is forced onto the virtualenv backend so the interpreter
under test stays MinGW.

Assisted-by: ClaudeCode:claude-opus-4.8

* test: account for MinGW POSIX venv layout in bin-path tests

On a real MSYS2/MinGW host sys.platform is win32 but the native venv uses a
POSIX bin/ layout (with .exe executables), so the Windows-layout assertions
must exclude MinGW. Exercised by the experimental MSYS2 CI job.

Assisted-by: ClaudeCode:claude-opus-4.8

* test: xfail uv-backend tests under MinGW until #1117

uv can't inspect the MinGW interpreter, so creating a uv venv from it fails
(#1088). Mark the affected uv/script-mode tests xfail on MinGW (non-strict, so
they xpass once #1117 lands) to keep the experimental MSYS2 job green.

Assisted-by: ClaudeCode:claude-opus-4.8

* ci: touch up comments on uv and msys

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>

---------

Signed-off-by: Henry Schreiner <henryfs@princeton.edu>
uv can't inspect the MSYS2/MinGW interpreter (it reports an unknown
operating system like `mingw_x86_64_ucrt_gnu`), so passing
`-p sys.executable` made `uv venv` fail in script mode. Skip `-p` on
MinGW when no interpreter is requested and let uv pick the default,
which works.

uv also builds a Windows-style venv (`Scripts`/`python.exe`) even under
MinGW, unlike the native interpreter and virtualenv/venv which use a
POSIX layout. A new `_windows_layout` property captures this so
`bin_paths` and the reuse check pick the right directory per backend.

Assisted-by: ClaudeCode:claude-opus-4.8
@henryiii henryiii force-pushed the fix/uv-mingw-venv branch from 82cef5a to a165a5e Compare June 29, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Creating virtual environment failed when using uv in MSYS2

2 participants