feat(venv): add relocatable flag (#5515)
## Summary Adds a `--relocatable` CLI arg to `uv venv`. This flag does two things: * ensures that the associated activation scripts do not rely on a hardcoded absolute path to the virtual environment (to the extent possible; `.csh` and `.nu` left as-is) * persists a `relocatable` flag in `pyvenv.cfg`. The flag in `pyvenv.cfg` in turn instructs the wheel `Installer` to create script entrypoints in a relocatable way (use `exec` trick + `dirname $0` on POSIX; use relative path to `python[w].exe` on Windows). Fixes: #3863 ## Test Plan * Relocatable console scripts covered as additional scenarios in existing test cases. * Integration testing of boilerplate generation in `venv`. * Manual testing of `uv venv` with and without `--relocatable`
This commit is contained in:
@@ -1743,6 +1743,22 @@ pub struct VenvArgs {
|
||||
#[arg(long)]
|
||||
pub system_site_packages: bool,
|
||||
|
||||
/// Make the virtual environment relocatable.
|
||||
///
|
||||
/// A relocatable virtual environment can be moved around and redistributed without
|
||||
/// invalidating its associated entrypoint and activation scripts.
|
||||
///
|
||||
/// Note that this can only be guaranteed for standard `console_scripts` and `gui_scripts`.
|
||||
/// Other scripts may be adjusted if they ship with a generic `#!python[w]` shebang,
|
||||
/// and binaries are left as-is.
|
||||
///
|
||||
/// As a result of making the environment relocatable (by way of writing relative, rather than
|
||||
/// absolute paths), the entrypoints and scripts themselves will _not_ be relocatable. In other
|
||||
/// words, copying those entrypoints and scripts to a location outside the environment will not
|
||||
/// work, as they reference paths relative to the environment itself.
|
||||
#[arg(long)]
|
||||
pub relocatable: bool,
|
||||
|
||||
#[command(flatten)]
|
||||
pub index_args: IndexArgs,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user