Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored and jdx committed Nov 27, 2024
1 parent a4e7fa9 commit 51f3710
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 49 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ jobs:
needs: [build-macos, build-windows]
runs-on: ${{ matrix.os }}
timeout-minutes: 20
if: github.ref_name == 'release' && 'true' || 'false'
env:
TEST_TRANCHE: ${{matrix.tranche}}
TEST_TRANCHE_COUNT: 4
Expand Down Expand Up @@ -353,5 +354,5 @@ jobs:
retry_wait_seconds: 30
max_attempts: 2
command: mise test-tool --all
# env:
# MISE_USE_VERSIONS_HOST: 0
env:
MISE_USE_VERSIONS_HOST: 0
2 changes: 1 addition & 1 deletion registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ mdbook.backends = ["asdf:cipherstash/asdf-mdbook"]
mdbook-linkcheck.backends = ["asdf:cipherstash/asdf-mdbook-linkcheck"]
melange.backends = ["aqua:chainguard-dev/melange", "asdf:omissis/asdf-melange"]
melange.os = ["linux", "macos"]
melange.test = ["melange version", "v{{version}}"]
# melange.test = ["melange version", "v{{version}}"] sometimes releases without assets
melt.backends = ["asdf:chessmango/asdf-melt"]
memcached.backends = ["asdf:furkanural/asdf-memcached"]
mercury.backends = ["asdf:susurri/asdf-mercury"]
Expand Down
70 changes: 32 additions & 38 deletions src/cli/ls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -82,7 +81,7 @@ impl Ls {
if self.current || self.global {
// TODO: global is a little weird: it will show global versions as the active ones even if
// they're overridden locally
runtimes.retain(|(_, _, _, source)| source.is_some());
runtimes.retain(|(_, _, _, source)| !source.is_unknown());
}
if self.installed {
runtimes.retain(|(_, p, tv, _)| p.is_version_installed(tv, true));
Expand Down Expand Up @@ -145,11 +144,15 @@ impl Ls {
.map(|(ls, p, tv, source)| Row {
tool: p.clone(),
version: (ls, p.as_ref(), &tv, &source).into(),
requested: match source.is_some() {
true => Some(tv.request.version()),
false => None,
requested: match source.is_unknown() {
true => None,
false => Some(tv.request.version()),
},
source: if source.is_unknown() {
None
} else {
Some(source)
},
source,
})
.collect::<Vec<_>>();
let mut table = Table::new(rows);
Expand All @@ -173,24 +176,13 @@ impl Ls {

let mut ts = Toolset::from(trs);
ts.resolve()?;
let mut versions: HashMap<(String, String), (Arc<dyn Backend>, ToolVersion)> = ts
.list_installed_versions()?
.into_iter()
.map(|(p, tv)| ((p.id().into(), tv.version.clone()), (p, tv)))
.collect();

let active = ts
.list_current_versions()
.into_iter()
.map(|(p, tv)| ((p.id().into(), tv.version.clone()), (p, tv)))
.collect::<HashMap<(String, String), (Arc<dyn Backend>, ToolVersion)>>();

versions.extend(active.clone());

let rvs: Vec<RuntimeRow> = versions
let rvs: Vec<RuntimeRow> = ts
.list_all_versions()?
.into_iter()
.filter(|(_, (f, _))| match &self.plugin {
Some(p) => p.contains(f.ba()),
.map(|(b, tv)| ((b, tv.version.clone()), tv))
.filter(|((b, _), _)| match &self.plugin {
Some(p) => p.contains(b.ba()),
None => true,
})
.sorted_by_cached_key(|((plugin_name, version), _)| {
Expand All @@ -200,15 +192,9 @@ impl Ls {
version.clone(),
)
})
.map(|(k, (p, tv))| {
let source = match &active.get(&k) {
Some((_, tv)) => ts.versions.get(tv.ba()).map(|tv| tv.source.clone()),
None => None,
};
(self, p, tv, source)
})
.map(|(k, tv)| (self, k.0, tv.clone(), tv.request.source().clone()))
// if it isn't installed and it's not specified, don't show it
.filter(|(_ls, p, tv, source)| source.is_some() || p.is_version_installed(tv, true))
.filter(|(_ls, p, tv, source)| !source.is_unknown() || p.is_version_installed(tv, true))
.filter(|(_ls, p, _, _)| match &self.plugin {
Some(backend) => backend.contains(p.ba()),
None => true,
Expand All @@ -235,7 +221,7 @@ struct JSONToolVersion {
active: bool,
}

type RuntimeRow<'a> = (&'a Ls, Arc<dyn Backend>, ToolVersion, Option<ToolSource>);
type RuntimeRow<'a> = (&'a Ls, Arc<dyn Backend>, ToolVersion, ToolSource);

#[derive(Tabled)]
#[tabled(rename_all = "PascalCase")]
Expand Down Expand Up @@ -274,9 +260,17 @@ impl From<RuntimeRow<'_>> for JSONToolVersion {
JSONToolVersion {
symlinked_to: p.symlink_path(&tv),
install_path: tv.install_path(),
version: tv.version,
requested_version: source.as_ref().map(|_| tv.request.version()),
source: source.map(|source| source.as_json()),
version: tv.version.clone(),
requested_version: if source.is_unknown() {
None
} else {
Some(tv.request.version())
},
source: if source.is_unknown() {
None
} else {
Some(source.as_json())
},
installed: !matches!(vs, VersionStatus::Missing(_)),
active: matches!(vs, VersionStatus::Active(_, _)),
}
Expand All @@ -290,13 +284,13 @@ enum VersionStatus {
Symlink(String, bool),
}

impl From<(&Ls, &dyn Backend, &ToolVersion, &Option<ToolSource>)> for VersionStatus {
fn from((ls, p, tv, source): (&Ls, &dyn Backend, &ToolVersion, &Option<ToolSource>)) -> Self {
impl From<(&Ls, &dyn Backend, &ToolVersion, &ToolSource)> for VersionStatus {
fn from((ls, p, tv, source): (&Ls, &dyn Backend, &ToolVersion, &ToolSource)) -> Self {
if p.symlink_path(tv).is_some() {
VersionStatus::Symlink(tv.version.clone(), source.is_some())
VersionStatus::Symlink(tv.version.clone(), !source.is_unknown())
} else if !p.is_version_installed(tv, true) {
VersionStatus::Missing(tv.version.clone())
} else if source.is_some() {
} else if !source.is_unknown() {
let outdated = if ls.offline {
false
} else {
Expand Down
10 changes: 5 additions & 5 deletions src/cli/prune.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::BTreeMap;
use std::sync::Arc;

use console::style;
use eyre::Result;
use crate::backend::Backend;
use crate::cli::args::BackendArg;
use crate::config::tracking::Tracker;
use crate::config::{Config, SETTINGS};
use crate::toolset::{ToolVersion, Toolset, ToolsetBuilder};
use crate::ui::multi_progress_report::MultiProgressReport;
use crate::ui::prompt;
use console::style;
use eyre::Result;

use super::trust::Trust;

Expand Down Expand Up @@ -67,8 +67,8 @@ impl Prune {
let mut to_delete = ts
.list_installed_versions()?
.into_iter()
.map(|(p, tv)| (tv.to_string(), (p, tv)))
.collect::<BTreeMap<String, (Arc<dyn Backend>, ToolVersion)>>();
.map(|(p, tv)| ((tv.ba().short.to_string(), tv.tv_pathname()), (p, tv)))
.collect::<BTreeMap<(String, String), (Arc<dyn Backend>, ToolVersion)>>();

if let Some(backends) = &self.plugin {
to_delete.retain(|_, (_, tv)| backends.contains(tv.ba()));
Expand All @@ -78,7 +78,7 @@ impl Prune {
let mut ts = Toolset::from(cf.to_tool_request_set()?);
ts.resolve()?;
for (_, tv) in ts.list_current_versions() {
to_delete.remove(&tv.to_string());
to_delete.remove(&(tv.ba().short.to_string(), tv.tv_pathname()));
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/toolset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ impl Toolset {
})
.collect()
}
pub fn list_all_versions(&self) -> Result<Vec<(Arc<dyn Backend>, ToolVersion)>> {
let versions = self
.list_current_versions()
.into_iter()
.chain(self.list_installed_versions()?)
.unique_by(|(ba, tv)| (ba.clone(), tv.tv_pathname().to_string()))
.collect();
Ok(versions)
}
pub fn list_current_installed_versions(&self) -> Vec<(Arc<dyn Backend>, ToolVersion)> {
self.list_current_versions()
.into_iter()
Expand Down
3 changes: 1 addition & 2 deletions src/toolset/tool_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::hash::hash_to_str;
use crate::toolset::{tool_request, ToolRequest, ToolVersionOptions};
use console::style;
use eyre::Result;
use heck::ToKebabCase;
#[cfg(windows)]
use path_absolutize::Absolutize;

Expand Down Expand Up @@ -269,7 +268,7 @@ impl ToolVersion {

impl Display for ToolVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
write!(f, "{}@{}", &self.ba().full(), &self.version.to_kebab_case())
write!(f, "{}@{}", &self.ba().full(), &self.version)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tasks/test/coverage
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ mise x -- bun i
echo "::endgroup::"
mise x -- ./e2e/run_all_tests
echo "::group::mise test-tool"
MISE_USE_VERSIONS_HOST=1 mise test-tool --all
MISE_USE_VERSIONS_HOST=0 mise test-tool --all
echo "::group::Render lcov report"
cargo llvm-cov report --lcov --output-path "coverage-${TEST_TRANCHE:-}.lcov"

0 comments on commit 51f3710

Please sign in to comment.