Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions crates/uv-install-wheel/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn format_shebang(executable: impl AsRef<Path>, os_name: &str, relocatable: bool
// (note: the Windows trampoline binaries natively support relative paths to executable)
if shebang_length > 127 || executable.contains(' ') || relocatable {
let prefix = if relocatable {
r#""$(CDPATH= cd -- "$(dirname -- "$0")" && echo "$PWD")"/"#
r#""$(dirname -- "$(realpath -- "$0")")"/"#
} else {
""
};
Expand Down Expand Up @@ -1019,7 +1019,7 @@ mod test {
let os_name = "posix";
assert_eq!(
format_shebang(executable, os_name, true),
"#!/bin/sh\n'''exec' \"$(CDPATH= cd -- \"$(dirname -- \"$0\")\" && echo \"$PWD\")\"/'python3' \"$0\" \"$@\"\n' '''"
"#!/bin/sh\n'''exec' \"$(dirname -- \"$(realpath -- \"$0\")\")\"/'python3' \"$0\" \"$@\"\n' '''"
);

// Except on Windows...
Expand Down
4 changes: 1 addition & 3 deletions crates/uv-virtualenv/src/virtualenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,7 @@ pub(crate) fn create(

let virtual_env_dir = match (relocatable, name.to_owned()) {
(true, "activate") => {
// Extremely verbose, but should cover all major POSIX shells,
// as well as platforms where `readlink` does not implement `-f`.
r#"'"$(dirname -- "$(CDPATH= cd -- "$(dirname -- "$SCRIPT_PATH")" > /dev/null && echo "$PWD")")"'"#
r#"'"$(dirname -- "$(dirname -- "$(realpath -- "$SCRIPT_PATH")")")"'"#
}
(true, "activate.bat") => r"%~dp0..",
(true, "activate.fish") => {
Expand Down
12 changes: 12 additions & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6810,6 +6810,18 @@ fn install_relocatable() -> Result<()> {
.success()
.stdout(predicate::str::contains("Hello world!"));

// Relocatable entrypoint should still be usable even if symlinked.
// Only testable on POSIX since symlinks require elevated privilege on Windows
#[cfg(unix)]
{
let script_symlink_path = context.temp_dir.join("black");
std::os::unix::fs::symlink(script_path, script_symlink_path.clone())?;
Command::new(script_symlink_path.as_os_str())
.assert()
.success()
.stdout(predicate::str::contains("Hello world!"));
}

Ok(())
}

Expand Down
4 changes: 3 additions & 1 deletion crates/uv/tests/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,9 @@ fn verify_pyvenv_cfg_relocatable() {

let activate_sh = scripts.child("activate");
activate_sh.assert(predicates::path::is_file());
activate_sh.assert(predicates::str::contains(r#"VIRTUAL_ENV=''"$(dirname -- "$(CDPATH= cd -- "$(dirname -- "$SCRIPT_PATH")" > /dev/null && echo "$PWD")")"''"#));
activate_sh.assert(predicates::str::contains(
r#"VIRTUAL_ENV=''"$(dirname -- "$(dirname -- "$(realpath -- "$SCRIPT_PATH")")")"''"#,
));

let activate_bat = scripts.child("activate.bat");
activate_bat.assert(predicates::path::is_file());
Expand Down