Skip to content

Commit b497296

Browse files
zaniebpaveldikov
authored andcommitted
Review
1 parent ee07f64 commit b497296

File tree

8 files changed

+226
-238
lines changed

8 files changed

+226
-238
lines changed

crates/uv-install-wheel/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ uv-normalize = { workspace = true }
2929
uv-pep440 = { workspace = true }
3030
uv-pypi-types = { workspace = true }
3131
uv-shell = { workspace = true }
32+
uv-trampoline-builder = { workspace = true }
3233
uv-warnings = { workspace = true }
3334

3435
clap = { workspace = true, optional = true, features = ["derive"] }
@@ -51,8 +52,6 @@ tracing = { workspace = true }
5152
walkdir = { workspace = true }
5253

5354
[target.'cfg(target_os = "windows")'.dependencies]
54-
uv-trampoline-builder = { workspace = true }
55-
5655
same-file = { workspace = true }
5756
self-replace = { workspace = true }
5857

crates/uv-install-wheel/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ pub enum Error {
8080
MismatchedVersion(Version, Version),
8181
#[error("Invalid egg-link")]
8282
InvalidEggLink(PathBuf),
83-
#[cfg(windows)]
8483
#[error(transparent)]
8584
LauncherError(#[from] uv_trampoline_builder::Error),
8685
#[error("Scripts must not use the reserved name {0}")]

crates/uv-install-wheel/src/wheel.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use uv_fs::{Simplified, persist_with_retry_sync, relative_to};
1717
use uv_normalize::PackageName;
1818
use uv_pypi_types::DirectUrl;
1919
use uv_shell::escape_posix_for_single_quotes;
20+
use uv_trampoline_builder::windows_script_launcher;
2021
use uv_warnings::warn_user_once;
2122

2223
use crate::record::RecordEntry;
@@ -225,18 +226,14 @@ pub(crate) fn write_script_entrypoints(
225226
);
226227

227228
// If necessary, wrap the launcher script in a Windows launcher binary.
228-
#[cfg(windows)]
229-
{
230-
use uv_trampoline_builder::windows_script_launcher;
229+
if cfg!(windows) {
231230
write_file_recorded(
232231
site_packages,
233232
&entrypoint_relative,
234233
&windows_script_launcher(&launcher_python_script, is_gui, &launcher_executable)?,
235234
record,
236235
)?;
237-
}
238-
#[cfg(not(windows))]
239-
{
236+
} else {
240237
write_file_recorded(
241238
site_packages,
242239
&entrypoint_relative,

crates/uv-python/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ uv-pypi-types = { workspace = true }
3434
uv-redacted = { workspace = true }
3535
uv-state = { workspace = true }
3636
uv-static = { workspace = true }
37+
uv-trampoline-builder = { workspace = true }
3738
uv-warnings = { workspace = true }
3839

3940
anyhow = { workspace = true }
@@ -68,8 +69,6 @@ which = { workspace = true }
6869
once_cell = { workspace = true }
6970

7071
[target.'cfg(target_os = "windows")'.dependencies]
71-
uv-trampoline-builder = { workspace = true }
72-
7372
windows-registry = { workspace = true }
7473
windows-result = { workspace = true }
7574
windows-sys = { workspace = true }

crates/uv-python/src/managed.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use uv_platform::{Error as PlatformError, Os};
2020
use uv_platform::{LibcDetectionError, Platform};
2121
use uv_state::{StateBucket, StateStore};
2222
use uv_static::EnvVars;
23+
use uv_trampoline_builder::{Launcher, LauncherKind};
2324

2425
use crate::downloads::{Error as DownloadError, ManagedPythonDownload};
2526
use crate::implementation::{
@@ -92,7 +93,6 @@ pub enum Error {
9293
},
9394
#[error("Failed to find a directory to install executables into")]
9495
NoExecutableDirectory,
95-
#[cfg(windows)]
9696
#[error(transparent)]
9797
LauncherError(#[from] uv_trampoline_builder::Error),
9898
#[error("Failed to read managed Python directory name: {0}")]
@@ -619,13 +619,9 @@ impl ManagedPythonInstallation {
619619
/// Returns `true` if the path is a link to this installation's binary, e.g., as created by
620620
/// [`create_bin_link`].
621621
pub fn is_bin_link(&self, path: &Path) -> bool {
622-
#[cfg(unix)]
623-
{
622+
if cfg!(unix) {
624623
same_file::is_same_file(path, self.executable(false)).unwrap_or_default()
625-
}
626-
#[cfg(windows)]
627-
{
628-
use uv_trampoline_builder::{Launcher, LauncherKind};
624+
} else if cfg!(windows) {
629625
let Some(launcher) = Launcher::try_from_path(path).unwrap_or_default() else {
630626
return false;
631627
};
@@ -637,9 +633,7 @@ impl ManagedPythonInstallation {
637633
// directly.
638634
dunce::canonicalize(&launcher.python_path).unwrap_or(launcher.python_path)
639635
== self.executable(false)
640-
}
641-
#[cfg(not(any(unix, windows)))]
642-
{
636+
} else {
643637
unreachable!("Only Windows and Unix are supported")
644638
}
645639
}
@@ -882,8 +876,7 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
882876
err,
883877
})?;
884878

885-
#[cfg(unix)]
886-
{
879+
if cfg!(unix) {
887880
// Note this will never copy on Unix — we use it here to allow compilation on Windows
888881
match symlink_or_copy_file(executable, link) {
889882
Ok(()) => Ok(()),
@@ -896,9 +889,7 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
896889
err,
897890
}),
898891
}
899-
}
900-
#[cfg(windows)]
901-
{
892+
} else if cfg!(windows) {
902893
use uv_trampoline_builder::windows_python_launcher;
903894

904895
// TODO(zanieb): Install GUI launchers as well
@@ -916,10 +907,8 @@ pub fn create_link_to_executable(link: &Path, executable: &Path) -> Result<(), E
916907
err,
917908
})
918909
}
919-
}
920-
#[cfg(not(any(unix, windows)))]
921-
{
922-
unimplemented!("Only Windows and Unix systems are supported.")
910+
} else {
911+
unimplemented!("Only Windows and Unix are supported.")
923912
}
924913
}
925914

0 commit comments

Comments
 (0)