Skip to content

Installer (Windows): fall back to the python-build-standalone mirror for uv-managed Python - #14686

Merged
danielhanchen merged 9 commits into
mainfrom
dh/win-python-mirror
Oct 23, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
dh/win-python-mirror

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

On Linux and macOS, install.sh falls back to the npmmirror python-build-standalone mirror (UV_PYTHON_INSTALL_MIRROR) when releases.astral.sh is slow or unreachable. On Windows, install.ps1 had no python host in its mirror table and ran uv python install with -NoMirror, so a blocked astral download failed the managed Python install even with the mirror fallback on.

Changes

  • Shared mirror block (install.ps1, copied to studio/setup.ps1 with scripts/sync_shared_ps1_helpers.py):
    • Test-MirrorConfigured -Tool python respects a user UV_PYTHON_INSTALL_MIRROR, UV_ASTRAL_MIRROR_URL (which UV_PYTHON_INSTALL_MIRROR would override), a custom downloads manifest (UV_PYTHON_DOWNLOADS_JSON_URL / python-downloads-json-url), or python-install-mirror in uv config.
    • Test-MirrorConfigured reads only UV_CONFIG_FILE when it is set and no file when UV_NO_CONFIG is true by uv's bool rules, no system file with UV_NO_SYSTEM_CONFIG, changes to UV_WORKING_DIR first and resolves a relative UV_PROJECT / UV_CONFIG_FILE from there, and still reads UV_CONFIG_FILE under UV_NO_CONFIG, as uv does, so a mirror in a discovered uv.toml that uv will ignore no longer stops the fallback. This applies to the index check too.
    • A python host (astral to npmmirror) maps to UV_PYTHON_INSTALL_MIRROR, named "releases.astral.sh (Python builds)".
    • Get-MirrorFailedHost maps python-build-standalone failures to it.
    • The speed race drops duplicate probe URLs, since Python and uv share the astral probe.
  • Invoke-InstallMirrorRetry treats uv python install failures as python, like _mirror_retry_install in install.sh.
  • Resolve-UvManagedPython no longer passes -NoMirror. A transport failure reruns once through the mirror; Pop-MirrorSpare uses the spare up, so later attempts do not retry again. With the fallback off nothing changes.
  • UV_PYTHON_INSTALL_MIRROR is saved and restored with the other mirror variables.

Tests

tests/studio/test_mirror_fallback.ps1: 142 passed here; on main the new Python checks fail (10 failures). scripts/sync_shared_ps1_helpers.py --check matches. tests/sh/test_mirror_fallback.sh (install.sh side, unchanged) 253 passed. Not run on a real Windows host behind a blocked astral.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T08:43:16.258762Z 1528a49 Manual request
🔒 Security Review ✅ Completed 2026-10-22T13:12:14.460155Z 36eef8d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36eef8d976

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1 Outdated
Comment on lines +4570 to +4572
if ($Tool -eq 'python') {
if ($env:UV_PYTHON_INSTALL_MIRROR) { return $true }
$pattern = '^\s*python-install-mirror\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor UV_CONFIG_FILE before accepting a Python mirror

When UV_CONFIG_FILE points to a custom uv.toml without python-install-mirror, but a discovered file such as %APPDATA%\uv\uv.toml contains that setting, this new branch incorrectly concludes that Python already has a mirror configured. uv specifies that an explicit config file is used in place of discovered configuration files (uv configuration files), so uv python install will use neither the ignored configured mirror nor the generated npmmirror fallback, and a blocked Astral download still fails. Restrict the scan to UV_CONFIG_FILE when it is set, and likewise avoid treating disabled configuration as active.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 36eef8d976

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

…th UV_NO_CONFIG

uv reads an explicit config file in place of the discovered ones, so a Python mirror
(or index) in %APPDATA%\uv\uv.toml did not apply and must not stop the fallback.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f139ea53ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1 Outdated
# uv reads UV_CONFIG_FILE in place of every discovered file, and none with UV_NO_CONFIG.
$files = @($env:UV_CONFIG_FILE, "$env:APPDATA\uv\uv.toml", "$env:ProgramData\uv\uv.toml")
$dir = (Get-Location -PSProvider FileSystem).ProviderPath
if ($env:UV_NO_CONFIG -and $env:UV_NO_CONFIG -notmatch '^(0|false|no|off)$') { $files = @(); $dir = $null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use uv's bool parser for UV_NO_CONFIG

When UV_NO_CONFIG is set to n or f, uv treats it as false (as the existing Test-UvEnvFlag helper documents), but this condition treats every value except 0, false, no, and off as true. In that configuration, uv still reads a discovered uv.toml, while the fallback ignores it and may export mirror environment variables that override the user's configured index or Python mirror. Use Test-UvEnvFlag 'UV_NO_CONFIG' here so the scan follows uv's full boolean syntax.

Useful? React with 👍 / 👎.

Comment thread install.ps1 Outdated
Comment on lines +4570 to +4572
if ($Tool -eq 'python') {
if ($env:UV_PYTHON_INSTALL_MIRROR) { return $true }
$pattern = '^\s*python-install-mirror\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Respect the general Astral mirror for Python

When a caller sets UV_ASTRAL_MIRROR_URL, this check still arms the Python fallback because it only recognizes UV_PYTHON_INSTALL_MIRROR. If the probe of the public Astral endpoint is slow or blocked, the fallback exports UV_PYTHON_INSTALL_MIRROR for npmmirror; uv documents that this more-specific variable takes precedence over UV_ASTRAL_MIRROR_URL, so the managed-Python download silently bypasses the operator's corporate Astral mirror. The pinned uv 0.12.1 supports this variable because it was added in 0.11.14; treat it as an already-configured Python source before adding the host. See the uv environment-variable reference.

Useful? React with 👍 / 👎.

…at UV_ASTRAL_MIRROR_URL as a Python mirror

UV_PYTHON_INSTALL_MIRROR wins over UV_ASTRAL_MIRROR_URL in uv, so arming the npmmirror
fallback would bypass the operator's Astral mirror.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c11154924c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1 Outdated
$files = @($env:UV_CONFIG_FILE, "$env:APPDATA\uv\uv.toml", "$env:ProgramData\uv\uv.toml")
$dir = (Get-Location -PSProvider FileSystem).ProviderPath
# uv's bool parser (Test-UvEnvFlag), inlined: setup.ps1 reaches this before it defines that helper.
if (@('1', 't', 'true', 'y', 'yes', 'on') -contains "$env:UV_NO_CONFIG".Trim().ToLowerInvariant()) { $files = @(); $dir = $null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor UV_NO_SYSTEM_CONFIG when scanning mirror settings

When UV_NO_SYSTEM_CONFIG is truthy and %ProgramData%\uv\uv.toml defines python-install-mirror, the new Python scan still treats that ignored file as an active mirror and suppresses the npmmirror fallback, so a blocked public Python download can still fail. uv 0.11.16+ documents that UV_NO_SYSTEM_CONFIG prevents reading system-level configuration; apply uv's boolean parsing to this flag and exclude the ProgramData file in both PowerShell copies.

Useful? React with 👍 / 👎.

Comment thread install.ps1 Outdated
if ("$env:UV_DEFAULT_INDEX$env:UV_INDEX_URL$env:UV_INDEX$env:UV_EXTRA_INDEX_URL") { return $true }
$pattern = '^\s*(\[\[(tool\.uv\.)?index\]\]|(pip\.)?(index|index-url|default-index|extra-index-url|no-index)\s*=)'
}
# uv reads UV_CONFIG_FILE in place of every discovered file, and none with UV_NO_CONFIG.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Start mirror discovery from uv's configured directory

When UV_PROJECT selects another project, or UV_WORKING_DIR/UV_WORKING_DIRECTORY changes uv's working directory, the new Python-mirror scan still walks upward from PowerShell's original Get-Location. uv documents that UV_PROJECT changes the root used to discover pyproject.toml and uv.toml, while UV_WORKING_DIR changes the working directory; consequently, a corporate Python mirror in the selected tree can be missed and overridden by UV_PYTHON_INSTALL_MIRROR, or an unrelated config in the original tree can suppress a needed fallback. Derive the scan root using uv's directory semantics in both PowerShell copies.

Useful? React with 👍 / 👎.

Comment thread install.ps1
return
}
if ($Output -match 'download(-r2)?\.pytorch\.org') { 'torch' }
elseif ($Output -match 'python-build-standalone') { 'python' }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retry Python downloads rejected with HTTP 403

When a firewall or regional gateway blocks the public Python-build URL with 403 Forbidden, the initial probe keeps the default because its slow-host filter ignores 4xx responses, and the subsequent uv error still does not reach this new python-build-standalone classification because the preceding transport-error regex recognizes neither 403 nor Forbidden. The Python mirror spare therefore remains unused even though this is a common blocked-host response; recognize access-denial statuses here while retaining the intentional no-retry behavior for missing artifacts such as 404.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one as is in this PR. The transport-error list is shared with install.sh's _mirror_failed_host and with every other host (PyPI, torch, npm), and neither installer treats a 4xx as a reason to switch mirrors: a 403 is as often an auth or policy answer from the user's own proxy as a regional block. Changing that belongs in its own change to both installers.

…_CONFIG, UV_PROJECT, UV_WORKING_DIR)

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 792c0c58d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1
Comment on lines +4585 to +4587
$workDir = if ($env:UV_WORKING_DIR) { $env:UV_WORKING_DIR } else { $env:UV_WORKING_DIRECTORY }
if ($workDir) { $dir = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($dir, $workDir)) }
if ($env:UV_PROJECT) { $dir = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($dir, $env:UV_PROJECT)) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve UV_PROJECT from the invocation directory

When both UV_WORKING_DIR and a relative UV_PROJECT are set, this resolves the project relative to the working-directory override, but uv resolves the project from the original invocation directory. Fresh evidence beyond the prior comment: a local uv python find probe with configs at <cwd>/proj and <cwd>/work/proj selected <cwd>/proj, while this code scans <cwd>/work/proj; uv help python install also distinguishes changing only the project root from changing the working directory. The mismatch can miss the active corporate Python mirror or treat an ignored mirror as active, so derive both relative paths from the original $dir rather than applying them sequentially.

Useful? React with 👍 / 👎.

Comment thread install.ps1
}
if (-not $env:UNSLOTH_NODE_MIRROR) { $hosts['node'] = @('node', 'npmmirror-node', "$npmMirror/-/binary/node", $null, $null) }
if (-not "$env:UNSLOTH_NPM_REGISTRY$env:NPM_CONFIG_REGISTRY") { $hosts['npm'] = @('npm', 'npmmirror', $npmMirror, $null, $null) }
if (-not (Test-MirrorConfigured -Tool python)) { $hosts['python'] = @('astral', 'npmmirror', $pythonMirror, $null, $null) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe the Python mirror tree before switching

When Astral is slow but usable and npmmirror's npm-package endpoint works while its /-/binary/python-build-standalone tree is unavailable, this entry immediately exports UV_PYTHON_INSTALL_MIRROR and removes the Python spare. The source named npmmirror is actually measured with the TypeScript tarball at line 4703, so none of the Python mirror content is verified; all managed-Python candidates then use the broken mirror and cannot return to the working Astral source. Probe a representative artifact from the Python-build tree, or retain Astral as a fallback after an eager switch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as is. It is the same choice install.sh makes for its npmmirror Python source: the npmmirror host is measured once and every npmmirror tree it serves (node, npm, python-build-standalone) rides on that measurement. Probing a python-build-standalone artifact would need a version-specific filename that tracks uv's pin, which is a change for both installers, not this parity fix.

Comment thread install.ps1 Outdated
Comment on lines +4588 to +4589
if ($uvTrue -contains "$env:UV_NO_CONFIG".Trim().ToLowerInvariant()) { $files = @(); $dir = $null }
elseif ($env:UV_CONFIG_FILE) { $files = @($env:UV_CONFIG_FILE); $dir = $null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prefer UV_CONFIG_FILE over UV_NO_CONFIG

When a caller sets both a truthy UV_NO_CONFIG and an explicit UV_CONFIG_FILE, uv still reads the explicitly named file: uv help python install defines --no-config as avoiding configuration-file discovery, while --config-file explicitly selects a file, and a local uv probe confirmed that the selected file remains active. This branch instead empties $files before reaching the UV_CONFIG_FILE case, so it misses a configured Python mirror and may export the higher-precedence npmmirror variable over it. Check UV_CONFIG_FILE first and apply UV_NO_CONFIG only to discovered files.

Useful? React with 👍 / 👎.

Comment thread install.ps1 Outdated
if ($Tool -eq 'python') {
# UV_ASTRAL_MIRROR_URL also serves Python builds, but UV_PYTHON_INSTALL_MIRROR would win over it.
if ("$env:UV_PYTHON_INSTALL_MIRROR$env:UV_ASTRAL_MIRROR_URL") { return $true }
$pattern = '^\s*python-install-mirror\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize dotted Python-mirror keys in pyproject.toml

A valid pyproject.toml can express this setting as the TOML dotted key tool.uv.python-install-mirror = "https://corp.example/pbs" (uv accepts the equivalent dotted tool.uv.* structure), but this regex only recognizes a bare python-install-mirror line. The surrounding discovery check also looks only for a bracketed [tool.uv] header, so the configured mirror is missed and UV_PYTHON_INSTALL_MIRROR is exported, overriding the user's corporate source. Parse the tool.uv table or recognize dotted and inline-table forms rather than matching only the conventional layout.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not handling this here. The scan matches the conventional [tool.uv] / uv.toml layout, the same way the existing index check in this function and install.sh's _mirror_configured do. A full TOML read (dotted keys, inline tables) would change every one of those checks and belongs in its own change.

Comment thread install.ps1 Outdated
if ($Tool -ne 'pip') {
if ($Tool -eq 'python') {
# UV_ASTRAL_MIRROR_URL also serves Python builds, but UV_PYTHON_INSTALL_MIRROR would win over it.
if ("$env:UV_PYTHON_INSTALL_MIRROR$env:UV_ASTRAL_MIRROR_URL") { return $true }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for older accepted uv versions before honoring UV_ASTRAL_MIRROR_URL

When an existing uv 0.8.16 through 0.11.13 is reused, it ignores UV_ASTRAL_MIRROR_URL because that variable was added in 0.11.14, yet this return suppresses the Python fallback. Fresh evidence beyond the prior comment is the installer’s version gate at lines 6815 and 6884, which accepts any uv at least 0.8.16 instead of always installing the pinned 0.12.1. On a machine carrying that older uv and a globally defined variable, a blocked public Astral download therefore still fails; either raise the accepted uv version or recognize this variable only for a compatible selected executable.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this as is. Before this PR, Windows had no Python fallback at all, so an old uv with UV_ASTRAL_MIRROR_URL set fails the same way it did on main; nothing regresses. Someone who sets that variable is pointing uv at their own mirror, and overriding it with npmmirror on a guess about the uv version would be the worse failure.

…, and read UV_CONFIG_FILE even with UV_NO_CONFIG
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e29528066e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1 Outdated
Comment on lines +4586 to +4588
$start = if ($env:UV_PROJECT) { $env:UV_PROJECT } elseif ($env:UV_WORKING_DIR) { $env:UV_WORKING_DIR } else { $env:UV_WORKING_DIRECTORY }
if ($start) { $dir = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($dir, $start)) }
if ($env:UV_CONFIG_FILE) { $files = @($env:UV_CONFIG_FILE); $dir = $null }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Resolve relative uv paths after changing directory

When UV_WORKING_DIR is combined with a relative UV_PROJECT or UV_CONFIG_FILE, this resolves those paths from the original PowerShell location. uv help python install documents that --directory changes directory before running and relative paths use that directory as their base; fresh evidence contrary to the prior comment is that the bundled uv 0.12.1 loaded <work>/proj/uv.toml and <work>/custom.toml in local probes, while this block checks the corresponding paths under <cwd>. Both this copy and studio/setup.ps1 can therefore miss the active corporate mirror and export UV_PYTHON_INSTALL_MIRROR over it, or suppress the fallback because an ignored file was found; resolve UV_WORKING_DIR first, then resolve the other relative paths against it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, and this reverses the previous round. Checked with uv python install --show-settings from a tree with proj/uv.toml, work/proj/uv.toml, custom.toml and work/custom.toml: UV_WORKING_DIR=work UV_PROJECT=proj picks work/proj, UV_WORKING_DIR=work UV_CONFIG_FILE=custom.toml picks work/custom.toml, and UV_CONFIG_FILE is still read under UV_NO_CONFIG. The scan now follows that order, with tests for each case. The downloads-manifest point is handled in the same commit.

Comment thread install.ps1 Outdated
Comment on lines +4572 to +4573
if ("$env:UV_PYTHON_INSTALL_MIRROR$env:UV_ASTRAL_MIRROR_URL") { return $true }
$pattern = '^\s*python-install-mirror\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve custom Python download manifests

When a caller supplies UV_PYTHON_DOWNLOADS_JSON_URL, or configures python-downloads-json-url, this check still considers Python unconfigured and may export UV_PYTHON_INSTALL_MIRROR when Astral is slow or blocked. The manifest setting overrides uv's hardcoded installation list specifically so operators can provide custom download URLs, and uv currently errors when a mirror variable is combined with a manifest URL that does not have the expected python-build-standalone shape, as demonstrated in uv issue #17005. This makes a working internal or offline Python source fail only after the fallback activates; treat either custom-manifest setting as an already configured Python source.

Useful? React with 👍 / 👎.

…m UV_WORKING_DIR, and leave a custom Python downloads manifest alone

Checked against uv python install --show-settings: uv changes to --directory first and
resolves the relative paths from there. UV_PYTHON_DOWNLOADS_JSON_URL names its own URLs,
and uv rejects it combined with a mirror (astral-sh/uv#17005).

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42340b02a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1
# uv's bool parser (Test-UvEnvFlag), inlined: setup.ps1 reaches this before it defines that helper.
$uvTrue = @('1', 't', 'true', 'y', 'yes', 'on')
$files = @("$env:APPDATA\uv\uv.toml")
if ($uvTrue -notcontains "$env:UV_NO_SYSTEM_CONFIG".Trim().ToLowerInvariant()) { $files += "$env:ProgramData\uv\uv.toml" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Gate UV_NO_SYSTEM_CONFIG handling on uv version

When the installer reuses uv 0.8.16–0.11.15 and UV_NO_SYSTEM_CONFIG is truthy, this excludes %ProgramData%\uv\uv.toml even though those uv versions still read it—the variable was only added in uv 0.11.16. Since install.ps1 accepts uv as old as 0.8.16 at line 6818, a corporate python-install-mirror in the system config can be missed and then overridden by the npmmirror environment fallback when Astral is slow. Fresh evidence beyond the earlier system-config comment is this mismatch between the newly honored flag and the existing old-uv reuse gate; either raise the minimum version or ignore this flag for uv versions that do not support it.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving this one. Someone who sets UV_NO_SYSTEM_CONFIG has asked for the system file to be ignored, and the narrow overlap (that variable set, an old uv reused, a Python mirror only in %ProgramData%, and a slow Astral) does not justify version-gating each flag. The fallback is also never worse than main here, which has no Python fallback on Windows at all.

Comment thread install.ps1
# UV_ASTRAL_MIRROR_URL also serves Python builds, but UV_PYTHON_INSTALL_MIRROR would win over it; a
# custom downloads manifest names its own URLs, which uv rejects combined with a mirror.
if ("$env:UV_PYTHON_INSTALL_MIRROR$env:UV_ASTRAL_MIRROR_URL$env:UV_PYTHON_DOWNLOADS_JSON_URL") { return $true }
$pattern = '^\s*(python-install-mirror|python-downloads-json-url)\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Discover Python mirror settings from the workspace root

When setup runs inside a uv workspace member that has any local [tool.uv] configuration while the workspace root defines the corporate python-install-mirror, this scan stops at the member file and never reads the active root setting. uv instead begins configuration discovery at the workspace root and ignores member configuration, as documented in uv configuration files. The scanner therefore reports Python as unconfigured and, when Astral is slow, exports UV_PYTHON_INSTALL_MIRROR for npmmirror; because environment settings outrank files, that overrides the working corporate mirror. Resolve the workspace root before selecting the project configuration file in both PowerShell copies.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not handling workspace-root resolution in this scan. The installer runs from wherever the user launches it, not from inside a uv workspace member, and the existing index check in this function and install.sh's _mirror_configured stop at the first [tool.uv] file in the same way. Doing full workspace discovery would change all of those checks and belongs in its own change.

@danielhanchen danielhanchen self-assigned this Oct 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1528a49d76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1
}
if (-not $env:UNSLOTH_NODE_MIRROR) { $hosts['node'] = @('node', 'npmmirror-node', "$npmMirror/-/binary/node", $null, $null) }
if (-not "$env:UNSLOTH_NPM_REGISTRY$env:NPM_CONFIG_REGISTRY") { $hosts['npm'] = @('npm', 'npmmirror', $npmMirror, $null, $null) }
if (-not (Test-MirrorConfigured -Tool python)) { $hosts['python'] = @('astral', 'npmmirror', $pythonMirror, $null, $null) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe the host uv actually uses for Python builds

When GitHub is slow or blocked but releases.astral.sh is healthy, this maps the Python check to the astral artifact at line 4704 and therefore leaves managed-Python downloads on the failing source. The bundled uv 0.13.5 says in uv help python install that --mirror replaces https://github.com/astral-sh/python-build-standalone/releases/download, so the uv-release probe does not measure the default Python-build host at all; a slow GitHub transfer can consequently sit through uv's long timeout/retries instead of triggering the eager npmmirror fallback. Give Python its own representative GitHub probe in both PowerShell copies rather than sharing the uv-binary probe.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the shared astral probe, as install.sh does: its python host is measured against the same uv-release artifact. A slow download that the eager probe misses is still covered by the failure path, since uv's error names python-build-standalone and that reruns the install once through the npmmirror spare. Giving Python its own probe would be a change to both installers.

Comment thread install.ps1
if ($Tool -eq 'python') {
# UV_PYTHON_INSTALL_MIRROR would override UV_ASTRAL_MIRROR_URL; uv rejects a mirror beside a custom manifest.
if ("$env:UV_PYTHON_INSTALL_MIRROR$env:UV_ASTRAL_MIRROR_URL$env:UV_PYTHON_DOWNLOADS_JSON_URL") { return $true }
$pattern = '^\s*(python-install-mirror|python-downloads-json-url)\s*='

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict Python source keys to the active TOML table

When a pyproject.toml contains any [tool.uv] section plus an unrelated table that defines python-install-mirror or python-downloads-json-url, this file-wide regex treats that unrelated key as uv configuration and suppresses the Python spare. A probe with the bundled uv 0.13.5 using [tool.uv] followed by [tool.other] and python-install-mirror = "https://corp.invalid/pbs" reports python_install_mirror: None under uv python install --show-settings, while this function returns true; if the real Python-build host is unavailable, no npmmirror retry is armed. Scope these keys to [tool.uv] when scanning pyproject.toml while continuing to read them at the root of uv.toml.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not scoping the scan to the [tool.uv] table here. The existing index check in this function and install.sh's _mirror_configured read pyproject.toml the same line-based way, and a python-install-mirror key under some other tool's table is not a layout we see in practice. A real TOML read would change all of those checks and belongs in its own change.

@danielhanchen
danielhanchen merged commit 5c1b054 into main Oct 23, 2026
10 of 51 checks passed
@danielhanchen
danielhanchen deleted the dh/win-python-mirror branch October 23, 2026 09:37
danielhanchen added a commit that referenced this pull request Oct 23, 2026
`Repo tests (CPU, studio-install)` fails on `main` (c5482a5). Four
tests fail in two groups, and both reproduce on a clean `main` checkout.

##
`test_uv_boolish_parity.py::test_every_resolver_variable_in_shipped_powershell_goes_through_a_reader[install.ps1,
setup.ps1]`

#14686 added `Test-MirrorConfigured`'s uv config discovery. It decides
`UV_NO_SYSTEM_CONFIG` and `UV_NO_CONFIG` with an inlined copy of uv's
boolish set, because `setup.ps1` reaches that code before it defines
`Test-UvEnvFlag`. The guard exists so every `UV_*` / `PIP_*` switch goes
through the one reader, so the code is what needed to change:

- Both scripts now call `Test-UvEnvFlag 'UV_NO_SYSTEM_CONFIG'` and
`Test-UvEnvFlag 'UV_NO_CONFIG'`.
- `setup.ps1` defines `Test-UvEnvFlag` / `Test-PipEnvFlag` ahead of
`Test-MirrorConfigured`. The block moved unchanged, with one added
comment line. `install.ps1` already defines it earlier in the same
function.
- New test
`test_setup_defines_the_uv_reader_before_its_first_mirror_probe` pins
that order. This hazard is what led to the inline copy in the first
place.

Behaviour is unchanged. Under `Set-StrictMode -Version Latest`,
`Test-MirrorConfigured -Tool uv` returns the same answer on base and
head, in both scripts, with a user `uv.toml` carrying an index and
`UV_NO_CONFIG` set to each of unset, `off`, `0`, `no`, `YES`, ` 1 `,
`true`.

##
`test_rocm_native_linux_lib_dirs.py::TestLlamaCppRuntimeNativeOrdering`

#14933 now holds the native-Linux ROCm dirs in `_system_rocm`, so it can
skip them when they hide the GPU. The source check still looked for the
old one-line
`lib_dirs.extend(_native_linux_system_rocm_lib_dirs(binary_dir))`. The
test was out of date. It now finds the helper call, follows the local it
is assigned to, and still asserts two orderings:
- helper call, then `lib_dirs.extend(...)`, then
`lib_dirs.append(binary_dir)`
- the WSL DXG decision comes before the native dirs

## Verification

- `tests/studio/install/test_rocm_native_linux_lib_dirs.py` and
`test_uv_boolish_parity.py`: 4 failed on `main`, 581 passed on this
branch.
- `tests/studio/install/test_denied_llama_cpp_preflight.py` (byte parity
of the shared install/setup helpers): passes.
- `pwsh tests/studio/test_mirror_fallback.ps1`: 142 PASS, 0 FAIL.
- Sabotage checks:
- Moving `lib_dirs.append(binary_dir)` above the native block fails the
ROCm ordering test.
- Restoring `main`'s `setup.ps1` fails both the reader test and the new
ordering test.
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.

1 participant