Skip to content

Commit

Permalink
compatibility with newer mach-nix
Browse files Browse the repository at this point in the history
  • Loading branch information
TyberiusPrime committed Nov 25, 2022
1 parent 02065d1 commit 3bfc8e1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 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.10.0"
version = "1.10.1"
authors = ["Florian Finkernagel <[email protected]>"]
edition = "2021"

Expand Down
10 changes: 5 additions & 5 deletions examples/just_python/anysnake2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ packages = ["which"]


[python] # python section is optional
version="3.10" # does not go down to 3.8.x. That's implicit in the nixpkgs (for now)
version="3.10" # does not go down to 3.x.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
# additional_mkpython_arguments = """
# """ # must be verbatim nix code

[clones.code]
# example-cli-python="git+https://github.com/ojixzzz/example-cli-python"
Expand All @@ -32,12 +31,13 @@ pandas="1.5.1"
example-cli-python="editable/code"
black=""
tomli=">1.2"
hatchling=""



# 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
# if using fetchFromGitHub, the necessary hash will be added to this file
# on a trust-on-first-use-basis


3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ impl Default for MachNix {

impl WithDefaultFlakeSource for MachNix {
fn default_rev() -> String {
"7e14360bde07dcae32e5e24f366c83272f52923f".to_string() // updated 2022-07-11
"913e6c16f986746ba5507878ef7ff992804d1fa8".to_string() //updated 2022-11-25
//"7e14360bde07dcae32e5e24f366c83272f52923f".to_string() // updated 2022-07-11
// "bdc97ba6b2ecd045a467b008cff4ae337b6a7a6b".to_string() // updated 2022-24-01
}
fn default_url() -> String {
Expand Down
50 changes: 39 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ use log::{debug, error, info, trace, warn};
use regex::Regex;
use serde::Deserialize;
use serde_json::json;
use std::borrow::Cow;
use std::io::BufRead;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::{borrow::Cow, ffi::OsStr};
use std::{collections::HashMap, str::FromStr};
use toml_edit::{value, Document, Table};
use url::Url;
Expand Down Expand Up @@ -346,7 +346,7 @@ fn inner_main() -> Result<()> {
configure_logging(&matches);

if handle_config_command(&matches)? {
return Ok(())
return Ok(());
};

let top_level_slop: Vec<&str> = match matches.values_of("slop") {
Expand Down Expand Up @@ -640,7 +640,8 @@ fn inner_main() -> Result<()> {
"ro".to_string(),
));
let egg_link = venv_dir.join(format!("{}.egg-link", safe_pkg));
let egg_target = fs::read_to_string(egg_link)?
let egg_target = fs::read_to_string(egg_link)
.context("could not find egg link")?
.split_once("\n")
.context("No newline in egg-link?")?
.0
Expand Down Expand Up @@ -1262,31 +1263,58 @@ fn fill_venv(
singularity_args.push(flake_dir.join("result/rootfs").to_string_lossy());
singularity_args.push("bash".into());
singularity_args.push("/anysnake2/install.sh".into());
info!("installing inside singularity");
let singularity_result = run_singularity(
&singularity_args[..],
outside_nixpkgs_url,
Some(&venv_dir.join("singularity.bash")),
None,
&flake_dir,
)?;
)
.context("singularity failed")?;
if !singularity_result.success() {
bail!(
"Singularity pip install failed with exit code {}",
singularity_result.code().unwrap()
);
}
// now patch those bin scripts
let target_egg_link = venv_dir.join(format!("{}.egg-link", safe_pkg));
let source_egg_link = td
// now copy the egg/pth files..
// appearntly bin patching is no longer necessary.
let source_egg_folder = td
.path()
.join("venv/lib")
.join(format!("python{}", python_version))
.join("site-packages")
.join(format!("{}.egg-link", &safe_pkg));
fs::write(target_egg_link, ex::fs::read_to_string(source_egg_link)?)?;
.join("site-packages");
let target_egg_link = venv_dir.join(format!("{}.egg-link", safe_pkg));
let paths = fs::read_dir(&source_egg_folder).context("could not read site-packages folder in temp venv")?;
let mut any_found = false;
for path in paths {
let path = path.unwrap().path();
let suffix = path.extension().unwrap_or(OsStr::new("")).to_string_lossy();
if suffix == "pth" || suffix == "egg-link" {
//we want to read {safe_pkg}.egg-link, not __editable__{safe_pkg}-{version}.pth
//because we don't *know* the version
//and this happens only once
fs::write(
target_egg_link,
ex::fs::read_to_string(path).context("Failed reading source link")?,
)?;
any_found = true;
break;
}
}
if !any_found {
let paths = fs::read_dir(source_egg_folder).unwrap();
for path in paths {
let path = path.unwrap().path();
info!("found in venv folder {}", path.display());
}
bail!("Could not find .egg or .pth in venv folder");
}

let target_anysnake_link = venv_dir.join(format!("{}.anysnake-link", safe_pkg));
fs::write(target_anysnake_link, &target_python_str)?;
fs::write(target_anysnake_link, &target_python_str)
.context("target anysnake link write failed")?;

/*keep it here in case we need it again...
* for dir_entry in walkdir::WalkDir::new(td.path()) {
Expand Down

0 comments on commit 3bfc8e1

Please sign in to comment.