Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit e3eda5c

Browse files
committed
Move PIXI_BIN_NAME to pixi_utils
1 parent cac2fb5 commit e3eda5c

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pixi_manifest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ indexmap = { workspace = true }
1616
itertools = { workspace = true }
1717
pep440_rs = { workspace = true }
1818
pep508_rs = { workspace = true }
19+
pixi_utils = { workspace = true }
1920
pixi_consts = { workspace = true }
2021
pixi_spec = { workspace = true }
2122
regex = { workspace = true }

crates/pixi_manifest/src/manifests/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl Manifest {
380380
let (Some(name), spec) = spec.clone().into_nameless() else {
381381
miette::bail!(
382382
"{} does not support wildcard dependencies",
383-
consts::PIXI_BIN_NAME.as_str()
383+
pixi_utils::executable_name()
384384
);
385385
};
386386
let spec = PixiSpec::from_nameless_matchspec(spec, channel_config);

crates/pixi_utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fd-lock = { workspace = true }
2828
fs-err = { workspace = true }
2929
indicatif = { workspace = true }
3030
itertools = { workspace = true }
31+
lazy_static = { workspace = true }
3132
miette = { workspace = true }
3233
pep508_rs = { workspace = true }
3334
pixi_config = { workspace = true }

crates/pixi_utils/src/executable_utils.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
use std::path::Path;
1+
use lazy_static::lazy_static;
2+
use std::{ffi::OsStr, path::Path};
3+
4+
lazy_static! {
5+
/// The name of the binary.
6+
pub static ref PIXI_BIN_NAME: String = std::env::args().next()
7+
.as_ref()
8+
.map(Path::new)
9+
.and_then(Path::file_stem)
10+
.and_then(OsStr::to_str)
11+
.map(String::from).unwrap_or("pixi".to_string());
12+
}
13+
14+
/// Returns the name of the binary. Since this is used in errors, it resolves to "pixi" if it can't
15+
/// find the resolve name rather than return an error itself.
16+
pub fn executable_name() -> &'static str {
17+
PIXI_BIN_NAME.as_str()
18+
}
219

320
/// Strips known Windows executable extensions from a file name.
421
pub(crate) fn strip_windows_executable_extension(file_name: String) -> String {

crates/pixi_utils/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ mod prefix_guard;
55
pub mod reqwest;
66

77
mod executable_utils;
8-
pub use executable_utils::{executable_from_path, is_binary_folder, strip_executable_extension};
8+
pub use executable_utils::{
9+
executable_from_path, executable_name, is_binary_folder, strip_executable_extension,
10+
};
911

1012
pub use cache::EnvironmentHash;
1113
pub use prefix_guard::{PrefixGuard, WriteGuard};

src/cli/completion.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn execute(args: Args) -> miette::Result<()> {
8282
/// Generate the completion script using clap_complete for a specified shell.
8383
fn get_completion_script(shell: Shell) -> String {
8484
let mut buf = vec![];
85-
let bin_name: &str = pixi_consts::consts::PIXI_BIN_NAME.as_str();
85+
let bin_name: &str = pixi_utils::executable_name();
8686
clap_complete::generate(shell, &mut CommandArgs::command(), bin_name, &mut buf);
8787
String::from_utf8(buf).expect("clap_complete did not generate a valid UTF8 script")
8888
}
@@ -92,7 +92,7 @@ fn replace_bash_completion(script: &str) -> Cow<str> {
9292
// Adds tab completion to the pixi run command.
9393
// NOTE THIS IS FORMATTED BY HAND
9494
// Replace the '-' with '__' since that's what clap's generator does as well for Bash Shell completion.
95-
let bin_name: &str = pixi_consts::consts::PIXI_BIN_NAME.as_str();
95+
let bin_name: &str = pixi_utils::executable_name();
9696
let clap_name = bin_name.replace("-", "__");
9797
let pattern = format!(r#"(?s){}__run\).*?opts="(.*?)".*?(if.*?fi)"#, &clap_name);
9898
let replacement = r#"CLAP_NAME__run)
@@ -121,7 +121,7 @@ fn replace_zsh_completion(script: &str) -> Cow<str> {
121121
// Adds tab completion to the pixi run command.
122122
// NOTE THIS IS FORMATTED BY HAND
123123
let pattern = r"(?ms)(\(run\))(?:.*?)(_arguments.*?)(\*::task)";
124-
let bin_name: &str = pixi_consts::consts::PIXI_BIN_NAME.as_str();
124+
let bin_name: &str = pixi_utils::executable_name();
125125
let replacement = r#"$1
126126
local tasks
127127
tasks=("$${(@s/ /)$$(BIN_NAME task list --machine-readable 2> /dev/null)}")
@@ -139,7 +139,7 @@ $2::task"#;
139139

140140
fn replace_fish_completion(script: &str) -> Cow<str> {
141141
// Adds tab completion to the pixi run command.
142-
let bin_name = pixi_consts::consts::PIXI_BIN_NAME.as_str();
142+
let bin_name = pixi_utils::executable_name();
143143
let addition = format!("complete -c {} -n \"__fish_seen_subcommand_from run\" -f -a \"(string split ' ' ({} task list --machine-readable 2> /dev/null))\"", bin_name, bin_name);
144144
let new_script = format!("{}{}\n", script, addition);
145145
let pattern = r#"-n "__fish_seen_subcommand_from run""#;
@@ -153,7 +153,7 @@ fn replace_fish_completion(script: &str) -> Cow<str> {
153153
fn replace_nushell_completion(script: &str) -> Cow<str> {
154154
// Adds tab completion to the pixi run command.
155155
// NOTE THIS IS FORMATTED BY HAND
156-
let bin_name = pixi_consts::consts::PIXI_BIN_NAME.as_str();
156+
let bin_name = pixi_utils::executable_name();
157157
let pattern = format!(
158158
r#"(#.*\n export extern "{} run".*\n.*...task: string)([^\]]*--environment\(-e\): string)"#,
159159
bin_name
@@ -216,7 +216,7 @@ _arguments "${_arguments_options[@]}" \
216216
217217
"#;
218218
let result = replace_zsh_completion(script);
219-
let replacement = format!("{} task list", pixi_consts::consts::PIXI_BIN_NAME.as_str());
219+
let replacement = format!("{} task list", pixi_utils::executable_name());
220220
insta::with_settings!({filters => vec![
221221
(replacement.as_str(), "pixi task list"),
222222
]}, {
@@ -273,13 +273,8 @@ _arguments "${_arguments_options[@]}" \
273273
;;
274274
"#;
275275
let result = replace_bash_completion(script);
276-
let replacement = format!("{} task list", pixi_consts::consts::PIXI_BIN_NAME.as_str());
277-
let zsh_arg_name = format!(
278-
"{}__",
279-
pixi_consts::consts::PIXI_BIN_NAME
280-
.as_str()
281-
.replace("-", "__")
282-
);
276+
let replacement = format!("{} task list", pixi_utils::executable_name());
277+
let zsh_arg_name = format!("{}__", pixi_utils::executable_name().replace("-", "__"));
283278
println!("{}", result);
284279
insta::with_settings!({filters => vec![
285280
(replacement.as_str(), "pixi task list"),
@@ -318,11 +313,8 @@ _arguments "${_arguments_options[@]}" \
318313
--help(-h) # Print help (see more with '--help')
319314
]"#;
320315
let result = replace_nushell_completion(script);
321-
let replacement = format!("{} run", pixi_consts::consts::PIXI_BIN_NAME.as_str());
322-
let nu_complete_run = format!(
323-
"nu-complete {} run",
324-
pixi_consts::consts::PIXI_BIN_NAME.as_str()
325-
);
316+
let replacement = format!("{} run", pixi_utils::executable_name());
317+
let nu_complete_run = format!("nu-complete {} run", pixi_utils::executable_name());
326318
println!("{}", result);
327319
insta::with_settings!({filters => vec![
328320
(replacement.as_str(), "[PIXI RUN]"),

src/project/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl Project {
229229
"could not find {} or {} which is configured to use {}",
230230
consts::PROJECT_MANIFEST,
231231
consts::PYPROJECT_MANIFEST,
232-
consts::PIXI_BIN_NAME.as_str()
232+
pixi_utils::executable_name()
233233
);
234234
}
235235

0 commit comments

Comments
 (0)