Repository navigation
Resolve executable symlinks when warming venv interpreter caches - #2548
astral-automations-bot[bot] wants to merge 5 commits into
Conversation
| if links >= 40 { | ||
| return Err( | ||
| io::Error::other("Too many symbolic links in Python executable").into(), | ||
| ); |
There was a problem hiding this comment.
[P2] Preserve successful venv creation at the symlink limit
An installation-local chain of 39 executable symlinks becomes 40 after adding the venv’s bin/python link. I verified that Linux canonicalization and CPython 3.12.14 both accept this environment; CPython falls back when deriving _base_executable. This new error instead propagates through cache_virtualenv to uv venv, making creation of a working environment fail. Match CPython’s fallback at this boundary, or skip cache warming when resolution reaches the limit.
Merging this PR will not alter performance
|
|
NB #2549 is an attempt at a simpler fix here. |
93729c7 to
e3272ea
Compare
de0b2a2 to
2d06bfe
Compare
| executable.pop(); | ||
| executable = uv_fs::normalize_absolute_path(&executable.join(target))?; |
There was a problem hiding this comment.
[P2] Preserve absolute symlink targets during cache inference
CPython’s getpath_realpath preserves absolute symlink targets verbatim and normalizes only relative targets. For example, with /tmp/alias -> /usr/lib, an absolute target /tmp/alias/../bin/python3.12 reaches /usr/bin/python3.12, but this loop changes it to /tmp/bin/python3.12. I reproduced this difference with CPython 3.12.3 and the extracted resolution loop. Cache writing still succeeds because it canonicalizes the original venv executable, leaving a nonexistent base executable in the warmed metadata. Creating another venv from that cached environment then fails, while querying Python gives a working target. Assign absolute targets directly and only join and normalize relative targets.
| executable.pop(); | ||
| uv_fs::normalize_absolute_path(&executable.join(target))? |
There was a problem hiding this comment.
[P2] Skip cache inference when normalization walks above root
A valid relative executable symlink can contain more .. components than its directory depth: POSIX and CPython clamp these at /, but normalize_absolute_path returns InvalidInput. I verified that CPython 3.12 runs such a venv and canonicalization succeeds, while the extracted inference loop errors. For a system interpreter, the earlier home-directory check does not skip this branch, so the error propagates through cache_virtualenv, making uv venv fail after creating a working environment. Return Ok(None) on this normalization failure to use the existing cache-clearing fallback, or match CPython’s root-clamping semantics.
Venv cache warming retained executable symlinks, causing cached and freshly queried base paths to differ. Match CPython’s executable-symlink resolution while preserving parent-directory links, and strengthen the regression to require matching metadata and downstream venv targets. Fixes astral-sh#22383
Stacked on astral-sh#22524.