Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions verifier/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
use std::{path::Path, process::Output};

use duct::cmd;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let venv = std::env::current_dir()?.join(".venv");
let venv = std::env::current_dir()?
.canonicalize()
.expect("Failed to determine the canonical form of the current directory path")
.join(".venv");

if venv.try_exists().ok() != Some(true) {
// Create the project-specific Python virtual environment.
println!("Creating the Python virtual environment...");
cmd!("uv", "sync", "--no-install-workspace").run()?;
println!("\n=== Creating the Python virtual environment ===\n");
cmd!("uv", "sync", "--no-install-workspace", "--managed-python")
.stderr_to_stdout()
.run()?;
}

cmd!("uv", "sync", "--all-packages")
// Tell `pyo3` where to find the project-specific
// virtual environment.
.env("VIRTUAL_ENV", &venv)
.run()?;
println!("\n=== Syncing Python packages ===\n");
run_in_venv(
cmd!("uv", "sync", "--all-packages", "--managed-python"),
&venv,
)?;

println!("Testing the Rust crate...");
cmd!("cargo", "test")
// Tell `pyo3` where to find the project-specific
// virtual environment.
.env("VIRTUAL_ENV", venv)
.run()?;
println!("Testing the Python package...");
cmd!("uv", "run", "pytest").run()?;
println!("\n=== Testing the Rust crate ===\n");
run_in_venv(cmd!("cargo", "test"), &venv)?;

println!("\n=== Testing the Python package ===\n");
run_in_venv(cmd!("uv", "run", "--managed-python", "pytest"), &venv)?;

Ok(())
}

/// Execute a command in an environment that's equivalent to what you'd get
/// after activating a Python virtual environment in a shell session via
/// `source .venv/bin/activate`.
fn run_in_venv(command: duct::Expression, venv: &Path) -> std::io::Result<Output> {
let path = {
let old = std::env::var("PATH").unwrap_or_default();
format!("{}:{old}", venv.join("bin").display())
};

command
.stderr_to_stdout()
.env("VIRTUAL_ENV", &venv)
.env("PATH", &path)
.env_remove("PYTHON_HOME")
.run()
}