feat: add executable flag to pixi run#5253
Conversation
| .or(Some(Platform::current())), | ||
| ); | ||
| let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false) | ||
| let task_graph = TaskGraph::from_cmd_args(&project, &search_env, args.task, false, false) |
There was a problem hiding this comment.
This is a bit of an anti-pattern. If we have multiple booleans as arguments it becomes hard to distinguish what the false indicates. Instead its good practice to introduce an enum. E.g. PreferExecutable with variants like Always, Never, IfNoTask or something along those lines.
There was a problem hiding this comment.
Thanks for the suggestion! I've updated the implementation to use a PreferExecutable enum with Never and Always variants instead of bool. I didn't include an IfNoTask variant since that behavior is already the default when using PreferExecutable::Never the code naturally falls back to executing the command when no matching task is found.
e036167 to
93a8394
Compare
93a8394 to
b267802
Compare
crates/pixi_task/src/task_graph.rs
Outdated
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum PreferExecutable { | ||
| /// Always try to resolve as a Pixi task first (default behavior) | ||
| Never, |
There was a problem hiding this comment.
Is this correct? The implementation would suggest it falls back to executing an executable. With Never I would suspect that only tasks are run.
There was a problem hiding this comment.
You’re right the current implementation falls back to executing it as an executable if no task exists. I’ll rename the enum to something clearer like TaskFirst to better reflect the actual behavior.
crates/pixi_cli/src/run.rs
Outdated
| /// Prefer running the command as an executable instead of a Pixi task | ||
| /// when both share the same name. Short: -x |
There was a problem hiding this comment.
| /// Prefer running the command as an executable instead of a Pixi task | |
| /// when both share the same name. Short: -x | |
| /// Execute command without matching with a task name. | |
| /// | |
| /// Usefull when a task name and an executable have the same name. |
I feel that "prefer" sends a signal that it might still use tasks. But IIUC it will not try any task logic anymore.
crates/pixi_task/src/task_graph.rs
Outdated
| /// Controls whether to prefer resolving commands as executables over Pixi tasks | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum PreferExecutable { | ||
| /// Try to resolve as a Pixi task first, fall back to executable if no task found (default) | ||
| TaskFirst, | ||
| /// Always treat as an executable, skip task resolution | ||
| Always, | ||
| } | ||
|
|
||
| impl Default for PreferExecutable { | ||
| fn default() -> Self { | ||
| Self::TaskFirst | ||
| } | ||
| } |
There was a problem hiding this comment.
| /// Controls whether to prefer resolving commands as executables over Pixi tasks | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | |
| pub enum PreferExecutable { | |
| /// Try to resolve as a Pixi task first, fall back to executable if no task found (default) | |
| TaskFirst, | |
| /// Always treat as an executable, skip task resolution | |
| Always, | |
| } | |
| impl Default for PreferExecutable { | |
| fn default() -> Self { | |
| Self::TaskFirst | |
| } | |
| } | |
| /// Controls whether to prefer resolving commands as executables over Pixi tasks | |
| #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] | |
| pub enum PreferExecutable { | |
| /// Try to resolve as a Pixi task first, fall back to executable if no task found | |
| #[default] | |
| TaskFirst, | |
| /// Always treat as an executable, skip task resolution | |
| Always, | |
| } |
Rust (>1.62) has the ability to use the default derive so you don't have to write the default implementation yourself. We try to use this as much as possible
crates/pixi_task/src/task_graph.rs
Outdated
| &search_envs, | ||
| run_args.iter().map(|arg| arg.to_string()).collect(), | ||
| skip_deps, | ||
| PreferExecutable::TaskFirst, |
There was a problem hiding this comment.
It would be good to add a test to check if the logic keeps working when you set it to always.
|
@ruben-arts thanks for the review! I have addressed all the comments. |
ruben-arts
left a comment
There was a problem hiding this comment.
Thank you! It works for me now!
|
As all @baszalmstra 's reviews are processed I'm merging this in. |
Description
Adds a
--executable(-x) flag topixi runto allow running executables even when a task with the same name exists.Fixes #5128
How Has This Been Tested?
AI Disclosure
Tools: {e.g., Claude, Codex, GitHub Copilot, ChatGPT, etc.}
Checklist:
schema/model.py.