summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuben Arts <ruben.arts@hotmail.com>2023-10-03 09:00:23 +0200
committerGitHub <noreply@github.com>2023-10-03 09:00:23 +0200
commit7d9702669b6318192debc6961404ac2ff8dac57a (patch)
tree253d7a71dfebe0f3de2ec6bafb2721a5d400b656
parente86c7615ef3b78d8f672bb62b2623990d4aa554e (diff)
fix: don't remove the '.11' from 'python3.11' binary file name (#366)
closes https://github.com/prefix-dev/pixi/issues/317 When a numeric end is found on the binary, we don't remove it.
-rw-r--r--src/cli/global/install.rs39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/cli/global/install.rs b/src/cli/global/install.rs
index 1e71e9f..f3b3804 100644
--- a/src/cli/global/install.rs
+++ b/src/cli/global/install.rs
@@ -17,6 +17,7 @@ use rattler_shell::{
shell::ShellEnum,
};
use rattler_solve::{resolvo, SolverImpl};
+use std::ffi::OsStr;
use std::{
path::{Path, PathBuf},
str::FromStr,
@@ -208,12 +209,44 @@ async fn map_executables_to_global_bin_scripts<'a>(
package_executables: &[&'a Path],
bin_dir: &BinDir,
) -> miette::Result<Vec<BinScriptMapping<'a>>> {
+ #[cfg(target_family = "windows")]
+ let extensions_list: Vec<String> = if let Ok(pathext) = std::env::var("PATHEXT") {
+ pathext.split(';').map(|s| s.to_lowercase()).collect()
+ } else {
+ tracing::debug!("Could not find 'PATHEXT' variable, using a default list");
+ [
+ ".COM", ".EXE", ".BAT", ".CMD", ".VBS", ".VBE", ".JS", ".JSE", ".WSF", ".WSH", ".MSC",
+ ".CPL",
+ ]
+ .iter()
+ .map(|&s| s.to_lowercase())
+ .collect()
+ };
+
+ #[cfg(target_family = "unix")]
+ // TODO: Find if there are more relevant cases, these cases are generated by our big friend GPT-4
+ let extensions_list: Vec<String> = vec![
+ ".sh", ".bash", ".zsh", ".csh", ".tcsh", ".ksh", ".fish", ".py", ".pl", ".rb", ".lua",
+ ".php", ".tcl", ".awk", ".sed",
+ ]
+ .iter()
+ .map(|&s| s.to_owned())
+ .collect();
+
let BinDir(bin_dir) = bin_dir;
let mut mappings = vec![];
+
for exec in package_executables.iter() {
- let file_name = exec
- .file_stem()
- .ok_or_else(|| miette::miette!("could not get filename from {}", exec.display()))?;
+ // Remove the extension of a file if it is in the list of known extensions.
+ let Some(file_name) = exec
+ .file_name()
+ .and_then(OsStr::to_str)
+ .map(str::to_lowercase) else { continue; };
+ let file_name = extensions_list
+ .iter()
+ .find_map(|ext| file_name.strip_suffix(ext))
+ .unwrap_or(file_name.as_str());
+
let mut executable_script_path = bin_dir.join(file_name);
if cfg!(windows) {