Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle uninstalled pull request channel case #997

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/bin/julialauncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use itertools::Itertools;
use juliaup::config_file::{load_config_db, JuliaupConfig, JuliaupConfigChannel};
use juliaup::global_paths::get_paths;
use juliaup::jsonstructs_versionsdb::JuliaupVersionDB;
use juliaup::operations::is_valid_channel;
use juliaup::operations::{is_pr_channel, is_valid_channel};
use juliaup::versions_file::load_versions_db;
#[cfg(not(windows))]
use nix::{
Expand Down Expand Up @@ -183,20 +183,26 @@ fn get_julia_path_from_channel(
JuliaupChannelSource::CmdLine => {
if channel_valid {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()) {
UserError { msg: format!("`{}` is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}`. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::EnvVar=> {
if channel_valid {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()) {
UserError { msg: format!("`{}` from environment variable JULIAUP_CHANNEL is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}` from environment variable JULIAUP_CHANNEL. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
}.into(),
JuliaupChannelSource::Override=> {
if channel_valid {
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install channel or version.", channel, channel) }
} else if is_pr_channel(&channel.to_string()){
UserError { msg: format!("`{}` from directory override is not installed. Please run `juliaup add {}` to install pull request channel if available.", channel, channel) }
} else {
UserError { msg: format!("Invalid Juliaup channel `{}` from directory override. Please run `juliaup list` to get a list of valid channels and versions.", channel) }
}
Expand Down
12 changes: 4 additions & 8 deletions src/command_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::operations::{channel_to_name, compatible_archs};
use crate::operations::{channel_to_name, get_channel_variations};
use crate::{global_paths::GlobalPaths, versions_file::load_versions_db};
use anyhow::{Context, Result};
use cli_table::{
Expand All @@ -20,13 +20,9 @@ pub fn run_command_list(paths: &GlobalPaths) -> Result<()> {
let versiondb_data =
load_versions_db(paths).with_context(|| "`list` command failed to load versions db.")?;

let non_db_channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(
compatible_archs()?
.into_iter()
.map(|arch| format!("nightly~{}", arch)),
)
.chain(std::iter::once("pr{number}".to_string()))
let non_db_channels: Vec<String> = (get_channel_variations("nightly")?)
.into_iter()
.chain(get_channel_variations("pr{number}")?)
.collect();
let non_db_rows: Vec<ChannelRow> = non_db_channels
.into_iter()
Expand Down
21 changes: 15 additions & 6 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use console::style;
use flate2::read::GzDecoder;
use indicatif::{ProgressBar, ProgressStyle};
use indoc::formatdoc;
use regex::Regex;
use semver::Version;
#[cfg(not(windows))]
use std::os::unix::fs::PermissionsExt;
Expand Down Expand Up @@ -473,11 +474,15 @@ pub fn compatible_archs() -> Result<Vec<String>> {
}

// which nightly channels are compatible with the current system
fn compatible_nightly_channels() -> Result<Vec<String>> {
let archs: Vec<String> = compatible_archs()?;

let channels: Vec<String> = std::iter::once("nightly".to_string())
.chain(archs.into_iter().map(|arch| format!("nightly~{}", arch)))
pub fn get_channel_variations(channel: &str) -> Result<Vec<String>> {
let archs = compatible_archs()?;

let channels: Vec<String> = std::iter::once(channel.to_string())
.chain(
archs
.into_iter()
.map(|arch| format!("{}~{}", channel, arch)),
)
.collect();
Ok(channels)
}
Expand All @@ -487,12 +492,16 @@ fn compatible_nightly_channels() -> Result<Vec<String>> {
pub fn is_valid_channel(versions_db: &JuliaupVersionDB, channel: &String) -> Result<bool> {
let regular = versions_db.available_channels.contains_key(channel);

let nightly_chans = compatible_nightly_channels()?;
let nightly_chans = get_channel_variations("nightly")?;

let nightly = nightly_chans.contains(channel);
Ok(regular || nightly)
}

pub fn is_pr_channel(channel: &String) -> bool {
return Regex::new(r"^(pr\d+)(~|$)").unwrap().is_match(channel);
}

// Identify the unversioned name of a nightly (e.g., `latest-macos-x86_64`) for a channel
pub fn channel_to_name(channel: &String) -> Result<String> {
let mut parts = channel.splitn(2, '~');
Expand Down
13 changes: 13 additions & 0 deletions tests/channel_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,17 @@ fn channel_selection() {
.assert()
.failure()
.stderr("ERROR: `nightly` is not installed. Please run `juliaup add nightly` to install channel or version.\n");

// https://github.com/JuliaLang/juliaup/issues/995
Command::cargo_bin("julia")
.unwrap()
.arg("+pr1")
.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("ERROR: `pr1` is not installed. Please run `juliaup add pr1` to install pull request channel if available.\n");
}