Skip to content

Commit

Permalink
clippy!
Browse files Browse the repository at this point in the history
flexatone committed Jan 8, 2025
1 parent 638b9b6 commit fbdebb7
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/exe_search.rs
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ fn get_search_origins() -> HashSet<(PathBuf, bool)> {

// Return True if the path points to a python executable. We assume this has already been proven to exist.
fn is_exe(path: &Path) -> bool {
return match path.file_name().and_then(|f| f.to_str()) {
match path.file_name().and_then(|f| f.to_str()) {
Some(file_name) if file_name.starts_with("python") => {
let suffix = &file_name[6..];
if suffix.is_empty() || suffix.chars().all(|c| c.is_ascii_digit() || c == '.')
@@ -95,7 +95,7 @@ fn is_exe(path: &Path) -> bool {
}
}
_ => false,
};
}
}

fn is_symlink(path: &Path) -> bool {
@@ -109,13 +109,13 @@ const PY_SYS_EXE: &str = "import sys;print(sys.executable)";

// Use the default Python to get its executable path.
fn get_exe_default() -> Option<PathBuf> {
return match Command::new("python3").arg("-c").arg(PY_SYS_EXE).output() {
match Command::new("python3").arg("-c").arg(PY_SYS_EXE).output() {
Ok(output) => match std::str::from_utf8(&output.stdout) {
Ok(s) => Some(PathBuf::from(s.trim())),
Err(_) => None,
},
Err(_) => None,
};
}
}
/// Try to find all Python executables given a starting directory. This will recursively search all directories that are not symlinks.
fn find_exe_inner(
7 changes: 3 additions & 4 deletions src/scan_fs.rs
Original file line number Diff line number Diff line change
@@ -35,13 +35,12 @@ pub(crate) enum Anchor {
}

//------------------------------------------------------------------------------
/// Given a path to a Python binary, call out to Python to get all known site packages; some site packages may not exist; we do not filter them here. This will include "dist-packages" on Linux. If `force_usite` is false, we use ENABLE_USER_SITE to determine if we should include the user site packages; if `force_usite` is true, we always include usite.
const PY_SITE_PACKAGES: &str = "import site;print(site.ENABLE_USER_SITE);print(\"\\n\".join(site.getsitepackages()));print(site.getusersitepackages())";

/// Given a path to a Python binary, call out to Python to get all known site packages; some site packages may not exist; we do not filter them here. This will include "dist-packages" on Linux. If `force_usite` is false, we use ENABLE_USER_SITE to determine if we should include the user site packages; if `force_usite` is true, we always include usite.
fn get_site_package_dirs(executable: &Path, force_usite: bool) -> Vec<PathShared> {
// let py = "import site;print(site.ENABLE_USER_SITE);print(\"\\n\".join(site.getsitepackages()));print(site.getusersitepackages())";
return match Command::new(executable)
match Command::new(executable)
.arg("-c")
.arg(PY_SITE_PACKAGES)
.output()
@@ -70,7 +69,7 @@ fn get_site_package_dirs(executable: &Path, force_usite: bool) -> Vec<PathShared
eprintln!("Failed to execute command with {:?}: {}", executable, e); // log this
Vec::with_capacity(0)
}
};
}
}

// Given a package directory, collect the name of all packages.

0 comments on commit fbdebb7

Please sign in to comment.