Skip to content

Commit b4a158f

Browse files
konstinDetachHead
andauthored
Clarify editable install behavior with setuptools and uv (#10888)
* Clarify editable install behavior with setuptools and uv Following a user question in uv (astral-sh/uv#15652), clarify the documentation around editables. From my uv experience, import hooks breaking static type checkers is almost exclusively a setuptools problem (see e.g. astral-sh/uv#1708 (comment) and astral-sh/uv#3898), so I clarified the docs that this is update using uv with setuptools. * Update docs/import-resolution.md Co-authored-by: DetachHead <57028336+DetachHead@users.noreply.github.com> * Remove "generally" --------- Co-authored-by: DetachHead <57028336+DetachHead@users.noreply.github.com>
1 parent d64f3fa commit b4a158f

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

docs/import-resolution.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,27 @@ Pyright uses the following mechanisms (in priority order) to determine which Pyt
4141
3. As a fallback, use the default Python environment (i.e. the one that is invoked when typing `python` in the shell).
4242

4343
### Editable installs
44-
45-
If you want to use static analysis tools with an editable install, you should configure the editable install to use `.pth` files that contain file paths rather than executable lines (prefixed with `import`) that install import hooks. See your package manager’s documentation for details on how to do this. We have provided some basic information for common package managers below.
44+
If you want to use static analysis tools with an editable install, you should configure the editable install to use `.pth` files that contain file paths rather than executable lines (prefixed with `import`) that install import hooks.
4645

4746
Import hooks can provide an editable installation that is a more accurate representation of your real installation. However, because resolving module locations using an import hook requires executing Python code, they are not usable by Pyright and other static analysis tools. Therefore, if your editable install is configured to use import hooks, Pyright will be unable to find the corresponding source files.
4847

49-
#### pip / setuptools
50-
`pip` (`setuptools`) supports two ways to avoid import hooks:
48+
Notably, setuptools uses import hooks by default. For setuptools-based editable installs to be usable with Pyright, setuptools needs to be configured to use path-based `.pth` files through the build frontend.
49+
50+
#### pip with setuptools
51+
`pip` with `setuptools` supports two ways to avoid import hooks:
5152
- [compat mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html#legacy-behavior)
5253
- [strict mode](https://setuptools.pypa.io/en/latest/userguide/development_mode.html#strict-editable-installs)
5354

54-
#### uv
55-
[uv](https://docs.astral.sh/uv/reference/settings/#config-settings) can be
56-
configured to avoid import hooks with
55+
#### uv with setuptools
56+
When using uv with setuptools, uv can be [configured](https://docs.astral.sh/uv/reference/settings/#config-settings) to avoid import hooks:
5757

5858
```toml
5959
[tool.uv]
6060
config-settings = { editable_mode = "compat" }
6161
```
6262

63+
The `uv_build` backend always uses path-based `.pth` files.
64+
6365
#### Hatch / Hatchling
6466
[Hatchling](https://hatch.pypa.io/latest/config/build/#dev-mode) uses path-based `.pth` files by
6567
default. It will only use import hooks if you set `dev-mode-exact` to `true`.

0 commit comments

Comments
 (0)