Skip to content

Commit

Permalink
compability with pre 2.0 versions (auto-version-switch)
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Sep 16, 2024
1 parent 2729af8 commit 565a37c
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 66 deletions.
5 changes: 3 additions & 2 deletions examples/basic/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/dev/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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}'}
Expand Down
2 changes: 1 addition & 1 deletion examples/docker/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/flake_auto_rev/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[anysnake2]
url = "dev"
url2 = "dev"

[nixpkgs]
url = "github:NixOS/nixpkgs/master/24.05"
Expand Down
4 changes: 3 additions & 1 deletion examples/flake_in_non_root_github/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion examples/full/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/github_tarballs_can_be_unstable/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
2 changes: 1 addition & 1 deletion examples/jupyter7/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion examples/just_python/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[anysnake2]
url="dev"
url2="dev"


[nixpkgs]
Expand Down
3 changes: 1 addition & 2 deletions examples/just_python_discover_newest_revision/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/just_python_package_from_pypi/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# see mbf_bam for an example

[anysnake2]
rev = "dev"
url = "github:TyberiusPrime/anysnake2/main/1.15.5"
url2 = "dev"


[nixpkgs]
Expand Down
5 changes: 3 additions & 2 deletions examples/just_python_poetry2nix_escape_hatch/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 1 addition & 2 deletions examples/just_python_trust_on_first_use/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# (example used for testing)
# package settings
[anysnake2]
rev = "dev"
url = "github:TyberiusPrime/anysnake2/main/1.15.5"
url2 = "dev"


[nixpkgs]
Expand Down
2 changes: 1 addition & 1 deletion examples/just_python_trust_on_first_use/test.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions examples/just_r/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
4 changes: 3 additions & 1 deletion examples/minimal/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 1 addition & 2 deletions examples/minimal_rust/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
3 changes: 1 addition & 2 deletions examples/python_310_nixpkgs_2205/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion examples/test_python_pulled_by_other_editable/anysnake2.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
17 changes: 11 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl ConfigToml {
pub fn from_file(config_file: &str) -> Result<ConfigToml> {
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(|| {
Expand Down Expand Up @@ -227,17 +227,22 @@ impl TryFrom<ParsedVCSorDev> for TofuVCSorDev {

#[derive(Deserialize, Debug)]
pub struct Anysnake2 {
pub url: Option<ParsedVCSorDev>,
#[serde(default = "Anysnake2::default_use_binary")]
pub use_binary: bool,
// for pre 2.0 to do the right thing
pub url: Option<String>,
pub rev: Option<String>,
pub use_binary: Option<bool>,
//now the real deal.
pub url2: Option<ParsedVCSorDev>,
pub do_not_modify_flake: Option<bool>,
#[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,
}
Expand Down
37 changes: 27 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -151,11 +154,19 @@ fn handle_config_command(matches: &ArgMatches) -> Result<bool> {
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'");
Expand Down Expand Up @@ -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 {
Expand All @@ -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];
Expand Down Expand Up @@ -652,7 +663,10 @@ fn run_singularity(
dtach_socket: &Option<String>,
flake_dir: &Path,
) -> Result<std::process::ExitStatus> {
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<String> = Vec::new();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 => {
Expand Down
Loading

0 comments on commit 565a37c

Please sign in to comment.