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

Only print tasks on pixi run #493

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rattler_conda_types::Platform;
use crate::prefix::Prefix;
use crate::progress::await_in_progress;
use crate::project::environment::get_metadata_env;
use crate::task::{quote_arguments, CmdArgs, Execute, Task};
use crate::task::{quote_arguments, CmdArgs, Custom, Task};
use crate::{environment::get_up_to_date_prefix, Project};
use rattler_shell::{
activation::{ActivationVariables, Activator, PathModificationBehavior},
Expand Down Expand Up @@ -88,9 +88,8 @@ pub fn order_tasks(
.unwrap_or_else(|| {
(
None,
Execute {
Custom {
cmd: CmdArgs::from(tasks),
depends_on: vec![],
cwd: Some(env::current_dir().unwrap_or(project.root().to_path_buf())),
}
.into(),
Expand Down Expand Up @@ -232,11 +231,11 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let ctrl_c = tokio::spawn(async { while tokio::signal::ctrl_c().await.is_ok() {} });
let script = create_script(&command, arguments).await?;

// Showing which command is being run if the level allows it. (default should be yes)
if tracing::enabled!(Level::WARN) {
// Showing which command is being run if the level and type allows it.
if tracing::enabled!(Level::WARN) && !matches!(command, Task::Custom(_)) {
eprintln!(
"{}{}",
console::style("✨ Pixi running: ").bold(),
console::style("✨ Pixi task: ").bold(),
console::style(
&command
.as_single_command()
Expand Down
3 changes: 2 additions & 1 deletion src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub struct Project {
pub manifest: ProjectManifest,
}

/// Returns a task a a toml item
/// Returns a task as a toml item
fn task_as_toml(task: Task) -> Item {
match task {
Task::Plain(str) => Item::Value(str.into()),
Expand Down Expand Up @@ -96,6 +96,7 @@ fn task_as_toml(task: Task) -> Item {
);
Item::Value(Value::InlineTable(table))
}
_ => Item::None,
}
}

Expand Down
32 changes: 27 additions & 5 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ pub enum Task {
Plain(String),
Execute(Execute),
Alias(Alias),
// We don't what a way for the deserializer to except a custom task, as they are meant for tasks given in the command line.
#[serde(skip)]
Custom(Custom),
}

impl Task {
/// Returns the names of the task that this task depends on
pub fn depends_on(&self) -> &[String] {
match self {
Task::Plain(_) => &[],
Task::Plain(_) | Task::Custom(_) => &[],
Task::Execute(cmd) => &cmd.depends_on,
Task::Alias(cmd) => &cmd.depends_on,
}
Expand Down Expand Up @@ -51,15 +54,16 @@ impl Task {
/// Returns true if this task is directly executable
pub fn is_executable(&self) -> bool {
match self {
Task::Plain(_) | Task::Execute(_) => true,
Task::Plain(_) | Task::Custom(_) | Task::Execute(_) => true,
Task::Alias(_) => false,
}
}

/// Returns the command to execute.
pub fn as_command(&self) -> Option<CmdArgs> {
match self {
Task::Plain(cmd) => Some(CmdArgs::Single(cmd.clone())),
Task::Plain(str) => Some(CmdArgs::Single(str.clone())),
Task::Custom(custom) => Some(custom.cmd.clone()),
Task::Execute(exe) => Some(exe.cmd.clone()),
Task::Alias(_) => None,
}
Expand All @@ -68,7 +72,8 @@ impl Task {
/// Returns the command to execute as a single string.
pub fn as_single_command(&self) -> Option<Cow<str>> {
match self {
Task::Plain(cmd) => Some(Cow::Borrowed(cmd)),
Task::Plain(str) => Some(Cow::Borrowed(str)),
Task::Custom(custom) => Some(custom.cmd.as_single()),
Task::Execute(exe) => Some(exe.cmd.as_single()),
Task::Alias(_) => None,
}
Expand All @@ -78,7 +83,8 @@ impl Task {
pub fn working_directory(&self) -> Option<&Path> {
match self {
Task::Plain(_) => None,
Task::Execute(t) => t.cwd.as_deref(),
Task::Custom(custom) => custom.cwd.as_deref(),
Task::Execute(exe) => exe.cwd.as_deref(),
Task::Alias(_) => None,
}
}
Expand Down Expand Up @@ -108,6 +114,22 @@ impl From<Execute> for Task {
}
}

/// A custom command script executes a single command in the environment
#[derive(Debug, Clone)]
pub struct Custom {
/// A list of arguments, the first argument denotes the command to run. When deserializing both
/// an array of strings and a single string are supported.
pub cmd: CmdArgs,

/// The working directory for the command relative to the root of the project.
pub cwd: Option<PathBuf>,
}
impl From<Custom> for Task {
fn from(value: Custom) -> Self {
Task::Custom(value)
}
}

#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum CmdArgs {
Expand Down