uv: uv's cache blocks setuptools from updating strict-mode editable install sandbox symlinks
Summary
“strict” editable installations for source-layout packages behave as follows (roughly, I might be missing steps!):
- An editable-install directory is created under the source package’s
builddirectory, with a name similar to__editable__.package-0.0.1-py3-none-any. Inside of this directory, 1 symlink is created per source file, that links to the source file contents. (This allows authors to edit source files rapidly without having to deal with the editable install process after the initial setup) - A .pth file is created in the venv’s site packages library directory, that contains the absolute path to the source package’s symlink directory under its
builddirectory.
This structure and definition allows Python and tooling (LSPs etc) to resolve import statements directly into the source directory of a package being developed.
When programmers add new files to their package, or rename files in their package, the symlinks in this special directory must be updated. If a developer renames foo.py to bar.py, they must re-run the editable install process from their package. This allows Python code from other packages to say from package import bar- under the hood, the import resolver lands in package’s symlink directory, and looks for bar.py.
If the symlinks in this directory are not updated, the directory will contain a now-dead symlink to foo.py, and no entry at all for bar.py.
uv pip install -e appears to not invoke setuptools to update this symlink directory when source files are renamed / added / deleted, but pip install -e does.
I’ve created a minimal repro case here: https://github.com/charlesnicholson/uv_editable_install_bug_repro
It defines two packages: repro_p1 and repro_p2. repro_p2 depends on repro_p1.
There are two test scripts that do the same thing, one in pip and one in uv. The steps are:
- Create a venv.
- Editable-install
repro_p1andrepro_p2, with strict mode enabled. - Call a simple function in
repro_p2that calls a simple function inrepro_p1, to show that the packages work. - Print a new source file into the
repro_p1directory, which has another simple function. - Re-run step 2, which should update the symlinks.
- Call a simple function in
repro_p2that calls the new function in the newrepro_p1file
This process succeeds with pip (run ./test_with_pip.sh) and fails with uv (run ./test_with_uv.sh).
I’ve only tested this on macOS, but if it’s helpful I can port this to windows or linux.
pip:
uv:
See how the uv test fails because the repro_p2 script is importing repro_p1’s newly-printed file, for which there exists no entry in the symlink directory.
Note that if you add --force-reinstall to step 5, then step 6 will succeed. But, force-reinstall does a whole lot more than just updating the symlinks, so it’s a reasonable short-term workaround but this still feels like a bug.
Thanks for reading!
Platform
macOS 15.2 arm64
Version
uv 0.5.23
Python version
Python 3.13.1
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 16 (6 by maintainers)
Since this is about a setuptools mode, not a uv mode, I wonder if the ticket should have its title changed.
Also not sure it’s actually uv’s place to warn you about setuptools behaviors, much less attempt to “fix” setuptools, except maybe to the extent that automatically applying some config settings may be apropos for known build backends.
Does the “compat” mode not work for you? I think returning to their previous behavior with that flag is a reasonable option. Otherwise, perhaps a different build backend? I wish they had not introduced a new default mode that’s so antagonistic to static analysis.
See also https://github.com/pypa/setuptools/issues/3518