diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 19dc4c5a8..4d5b3f4b3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,6 +52,8 @@ Alternatively, you can install `zstandard` from PyPI, then run: python3.12 scripts/bootstrap/install.py ``` +You can configure the bootstrapping directory with `UV_BOOTSTRAP_DIR`. + ### Local testing You can invoke your development version of uv with `cargo run -- `. For example: diff --git a/crates/uv/tests/common/mod.rs b/crates/uv/tests/common/mod.rs index a5e441615..e8b68b63f 100644 --- a/crates/uv/tests/common/mod.rs +++ b/crates/uv/tests/common/mod.rs @@ -14,10 +14,10 @@ use assert_fs::fixture::PathChild; use fs_err::os::unix::fs::symlink as symlink_file; #[cfg(windows)] use fs_err::os::windows::fs::symlink_file; -use platform_host::Platform; use regex::Regex; -use uv_cache::Cache; +use platform_host::Platform; +use uv_cache::Cache; use uv_interpreter::find_requested_python; // Exclude any packages uploaded after this date. @@ -117,14 +117,26 @@ pub fn venv_to_interpreter(venv: &Path) -> PathBuf { /// Python versions are sorted from newest to oldest. pub fn bootstrapped_pythons() -> Option> { // Current dir is `/crates/uv`. - let bootstrapped_pythons = std::env::current_dir() + let project_root = std::env::current_dir() .unwrap() .parent() .unwrap() .parent() .unwrap() - .join("bin") - .join("versions"); + .to_path_buf(); + let boostrap_dir = if let Some(boostrap_dir) = env::var_os("UV_BOOTSTRAP_DIR") { + let boostrap_dir = PathBuf::from(boostrap_dir); + if boostrap_dir.is_absolute() { + boostrap_dir + } else { + // cargo test changes directory to the test crate, but doesn't tell us from where the user is running the + // tests. We'll assume that it's the project root. + project_root.join(boostrap_dir) + } + } else { + project_root.join("bin") + }; + let bootstrapped_pythons = boostrap_dir.join("versions"); let Ok(bootstrapped_pythons) = fs_err::read_dir(bootstrapped_pythons) else { return None; }; diff --git a/scripts/bootstrap/install.py b/scripts/bootstrap/install.py index a79d8554a..8eda4d468 100755 --- a/scripts/bootstrap/install.py +++ b/scripts/bootstrap/install.py @@ -30,6 +30,7 @@ import hashlib import json +import os import platform import shutil import sys @@ -48,7 +49,10 @@ except ImportError: # Setup some file paths THIS_DIR = Path(__file__).parent ROOT_DIR = THIS_DIR.parent.parent -BIN_DIR = ROOT_DIR / "bin" +if bin_dir := os.environ.get("UV_BOOTSTRAP_DIR"): + BIN_DIR = Path(bin_dir) +else: + BIN_DIR = ROOT_DIR / "bin" INSTALL_DIR = BIN_DIR / "versions" VERSIONS_FILE = ROOT_DIR / ".python-versions" VERSIONS_METADATA_FILE = THIS_DIR / "versions.json"