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!):

  1. An editable-install directory is created under the source package’s build directory, 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)
  2. 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 build directory.

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:

  1. Create a venv.
  2. Editable-install repro_p1 and repro_p2, with strict mode enabled.
  3. Call a simple function in repro_p2 that calls a simple function in repro_p1, to show that the packages work.
  4. Print a new source file into the repro_p1 directory, which has another simple function.
  5. Re-run step 2, which should update the symlinks.
  6. Call a simple function in repro_p2 that calls the new function in the new repro_p1 file

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: Image

uv: Image

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)

Most upvoted comments

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