Skip to content

Commit

Permalink
sorting flakes in the output flake
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Dec 13, 2021
1 parent 331fb30 commit 2dd0de1
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anysnake2"
version = "1.0.5"
version = "1.0.6"
authors = ["Florian Finkernagel <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 2 additions & 0 deletions examples/flake_in_non_root_github/no-home/.bash_history
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ fastq-dump --version
vdb-config --interactive
fastq-dump --version
fastq-dump --version
fastq-dump --version
fastq-dump --version
4 changes: 3 additions & 1 deletion examples/full/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ packages = [
# you can use an url like $ANYSNAKE2_ROOT/path/to/flake for local flakes
# $ANYSNAKE2_ROOT will be replaced by abspath('anysnake2.toml') (or whatever your config file is)
follows = ["nixpkgs"] # so we overwrite the flakes dependencies
packages = ["defaultPackage.x86_64-linux"]
# default packages is ["defaultPackage.x86_64-linux"],
# in which case you can ommit this entry
#packages = ["defaultPackage.x86_64-linux"]

[rust]
# version/rust section is optional. leave of for no rust
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,17 @@ pub struct Flake {
pub url: String,
pub rev: String,
pub follows: Option<Vec<String>>,
#[serde(default = "Flake::default_packages")]
pub packages: Vec<String>,
}

impl Flake {
fn default_packages() -> Vec<String> {
vec!["defaultPackage.x86_64-linux".to_string()]
}

}

#[derive(Deserialize, Debug)]
pub struct Container {
pub home: Option<String>,
Expand Down
11 changes: 5 additions & 6 deletions src/flake_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ pub fn write_flake(
flake_contents = match &parsed_config.flakes {
Some(flakes) => {
let mut flake_packages = "".to_string();
for (name, flake) in flakes.iter() {
let mut names: Vec<&String> = flakes.keys().collect();
names.sort();
for name in names {
let flake = flakes.get(name).unwrap();
let rev_follows: Vec<&str> = match &flake.follows {
Some(f) => f.iter().map(|x| &x[..]).collect(),
None => Vec::new(),
Expand Down Expand Up @@ -400,11 +403,7 @@ fn format_input_defs(inputs: &[InputFlake]) -> String {
url = \"{}{}rev={}\";
{}
}};",
fl.name,
fl.url,
if !fl.url.contains("?") { "?" } else { "&" },
fl.rev,
&str_follows
fl.name, fl.url,if !fl.url.contains("?") {"?"} else {"&"}, fl.rev, &str_follows
))
}
out
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,11 @@ use url::Url;
*
* * test hg?rev=xyz clone
* * test wrong urls (no git+, etc)
* unify tests on the same flake
*/

mod config;
mod flake_writer;
#[cfg(test)]
mod integration_tests;
mod maps_duplicate_key_is_error;
mod python_parsing;

Expand Down
49 changes: 36 additions & 13 deletions src/integration_tests.rs → tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ fn run_test(cwd: &str, args: &[&str]) -> (i32, String, String) {
std::fs::remove_file(result_dir).unwrap();
}



let p = std::env::current_exe()
.expect("No current exe?")
.parent()
.unwrap()
.parent()
.unwrap()
.join("anysnake2");
println!("Current exe {:?}", p);
let mut full_args = vec!["--no-version-switch"];
full_args.extend(args);
let output = Command::new(p)
Expand Down Expand Up @@ -158,12 +161,12 @@ fn test_full() {
.current_dir("examples/full/code/dppd_plotnine")
.output()
.expect("git log failed");
assert!(std::str::from_utf8(&out.stdout)
.unwrap()
.split('\n')
.next()
.unwrap()
.contains("8ed7651af759f3f0b715a2fbda7bf5119f7145d7"))
assert!(std::str::from_utf8(&out.stdout).unwrap().split('\n')
.next().unwrap().contains("8ed7651af759f3f0b715a2fbda7bf5119f7145d7"))




}

#[test]
Expand All @@ -172,13 +175,11 @@ fn test_full_r_packages() {
let _guad = lock.lock().unwrap();

rm_clones("examples/full");
let (_code, stdout, _stderr) = run_test(
"examples/full",
&["run", "--", "R", "-e", "'library(ACA);sessionInfo();'"],
);
let (_code, stdout, _stderr) = run_test("examples/full", &["run", "--", "R", "-e", "'library(ACA);sessionInfo();'"]);
assert!(stdout.contains("ACA_1.1"));
}


#[test]
fn test_full_hello() {
let lock = NamedLock::create("anysnaketest_full").unwrap();
Expand Down Expand Up @@ -212,26 +213,48 @@ fn test_full_rpy2_sitepaths() {
let _guad = lock.lock().unwrap();

rm_clones("examples/full");
let (_code, stdout, _stderr) = run_test("examples/full", &["test_rpy2"]);
let (_code, stdout, _stderr) = run_test(
"examples/full",
&[
"test_rpy2"
],
);
assert!(stdout.contains("Rcpp_1.0.7"));
assert!(!stdout.contains("Rcpp_1.0.5"));
assert!(stdout.contains("ACA_1.1"));
}


#[test]
fn test_just_r() {

let (_code, stdout, _stderr) = run_test(
"examples/just_r",
&["run", "--", "R", "-e", "'library(Rcpp); sessionInfo()'"],
&[
"run",
"--",
"R",
"-e",
"'library(Rcpp); sessionInfo()'"
],
);
assert!(stdout.contains("Rcpp_1.0.7"));
}


#[test]
fn test_flake_with_dir() {

let (_code, stdout, _stderr) = run_test(
"examples/flake_in_non_root_github",
&["run", "--", "fastq-dump", "--version"],
&[
"run",
"--",
"fastq-dump",
"--version",
],
);
assert!(stdout.contains("\"fastq-dump\" version 2.11.2"));
}


0 comments on commit 2dd0de1

Please sign in to comment.