Skip to content

Commit

Permalink
fix: correct python ls-remote with python.compile option
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Oct 28, 2024
1 parent ca0360f commit acfd7f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fs::File;
use std::io::Write;
use std::io::{Read, Write};
use std::path::Path;
use std::time::Duration;

use eyre::{bail, Report, Result};
use flate2::read::GzDecoder;
use once_cell::sync::Lazy;
use reqwest::header::HeaderMap;
use reqwest::{ClientBuilder, IntoUrl, Response};
Expand Down Expand Up @@ -99,6 +100,14 @@ impl Client {
Ok(text)
}

pub fn get_text_gz<U: IntoUrl>(&self, url: U) -> Result<String> {
let text = self.get_text(url)?;
let bytes = GzDecoder::new(text.as_bytes())
.bytes()
.collect::<Result<Vec<u8>, _>>()?;
Ok(String::from_utf8(bytes)?)
}

pub fn json_headers<T, U: IntoUrl>(&self, url: U) -> Result<(T, HeaderMap)>
where
T: serde::de::DeserializeOwned,
Expand Down
24 changes: 14 additions & 10 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ impl PythonPlugin {
fn fetch_precompiled_remote_versions(&self) -> eyre::Result<&Vec<(String, String, String)>> {
self.precompiled_cache.get_or_try_init(|| {
let raw = match SETTINGS.paranoid {
true => HTTP_FETCH.get_text("https://mise-versions.jdx.dev/python-precompiled"),
true => {
HTTP_FETCH.get_text_gz("https://mise-versions.jdx.dev/python-precompiled.gz")
}
// 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_gz("http://mise-versions.jdx.dev/python-precompiled.gz")
}
}?;
let arch = python_arch();
let os = python_os();
Expand Down Expand Up @@ -338,13 +342,7 @@ impl Backend for PythonPlugin {
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if SETTINGS.python.compile == Some(false) {
Ok(self
.fetch_precompiled_remote_versions()?
.iter()
.map(|(v, _, _)| v.clone())
.collect())
} else {
if SETTINGS.python.compile == Some(true) {
self.install_or_update_python_build()?;
let python_build_bin = self.python_build_bin();
CorePlugin::run_fetch_task_with_timeout(move || {
Expand All @@ -358,6 +356,12 @@ impl Backend for PythonPlugin {
.collect();
Ok(versions)
})
} else {
Ok(self
.fetch_precompiled_remote_versions()?
.iter()
.map(|(v, _, _)| v.clone())
.collect())
}
}

Expand All @@ -367,7 +371,7 @@ impl Backend for PythonPlugin {
.get_or_init(|| {
CacheManagerBuilder::new(self.fa().cache_path.join("remote_versions.msgpack.z"))
.with_fresh_duration(SETTINGS.fetch_remote_versions_cache())
.with_cache_key((SETTINGS.python.compile == Some(false)).to_string())
.with_cache_key((SETTINGS.python.compile == Some(true)).to_string())
.build()
.into()
})
Expand Down

0 comments on commit acfd7f1

Please sign in to comment.