From 565a37cbc780cd0fdae5bf13609320e64fd7ab95 Mon Sep 17 00:00:00 2001 From: Florian Finkernagel Date: Fri, 13 Sep 2024 17:10:19 +0200 Subject: [PATCH] compability with pre 2.0 versions (auto-version-switch) --- examples/basic/anysnake2.toml | 5 +- examples/dev/anysnake2.toml | 2 +- examples/docker/anysnake2.toml | 2 +- examples/flake_auto_rev/anysnake2.toml | 2 +- .../flake_in_non_root_github/anysnake2.toml | 4 +- examples/full/anysnake2.toml | 4 +- .../anysnake2.toml | 2 +- examples/jupyter7/anysnake2.toml | 2 +- examples/just_python/anysnake2.toml | 2 +- .../anysnake2.toml | 3 +- .../anysnake2.toml | 3 +- .../anysnake2.toml | 5 +- .../anysnake2.toml | 3 +- .../just_python_trust_on_first_use/test.toml | 2 +- examples/just_r/anysnake2.toml | 3 +- examples/minimal/anysnake2.toml | 4 +- examples/minimal_rust/anysnake2.toml | 3 +- .../python_310_nixpkgs_2205/anysnake2.toml | 3 +- .../anysnake2.toml | 5 +- examples/test_empty/anysnake2.toml | 0 .../anysnake2.toml | 4 +- src/config.rs | 17 +- src/main.rs | 37 +++-- src/tofu.rs | 146 +++++++++++++++--- tests/integration_tests.rs | 16 ++ 25 files changed, 213 insertions(+), 66 deletions(-) create mode 100644 examples/test_empty/anysnake2.toml diff --git a/examples/basic/anysnake2.toml b/examples/basic/anysnake2.toml index eb8bb93..985f3af 100644 --- a/examples/basic/anysnake2.toml +++ b/examples/basic/anysnake2.toml @@ -1,8 +1,9 @@ # basic anysnake2.toml example # package settings [anysnake2] - url = "dev" - use_binary=false # optional, default = true. Download anysnake2 binary instead of building from source (both via a flake) + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" [nixpkgs] diff --git a/examples/dev/anysnake2.toml b/examples/dev/anysnake2.toml index a161e85..96ba340 100644 --- a/examples/dev/anysnake2.toml +++ b/examples/dev/anysnake2.toml @@ -1,5 +1,5 @@ [anysnake2] -url = "dev" # replace with fixed version outside of tests/examples +url2 = "dev" # replace with fixed version outside of tests/examples [python.packages.rpy2] version = '*' poetry2nix.env = {R_HOME = '${R_tracked}'} diff --git a/examples/docker/anysnake2.toml b/examples/docker/anysnake2.toml index 9ce5844..c277163 100644 --- a/examples/docker/anysnake2.toml +++ b/examples/docker/anysnake2.toml @@ -2,7 +2,7 @@ # torpedos all 'don't run as root' protection though. # (remember, being allowed to run docker containers == root access) [anysnake2] -url = "dev" # replace with fixed version outside of tests/examples +url2 = "dev" # replace with fixed version outside of tests/examples [nixpkgs] diff --git a/examples/flake_auto_rev/anysnake2.toml b/examples/flake_auto_rev/anysnake2.toml index d23828d..58138c9 100644 --- a/examples/flake_auto_rev/anysnake2.toml +++ b/examples/flake_auto_rev/anysnake2.toml @@ -1,5 +1,5 @@ [anysnake2] -url = "dev" +url2 = "dev" [nixpkgs] url = "github:NixOS/nixpkgs/master/24.05" diff --git a/examples/flake_in_non_root_github/anysnake2.toml b/examples/flake_in_non_root_github/anysnake2.toml index a87d007..65a6dd6 100644 --- a/examples/flake_in_non_root_github/anysnake2.toml +++ b/examples/flake_in_non_root_github/anysnake2.toml @@ -1,6 +1,8 @@ # the absolute minimal anysnake2.toml example [anysnake2] - url = "dev" # replace with fixed version outside of tests/examples + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" # replace with fixed version outside of tests/examples # the nixpkgs used to run singularity and nixfmt diff --git a/examples/full/anysnake2.toml b/examples/full/anysnake2.toml index 6ba801f..000a081 100644 --- a/examples/full/anysnake2.toml +++ b/examples/full/anysnake2.toml @@ -1,9 +1,11 @@ # fully featured anysnake2.toml example # this is fully tofu resolved as well. [anysnake2] + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 # We leverage nix flakes to run exactly that version. # rev = "dev" = do not switch to fixed version, used in development. - url = "dev" # replace with fixed version outside of tests/examples. + url2 = "dev" # replace with fixed version outside of tests/examples. # leave off to auto detect the newest version # looks like this TOFU # url = "github:TyberiusPrime/anysnake2/main/1.15.5" diff --git a/examples/github_tarballs_can_be_unstable/anysnake2.toml b/examples/github_tarballs_can_be_unstable/anysnake2.toml index ca5ae47..59f25ac 100644 --- a/examples/github_tarballs_can_be_unstable/anysnake2.toml +++ b/examples/github_tarballs_can_be_unstable/anysnake2.toml @@ -1,5 +1,5 @@ [anysnake2] - url = "dev" # replace with fixed version outside of tests/examples + url2 = "dev" # replace with fixed version outside of tests/examples [nixpkgs] diff --git a/examples/jupyter7/anysnake2.toml b/examples/jupyter7/anysnake2.toml index 1073eb2..bdf9820 100644 --- a/examples/jupyter7/anysnake2.toml +++ b/examples/jupyter7/anysnake2.toml @@ -1,7 +1,7 @@ # basic anysnake2.toml example # package settings [anysnake2] - url = "dev" + url2 = "dev" use_binary=false # optional, default = true. Download anysnake2 binary instead of building from source (both via a flake) diff --git a/examples/just_python/anysnake2.toml b/examples/just_python/anysnake2.toml index e57272c..f09cba3 100644 --- a/examples/just_python/anysnake2.toml +++ b/examples/just_python/anysnake2.toml @@ -1,5 +1,5 @@ [anysnake2] - url="dev" + url2="dev" [nixpkgs] diff --git a/examples/just_python_discover_newest_revision/anysnake2.toml b/examples/just_python_discover_newest_revision/anysnake2.toml index 13c258b..43827a5 100644 --- a/examples/just_python_discover_newest_revision/anysnake2.toml +++ b/examples/just_python_discover_newest_revision/anysnake2.toml @@ -3,8 +3,7 @@ # (example used for testing) # package settings [anysnake2] -rev = "dev" -url = "github:TyberiusPrime/anysnake2/main/1.15.5" +url2="dev" [nixpkgs] # the nixpkgs used inside the container diff --git a/examples/just_python_package_from_pypi/anysnake2.toml b/examples/just_python_package_from_pypi/anysnake2.toml index 46de0a8..299e0b5 100644 --- a/examples/just_python_package_from_pypi/anysnake2.toml +++ b/examples/just_python_package_from_pypi/anysnake2.toml @@ -7,8 +7,7 @@ # see mbf_bam for an example [anysnake2] - rev = "dev" - url = "github:TyberiusPrime/anysnake2/main/1.15.5" + url2 = "dev" [nixpkgs] diff --git a/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml b/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml index be124f6..d2ba6f2 100644 --- a/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml +++ b/examples/just_python_poetry2nix_escape_hatch/anysnake2.toml @@ -1,7 +1,8 @@ # basic anysnake2.toml example using python [anysnake2] - rev = "dev" - url = "github:TyberiusPrime/anysnake2/main/1.15.5" + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" [nixpkgs] diff --git a/examples/just_python_trust_on_first_use/anysnake2.toml b/examples/just_python_trust_on_first_use/anysnake2.toml index 86e4d26..8c6b559 100644 --- a/examples/just_python_trust_on_first_use/anysnake2.toml +++ b/examples/just_python_trust_on_first_use/anysnake2.toml @@ -3,8 +3,7 @@ # (example used for testing) # package settings [anysnake2] - rev = "dev" - url = "github:TyberiusPrime/anysnake2/main/1.15.5" + url2 = "dev" [nixpkgs] diff --git a/examples/just_python_trust_on_first_use/test.toml b/examples/just_python_trust_on_first_use/test.toml index a1c609c..862426f 100644 --- a/examples/just_python_trust_on_first_use/test.toml +++ b/examples/just_python_trust_on_first_use/test.toml @@ -1,7 +1,7 @@ # basic anysnake2.toml example # package settings [anysnake2] -rev = "dev" +url2 = "dev" [outside_nixpkgs] rev = "21.05" # the nixpgks version or github hash diff --git a/examples/just_r/anysnake2.toml b/examples/just_r/anysnake2.toml index 4f29d1b..9112ec5 100644 --- a/examples/just_r/anysnake2.toml +++ b/examples/just_r/anysnake2.toml @@ -1,8 +1,7 @@ # fully featured anysnake2.toml example [anysnake2] # We leverage nix flakes to run exactly that version. - rev = "dev" # replace with fixed version outside of tests/examples - url = "github:TyberiusPrime/anysnake2/main/1.15.5" + url2 = "dev" [nixpkgs] diff --git a/examples/minimal/anysnake2.toml b/examples/minimal/anysnake2.toml index 0dab6d0..917e5d1 100644 --- a/examples/minimal/anysnake2.toml +++ b/examples/minimal/anysnake2.toml @@ -1,5 +1,7 @@ [anysnake2] - url = "github:TyberiusPrime/anysnake2_release_flakes/main/1.15.4" + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" [nixpkgs] diff --git a/examples/minimal_rust/anysnake2.toml b/examples/minimal_rust/anysnake2.toml index de5ccc3..d23e3d9 100644 --- a/examples/minimal_rust/anysnake2.toml +++ b/examples/minimal_rust/anysnake2.toml @@ -1,7 +1,6 @@ # the absolute minimal anysnake2.toml example [anysnake2] -rev = "dev" # replace with fixed version outside of tests/examples -url = "github:TyberiusPrime/anysnake2/main/1.15.5" +url2 = "dev" [nixpkgs] diff --git a/examples/python_310_nixpkgs_2205/anysnake2.toml b/examples/python_310_nixpkgs_2205/anysnake2.toml index 5e9a7c3..f18262e 100644 --- a/examples/python_310_nixpkgs_2205/anysnake2.toml +++ b/examples/python_310_nixpkgs_2205/anysnake2.toml @@ -2,8 +2,7 @@ # only supporting the current release at any one point in time. [anysnake2] # We leverage nix flakes to run exactly that version. -rev = "dev" # replace with fixed version outside of tests/examples -url = "github:TyberiusPrime/anysnake2/main/1.15.5" +url2 = "dev" [nixpkgs] packages = ['strace', 'python38'] diff --git a/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml b/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml index 64ec2ab..dcb2cc9 100644 --- a/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml +++ b/examples/python_buildPackage_interdependency_with_overrides/anysnake2.toml @@ -1,8 +1,9 @@ # basic anysnake2.toml example # package settings [anysnake2] - rev = "dev" - url = "github:TyberiusPrime/anysnake2/main/1.15.5" + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" [nixpkgs] diff --git a/examples/test_empty/anysnake2.toml b/examples/test_empty/anysnake2.toml new file mode 100644 index 0000000..e69de29 diff --git a/examples/test_python_pulled_by_other_editable/anysnake2.toml b/examples/test_python_pulled_by_other_editable/anysnake2.toml index 72ca06f..0bd7a6f 100644 --- a/examples/test_python_pulled_by_other_editable/anysnake2.toml +++ b/examples/test_python_pulled_by_other_editable/anysnake2.toml @@ -1,6 +1,8 @@ # basic anysnake2.toml example [anysnake2] - url = "dev" + rev = "dev" # pre 2.0 - 2.0+ uses url2 + url = "github:TyberiusPrime/anysnake2_release_flakes" # pre 2.0 - 2.0+ uses url2 + url2 = "dev" [nixpkgs] diff --git a/src/config.rs b/src/config.rs index 625a9d3..1bfa624 100644 --- a/src/config.rs +++ b/src/config.rs @@ -137,7 +137,7 @@ impl ConfigToml { pub fn from_file(config_file: &str) -> Result { use ex::fs; let abs_config_path = - fs::canonicalize(config_file).context("Could not find config file")?; + fs::canonicalize(config_file).context("Could not find config file. To start with an empty config, run 'touch anysnake2.toml' an dtry again")?; let raw_config = fs::read_to_string(&abs_config_path).context("Could not read config file")?; let mut parsed_config: ConfigToml = Self::from_str(&raw_config).with_context(|| { @@ -227,17 +227,22 @@ impl TryFrom for TofuVCSorDev { #[derive(Deserialize, Debug)] pub struct Anysnake2 { - pub url: Option, - #[serde(default = "Anysnake2::default_use_binary")] - pub use_binary: bool, + // for pre 2.0 to do the right thing + pub url: Option, + pub rev: Option, + pub use_binary: Option, + //now the real deal. + pub url2: Option, pub do_not_modify_flake: Option, #[serde(default = "Anysnake2::default_dtach")] pub dtach: bool, } #[derive(Debug)] pub struct TofuAnysnake2 { - pub url: TofuVCSorDev, - pub use_binary: bool, + pub url: String, + pub rev: String, + + pub url2: TofuVCSorDev, pub do_not_modify_flake: bool, pub dtach: bool, } diff --git a/src/main.rs b/src/main.rs index 3881d72..e8e310a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,10 @@ extern crate clap; use anyhow::{anyhow, bail, Context, Result}; use anysnake2::util::{add_line_numbers, dir_empty, CloneStringLossy}; -use anysnake2::{install_ctrl_c_handler, run_without_ctrl_c, ErrorWithExitCode, safe_python_package_name}; +use anysnake2::{ + install_ctrl_c_handler, run_without_ctrl_c, safe_python_package_name, ErrorWithExitCode, +}; +use clap::parser::ValueSource; use clap::{Arg, ArgMatches}; use ex::fs; use indoc::indoc; @@ -151,11 +154,19 @@ fn handle_config_command(matches: &ArgMatches) -> Result { std::include_str!("../examples/minimal/anysnake2.toml") ), Some(("full", _)) => { - println!("{}", std::include_str!("../examples/full/anysnake2.toml").replace("url = \"dev\"\n", "")); + println!( + "{}", + std::include_str!("../examples/full/anysnake2.toml") + .replace("url = \"dev\"\n", "") + ); } Some(("basic", _)) => { // includes basic - println!("{}", std::include_str!("../examples/basic/anysnake2.toml").replace("url = \"dev\"\n", "")); + println!( + "{}", + std::include_str!("../examples/basic/anysnake2.toml") + .replace("url = \"dev\"\n", "") + ); } _ => { bail!("Could not find that config. Try to pass minimial/basic/full as in 'anysnake2 config basic'"); @@ -196,12 +207,12 @@ fn switch_to_configured_version( parsed_config: &config::TofuMinimalConfigToml, matches: &ArgMatches, ) -> Result<()> { - match &parsed_config.anysnake2.url { + match &parsed_config.anysnake2.url2 { config::TofuVCSorDev::Dev => { info!("Using development version of anysnake"); } config::TofuVCSorDev::Vcs(url) => { - if matches.contains_id("no-version-switch") { + if matches.value_source("no-version-switch") == Some(ValueSource::CommandLine) { info!("--no-version-switch was passed, not switching versions"); } else { let rev = match url { @@ -226,8 +237,8 @@ fn switch_to_configured_version( .cloned() .unwrap_or_else(|| "noversionspecified".to_string()) { - info!("restarting with version from {}", url.to_string()); - let repo = url.to_string(); + info!("restarting with version from {}", url.to_nix_string()); + let repo = url.to_nix_string(); let mut args = vec!["shell", &repo, "-c", "anysnake2", "--_running_version", rev]; @@ -652,7 +663,10 @@ fn run_singularity( dtach_socket: &Option, flake_dir: &Path, ) -> Result { - let singularity_url = format!("{}#singularity", anysnake2::get_outside_nixpkgs_url().unwrap()); + let singularity_url = format!( + "{}#singularity", + anysnake2::get_outside_nixpkgs_url().unwrap() + ); register_nix_gc_root(&singularity_url, flake_dir)?; run_without_ctrl_c(|| { let mut nix_full_args: Vec = Vec::new(); @@ -780,7 +794,10 @@ fn download_and_unzip(url: &str, target_dir: &Path) -> Result<()> { { let tf = ex::fs::File::create(&download_filename)?; let mut btf = std::io::BufWriter::new(tf); - let mut req = anysnake2::util::get_proxy_req()?.get(url).call()?.into_reader(); + let mut req = anysnake2::util::get_proxy_req()? + .get(url) + .call()? + .into_reader(); std::io::copy(&mut req, &mut btf)?; } //call tar to unpack @@ -1176,7 +1193,7 @@ fn add_r_library_path( ) -> Result<()> { use std::collections::hash_map::Entry; let key = format!("r_ld_path~{}~{}", sha256::digest(r.url.to_string()), r.date); - #[allow(clippy::single_match_else)] + #[allow(clippy::single_match_else)] let ld_library_path = match in_non_spec_but_cached_values.get(&key) { Some(ld_library_path) => ld_library_path.clone(), None => { diff --git a/src/tofu.rs b/src/tofu.rs index c40cba1..0e69da6 100644 --- a/src/tofu.rs +++ b/src/tofu.rs @@ -6,7 +6,7 @@ use toml_edit::value; use log::{debug, error, info, warn}; use crate::{ - config::{self, TofuAnysnake2, TofuConfigToml, TofuDevShell}, + config::{self, TofuAnysnake2, TofuConfigToml, TofuDevShell, TofuVCSorDev}, vcs::{self, BranchOrTag, ParsedVCS, TofuVCS}, }; use anysnake2::util::{change_toml_file, get_proxy_req, TomlUpdates}; @@ -61,20 +61,35 @@ impl Tofu for config::ConfigToml { } }; + let parsed_url: config::TofuVCSorDev = { + self.anysnake2 + .url2 + .and_then(|x| { + >::try_into(x).ok() + }) + .expect("Expected to have a completely resolved anysnake2 at this point. Does your anysnake2.toml have a anysnake2.url2 field?") + }; + + let (pre_2_0_url, pre_2_0_rev) = add_pre_2_0_url_and_rev( + &self.anysnake2.url, + &self.anysnake2.rev, + &parsed_url, + self.anysnake2.use_binary, + updates, + ); + Ok(config::TofuConfigToml { anysnake2_toml_path: self.anysnake2_toml_path, anysnake2: { config::TofuAnysnake2 { - url: { - self.anysnake2.url.and_then(|x| x.try_into().ok()).expect( - "Expected to have a completely resolved anysnake2 at this point", - ) - }, - use_binary: self.anysnake2.use_binary, + url: pre_2_0_url, + rev: pre_2_0_rev, + url2: parsed_url, do_not_modify_flake: self.anysnake2.do_not_modify_flake.unwrap_or(false), dtach: self.anysnake2.dtach, } }, + nixpkgs: self.nixpkgs.tofu_to_tag( &["nixpkgs", "url"], updates, @@ -164,6 +179,77 @@ fn add_rpy2_if_missing(python: &mut Option, _updates: &mut TomlU } } +fn add_pre_2_0_url_and_rev( + incoming_pre_2_0_url: &Option, + incoming_rev: &Option, + parsed_url: &TofuVCSorDev, + use_binary: Option, + updates: &mut TomlUpdates, +) -> (String, String) { + let use_binary: bool = use_binary.unwrap_or(match parsed_url { + TofuVCSorDev::Vcs(x) => x.to_string().contains("anysnake2_release_flakes"), + TofuVCSorDev::Dev => config::Anysnake2::default_use_binary(), + }); + + let pre_2_0_url = incoming_pre_2_0_url.clone().unwrap_or_else(|| { + (if use_binary { + "github:TyberiusPrime/anysnake2_release_flakes" + } else { + "github:TyberiusPrime/anysnake2" + }) + .try_into() + .expect("invalid default url") + }); + let pre_2_0_rev = match &parsed_url { + config::TofuVCSorDev::Dev => "dev".to_string(), + config::TofuVCSorDev::Vcs(vcs) => vcs.get_url_rev_branch().1.to_string(), + }; + let mut pre_2_0_url_toml = value(pre_2_0_url.to_string()); + pre_2_0_url_toml + .as_value_mut() + .unwrap() + .decor_mut() + .set_suffix(" # pre 2.0 - 2.0+ uses url2"); + + let mut pre_2_0_rev_toml = value(pre_2_0_rev.to_string()); + pre_2_0_rev_toml + .as_value_mut() + .unwrap() + .decor_mut() + .set_suffix(" # pre 2.0 - 2.0+ uses url2"); + + let update_url = match &incoming_pre_2_0_url { + None => true, + Some(s) => s != pre_2_0_url.as_str(), + }; + if update_url { + updates.push(( + ["anysnake2", "url"] + .iter() + .map(ToString::to_string) + .collect(), + value(pre_2_0_url_toml.as_value().unwrap()), + )); + } + + let update_rev = { + match &incoming_rev { + None => true, + Some(s) => s != pre_2_0_rev.as_str(), + } + }; + if update_rev { + updates.push(( + ["anysnake2", "rev"] + .iter() + .map(ToString::to_string) + .collect(), + value(pre_2_0_rev_toml.as_value().unwrap()), + )); + } + (pre_2_0_url, pre_2_0_rev) +} + fn clone_regex_strings_to_regex( clone_regex: HashMap, ) -> Result> { @@ -436,33 +522,44 @@ impl Tofu for config::MinimalConfigToml { let anysnake = match self.anysnake2 { Some(value) => value, None => config::Anysnake2 { - url: None, - use_binary: config::Anysnake2::default_use_binary(), + //my own cargo version + rev: Some(env!("CARGO_PKG_VERSION").to_string()), + url: Some("github:TyberiusPrime/anysnake2_release_flakes".to_string()), + url2: None, + use_binary: Some(config::Anysnake2::default_use_binary()), do_not_modify_flake: None, dtach: config::Anysnake2::default_dtach(), }, }; - let new_url = match anysnake.url { + let new_url = match anysnake.url2 { Some(config::ParsedVCSorDev::Dev) => config::TofuVCSorDev::Dev, other => { + let base = if let Some(true) = anysnake.use_binary { + "github:TyberiusPrime/anysnake2_release_flakes" + } else { + "github:TyberiusPrime/anysnake2" + }; + let url = match other { Some(config::ParsedVCSorDev::Vcs(vcs)) => vcs, Some(_) => unreachable!(), - None => "github:TyberiusPrime/anysnake2" - .try_into() - .expect("invalid default url"), + None => base.clone().try_into().expect("invalid default url"), }; let new_url = tofu_repo_to_tag( - &["anysnake2", "url"], + &["anysnake2", "url2"], updates, Some(url), - if anysnake.use_binary { - "github:TyberiusPrime/anysnake2_release_flakes" - } else { - "github:TyberiusPrime/anysnake2" - }, + base, r"(\d\.){1,3}", )?; + add_pre_2_0_url_and_rev( + &None, + &None, + &TofuVCSorDev::Vcs(new_url.clone()), + anysnake.use_binary, + updates, + ); + config::TofuVCSorDev::Vcs(new_url) } }; @@ -470,8 +567,15 @@ impl Tofu for config::MinimalConfigToml { Ok(config::TofuMinimalConfigToml { anysnake2_toml_path: self.anysnake2_toml_path, anysnake2: TofuAnysnake2 { - url: new_url, - use_binary: anysnake.use_binary, + url: match &new_url { + config::TofuVCSorDev::Vcs(x) => x.get_url_rev_branch().0, + config::TofuVCSorDev::Dev => "dev".to_string(), + }, + rev: match &new_url { + config::TofuVCSorDev::Vcs(x) => x.get_url_rev_branch().1.to_string(), + config::TofuVCSorDev::Dev => "github:TyberiusPrime/anysnake2".to_string(), + }, + url2: new_url, do_not_modify_flake: anysnake.do_not_modify_flake.unwrap_or(false), dtach: anysnake.dtach, }, diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 21e37bf..16ba5f9 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -654,3 +654,19 @@ fn test_jupyter_kernels() { assert!(stdout.contains("kernels/R")); assert!(stdout.contains("kernels/R")); } + +#[test] +fn test_empty() { + let ((_code, stdout, _stderr), td) = + run_test_tempdir("examples/test_empty", &["run", "--", "bash", "--version"]); + assert!(stdout.contains("GNU bash")); + let generated_anysnake2_toml = td.path().join("anysnake2.toml"); + let read = ex::fs::read_to_string(&generated_anysnake2_toml).unwrap(); + let parsed_toml = read.parse::().unwrap(); + assert!(parsed_toml.contains_key("anysnake2")); + assert!(parsed_toml["anysnake2"]["rev"].as_str().is_some()); + assert!(parsed_toml["anysnake2"]["url2"] + .as_str() + .unwrap() + .starts_with("github:TyberiusPrime/anysnake2_release_flakes")); +}