Skip to content

Commit

Permalink
example->python 3.10, allow arbitrary additonal_mkPython_arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Nov 24, 2022
1 parent 149c978 commit 02065d1
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 15 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.9.2"
version = "1.10.0"
authors = ["Florian Finkernagel <[email protected]>"]
edition = "2021"

Expand Down
18 changes: 13 additions & 5 deletions examples/just_python/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
rev = "dev"

[outside_nixpkgs]
rev = "21.05" # the nixpgks version or github hash
rev = "22.05" # the nixpgks version or github hash

[nixpkgs]
# the nixpkgs used inside the container
rev = "21.05" # the nixpgks version or github hash
rev = "22.05" # the nixpgks version or github hash
packages = ["which"]


[python] # python section is optional
version="3.8" # does not go down to 3.8.x. That's implicit in the nixpkgs (for now)
ecosystem_date="2022-02-16" # you get whatever packages the solver would have produced on that day
version="3.10" # does not go down to 3.8.x. That's implicit in the nixpkgs (for now)
ecosystem_date="2022-11-23" # you get whatever packages the solver would have produced on that day

additional_mkpython_arguments = """
providers. platformdirs="nixpkgs";
""" # must be verbatim nix code

[clones.code]
# example-cli-python="git+https://github.com/ojixzzz/example-cli-python"
Expand All @@ -23,9 +27,13 @@ example-cli-python="file://./example-cli-python/"
[python.packages]
# you can use standard python requirements.txt version specification syntax
# i.e. version specifiers from https://www.python.org/dev/peps/pep-0440/#id53
pandas="1.2"
pandas="1.5.1"
# you can refer to the repos you cloned
example-cli-python="editable/code"
black=""
tomli=">1.2"



# and you can fetch from github, git and mercurial (any nix fetcher actually, see
# https://nixos.org/manual/nixpkgs/stable/#chap-pkgs-fetchers)
Expand Down
Empty file.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub struct Python {
pub ecosystem_date: String,
#[serde(deserialize_with = "de_python_package_definition")]
pub packages: HashMap<String, PythonPackageDefinition>,
pub additional_mkpython_arguments: Option<String>,
}

impl Python {
Expand Down
1 change: 1 addition & 0 deletions src/flake_template.nix
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
substituteInPlace 'requirements.txt' --replace 'pytest' ""
'';
%PYTHON_BUILD_PACKAGES%
%PYTHON_ADDITIONAL_MKPYTHON_ARGUMENTS%
};
};
in rec {
Expand Down
11 changes: 9 additions & 2 deletions src/flake_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ pub fn write_flake(
&mut flakes_used_for_python_packages,
)?;

let out_additional_mkpython_arguments =
&python.additional_mkpython_arguments.as_deref().unwrap_or("");

let ecosystem_date = python
.parsed_ecosystem_date()
.context("Failed to parse python.ecosystem-date")?;
Expand All @@ -170,6 +173,10 @@ pub fn write_flake(
//.replace("%PYTHON_MAJOR_MINOR%", &python_major_minor)
.replace("%PYTHON_PACKAGES%", &out_python_packages)
.replace("%PYTHON_BUILD_PACKAGES%", &out_python_build_packages)
.replace(
"%PYTHON_ADDITIONAL_MKPYTHON_ARGUMENTS%",
&&out_additional_mkpython_arguments,
)
.replace("%PYTHON_MAJOR_DOT_MINOR%", &python_major_dot_minor)
.replace("%PYPI_DEPS_DB_REV%", &pypi_debs_db_rev)
.replace(
Expand All @@ -190,7 +197,8 @@ pub fn write_flake(
None => flake_contents
.replace("\"%MACHNIX%\"", "null")
.replace("%DEVELOP_PYTHON_PATH%", "")
.replace("%PYTHON_BUILD_PACKAGES%", ""),
.replace("%PYTHON_BUILD_PACKAGES%", "")
.replace("%PYTHON_ADDITIONAL_MKPYTHON_ARGUMENTS%", ""),
};

flake_contents = match &parsed_config.flakes {
Expand Down Expand Up @@ -460,7 +468,6 @@ fn format_input_defs(inputs: &[InputFlake]) -> String {
let mut iter = fl.url.rsplitn(2, "/");
iter.next(); // eat the branch
iter.collect()

} else {
fl.url.to_string()
};
Expand Down
12 changes: 6 additions & 6 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fn run_test(cwd: &str, args: &[&str]) -> (i32, String, String) {
let p = std::env::current_exe()
.expect("No current exe?")
.parent()
.unwrap()
.expect("no parent")
.parent()
.unwrap()
.expect("no parent parent")
.join("anysnake2");
println!("Current exe {:?}", p);
let mut full_args = vec!["--no-version-switch"];
Expand Down Expand Up @@ -90,7 +90,7 @@ fn test_just_python() {
"examples/just_python",
&["run", "--", "python", "--version"],
);
assert!(stdout.contains("3.8.9"));
assert!(stdout.contains("3.10.4"));

let td_path = td.path().to_string_lossy();

Expand All @@ -105,7 +105,7 @@ fn test_just_python() {
],
);

assert!(stdout.contains("1.2.0"));
assert!(stdout.contains("1.5.1"));

let (_code, stdout, _stderr) = run_test(&td_path, &["run", "--", "hello"]);
dbg!(&stdout);
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_python_pip_reinstall_if_venv_changes() {
run_test_tempdir("examples/just_python", &["run", "--", "cat"]);
println!("first: {}", stdout);
let first =
ex::fs::read_to_string(td.path().join(".anysnake2_flake/venv/3.8/bin/hello")).unwrap();
ex::fs::read_to_string(td.path().join(".anysnake2_flake/venv/3.10/bin/hello")).unwrap();

let toml_path = td.path().join("anysnake2.toml");
let mut toml = ex::fs::read_to_string(&toml_path).unwrap();
Expand All @@ -305,7 +305,7 @@ fn test_python_pip_reinstall_if_venv_changes() {
let (_code, stdout, _stderr) = run_test(&td_path, &["run", "--", "which", "hello"]);
println!("second: {}", stdout);
let second =
ex::fs::read_to_string(td.path().join(".anysnake2_flake/venv/3.8/bin/hello")).unwrap();
ex::fs::read_to_string(td.path().join(".anysnake2_flake/venv/3.10/bin/hello")).unwrap();

let lines_first: Vec<_> = first.split("\n").collect();
let lines_second: Vec<_> = second.split("\n").collect();
Expand Down

0 comments on commit 02065d1

Please sign in to comment.