Skip to content

Commit

Permalink
Remove win-specific deps
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 3, 2024
1 parent 58ee578 commit f3b4dc0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 53 additions & 5 deletions crates/uv-fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,67 @@ pub fn canonicalize_executable(path: impl AsRef<Path>) -> std::io::Result<PathBu
let path = path.as_ref();
match fs_err::canonicalize(path) {
Ok(path) => Ok(path),
Err(err) => {
Err(err) => {
if cfg!(windows) {
if path.is_absolute() {
if path.components().any(|component| component.as_os_str() == "Microsoft") {
return Ok(path.to_path_buf());
}
if is_windows_store_python(path) {
return Ok(path.to_path_buf());
}
}
Err(err)
}
}
}

/// Returns `true` if this is a Python executable installed via the Windows Store, like:
///
/// `C:\Users\crmar\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.11_qbs5n2kfra8p0\python.exe`.
fn is_windows_store_python(path: &Path) -> bool {
if cfg!(windows) {
if path.is_absolute() {
let mut components = path.components().rev();

// Ex) `python.exe`
if !components
.next()
.and_then(|component| component.as_os_str().to_str())
.is_some_and(|component| component.starts_with("python"))
{
return false;
}

// Ex) `PythonSoftwareFoundation.Python.3.11_qbs5n2kfra8p0`
if !components
.next()
.and_then(|component| component.as_os_str().to_str())
.is_some_and(|component| {
component.starts_with("PythonSoftwareFoundation.Python.3.")
})
{
return false;
}

// Ex) `WindowsApps`
if !components
.next()
.is_some_and(|component| component.as_os_str() == "WindowsApps")
{
return false;
}

// Ex) `Microsoft`
if !components
.next()
.is_some_and(|component| component.as_os_str() == "Microsoft")
{
return false;
}

return true;
}
}
false
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 0 additions & 1 deletion crates/uv-virtualenv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ thiserror = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, optional = true }
which = { workspace = true }
windows-sys = "0.52.0"

[features]
cli = ["clap", "tracing-subscriber"]
2 changes: 1 addition & 1 deletion crates/uv-virtualenv/src/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::env;
use std::env::consts::EXE_SUFFIX;
use std::io;
use std::io::{BufWriter, Write};
use std::path::{Path, PathBuf};
use std::path::Path;

use fs_err as fs;
use fs_err::File;
Expand Down

0 comments on commit f3b4dc0

Please sign in to comment.