diff --git a/src/plugins/core/python.rs b/src/plugins/core/python.rs index adc723d8fd..b39a214b88 100644 --- a/src/plugins/core/python.rs +++ b/src/plugins/core/python.rs @@ -10,9 +10,10 @@ use crate::http::{HTTP, HTTP_FETCH}; use crate::install_context::InstallContext; use crate::toolset::{ToolRequest, ToolVersion, Toolset}; use crate::ui::progress_report::SingleReport; -use crate::{cmd, file, plugins}; +use crate::{cmd, dirs, file, plugins}; use eyre::{bail, eyre}; use itertools::Itertools; +use once_cell::sync::Lazy; use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use std::sync::{Arc, OnceLock}; @@ -22,21 +23,12 @@ use xx::regex; #[derive(Debug)] pub struct PythonPlugin { ba: BackendArg, - precompiled_cache: CacheManager>, } impl PythonPlugin { pub fn new() -> Self { let ba = plugins::core::new_backend_arg("python"); - Self { - precompiled_cache: CacheManagerBuilder::new( - ba.cache_path.join("precompiled.msgpack.z"), - ) - .with_fresh_duration(SETTINGS.fetch_remote_versions_cache()) - .with_cache_key(python_precompiled_platform()) - .build(), - ba, - } + Self { ba } } fn python_build_path(&self) -> PathBuf { @@ -87,11 +79,21 @@ impl PythonPlugin { } fn fetch_precompiled_remote_versions(&self) -> eyre::Result<&Vec<(String, String, String)>> { - self.precompiled_cache.get_or_try_init(|| { + static PRECOMPILED_CACHE: Lazy>> = + Lazy::new(|| { + CacheManagerBuilder::new(dirs::CACHE.join("python").join("precompiled.msgpack.z")) + .with_fresh_duration(SETTINGS.fetch_remote_versions_cache()) + .with_cache_key(python_precompiled_platform()) + .build() + }); + PRECOMPILED_CACHE.get_or_try_init(|| { + let arch = python_arch(); + let os = python_os(); + let url_path = format!("python-precompiled-{arch}-{os}"); let raw = match SETTINGS.paranoid { - true => HTTP_FETCH.get_text("https://mise-versions.jdx.dev/python-precompiled"), + true => HTTP_FETCH.get_text(format!("https://mise-versions.jdx.dev/{url_path}")), // using http is not a security concern and enabling tls makes mise significantly slower - false => HTTP_FETCH.get_text("http://mise-versions.jdx.dev/python-precompiled"), + false => HTTP_FETCH.get_text(format!("http://mise-versions.jdx.dev/{url_path}")), }?; let platform = python_precompiled_platform(); // order by version, whether it is a release candidate, date, and in the preferred order of install types