Skip to content

Commit

Permalink
fix(windows): java and python fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 11, 2024
1 parent cfee775 commit c06f992
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 57 deletions.
52 changes: 26 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ tar = "0.4"
tempfile = "3"
tera = "1"
terminal_size = "0.4"
thiserror = "1"
thiserror = "2"
tokio = { version = "1", features = [
"io-std",
"rt",
Expand Down
4 changes: 2 additions & 2 deletions e2e-win/java.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Describe 'java' {
It 'executes java' {
mise x java@21 -- java --version | Select -First 1 | Should -BeLike 'openjdk 21.*'
It 'executes java@temurin-21' {
mise x java@temurin-21 -- java --version | Select -Last 1 | Should -BeLike '*Temurin-21.*'
}
}
3 changes: 0 additions & 3 deletions e2e-win/node.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

Describe 'node' {
It 'executes node 22.0.0' {
mise x node@22.0.0 -- node -v
mise x node@22.0.0 -- where node
mise x node@22.0.0 -- set
mise x node@22.0.0 -- node -v | Should -be "v22.0.0"
}
}
11 changes: 11 additions & 0 deletions e2e-win/python.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Describe 'node' {
It 'executes python 3.12.0' {
mise x python@3.12.0 -- where python
mise x python@3.12.0 -- python --version | Should -Be "Python 3.12.0"
}
It 'executes vfox:python 3.13.0' {
mise x vfox:python@3.13.0 -- where python
mise x vfox:python@3.13.0 -- python --version | Should -Be "Python 3.13.0"
}
}
1 change: 1 addition & 0 deletions e2e-win/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ if ($TestName) {
}

$env:MISE_DEBUG = "1"
$env:PATH = "$PSScriptRoot\..\target\debug;$env:PATH"

Invoke-Pester -Configuration $config
1 change: 1 addition & 0 deletions registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ pulumi = ["asdf:canha/asdf-pulumi"]
purerl = ["asdf:GoNZooo/asdf-purerl"]
purescript = ["asdf:jrrom/asdf-purescript"]
purty = ["asdf:nsaunders/asdf-purty"]
python = ["core:python", "vfox:version-fox/vfox-python"]
qdns = ["asdf:moritz-makandra/asdf-plugin-qdns"]
quarkus = ["asdf:asdf-community/asdf-quarkus"]
r = ["asdf:asdf-community/asdf-r"]
Expand Down
73 changes: 52 additions & 21 deletions src/backend/vfox.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{env, plugins};
use heck::ToKebabCase;
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashMap};
use std::fmt::Debug;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use std::thread;

use crate::backend::{ABackend, Backend, BackendList, BackendType};
Expand All @@ -22,7 +22,7 @@ pub struct VfoxBackend {
ba: BackendArg,
plugin: Box<VfoxPlugin>,
remote_version_cache: CacheManager<Vec<String>>,
exec_env_cache: CacheManager<BTreeMap<String, String>>,
exec_env_cache: RwLock<HashMap<String, CacheManager<BTreeMap<String, String>>>>,
pathname: String,
}

Expand Down Expand Up @@ -90,7 +90,11 @@ impl Backend for VfoxBackend {
_ts: &Toolset,
tv: &ToolVersion,
) -> eyre::Result<BTreeMap<String, String>> {
self._exec_env(tv).cloned()
Ok(self
._exec_env(tv)?
.into_iter()
.filter(|(k, _)| k.to_uppercase() != "PATH")
.collect())
}

fn get_dependencies(&self, tvr: &ToolRequest) -> eyre::Result<Vec<BackendArg>> {
Expand Down Expand Up @@ -130,29 +134,56 @@ impl VfoxBackend {
.with_fresh_file(plugin_path.to_path_buf())
.with_fresh_file(ba.installs_path.to_path_buf())
.build(),
exec_env_cache: CacheManagerBuilder::new(ba.cache_path.join("exec_env.msgpack.z"))
.with_fresh_file(dirs::DATA.to_path_buf())
.with_fresh_file(plugin_path.to_path_buf())
.with_fresh_file(ba.installs_path.to_path_buf())
.build(),
exec_env_cache: Default::default(),
plugin: Box::new(plugin),
ba,
pathname,
}
}

fn _exec_env(&self, tv: &ToolVersion) -> eyre::Result<&BTreeMap<String, String>> {
self.exec_env_cache.get_or_try_init(|| {
self.ensure_plugin_installed()?;
let (vfox, _log_rx) = self.plugin.vfox();
Ok(self
.plugin
.runtime()?
.block_on(vfox.env_keys(&self.pathname, &tv.version))?
.into_iter()
.map(|envkey| (envkey.key, envkey.value))
.collect())
})
fn _exec_env(&self, tv: &ToolVersion) -> eyre::Result<BTreeMap<String, String>> {
let key = tv.to_string();
if !self.exec_env_cache.read().unwrap().contains_key(&key) {
let mut caches = self.exec_env_cache.write().unwrap();
caches.insert(
key.clone(),
CacheManagerBuilder::new(tv.cache_path().join("exec_env.msgpack.z"))
.with_fresh_file(dirs::DATA.to_path_buf())
.with_fresh_file(self.plugin.plugin_path.to_path_buf())
.with_fresh_file(self.fa().installs_path.to_path_buf())
.build(),
);
}
let exec_env_cache = self.exec_env_cache.read().unwrap();
let cache = exec_env_cache.get(&key).unwrap();
cache
.get_or_try_init(|| {
self.ensure_plugin_installed()?;
let (vfox, _log_rx) = self.plugin.vfox();
Ok(self
.plugin
.runtime()?
.block_on(vfox.env_keys(&self.pathname, &tv.version))?
.into_iter()
.fold(BTreeMap::new(), |mut acc, env_key| {
let key = &env_key.key;
if let Some(val) = acc.get(key) {
let mut paths = env::split_paths(val).collect::<Vec<PathBuf>>();
paths.push(PathBuf::from(env_key.value));
acc.insert(
env_key.key,
env::join_paths(paths)
.unwrap()
.to_string_lossy()
.to_string(),
);
} else {
acc.insert(key.clone(), env_key.value);
}
acc
}))
})
.cloned()
}

fn ensure_plugin_installed(&self) -> eyre::Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/core/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl Backend for PythonPlugin {
}

fn _list_remote_versions(&self) -> eyre::Result<Vec<String>> {
if SETTINGS.python.compile == Some(false) {
if cfg!(windows) || SETTINGS.python.compile == Some(false) {
Ok(self
.fetch_precompiled_remote_versions()?
.iter()
Expand Down Expand Up @@ -385,10 +385,10 @@ impl Backend for PythonPlugin {

fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> {
let config = Config::get();
if cfg!(windows) || SETTINGS.python.compile == Some(true) {
self.install_compiled(ctx)?;
} else {
if cfg!(windows) || SETTINGS.python.compile == Some(false) {
self.install_precompiled(ctx)?;
} else {
self.install_compiled(ctx)?;
}
self.test_python(&config, &ctx.tv, ctx.pr.as_ref())?;
if let Err(e) = self.get_virtualenv(&config, &ctx.tv, Some(ctx.pr.as_ref())) {
Expand Down

0 comments on commit c06f992

Please sign in to comment.