Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't remove the '.11' from 'python3.11' binary file name #366

Merged
merged 6 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading