Respect [tool.uv.sources] in build requirements (#7172)

## Summary

We weren't respecting `tool.uv.sources` for `build-requires`.

Closes https://github.com/astral-sh/uv/issues/7147.
This commit is contained in:
Charlie Marsh
2024-10-15 11:31:04 -04:00
committed by GitHub
parent 0943144cf5
commit 855c1917e1
15 changed files with 459 additions and 65 deletions
+67 -27
View File
@@ -323,6 +323,73 @@ To add a development dependency, include the `--dev` flag:
$ uv add ruff --dev
```
## Build dependencies
If a project is structured as [Python package](./projects.md#build-systems), it may declare
dependencies that are required to build the project, but not required to run it. These dependencies
are specified in the `[build-system]` table under `build-system.requires`, following
[PEP 518](https://peps.python.org/pep-0518/).
For example, if a project uses `setuptools` as its build backend, it should declare `setuptools` as
a build dependency:
```toml title="pyproject.toml"
[project]
name = "pandas"
version = "0.1.0"
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
```
By default, uv will respect `tool.uv.sources` when resolving build dependencies. For example, to use
a local version of `setuptools` for building, add the source to `tool.uv.sources`:
```toml title="pyproject.toml"
[project]
name = "pandas"
version = "0.1.0"
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
[tool.uv.sources]
setuptools = { path = "./packages/setuptools" }
```
When publishing a package, we recommend running `uv build --no-sources` to ensure that the package
builds correctly when `tool.uv.sources` is disabled, as is the case when using other build tools,
like [`pypa/build`](https://github.com/pypa/build).
## Editable dependencies
A regular installation of a directory with a Python package first builds a wheel and then installs
that wheel into your virtual environment, copying all source files. When the package source files
are edited, the virtual environment will contain outdated versions.
Editable installations solve this problem by adding a link to the project within the virtual
environment (a `.pth` file), which instructs the interpreter to include the source files directly.
There are some limitations to editables (mainly: the build backend needs to support them, and native
modules aren't recompiled before import), but they are useful for development, as the virtual
environment will always use the latest changes to the package.
uv uses editable installation for workspace packages by default.
To add an editable dependency, use the `--editable` flag:
```console
$ uv add --editable ./path/foo
```
Or, to opt-out of using an editable dependency in a workspace:
```console
$ uv add --no-editable ./path/foo
```
## PEP 508
[PEP 508](https://peps.python.org/pep-0508/) defines a syntax for dependency specification. It is
@@ -355,30 +422,3 @@ Markers are combined with `and`, `or`, and parentheses, e.g.,
`aiohttp >=3.7.4,<4; (sys_platform != 'win32' or implementation_name != 'pypy') and python_version >= '3.10'`.
Note that versions within markers must be quoted, while versions _outside_ of markers must _not_ be
quoted.
## Editable dependencies
A regular installation of a directory with a Python package first builds a wheel and then installs
that wheel into your virtual environment, copying all source files. When the package source files
are edited, the virtual environment will contain outdated versions.
Editable installations solve this problem by adding a link to the project within the virtual
environment (a `.pth` file), which instructs the interpreter to include the source files directly.
There are some limitations to editables (mainly: the build backend needs to support them, and native
modules aren't recompiled before import), but they are useful for development, as the virtual
environment will always use the latest changes to the package.
uv uses editable installation for workspace packages by default.
To add an editable dependency, use the `--editable` flag:
```console
$ uv add --editable ./path/foo
```
Or, to opt-out of using an editable dependency in a workspace:
```console
$ uv add --no-editable ./path/foo
```