Skip to content

Commit e5cdb1b

Browse files
committed
Add Pixi support to RunSpec and native executor
- Add pixi field to RunSpec and a builder to set it - Load pixi recipe from assets and run Pixi setup in native executor - Introduce include_asset macro to embed assets and expose it - Extend rfdiffusion to embed its pixi recipe via include_asset - Update Command::cd to take a Path for robust path handling
1 parent a34d62f commit e5cdb1b

File tree

5 files changed

+45
-12
lines changed

5 files changed

+45
-12
lines changed

src/app.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ pub enum MountRole {
6666
pub struct RunSpec {
6767
pub image: Image,
6868
pub args: Vec<String>,
69-
//pub scratch: Option<PathBuf>,
69+
7070
pub mounts: HashMap<MountRole, String>,
71+
72+
pub pixi: Option<String>,
7173
}
7274

7375
impl RunSpec {
@@ -76,6 +78,7 @@ impl RunSpec {
7678
image: Image(image.into()),
7779
args,
7880
mounts: HashMap::new(),
81+
pixi: None,
7982
}
8083
}
8184
pub fn scratch(mut self, p: impl Into<String>) -> Self {
@@ -86,6 +89,11 @@ impl RunSpec {
8689
self.mounts.insert(MountRole::WorkingDir, p.into());
8790
self
8891
}
92+
93+
pub fn pixi(mut self, p: impl Into<String>) -> Self {
94+
self.pixi = Some(p.into());
95+
self
96+
}
8997
}
9098

9199
impl App {

src/app/rfdiffusion.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::app::RunSpec;
1+
use crate::{app::RunSpec, util::include_asset};
22

33
pub fn spec(mut app_args: Vec<String>) -> RunSpec {
44
app_args.splice(
@@ -11,4 +11,5 @@ pub fn spec(mut app_args: Vec<String>) -> RunSpec {
1111
RunSpec::new("rosettacommons/rfdiffusion", app_args)
1212
.scratch("/app/RFdiffusion/schedules")
1313
.working_dir("/w")
14+
.pixi(include_asset!("pixi/rfdiffusion.toml"))
1415
}

src/executor/native.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1+
use anyhow::Context;
12
use anyhow::Result;
23
use anyhow::anyhow;
4+
use home::home_dir;
35
use yansi::Paint;
46

7+
use crate::util::Command;
58
use crate::util::ensure_dir_signature;
69
use crate::{ContainerEngine, app::RunSpec, executor::Executor};
710

811
impl Executor {
9-
pub(super) fn execute_native(&self, _spec: RunSpec) -> Result<()> {
12+
pub(super) fn execute_native(&self, spec: RunSpec) -> Result<()> {
1013
assert!(matches!(self.engine, ContainerEngine::None));
1114

12-
Self::check_if_pixi_is_installed()?;
13-
14-
let pixi_evn_root = self.working_dir.join(format!("{}.pixi", self.app));
15+
let recipe = spec
16+
.pixi
17+
.with_context(|| format!("Pixi recipe for app '{}' was not found", self.app))?;
1518

16-
ensure_dir_signature(&pixi_evn_root, &["qwe", &_spec.image.0], |_d| Ok(()))?;
17-
18-
//write_signature(&self.root, &hash.to_string())?;
19+
Self::check_if_pixi_is_installed()?;
1920

20-
todo!("ContainerEngine::None")
21+
//let pixi_evn_root = self.working_dir.join(format!("{}.pixi", self.app));
22+
let pixi_evn_root = home_dir()
23+
.unwrap()
24+
.join(format!(".cache/rosettacommons/rc/native/{}.pixi", self.app));
25+
26+
ensure_dir_signature(&pixi_evn_root, &[&spec.image.0, &recipe], |d| {
27+
std::fs::write(d.join("pixi.toml"), &recipe)?;
28+
Command::new("pixi")
29+
.cd(d)
30+
.arg("run")
31+
.arg("setup")
32+
.live()
33+
.exec()?;
34+
Ok(())
35+
})?;
36+
37+
Ok(())
2138
}
2239

2340
/// Check if Pixi is installed

src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ pub fn sleep(message: impl AsRef<str>, seconds: usize) {
2929
print!("\r{:width$}\r", "", width = max_len);
3030
io::stdout().flush().unwrap();
3131
}
32+
33+
macro_rules! include_asset {
34+
($path:literal) => {
35+
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/", $path))
36+
};
37+
}
38+
pub(crate) use include_asset;

src/util/command.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::marker::PhantomData;
1+
use std::path::Path;
22
use std::sync::mpsc::Sender;
33
use std::{
44
fmt::{self},
@@ -67,7 +67,7 @@ impl Command {
6767
self
6868
}
6969

70-
pub fn cd(mut self, path: impl AsRef<str>) -> Self {
70+
pub fn cd(mut self, path: impl AsRef<Path>) -> Self {
7171
let path = std::fs::canonicalize(path.as_ref()).unwrap();
7272
self.cd = Some(path);
7373
self

0 commit comments

Comments
 (0)