Skip to content

Commit 01c0d05

Browse files
Add Pyodide installation mirrors (#22271)
## Summary We add `UV_PYODIDE_INSTALL_MIRROR`, the `pyodide-install-mirror` setting, and `--pyodide-mirror` for Python install and upgrade, following the existing PyPy and GraalPy mirrors. The mirror replaces `https://github.com/pyodide/pyodide/releases/download`, retaining the release path and filename. Local `file://` mirrors are also supported. Pyodide is recorded as CPython on Emscripten. We use the normalized implementation when selecting a mirror so Pyodide downloads use their own setting and are unaffected by a configured CPython mirror. The mirror-creation helper also supports Pyodide releases. Follow-up to #22269.
1 parent 7248453 commit 01c0d05

13 files changed

Lines changed: 167 additions & 3 deletions

File tree

‎crates/uv-cli/src/lib.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6169,6 +6169,15 @@ pub struct PythonInstallArgs {
61696169
#[arg(long, value_hint = ValueHint::Url)]
61706170
graalpy_mirror: Option<String>,
61716171

6172+
/// Set the URL to use as the source for downloading Pyodide installations.
6173+
///
6174+
/// The provided URL will replace `https://github.com/pyodide/pyodide/releases/download` in, e.g.,
6175+
/// `https://github.com/pyodide/pyodide/releases/download/0.29.5/xbuildenv-0.29.5.tar.gz`.
6176+
///
6177+
/// Distributions can be read from a local directory by using the `file://` URL scheme.
6178+
#[arg(long, value_hint = ValueHint::Url)]
6179+
pyodide_mirror: Option<String>,
6180+
61726181
/// URL pointing to JSON of custom Python installations.
61736182
#[arg(long, value_hint = ValueHint::Other)]
61746183
python_downloads_json_url: Option<String>,
@@ -6228,6 +6237,7 @@ impl PythonInstallArgs {
62286237
python_install_mirror: self.mirror.clone(),
62296238
pypy_install_mirror: self.pypy_mirror.clone(),
62306239
graalpy_install_mirror: self.graalpy_mirror.clone(),
6240+
pyodide_install_mirror: self.pyodide_mirror.clone(),
62316241
python_downloads_json_url: self.python_downloads_json_url.clone(),
62326242
}
62336243
}
@@ -6279,6 +6289,15 @@ pub struct PythonUpgradeArgs {
62796289
#[arg(long, value_hint = ValueHint::Url)]
62806290
graalpy_mirror: Option<String>,
62816291

6292+
/// Set the URL to use as the source for downloading Pyodide installations.
6293+
///
6294+
/// The provided URL will replace `https://github.com/pyodide/pyodide/releases/download` in, e.g.,
6295+
/// `https://github.com/pyodide/pyodide/releases/download/0.29.5/xbuildenv-0.29.5.tar.gz`.
6296+
///
6297+
/// Distributions can be read from a local directory by using the `file://` URL scheme.
6298+
#[arg(long, value_hint = ValueHint::Url)]
6299+
pyodide_mirror: Option<String>,
6300+
62826301
/// Reinstall the latest Python patch, if it's already installed.
62836302
///
62846303
/// By default, uv will exit successfully if the latest patch is already
@@ -6301,6 +6320,7 @@ impl PythonUpgradeArgs {
63016320
python_install_mirror: self.mirror.clone(),
63026321
pypy_install_mirror: self.pypy_mirror.clone(),
63036322
graalpy_install_mirror: self.graalpy_mirror.clone(),
6323+
pyodide_install_mirror: self.pyodide_mirror.clone(),
63046324
python_downloads_json_url: self.python_downloads_json_url.clone(),
63056325
}
63066326
}

‎crates/uv-cli/src/settings.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,7 @@ impl PythonInstallSettings {
15501550
mirror: _,
15511551
pypy_mirror: _,
15521552
graalpy_mirror: _,
1553+
pyodide_mirror: _,
15531554
python_downloads_json_url: _,
15541555
default,
15551556
compile_bytecode,
@@ -1636,6 +1637,7 @@ impl PythonUpgradeSettings {
16361637
mirror: _,
16371638
pypy_mirror: _,
16381639
graalpy_mirror: _,
1640+
pyodide_mirror: _,
16391641
reinstall,
16401642
python_downloads_json_url: _,
16411643
compile_bytecode,
@@ -1729,6 +1731,7 @@ impl PythonFindSettings {
17291731
python_install_mirror: _,
17301732
pypy_install_mirror: _,
17311733
graalpy_install_mirror: _,
1734+
pyodide_install_mirror: _,
17321735
python_downloads_json_url,
17331736
} = install_mirrors;
17341737

‎crates/uv-python/src/downloads.rs‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ impl ManagedPythonDownload {
15611561
astral_mirror_url: Option<&str>,
15621562
) -> Result<Vec<DisplaySafeUrl>, Error> {
15631563
let astral_mirror_url = custom_astral_mirror_url(astral_mirror_url);
1564-
match self.key.implementation {
1564+
match self.key.implementation().as_ref() {
15651565
LenientImplementationName::Known(ImplementationName::CPython) => {
15661566
if let Some(mirror) = mirrors.cpython {
15671567
// User-configured mirror: use it exclusively, no automatic fallback.
@@ -1623,6 +1623,23 @@ impl ManagedPythonDownload {
16231623
}
16241624
}
16251625

1626+
LenientImplementationName::Known(ImplementationName::Pyodide) => {
1627+
if let Some(mirror) = mirrors.pyodide {
1628+
let Some(suffix) = self
1629+
.url
1630+
.strip_prefix("https://github.com/pyodide/pyodide/releases/download/")
1631+
else {
1632+
return Err(Error::Mirror(
1633+
EnvVars::UV_PYODIDE_INSTALL_MIRROR,
1634+
self.url.to_string(),
1635+
));
1636+
};
1637+
return Ok(vec![DisplaySafeUrl::parse(
1638+
format!("{}/{}", mirror.trim_end_matches('/'), suffix).as_str(),
1639+
)?]);
1640+
}
1641+
}
1642+
16261643
_ => {}
16271644
}
16281645

‎crates/uv-python/src/mirrors.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ pub struct PythonDownloadMirrors<'a> {
77
pub pypy: Option<&'a str>,
88
/// Mirror for GraalPy distributions.
99
pub graalpy: Option<&'a str>,
10+
/// Mirror for Pyodide distributions.
11+
pub pyodide: Option<&'a str>,
1012
}

‎crates/uv-settings/src/lib.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ fn warn_uv_toml_masked_fields(options: &Options) {
449449
python_install_mirror,
450450
pypy_install_mirror,
451451
graalpy_install_mirror,
452+
pyodide_install_mirror,
452453
python_downloads_json_url,
453454
},
454455
publish:
@@ -636,6 +637,9 @@ fn warn_uv_toml_masked_fields(options: &Options) {
636637
if graalpy_install_mirror.is_some() {
637638
masked_fields.push("graalpy-install-mirror");
638639
}
640+
if pyodide_install_mirror.is_some() {
641+
masked_fields.push("pyodide-install-mirror");
642+
}
639643
if python_downloads_json_url.is_some() {
640644
masked_fields.push("python-downloads-json-url");
641645
}
@@ -872,6 +876,9 @@ impl EnvironmentOptions {
872876
graalpy_install_mirror: parse_string_environment_variable(
873877
EnvVars::UV_GRAALPY_INSTALL_MIRROR,
874878
)?,
879+
pyodide_install_mirror: parse_string_environment_variable(
880+
EnvVars::UV_PYODIDE_INSTALL_MIRROR,
881+
)?,
875882
python_downloads_json_url: parse_string_environment_variable(
876883
EnvVars::UV_PYTHON_DOWNLOADS_JSON_URL,
877884
)?,

‎crates/uv-settings/src/settings.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,22 @@ pub struct PythonInstallMirrors {
13741374
"#
13751375
)]
13761376
pub graalpy_install_mirror: Option<String>,
1377+
/// Mirror URL to use for downloading managed Pyodide installations.
1378+
///
1379+
/// By default, managed Pyodide installations are downloaded from [GitHub](https://github.com/pyodide/pyodide/releases).
1380+
/// This variable can be set to a mirror URL to use a different source for Pyodide installations.
1381+
/// The provided URL will replace `https://github.com/pyodide/pyodide/releases/download` in, e.g., `https://github.com/pyodide/pyodide/releases/download/0.29.5/xbuildenv-0.29.5.tar.gz`.
1382+
///
1383+
/// Distributions can be read from a local directory by using the `file://` URL scheme.
1384+
#[option(
1385+
default = "None",
1386+
value_type = "str",
1387+
uv_toml_only = true,
1388+
example = r#"
1389+
pyodide-install-mirror = "https://github.com/pyodide/pyodide/releases/download"
1390+
"#
1391+
)]
1392+
pub pyodide_install_mirror: Option<String>,
13771393

13781394
/// URL pointing to JSON of custom Python installations.
13791395
#[option(
@@ -1394,6 +1410,7 @@ impl PythonInstallMirrors {
13941410
cpython: self.python_install_mirror.as_deref(),
13951411
pypy: self.pypy_install_mirror.as_deref(),
13961412
graalpy: self.graalpy_install_mirror.as_deref(),
1413+
pyodide: self.pyodide_install_mirror.as_deref(),
13971414
}
13981415
}
13991416

@@ -1403,6 +1420,7 @@ impl PythonInstallMirrors {
14031420
python_install_mirror: self.python_install_mirror.or(other.python_install_mirror),
14041421
pypy_install_mirror: self.pypy_install_mirror.or(other.pypy_install_mirror),
14051422
graalpy_install_mirror: self.graalpy_install_mirror.or(other.graalpy_install_mirror),
1423+
pyodide_install_mirror: self.pyodide_install_mirror.or(other.pyodide_install_mirror),
14061424
python_downloads_json_url: self
14071425
.python_downloads_json_url
14081426
.or(other.python_downloads_json_url),
@@ -2643,6 +2661,7 @@ struct OptionsWire {
26432661
python_install_mirror: Option<String>,
26442662
pypy_install_mirror: Option<String>,
26452663
graalpy_install_mirror: Option<String>,
2664+
pyodide_install_mirror: Option<String>,
26462665
python_downloads_json_url: Option<String>,
26472666

26482667
// #[serde(flatten)]
@@ -2705,6 +2724,7 @@ impl TryFrom<OptionsWire> for Options {
27052724
python_install_mirror,
27062725
pypy_install_mirror,
27072726
graalpy_install_mirror,
2727+
pyodide_install_mirror,
27082728
python_downloads_json_url,
27092729
concurrent_downloads,
27102730
concurrent_builds,
@@ -2841,6 +2861,7 @@ impl TryFrom<OptionsWire> for Options {
28412861
python_install_mirror,
28422862
pypy_install_mirror,
28432863
graalpy_install_mirror,
2864+
pyodide_install_mirror,
28442865
python_downloads_json_url,
28452866
},
28462867
conflicts,

‎crates/uv-static/src/env_vars.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,15 @@ impl EnvVars {
541541
#[attr_added_in("next release")]
542542
pub const UV_GRAALPY_INSTALL_MIRROR: &'static str = "UV_GRAALPY_INSTALL_MIRROR";
543543

544+
/// Managed Pyodide installations are downloaded from [GitHub](https://github.com/pyodide/pyodide/releases).
545+
///
546+
/// This variable can be set to a mirror URL to use a different source for Pyodide installations.
547+
/// The provided URL will replace `https://github.com/pyodide/pyodide/releases/download` in, e.g.,
548+
/// `https://github.com/pyodide/pyodide/releases/download/0.29.5/xbuildenv-0.29.5.tar.gz`.
549+
/// Distributions can be read from a local directory by using the `file://` URL scheme.
550+
#[attr_added_in("next release")]
551+
pub const UV_PYODIDE_INSTALL_MIRROR: &'static str = "UV_PYODIDE_INSTALL_MIRROR";
552+
544553
/// Replaces the `https://releases.astral.sh` base URL for all Astral-mirrored
545554
/// metadata and artifact downloads.
546555
///

‎crates/uv/tests/it/help.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,15 @@ fn help_subsubcommand() {
619619
620620
Distributions can be read from a local directory by using the `file://` URL scheme.
621621
622+
--pyodide-mirror <PYODIDE_MIRROR>
623+
Set the URL to use as the source for downloading Pyodide installations.
624+
625+
The provided URL will replace `https://github.com/pyodide/pyodide/releases/download` in,
626+
e.g.,
627+
`https://github.com/pyodide/pyodide/releases/download/0.29.5/xbuildenv-0.29.5.tar.gz`.
628+
629+
Distributions can be read from a local directory by using the `file://` URL scheme.
630+
622631
--python-downloads-json-url <PYTHON_DOWNLOADS_JSON_URL>
623632
URL pointing to JSON of custom Python installations
624633
@@ -911,6 +920,8 @@ fn help_flag_subsubcommand() {
911920
Set the URL to use as the source for downloading PyPy installations
912921
--graalpy-mirror <GRAALPY_MIRROR>
913922
Set the URL to use as the source for downloading GraalPy installations
923+
--pyodide-mirror <PYODIDE_MIRROR>
924+
Set the URL to use as the source for downloading Pyodide installations
914925
--python-downloads-json-url <PYTHON_DOWNLOADS_JSON_URL>
915926
URL pointing to JSON of custom Python installations
916927
-r, --reinstall

‎crates/uv/tests/pip_install/pip_install.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ fn invalid_pyproject_toml_option_unknown_field() -> Result<()> {
705705
|
706706
2 | unknown = "field"
707707
| ^^^^^^^
708-
unknown field `unknown`, expected one of `required-version`, `system-certs`, `native-tls`, `offline`, `no-cache`, `cache-dir`, `preview`, `preview-features`, `python-preference`, `python-downloads`, `concurrent-downloads`, `concurrent-builds`, `concurrent-installs`, `index`, `index-url`, `extra-index-url`, `no-index`, `find-links`, `index-strategy`, `keyring-provider`, `http-proxy`, `https-proxy`, `no-proxy`, `allow-insecure-host`, `resolution`, `prerelease`, `prerelease-package`, `fork-strategy`, `dependency-metadata`, `config-settings`, `config-settings-package`, `no-build-isolation`, `no-build-isolation-package`, `extra-build-dependencies`, `extra-build-variables`, `exclude-newer`, `exclude-newer-package`, `link-mode`, `compile-bytecode`, `no-sources`, `no-sources-package`, `upgrade`, `upgrade-package`, `reinstall`, `reinstall-package`, `no-build`, `no-build-package`, `no-binary`, `no-binary-package`, `torch-backend`, `python-install-mirror`, `pypy-install-mirror`, `graalpy-install-mirror`, `python-downloads-json-url`, `publish-url`, `trusted-publishing`, `check-url`, `add-bounds`, `audit`, `pip`, `cache-keys`, `override-dependencies`, `exclude-dependencies`, `constraint-dependencies`, `build-constraint-dependencies`, `environments`, `required-environments`, `minimum-libc-version`, `conflicts`, `workspace`, `sources`, `managed`, `package`, `default-groups`, `dependency-groups`, `dev-dependencies`, `build-backend`
708+
unknown field `unknown`, expected one of `required-version`, `system-certs`, `native-tls`, `offline`, `no-cache`, `cache-dir`, `preview`, `preview-features`, `python-preference`, `python-downloads`, `concurrent-downloads`, `concurrent-builds`, `concurrent-installs`, `index`, `index-url`, `extra-index-url`, `no-index`, `find-links`, `index-strategy`, `keyring-provider`, `http-proxy`, `https-proxy`, `no-proxy`, `allow-insecure-host`, `resolution`, `prerelease`, `prerelease-package`, `fork-strategy`, `dependency-metadata`, `config-settings`, `config-settings-package`, `no-build-isolation`, `no-build-isolation-package`, `extra-build-dependencies`, `extra-build-variables`, `exclude-newer`, `exclude-newer-package`, `link-mode`, `compile-bytecode`, `no-sources`, `no-sources-package`, `upgrade`, `upgrade-package`, `reinstall`, `reinstall-package`, `no-build`, `no-build-package`, `no-binary`, `no-binary-package`, `torch-backend`, `python-install-mirror`, `pypy-install-mirror`, `graalpy-install-mirror`, `pyodide-install-mirror`, `python-downloads-json-url`, `publish-url`, `trusted-publishing`, `check-url`, `add-bounds`, `audit`, `pip`, `cache-keys`, `override-dependencies`, `exclude-dependencies`, `constraint-dependencies`, `build-constraint-dependencies`, `environments`, `required-environments`, `minimum-libc-version`, `conflicts`, `workspace`, `sources`, `managed`, `package`, `default-groups`, `dependency-groups`, `dev-dependencies`, `build-backend`
709709

710710
Resolved in [TIME]
711711
Checked in [TIME]

‎crates/uv/tests/python/python_list.rs‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,10 @@ fn python_list_with_mirrors() -> Result<()> {
795795
r"(https://graalpy-mirror\.example\.com/).*".to_string(),
796796
"$1[FILE-PATH]".to_string(),
797797
))
798+
.with_filter((
799+
r"(https://pyodide-mirror\.example\.com/).*".to_string(),
800+
"$1[FILE-PATH]".to_string(),
801+
))
798802
.with_filter((
799803
r"(https://github\.com/astral-sh/python-build-standalone/releases/download/).*"
800804
.to_string(),
@@ -812,6 +816,10 @@ fn python_list_with_mirrors() -> Result<()> {
812816
.with_filter((
813817
r"(https://github\.com/oracle/graalpython/releases/download/).*".to_string(),
814818
"$1[FILE-PATH]".to_string(),
819+
))
820+
.with_filter((
821+
r"(https://github\.com/pyodide/pyodide/releases/download/).*".to_string(),
822+
"$1[FILE-PATH]".to_string(),
815823
));
816824

817825
// Test with UV_PYTHON_INSTALL_MIRROR environment variable - verify mirror URL is used
@@ -847,13 +855,25 @@ fn python_list_with_mirrors() -> Result<()> {
847855
graalpy-3.10.0-[PLATFORM] https://graalpy-mirror.example.com/[FILE-PATH]
848856
");
849857

858+
// Test with UV_PYODIDE_INSTALL_MIRROR environment variable.
859+
uv_snapshot!(context.filters(), context.python_list()
860+
.arg("pyodide@3.13")
861+
.arg("--show-urls")
862+
.env(EnvVars::UV_PYODIDE_INSTALL_MIRROR, "https://pyodide-mirror.example.com")
863+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
864+
exit_code: 0 (success)
865+
----- stdout -----
866+
pyodide-3.13.2-emscripten-wasm32-musl https://pyodide-mirror.example.com/[FILE-PATH]
867+
");
868+
850869
// Test with all mirror environment variables set.
851870
uv_snapshot!(context.filters(), context.python_list()
852871
.arg("3.10")
853872
.arg("--show-urls")
854873
.env(EnvVars::UV_PYTHON_INSTALL_MIRROR, "https://python-mirror.example.com")
855874
.env(EnvVars::UV_PYPY_INSTALL_MIRROR, "https://pypy-mirror.example.com")
856875
.env(EnvVars::UV_GRAALPY_INSTALL_MIRROR, "https://graalpy-mirror.example.com")
876+
.env(EnvVars::UV_PYODIDE_INSTALL_MIRROR, "https://pyodide-mirror.example.com")
857877
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
858878
exit_code: 0 (success)
859879
----- stdout -----
@@ -862,6 +882,18 @@ fn python_list_with_mirrors() -> Result<()> {
862882
graalpy-3.10.0-[PLATFORM] https://graalpy-mirror.example.com/[FILE-PATH]
863883
");
864884

885+
// Pyodide uses its own mirror when the CPython mirror is also set.
886+
uv_snapshot!(context.filters(), context.python_list()
887+
.arg("pyodide@3.13")
888+
.arg("--show-urls")
889+
.env(EnvVars::UV_PYTHON_INSTALL_MIRROR, "https://python-mirror.example.com")
890+
.env(EnvVars::UV_PYODIDE_INSTALL_MIRROR, "https://pyodide-mirror.example.com")
891+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
892+
exit_code: 0 (success)
893+
----- stdout -----
894+
pyodide-3.13.2-emscripten-wasm32-musl https://pyodide-mirror.example.com/[FILE-PATH]
895+
");
896+
865897
// Test without mirrors - verify the default Astral mirror URL is used for CPython
866898
uv_snapshot!(context.filters(), context.python_list()
867899
.arg("3.10")
@@ -874,10 +906,22 @@ fn python_list_with_mirrors() -> Result<()> {
874906
graalpy-3.10.0-[PLATFORM] https://github.com/oracle/graalpython/releases/download/[FILE-PATH]
875907
");
876908

909+
// The CPython mirror does not change the default Pyodide URL.
910+
uv_snapshot!(context.filters(), context.python_list()
911+
.arg("pyodide@3.13")
912+
.arg("--show-urls")
913+
.env(EnvVars::UV_PYTHON_INSTALL_MIRROR, "https://python-mirror.example.com")
914+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
915+
exit_code: 0 (success)
916+
----- stdout -----
917+
pyodide-3.13.2-emscripten-wasm32-musl https://github.com/pyodide/pyodide/releases/download/[FILE-PATH]
918+
");
919+
877920
context.temp_dir.child("uv.toml").write_str(indoc! {r#"
878921
python-install-mirror = "https://python-mirror.example.com"
879922
pypy-install-mirror = "https://pypy-mirror.example.com"
880923
graalpy-install-mirror = "https://graalpy-mirror.example.com"
924+
pyodide-install-mirror = "https://pyodide-mirror.example.com"
881925
"#})?;
882926

883927
uv_snapshot!(context.filters(), context.python_list()
@@ -891,6 +935,15 @@ fn python_list_with_mirrors() -> Result<()> {
891935
graalpy-3.10.0-[PLATFORM] https://graalpy-mirror.example.com/[FILE-PATH]
892936
");
893937

938+
uv_snapshot!(context.filters(), context.python_list()
939+
.arg("pyodide@3.13")
940+
.arg("--show-urls")
941+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
942+
exit_code: 0 (success)
943+
----- stdout -----
944+
pyodide-3.13.2-emscripten-wasm32-musl https://pyodide-mirror.example.com/[FILE-PATH]
945+
");
946+
894947
// Each environment variable overrides only its corresponding configured mirror.
895948
uv_snapshot!(context.filters(), context.python_list()
896949
.arg("3.10")
@@ -904,5 +957,15 @@ fn python_list_with_mirrors() -> Result<()> {
904957
graalpy-3.10.0-[PLATFORM] https://graalpy-mirror.example.com/[FILE-PATH]
905958
");
906959

960+
uv_snapshot!(context.filters(), context.python_list()
961+
.arg("pyodide@3.13")
962+
.arg("--show-urls")
963+
.env(EnvVars::UV_PYODIDE_INSTALL_MIRROR, "https://mirror.example.com")
964+
.env_remove(EnvVars::UV_PYTHON_DOWNLOADS), @"
965+
exit_code: 0 (success)
966+
----- stdout -----
967+
pyodide-3.13.2-emscripten-wasm32-musl https://mirror.example.com/[FILE-PATH]
968+
");
969+
907970
Ok(())
908971
}

0 commit comments

Comments
 (0)
⌂ 换网址