Skip to content

Commit e036167

Browse files
committed
use PreferExecutable enum for pixi run
1 parent 1f5811f commit e036167

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

crates/pixi/tests/integration_rust/common/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use pixi_manifest::{EnvironmentName, FeatureName};
3838
use pixi_progress::global_multi_progress;
3939
use pixi_task::{
4040
ExecutableTask, RunOutput, SearchEnvironments, TaskExecutionError, TaskGraph, TaskGraphError,
41-
TaskName, get_task_env,
41+
TaskName, get_task_env, PreferExecutable,
4242
};
4343
use rattler_conda_types::{MatchSpec, ParseStrictness::Lenient, Platform};
4444
use rattler_lock::{LockFile, LockedPackageRef, UrlOrPath};
@@ -591,7 +591,7 @@ impl PixiControl {
591591
.map(|e| e.best_platform())
592592
.or(Some(Platform::current())),
593593
);
594-
let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false, false)
594+
let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false, PreferExecutable::Never)
595595
.map_err(RunError::TaskGraphError)?;
596596

597597
// Iterate over all tasks in the graph and execute them.

crates/pixi_cli/src/run.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use pixi_manifest::{FeaturesExt, TaskName};
2626
use pixi_progress::global_multi_progress;
2727
use pixi_task::{
2828
AmbiguousTask, CanSkip, ExecutableTask, FailedToParseShellScript, InvalidWorkingDirectory,
29-
SearchEnvironments, TaskAndEnvironment, TaskGraph, get_task_env,
29+
SearchEnvironments, TaskAndEnvironment, TaskGraph, get_task_env, PreferExecutable,
3030
};
3131
use rattler_conda_types::Platform;
3232
use thiserror::Error;
@@ -183,9 +183,17 @@ pub async fn execute(args: Args) -> miette::Result<()> {
183183
SearchEnvironments::from_opt_env(&workspace, explicit_environment.clone(), search_platform)
184184
.with_disambiguate_fn(disambiguate_task_interactive);
185185

186-
let task_graph =
187-
TaskGraph::from_cmd_args(&workspace, &search_environment, args.task, args.skip_deps, args.executable)?;
188-
186+
let task_graph = TaskGraph::from_cmd_args(
187+
&workspace,
188+
&search_environment,
189+
args.task,
190+
args.skip_deps,
191+
if args.executable {
192+
PreferExecutable::Always
193+
} else {
194+
PreferExecutable::Never
195+
},
196+
)?;
189197
tracing::debug!("Task graph: {}", task_graph);
190198

191199
// Print dry-run message if dry-run mode is enabled

crates/pixi_task/src/task_graph.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ fn join_args_with_single_quotes<'a>(args: impl IntoIterator<Item = &'a str>) ->
4343
.join(" ")
4444
}
4545

46+
/// Controls whether to prefer resolving commands as executables over Pixi tasks
47+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48+
pub enum PreferExecutable {
49+
/// Always try to resolve as a Pixi task first (default behavior)
50+
Never,
51+
/// Always treat as an executable, skip task resolution
52+
Always,
53+
}
54+
55+
impl Default for PreferExecutable {
56+
fn default() -> Self {
57+
Self::Never
58+
}
59+
}
60+
4661
/// A task ID is a unique identifier for a [`TaskNode`] in a [`TaskGraph`].
4762
///
4863
/// To get a task from a [`TaskGraph`], you can use the [`TaskId`] as an index.
@@ -199,7 +214,7 @@ impl<'p> TaskGraph<'p> {
199214
search_envs: &SearchEnvironments<'p, D>,
200215
args: Vec<String>,
201216
skip_deps: bool,
202-
prefer_executable: bool,
217+
prefer_executable: PreferExecutable,
203218
) -> Result<Self, TaskGraphError> {
204219
// Split 'args' into arguments if it's a single string, supporting commands
205220
// like: `"test 1 == 0 || echo failed"` or `"echo foo && echo bar"` or
@@ -214,7 +229,7 @@ impl<'p> TaskGraph<'p> {
214229
(args, true)
215230
};
216231

217-
if !prefer_executable && let Some(name) = args.first() {
232+
if prefer_executable == PreferExecutable::Never && let Some(name) = args.first() {
218233
match search_envs.find_task(TaskName::from(name.clone()), FindTaskSource::CmdArgs, None)
219234
{
220235
Err(FindTaskError::MissingTask(_)) => {}
@@ -639,7 +654,7 @@ mod test {
639654
&search_envs,
640655
run_args.iter().map(|arg| arg.to_string()).collect(),
641656
skip_deps,
642-
false,
657+
PreferExecutable::Never,
643658
)
644659
.unwrap();
645660

0 commit comments

Comments
 (0)