Skip to content

Commit

Permalink
Update windows-registry to 0.3.0 (#8696)
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin authored Oct 30, 2024
1 parent 4bf01ed commit d0afd10
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
28 changes: 24 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ url = { version = "2.5.2" }
urlencoding = { version = "2.1.3" }
walkdir = { version = "2.5.0" }
which = { version = "6.0.3", features = ["regex"] }
windows-registry = { version = "0.2.0" }
windows-registry = { version = "0.3.0" }
windows-result = { version = "0.2.0" }
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Security", "Win32_Storage_FileSystem", "Win32_System_Ioctl", "Win32_System_IO"] }
winreg = { version = "0.52.0" }
Expand Down
21 changes: 4 additions & 17 deletions crates/uv-python/src/py_launcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::Ordering;
use std::path::PathBuf;
use std::str::FromStr;
use tracing::debug;
use windows_registry::{Key, Value, CURRENT_USER, LOCAL_MACHINE};
use windows_registry::{Key, CURRENT_USER, LOCAL_MACHINE};

/// A Python interpreter found in the Windows registry through PEP 514 or from a known Microsoft
/// Store path.
Expand All @@ -16,15 +16,6 @@ pub(crate) struct WindowsPython {
pub(crate) version: Option<PythonVersion>,
}

/// Adding `windows_registry::Value::into_string()`.
fn value_to_string(value: Value) -> Option<String> {
match value {
Value::String(string) => Some(string),
Value::Bytes(bytes) => String::from_utf8(bytes.clone()).ok(),
Value::U32(_) | Value::U64(_) | Value::MultiString(_) | Value::Unknown(_) => None,
}
}

/// Find all Pythons registered in the Windows registry following PEP 514.
pub(crate) fn registry_pythons() -> Result<Vec<WindowsPython>, windows_result::Error> {
let mut registry_pythons = Vec::new();
Expand Down Expand Up @@ -72,11 +63,10 @@ pub(crate) fn registry_pythons() -> Result<Vec<WindowsPython>, windows_result::E

fn read_registry_entry(company: &str, tag: &str, tag_key: &Key) -> Option<WindowsPython> {
// `ExecutablePath` is mandatory for executable Pythons.
let Some(executable_path) = tag_key
let Ok(executable_path) = tag_key
.open("InstallPath")
.and_then(|install_path| install_path.get_value("ExecutablePath"))
.ok()
.and_then(value_to_string)
.and_then(String::try_from)
else {
debug!(
r"Python interpreter in the registry is not executable: `Software\Python\{}\{}",
Expand All @@ -88,11 +78,8 @@ fn read_registry_entry(company: &str, tag: &str, tag_key: &Key) -> Option<Window
// `SysVersion` is optional.
let version = tag_key
.get_value("SysVersion")
.and_then(String::try_from)
.ok()
.and_then(|value| match value {
Value::String(s) => Some(s),
_ => None,
})
.and_then(|s| match PythonVersion::from_str(&s) {
Ok(version) => Some(version),
Err(err) => {
Expand Down

0 comments on commit d0afd10

Please sign in to comment.