Skip to content

Commit fdde92b

Browse files
authored
Use path file instead of sitecustomize.py (#7161)
## Summary Use a path file (`.pth`) instead of `sitecustomize.py` for configuring path in emphemeral virtualenvs, overlaying the ephemeral venv on top of the base `.venv`. `sitecustomize.py` is a module in the python installation and as such a unique resource - homebrew pythons on macos already install such a file and thus uv's `sitecustomize.py`, placed in the ephemeral env, did not have any effect. I don't find any documentation explicitly saying that addsitedir is valid in `.pth` files but from trial it seems to be - and there is the precedent of the existing _virtualenv.pth _virtualenv.py pair that do nontrivial operations. ## Test Plan - Testing on ephemeral venv, resolving to base venv including editable install in base: done (py3.7, 3.12) - Testing on homebrew python/macos: done (py3.11) - tests: run_editable Fixes #7152
1 parent 9476196 commit fdde92b

File tree

1 file changed

+4
-2
lines changed
  • crates/uv/src/commands/project

1 file changed

+4
-2
lines changed

crates/uv/src/commands/project/run.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ pub(crate) async fn run(
612612
})
613613
};
614614

615-
// If we're running in an ephemeral environment, add a `sitecustomize.py` to enable loading of
615+
// If we're running in an ephemeral environment, add a path file to enable loading of
616616
// the base environment's site packages. Setting `PYTHONPATH` is insufficient, as it doesn't
617617
// resolve `.pth` files in the base environment.
618+
// And `sitecustomize.py` would be an alternative but it can be shadowed by an existing such
619+
// module in the python installation.
618620
if let Some(ephemeral_env) = ephemeral_env.as_ref() {
619621
let ephemeral_site_packages = ephemeral_env
620622
.site_packages()
@@ -626,7 +628,7 @@ pub(crate) async fn run(
626628
.ok_or_else(|| anyhow!("Base environment has no site packages directory"))?;
627629

628630
fs_err::write(
629-
ephemeral_site_packages.join("sitecustomize.py"),
631+
ephemeral_site_packages.join("_uv_ephemeral_overlay.pth"),
630632
format!(
631633
"import site; site.addsitedir(\"{}\")",
632634
base_site_packages.escape_for_python()

0 commit comments

Comments
 (0)