Skip to content

Commit

Permalink
repaired test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Jan 25, 2022
1 parent 0347a03 commit b23bcfa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
2 changes: 1 addition & 1 deletion examples/full/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dppd_plotnine = "editable/code"
# allowing you to specify arbitrary nix sources for a mach-nixbuildPython call.
# for example from github
# (you can leave of the sha256, and copy paste it from the output on first build)
plotnine = {method = "fetchFromGitHub", owner = "has2k1", repo = "plotnine", rev = "6c82cdc20d6f81c96772da73fc07a672a0a0a6ef", sha256="sha256-OllL3ecgs7xwpsglhGl4LzW3zWBXuLlDNn66xVooxvc="}
plotnine = {method = "fetchFromGitHub", owner = "has2k1", repo = "plotnine", rev = "6c82cdc20d6f81c96772da73fc07a672a0a0a6ef", sha256="sha256-OllL3ecgs7xwpsglhGl4LzW3zWBXuLlDNn66xVooxvc=", hash_6c82cdc20d6f81c96772da73fc07a672a0a0a6ef = "sha256-E5nR5xK+sqV3tlxnPDNE0TdTtYtPK47zgwzTG/KmXF0="}
# pandas="<1.0"

[clones.code] # target directory
Expand Down
7 changes: 3 additions & 4 deletions examples/just_python/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ example-cli-python="editable/code"

# and you can fetch from github, git and mercurial (any nix fetcher actually, see
# https://nixos.org/manual/nixpkgs/stable/#chap-pkgs-fetchers)
# if using fetchFromGitHub, the necessary hash will be added to this file
# on a trust-on-first-use-basis

#ugly syntax:
plotnine = {method = "fetchFromGitHub", owner = "has2k1", repo = "plotnine", rev = "6c82cdc20d6f81c96772da73fc07a672a0a0a6ef", hash = "sha256-E5nR5xK+sqV3tlxnPDNE0TdTtYtPK47zgwzTG/KmXF0="}
plotnine = {method = "fetchFromGitHub", owner = "has2k1", repo = "plotnine", rev = "6c82cdc20d6f81c96772da73fc07a672a0a0a6ef"}
# pretty syntax
[python.packages.dppd]
method = "fetchFromGitHub"
owner = "TyberiusPrime"
repo = "dppd"
rev = "b55ac32ef322a8edfc7fa1b6e4553f66da26a156"
hash = "sha256-fyDDeJRbm9hMkefqiyxHazZut38rxgZVcyp+YpUglGI="
#hash = "sha256-fyDDeJRbm9hMkefqiyxHazZut38rxgZVcyp+YpUglGI="
# pandas="<1.0"
2 changes: 1 addition & 1 deletion src/flake_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn write_flake(
None => flake_contents
.replace("\"%MACHNIX%\"", "null")
.replace("%DEVELOP_PYTHON_PATH%", "")
.replace("%%PYTHON_BUILD_PACKAGES%", ""),
.replace("%PYTHON_BUILD_PACKAGES%", ""),
};

flake_contents = match &parsed_config.flakes {
Expand Down
30 changes: 18 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,18 +1400,24 @@ fn apply_trust_on_first_use(
.get("method")
.expect("missing method - should have been caught earlier");
if method == "fetchFromGitHub" {
write = true;
println!("Using Trust-On-First-Use for python package {}, updating your anysnake2.toml", k);

let hash = prefetch_github_hash(
spec.get("owner").expect("missing owner"),
spec.get("repo").expect("missing repo"),
spec.get("rev").expect("missing rev"),
)?;
println!("hash is {}", hash);
let key = k.to_owned();
doc["python"]["packages"][key]["hash"] = value(&hash);
spec.insert("hash".to_string(), hash.to_owned());
let rev = spec.get("rev").expect("missing rev");
let hash_key = format!("hash_{}", rev);
if !spec.contains_key(&hash_key) {
write = true;
println!("Using Trust-On-First-Use for python package {}, updating your anysnake2.toml", k);

let hash = prefetch_github_hash(
spec.get("owner").expect("missing owner"),
spec.get("repo").expect("missing repo"),
rev,
)?;
println!("nix-prefetch-hash for {} is {}", k, hash);
let key = k.to_owned();
doc["python"]["packages"][key][&hash_key] = value(&hash);
spec.insert(hash_key.to_string(), hash.to_owned());
}
spec.insert("hash".to_string(), spec.get(&hash_key).unwrap().to_string());
spec.retain(|key, _| !key.starts_with("hash_"));
}
}
if write {
Expand Down
24 changes: 15 additions & 9 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ fn run_test(cwd: &str, args: &[&str]) -> (i32, String, String) {
(code, stdout.to_string(), stderr.to_string())
}

fn run_test_tempdir(cwd: &str, args: &[&str]) -> (i32, String, String) {
let td = TempDir::new("anysnake_test").expect("could not create tempdir");
std::fs::copy(
PathBuf::from(&cwd).join("anysnake2.toml"),
td.path().join("anysnake2.toml"),
)
.expect("Could not create anysnake2.toml in tempdir");

run_test(&td.path().to_string_lossy(), args)
}

#[test]
fn test_minimal_no_python() {
let (code, _stdout, stderr) =
Expand All @@ -61,21 +72,16 @@ fn test_minimal_bash_version() {
#[test]
fn test_just_python() {
// needs to be copied to test the tofu functionality.
let td = TempDir::new("anysnake_test").expect("could not create tempdir");
std::fs::copy(
"examples/just_python/anysnake2.toml",
td.path().join("anysnake2.toml"),
).expect("Could not create anysnake2.toml in tempdir");
let (_code, stdout, _stderr) = run_test(
&td.path().to_string_lossy(),
let (_code, stdout, _stderr) = run_test_tempdir(
"examples/just_python",
&["run", "--", "python", "--version"],
);
assert!(stdout.contains("3.8.9"));
}

#[test]
fn test_just_python_pandas_version() {
let (_code, stdout, _stderr) = run_test(
let (_code, stdout, _stderr) = run_test_tempdir(
"examples/just_python",
&[
"run",
Expand All @@ -90,7 +96,7 @@ fn test_just_python_pandas_version() {

#[test]
fn test_just_python_venv_bin() {
let (_code, stdout, _stderr) = run_test("examples/just_python", &["run", "--", "hello"]);
let (_code, stdout, _stderr) = run_test_tempdir("examples/just_python", &["run", "--", "hello"]);
assert!(stdout.contains("Argument strings:"));
}

Expand Down

0 comments on commit b23bcfa

Please sign in to comment.