Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/test harness #138

Merged
merged 29 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
898510b
feat: initial version of test-harness
tdejager Jun 22, 2023
9aee63a
feat: run in test harness
tdejager Jun 23, 2023
7cd9bdf
Merge branch 'main' into feat/test-harness
tdejager Jun 23, 2023
877c5f1
Merge branch 'main' into feat/test-harness
tdejager Jun 23, 2023
709aa3e
feat: added convenience method for run output
tdejager Jun 23, 2023
dd59d75
fix: add some comments
tdejager Jun 23, 2023
d22153c
Merge branch 'main' into feat/test-harness
tdejager Jun 23, 2023
7b53199
feat: put integration test behind a feature flag
tdejager Jun 23, 2023
6dc2c7d
fix: typo, should be --features
tdejager Jun 23, 2023
48d1339
Merge remote-tracking branch 'upstream/main' into feat/test-harness
baszalmstra Jun 23, 2023
c5bf26e
fix: fmt
tdejager Jun 23, 2023
d5563c9
Merge branch 'main' into feat/test-harness
tdejager Jun 26, 2023
0ea7ff4
fix: set XDG_CACHE_HOME
baszalmstra Jun 26, 2023
6eaa87a
fix: use cross to pass through cache volume
baszalmstra Jun 26, 2023
f11431d
fix: windows test
baszalmstra Jun 26, 2023
39637c4
fix: ensure cache directory exists
baszalmstra Jun 26, 2023
7a9131b
fix: workflow
baszalmstra Jun 26, 2023
b812f5e
fix: mount in right directory
baszalmstra Jun 26, 2023
3993cd1
fix: also passthrough variable
baszalmstra Jun 26, 2023
7bd28ba
wip: changing interface
tdejager Jun 26, 2023
9608ddb
feat: add manifest-path to shell command
ruben-arts Jun 26, 2023
73815f8
feat: remove use of env_current_dir
tdejager Jun 26, 2023
b3c73f8
fix: remove dbg
tdejager Jun 26, 2023
a952de3
Add help to shell command
ruben-arts Jun 26, 2023
bf22696
Add changelog
ruben-arts Jun 26, 2023
797fb50
bump: bump versions to v0.0.4
ruben-arts Jun 26, 2023
92becc4
fix pixi.toml project name on init (#144)
ruben-arts Jun 26, 2023
684a351
fix: change api of pixi controller
tdejager Jun 26, 2023
2ea2930
Merge branch 'main' into feat/test-harness
tdejager Jun 26, 2023
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
13 changes: 11 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ env:
RUSTFLAGS: "-D warnings"
CARGO_TERM_COLOR: always
CICD_INTERMEDIATES_DIR: "_cicd-intermediates"
TEST_FEATURES: "slow_integration_tests"
XDG_CACHE_HOME: ${{ github.workspace }}/.cache

jobs:
check-rustdoc-links:
Expand Down Expand Up @@ -118,7 +120,7 @@ jobs:
- name: Setup | Install cargo-wix [Windows]
continue-on-error: true
# aarch64 is only supported in wix 4.0 development builds
if: matrix.os == 'windows-latest' && matrix.target != 'aarch64-pc-windows-msvc'
if: matrix.job.os == 'windows-latest' && matrix.target != 'aarch64-pc-windows-msvc'
run: cargo install --version 0.3.4 cargo-wix
env:
# cargo-wix does not require static crt
Expand All @@ -130,6 +132,12 @@ jobs:
with:
tool: cross

- name: Ensure cache directory exists
shell: bash
if: matrix.job.os == 'ubuntu-20.04' && matrix.job.use-cross
run: |
mkdir -p ${XDG_CACHE_HOME}

- name: Overwrite build command env variable
if: matrix.job.use-cross
shell: bash
Expand Down Expand Up @@ -211,6 +219,7 @@ jobs:
# test only library unit tests and binary for arm-type targets
unset CARGO_TEST_OPTIONS
unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--bin ${{ needs.crate_metadata.outputs.name }}" ;; esac;
CARGO_TEST_OPTIONS="${CARGO_TEST_OPTIONS} --features ${{ env.TEST_FEATURES }}"
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT

- name: Run tests
Expand Down Expand Up @@ -333,7 +342,7 @@ jobs:

- name: "Artifact upload: windows installer"
continue-on-error: true
if: matrix.os == 'windows-latest' && matrix.job.target != 'aarch64-pc-windows-msvc'
if: matrix.job.os == 'windows-latest' && matrix.job.target != 'aarch64-pc-windows-msvc'
uses: actions/upload-artifact@v3
with:
name: pixi-${{ matrix.job.target }}.msi
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "docs/README.md"
default = ["native-tls"]
native-tls = ["reqwest/native-tls", "rattler_repodata_gateway/native-tls", "rattler/native-tls"]
rustls-tls = ["reqwest/rustls-tls", "rattler_repodata_gateway/rustls-tls", "rattler/rustls-tls"]
slow_integration_tests = []

[dependencies]
anyhow = "1.0.70"
Expand Down
7 changes: 7 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[target.x86_64-unknown-linux-musl.env]
volumes = [
"XDG_CACHE_HOME",
]
passthrough = [
"XDG_CACHE_HOME",
]
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "pixi"
version = "0.0.5"
description = "Package manamgent made easy!"
description = "Package management made easy!"
authors = ["Wolf Vollprecht <wolf@prefix.dev>", "Bas Zalmstra <bas@prefix.dev>", "Tim de Jager <tim@prefix.dev>", "Ruben Arts <ruben@prefix.dev>"]
channels = ["conda-forge"]
platforms = ["linux-64", "win-64", "osx-64", "osx-arm64"]
Expand Down
24 changes: 16 additions & 8 deletions src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::collections::HashMap;
use std::path::PathBuf;

/// Adds a dependency to the project
#[derive(Parser, Debug)]
#[derive(Parser, Debug, Default)]
#[clap(arg_required_else_help = true)]
pub struct Args {
/// Specify the dependencies you wish to add to the project.
Expand All @@ -34,22 +34,27 @@ pub struct Args {
/// Adding multiple dependencies at once is also supported:
///
/// - `pixi add python pytest`: This will add both `python` and `pytest` to the project's dependencies.
specs: Vec<MatchSpec>,
pub specs: Vec<MatchSpec>,

/// The path to 'pixi.toml'
#[arg(long)]
manifest_path: Option<PathBuf>,
pub manifest_path: Option<PathBuf>,
}

pub async fn execute(args: Args) -> anyhow::Result<()> {
let mut project = match args.manifest_path {
Some(path) => Project::load(path.as_path())?,
None => Project::discover()?,
};
add_specs_to_project(&mut project, args.specs).await
}

pub async fn add_specs_to_project(
project: &mut Project,
specs: Vec<MatchSpec>,
) -> anyhow::Result<()> {
// Split the specs into package name and version specifier
let new_specs = args
.specs
let new_specs = specs
.into_iter()
.map(|spec| match &spec.name {
Some(name) => Ok((name.clone(), spec.into())),
Expand Down Expand Up @@ -119,10 +124,14 @@ pub async fn execute(args: Args) -> anyhow::Result<()> {
added_specs.push(spec);
}

// TODO why is this only needed in the test?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this cleared up now?

// project.save()?;
// project.reload()?;

// Update the lock file and write to disk
update_lock_file(
&project,
load_lock_file(&project).await?,
project,
load_lock_file(project).await?,
Some(sparse_repo_data),
)
.await?;
Expand All @@ -135,7 +144,6 @@ pub async fn execute(args: Args) -> anyhow::Result<()> {
spec
);
}

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{fs, path::PathBuf};
pub struct Args {
/// Where to place the project (defaults to current path)
#[arg(default_value = ".")]
path: PathBuf,
pub path: PathBuf,
}

/// The pixi.toml template
Expand Down
24 changes: 15 additions & 9 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::progress;
use anyhow::Error;
use tracing_subscriber::{filter::LevelFilter, util::SubscriberInitExt, EnvFilter};

mod add;
mod auth;
mod global;
mod init;
mod install;
mod run;
mod shell;
pub mod add;
pub mod auth;
pub mod global;
pub mod init;
pub mod install;
pub mod run;
pub mod shell;

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand All @@ -37,7 +37,7 @@ pub struct CompletionCommand {
}

#[derive(Parser, Debug)]
enum Command {
pub enum Command {
Completion(CompletionCommand),
Init(init::Args),
#[clap(alias = "a")]
Expand Down Expand Up @@ -89,7 +89,13 @@ pub async fn execute() -> anyhow::Result<()> {
.finish()
.try_init()?;

match args.command {
// Execute the command
execute_command(args.command).await
}

/// Execute the actual command
pub async fn execute_command(command: Command) -> Result<(), Error> {
match command {
Command::Completion(cmd) => completion(cmd),
Command::Init(cmd) => init::execute(cmd).await,
Command::Add(cmd) => add::execute(cmd).await,
Expand Down
50 changes: 33 additions & 17 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
use std::collections::{HashSet, VecDeque};
use std::path::Path;
use std::string::String;
use std::{fmt::Write, path::PathBuf};

use crate::Project;
use clap::Parser;
use is_executable::IsExecutable;
use rattler_conda_types::Platform;

use crate::command::{CmdArgs, Command, ProcessCmd};
use crate::environment::get_up_to_date_prefix;
use crate::project::environment::add_metadata_as_env_vars;
use rattler_shell::activation::ActivationResult;
use crate::{
command::{CmdArgs, Command, ProcessCmd},
environment::get_up_to_date_prefix,
project::environment::add_metadata_as_env_vars,
Project,
};
use rattler_shell::{
activation::ActivationResult,
activation::{ActivationVariables, Activator},
shell::{Shell, ShellEnum},
};

/// Runs command in project.
#[derive(Parser, Debug)]
#[derive(Parser, Debug, Default)]
#[clap(trailing_var_arg = true, arg_required_else_help = true)]
pub struct Args {
/// The command you want to run in the projects environment.
command: Vec<String>,
pub command: Vec<String>,

/// The path to 'pixi.toml'
#[arg(long)]
manifest_path: Option<PathBuf>,
pub manifest_path: Option<PathBuf>,
}

pub async fn execute(args: Args) -> anyhow::Result<()> {
pub struct RunScriptCommand {
/// The command to execute
pub command: std::process::Command,
/// Tempfile to keep a handle on, otherwise it is dropped and deleted
_script: tempfile::NamedTempFile,
}

pub async fn create_command(args: Args) -> anyhow::Result<RunScriptCommand> {
let command: Vec<_> = args.command.iter().map(|c| c.to_string()).collect();
let project = match args.manifest_path {
Some(path) => Project::load(path.as_path())?,
None => Project::discover()?,
};

// Get the script to execute from the command line.
let (command_name, command) = args
.command
let (command_name, command) = command
.first()
.and_then(|cmd_name| {
project
Expand Down Expand Up @@ -125,12 +134,19 @@ pub async fn execute(args: Args) -> anyhow::Result<()> {
std::io::Write::write_all(&mut temp_file, script.as_bytes())?;

// Execute the script with the shell
let mut command = shell
.create_run_script_command(temp_file.path())
.spawn()
.expect("failed to execute process");
let command = shell.create_run_script_command(temp_file.path());

std::process::exit(command.wait()?.code().unwrap_or(1));
Ok(RunScriptCommand {
command,
_script: temp_file,
})
}

/// CLI entry point for `pixi run`
pub async fn execute(args: Args) -> anyhow::Result<()> {
let mut script_command = create_command(args).await?;
let status = script_command.command.spawn()?.wait()?.code().unwrap_or(1);
std::process::exit(status);
}

/// Given a command and arguments to invoke it, format it so that it is as generalized as possible.
Expand Down
5 changes: 5 additions & 0 deletions src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ pub async fn get_up_to_date_prefix(project: &Project) -> anyhow::Result<Prefix>
Ok(prefix)
}

/// Loads the lockfile for the specified project or returns a dummy one if none could be found.
pub async fn load_lock_for_manifest_path(path: &Path) -> anyhow::Result<CondaLock> {
load_lock_file(&Project::load(path)?).await
}

/// Loads the lockfile for the specified project or returns a dummy one if none could be found.
pub async fn load_lock_file(project: &Project) -> anyhow::Result<CondaLock> {
let lock_file_path = project.lock_file_path();
Expand Down
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub mod cli;
pub mod command;
pub mod config;
pub mod consts;
pub mod environment;
pub mod prefix;
pub mod progress;
pub mod project;
pub mod repodata;
pub mod report_error;
pub mod util;
pub mod virtual_packages;

pub use project::Project;
17 changes: 2 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
use console::style;

mod cli;
mod command;
mod config;
mod consts;
mod environment;
mod prefix;
mod progress;
mod project;
mod repodata;
mod report_error;
mod util;
mod virtual_packages;

pub use project::Project;
use pixi::cli;
use pixi::report_error;

#[tokio::main]
pub async fn main() {
Expand Down
8 changes: 8 additions & 0 deletions src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ impl Project {
})
}

pub fn reload(&mut self) -> anyhow::Result<()> {
let project = Self::load(self.root().join(consts::PROJECT_MANIFEST).as_path())?;
self.root = project.root;
self.doc = project.doc;
self.manifest = project.manifest;
Ok(())
}

/// Loads a project manifest.
pub fn from_manifest_str(root: &Path, contents: impl Into<String>) -> anyhow::Result<Self> {
let contents = contents.into();
Expand Down
Loading