Skip to content

Commit

Permalink
Support short channel matching
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangnrd committed Feb 14, 2024
1 parent d3acca0 commit 9c06002
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,42 @@ fn get_julia_path_from_channel(
juliaupconfig_path: &Path,

Check warning on line 166 in src/bin/julialauncher.rs

View workflow job for this annotation

GitHub Actions / Rustfmt Check

Diff in /home/runner/work/juliaup/juliaup/src/bin/julialauncher.rs
juliaup_channel_source: JuliaupChannelSource,
) -> Result<(PathBuf, Vec<String>)> {
let potential_matches: Vec<_> = config_data.installed_channels.keys()
.filter(|&item| item.starts_with(channel))
.cloned()
.collect();
let actualchannel = if potential_matches.len() == 1 {
potential_matches.first().expect("length should be 1").as_str()
} else {
channel
};

let channel_info = config_data
.installed_channels
.get(channel)
.get(actualchannel)
.ok_or_else(|| match juliaup_channel_source {
JuliaupChannelSource::CmdLine => {
if versions_db.available_channels.contains_key(channel) {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
if versions_db.available_channels.contains_key(actualchannel) {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) }
}
}.into(),
JuliaupChannelSource::EnvVar=> {
if versions_db.available_channels.contains_key(channel) {
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
if versions_db.available_channels.contains_key(actualchannel) {
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) }
}
}.into(),
JuliaupChannelSource::Override=> {
if versions_db.available_channels.contains_key(channel) {
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
if versions_db.available_channels.contains_key(actualchannel) {
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", actualchannel, actualchannel) }
} else {
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
UserError { msg: format!("ERROR: Invalid Juliaup channel `{}` in directory override. Please run `juliaup list` to get a list of valid channels and versions.", actualchannel) }
}
}.into(),
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", channel)
JuliaupChannelSource::Default => anyhow!("The Juliaup configuration is in an inconsistent state, the currently configured default channel `{}` is not installed.", actualchannel)
})?;

match channel_info {
Expand All @@ -204,12 +214,12 @@ fn get_julia_path_from_channel(
JuliaupConfigChannel::SystemChannel { version } => {
let path = &config_data
.installed_versions.get(version)
.ok_or_else(|| anyhow!("The juliaup configuration is in an inconsistent state, the channel {} is pointing to Julia version {}, which is not installed.", channel, version))?.path;
.ok_or_else(|| anyhow!("The juliaup configuration is in an inconsistent state, the channel {} is pointing to Julia version {}, which is not installed.", actualchannel, version))?.path;

check_channel_uptodate(channel, version, versions_db).with_context(|| {
check_channel_uptodate(actualchannel, version, versions_db).with_context(|| {
format!(
"The Julia launcher failed while checking whether the channel {} is up-to-date.",
channel
actualchannel
)
})?;
let absolute_path = juliaupconfig_path
Expand Down Expand Up @@ -237,12 +247,12 @@ fn get_julia_path_from_channel(
if local_etag != server_etag {
eprintln!(
"A new version of Julia for the `{}` channel is available. Run:",
channel
actualchannel
);
eprintln!();

Check warning on line 252 in src/bin/julialauncher.rs

View workflow job for this annotation

GitHub Actions / Rustfmt Check

Diff in /home/runner/work/juliaup/juliaup/src/bin/julialauncher.rs
eprintln!(" juliaup update");
eprintln!();
eprintln!("to install the latest Julia for the `{}` channel.", channel);
eprintln!("to install the latest Julia for the `{}` channel.", actualchannel);
}

let absolute_path = juliaupconfig_path
Expand Down
37 changes: 37 additions & 0 deletions tests/channel_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,41 @@ fn channel_selection() {
.assert()
.failure()

Check warning on line 126 in tests/channel_selection.rs

View workflow job for this annotation

GitHub Actions / Rustfmt Check

Diff in /home/runner/work/juliaup/juliaup/tests/channel_selection.rs
.stderr("ERROR: Invalid Juliaup channel `1.8.6`. Please run `juliaup list` to get a list of valid channels and versions.\n");


// Now testing short channel matching

Command::cargo_bin("julia")
.unwrap()
.arg("+1.8")
.arg("-e")
.arg("print(VERSION)")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_CHANNEL", "1.7.3")
.assert()
.success()
.stdout("1.8.5");

Command::cargo_bin("juliaup")
.unwrap()
.arg("add")
.arg("1.8.4")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.assert()
.success()
.stdout("");

Command::cargo_bin("julia")
.unwrap()
.arg("+1.8")
.arg("-e")
.arg("print(VERSION)")
.env("JULIA_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_DEPOT_PATH", depot_dir.path())
.env("JULIAUP_CHANNEL", "1.7.4")

Check warning on line 161 in tests/channel_selection.rs

View workflow job for this annotation

GitHub Actions / Rustfmt Check

Diff in /home/runner/work/juliaup/juliaup/tests/channel_selection.rs
.assert()
.failure()
.stderr("`1.8` is not installed. Please run `juliaup add 1.8` to install channel or version.\n");
}

0 comments on commit 9c06002

Please sign in to comment.