mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 20:31:12 +00:00
Add support for dynamic cache keys (#7136)
## Summary
This PR adds a more flexible cache invalidation abstraction for uv, and
uses that new abstraction to improve support for dynamic metadata.
Specifically, instead of relying solely on a timestamp, we now pass
around a `CacheInfo` struct which (as of now) contains
`Option<Timestamp>` and `Option<Commit>`. The `CacheInfo` is saved in
`dist-info` as `uv_cache.json`, so we can test already-installed
distributions for cache validity (along with testing _cached_
distributions for cache validity).
Beyond the defaults (`pyproject.toml`, `setup.py`, and `setup.cfg`
changes), users can also specify additional cache keys, and it's easy
for us to extend support in the future. Right now, cache keys can either
be instructions to include the current commit (for `setuptools_scm` and
similar) or file paths (for `hatch-requirements-txt` and similar):
```toml
[tool.uv]
cache-keys = [{ file = "requirements.txt" }, { git = true }]
```
This change should be fully backwards compatible.
Closes https://github.com/astral-sh/uv/issues/6964.
Closes https://github.com/astral-sh/uv/issues/6255.
Closes https://github.com/astral-sh/uv/issues/6860.
This commit is contained in:
parent
9a7262c360
commit
4f2349119c
47 changed files with 1036 additions and 206 deletions
|
|
@ -59,6 +59,52 @@ Linux, and `%LOCALAPPDATA%\uv\cache` on Windows.
|
|||
|
||||
---
|
||||
|
||||
#### [`cache-keys`](#cache-keys) {: #cache-keys }
|
||||
|
||||
The keys to consider when caching builds for the project.
|
||||
|
||||
Cache keys enable you to specify the files or directories that should trigger a rebuild when
|
||||
modified. By default, uv will rebuild a project whenever the `pyproject.toml`, `setup.py`,
|
||||
or `setup.cfg` files in the project directory are modified, i.e.:
|
||||
|
||||
```toml
|
||||
cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]
|
||||
```
|
||||
|
||||
As an example: if a project uses dynamic metadata to read its dependencies from a
|
||||
`requirements.txt` file, you can specify `cache-keys = [{ file = "requirements.txt" }, { file = "pyproject.toml" }]`
|
||||
to ensure that the project is rebuilt whenever the `requirements.txt` file is modified (in
|
||||
addition to watching the `pyproject.toml`).
|
||||
|
||||
Cache keys can also include version control information. For example, if a project uses
|
||||
`setuptools_scm` to read its version from a Git tag, you can specify `cache-keys = [{ git = true }, { file = "pyproject.toml" }]`
|
||||
to include the current Git commit hash in the cache key (in addition to the
|
||||
`pyproject.toml`).
|
||||
|
||||
Cache keys only affect the project defined by the `pyproject.toml` in which they're
|
||||
specified (as opposed to, e.g., affecting all members in a workspace).
|
||||
|
||||
**Default value**: `[{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]`
|
||||
|
||||
**Type**: `list[dict]`
|
||||
|
||||
**Example usage**:
|
||||
|
||||
=== "pyproject.toml"
|
||||
|
||||
```toml
|
||||
[tool.uv]
|
||||
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]
|
||||
```
|
||||
=== "uv.toml"
|
||||
|
||||
```toml
|
||||
|
||||
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
#### [`compile-bytecode`](#compile-bytecode) {: #compile-bytecode }
|
||||
|
||||
Compile Python files to bytecode after installation.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue