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 Jul 3, 2024
1 parent 17085a5 commit cfbbe53
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,47 @@ fn get_julia_path_from_channel(
juliaupconfig_path: &Path,
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 actual_channel = 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(actual_channel)
.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(actual_channel) {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", actual_channel, actual_channel) }
} 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.", actual_channel) }
}
}.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(actual_channel) {
UserError { msg: format!("`{}` for environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", actual_channel, actual_channel) }
} 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.", actual_channel) }
}
}.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(actual_channel) {
UserError { msg: format!("`{}` for directory override is not installed. Please run `juliaup add {}` to install channel or version.", actual_channel, actual_channel) }
} 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.", actual_channel) }
}
}.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.", actual_channel)
})?;

match channel_info {
Expand All @@ -204,12 +219,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.", actual_channel, version))?.path;

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

let absolute_path = juliaupconfig_path
Expand Down
38 changes: 38 additions & 0 deletions tests/channel_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,42 @@ fn channel_selection() {
.assert()
.failure()
.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")
.assert()
.failure()
.stderr(
"`1.8` is not installed. Please run `juliaup add 1.8` to install channel or version.\n",
);
}

0 comments on commit cfbbe53

Please sign in to comment.