Skip to content

Commit

Permalink
fix: don't remove the '.11' from 'python3.11' binary file name (#366)
Browse files Browse the repository at this point in the history
closes #317

When a numeric end is found on the binary, we don't remove it.
  • Loading branch information
ruben-arts authored Oct 3, 2023
1 parent e86c761 commit 7d97026
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/cli/global/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7d97026

Please sign in to comment.