Skip to content

Commit 8ff7dad

Browse files
committed
Use defaults
1 parent 8ced25c commit 8ff7dad

File tree

5 files changed

+78
-61
lines changed

5 files changed

+78
-61
lines changed

crates/uv-cache-info/src/cache_info.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,7 @@ impl CacheInfo {
4444
/// Compute the cache info for a given directory.
4545
pub fn from_directory(directory: &Path) -> io::Result<Self> {
4646
let mut commit = None;
47-
48-
// Always compute the modification timestamp for the `pyproject.toml`, `setup.py`, and
49-
// `setup.cfg` files, if they exist.
50-
let mut timestamp = {
51-
let pyproject_toml = directory
52-
.join("pyproject.toml")
53-
.metadata()
54-
.ok()
55-
.filter(std::fs::Metadata::is_file)
56-
.as_ref()
57-
.map(Timestamp::from_metadata);
58-
59-
let setup_py = directory
60-
.join("setup.py")
61-
.metadata()
62-
.ok()
63-
.filter(std::fs::Metadata::is_file)
64-
.as_ref()
65-
.map(Timestamp::from_metadata);
66-
67-
let setup_cfg = directory
68-
.join("setup.cfg")
69-
.metadata()
70-
.ok()
71-
.filter(std::fs::Metadata::is_file)
72-
.as_ref()
73-
.map(Timestamp::from_metadata);
74-
75-
max(pyproject_toml, max(setup_py, setup_cfg))
76-
};
47+
let mut timestamp = None;
7748

7849
// Read the cache keys.
7950
let cache_keys =
@@ -83,14 +54,22 @@ impl CacheInfo {
8354
.tool
8455
.and_then(|tool| tool.uv)
8556
.and_then(|tool_uv| tool_uv.cache_keys)
86-
.unwrap_or_default()
8757
} else {
88-
Vec::new()
58+
None
8959
}
9060
} else {
91-
Vec::new()
61+
None
9262
};
9363

64+
// If no cache keys were defined, use the defaults.
65+
let cache_keys = cache_keys.unwrap_or_else(|| {
66+
vec![
67+
CacheKey::Path("pyproject.toml".into()),
68+
CacheKey::Path("setup.py".into()),
69+
CacheKey::Path("setup.cfg".into()),
70+
]
71+
});
72+
9473
// Incorporate any additional timestamps or VCS information.
9574
for cache_key in &cache_keys {
9675
match cache_key {

crates/uv-settings/src/settings.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,31 @@ pub struct Options {
4545

4646
/// The keys to consider when caching builds for the project.
4747
///
48-
/// By default, uv will rebuild a project whenever the `pyproject.toml`, `setup.py`, or
49-
/// `setup.cfg` files in the project directory are modified. Cache keys enable you to specify
50-
/// additional files or directories that should trigger a rebuild when modified.
48+
/// Cache keys enable you to specify the files or directories that should trigger a rebuild when
49+
/// modified. By default, uv will rebuild a project whenever the `pyproject.toml`, `setup.py`,
50+
/// or `setup.cfg` files in the project directory are modified, i.e.:
5151
///
52-
/// For example, if a project uses dynamic metadata to read its dependencies from a
53-
/// `requirements.txt` file, you can specify `cache-keys = [{ file = "requirements.txt" }]` to
54-
/// ensure that the project is rebuilt whenever the `requirements.txt` file is modified.
52+
/// ```toml
53+
/// cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]
54+
/// ```
55+
///
56+
/// As an example: if a project uses dynamic metadata to read its dependencies from a
57+
/// `requirements.txt` file, you can specify `cache-keys = [{ file = "requirements.txt" }, { file = "pyproject.toml" }]`
58+
/// to ensure that the project is rebuilt whenever the `requirements.txt` file is modified (in
59+
/// addition to watching the `pyproject.toml`).
5560
///
5661
/// Cache keys can also include version control information. For example, if a project uses
57-
/// `setuptools_scm` to read its version from a Git tag, you can specify
58-
/// `cache-keys = [{ git = true }]` to include the current Git commit hash in the cache key.
62+
/// `setuptools_scm` to read its version from a Git tag, you can specify `cache-keys = [{ git = true }, { file = "pyproject.toml" }]`
63+
/// to include the current Git commit hash in the cache key (in addition to the
64+
/// `pyproject.toml`).
5965
///
6066
/// Cache keys only affect the project defined by the `pyproject.toml` in which they're
6167
/// specified (as opposed to, e.g., affecting all members in a workspace).
6268
#[option(
63-
default = r#"[]"#,
69+
default = r#"[{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]"#,
6470
value_type = "list[dict]",
6571
example = r#"
66-
cache-keys = [{ file = "requirements.txt" }, { git = true }]
72+
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]
6773
"#
6874
)]
6975
#[serde(default, skip_serializing)]

crates/uv/tests/pip_install.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2951,7 +2951,7 @@ requires-python = ">=3.8"
29512951
"#,
29522952
)?;
29532953

2954-
// Re-installing should update the package.
2954+
// Installing again should update the package.
29552955
uv_snapshot!(context.filters(), context.pip_install()
29562956
.arg("--editable")
29572957
.arg(editable_dir.path()), @r###"
@@ -3015,7 +3015,7 @@ dependencies = {file = ["requirements.txt"]}
30153015
"###
30163016
);
30173017

3018-
// Re-installing should not re-install, as we don't special-case dynamic metadata.
3018+
// Installing again should not re-install, as we don't special-case dynamic metadata.
30193019
uv_snapshot!(context.filters(), context.pip_install()
30203020
.arg("--editable")
30213021
.arg(editable_dir.path()), @r###"
@@ -3093,7 +3093,7 @@ requires-python = ">=3.8"
30933093
"#,
30943094
)?;
30953095

3096-
// Re-installing should update the package.
3096+
// Installing again should update the package.
30973097
uv_snapshot!(context.filters(), context.pip_install()
30983098
.arg("example @ .")
30993099
.current_dir(editable_dir.path()), @r###"
@@ -3175,7 +3175,7 @@ fn invalidate_path_on_cache_key() -> Result<()> {
31753175
// Modify the constraints file.
31763176
constraints_txt.write_str("idna<3.5")?;
31773177

3178-
// Re-installing should update the package.
3178+
// Installing again should update the package.
31793179
uv_snapshot!(context.filters(), context.pip_install()
31803180
.arg("example @ .")
31813181
.current_dir(editable_dir.path()), @r###"
@@ -3195,7 +3195,7 @@ fn invalidate_path_on_cache_key() -> Result<()> {
31953195
// Modify the requirements file.
31963196
requirements_txt.write_str("flask")?;
31973197

3198-
// Re-installing should update the package.
3198+
// Installing again should update the package.
31993199
uv_snapshot!(context.filters(), context.pip_install()
32003200
.arg("example @ .")
32013201
.current_dir(editable_dir.path()), @r###"
@@ -3212,6 +3212,32 @@ fn invalidate_path_on_cache_key() -> Result<()> {
32123212
"###
32133213
);
32143214

3215+
// Modify the `pyproject.toml` file (but not in a meaningful way).
3216+
pyproject_toml.write_str(
3217+
r#"[project]
3218+
name = "example"
3219+
version = "0.0.0"
3220+
dependencies = ["anyio==4.0.0"]
3221+
requires-python = ">=3.8"
3222+
3223+
[tool.uv]
3224+
cache-keys = [{ file = "requirements.txt" }, "constraints.txt"]
3225+
"#,
3226+
)?;
3227+
3228+
// Installing again should be a no-op, since `pyproject.toml` was not included as a cache key.
3229+
uv_snapshot!(context.filters(), context.pip_install()
3230+
.arg("example @ .")
3231+
.current_dir(editable_dir.path()), @r###"
3232+
success: true
3233+
exit_code: 0
3234+
----- stdout -----
3235+
3236+
----- stderr -----
3237+
Audited 1 package in [TIME]
3238+
"###
3239+
);
3240+
32153241
Ok(())
32163242
}
32173243

@@ -3291,7 +3317,7 @@ fn invalidate_path_on_commit() -> Result<()> {
32913317
.child("main")
32923318
.write_str("a1a42cbd10d83bafd8600ba81f72bbef6c579385")?;
32933319

3294-
// Re-installing should update the package.
3320+
// Installing again should update the package.
32953321
uv_snapshot!(context.filters(), context.pip_install()
32963322
.arg("example @ .")
32973323
.current_dir(editable_dir.path()), @r###"

docs/reference/settings.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,28 @@ Linux, and `%LOCALAPPDATA%\uv\cache` on Windows.
6363

6464
The keys to consider when caching builds for the project.
6565

66-
By default, uv will rebuild a project whenever the `pyproject.toml`, `setup.py`, or
67-
`setup.cfg` files in the project directory are modified. Cache keys enable you to specify
68-
additional files or directories that should trigger a rebuild when modified.
66+
Cache keys enable you to specify the files or directories that should trigger a rebuild when
67+
modified. By default, uv will rebuild a project whenever the `pyproject.toml`, `setup.py`,
68+
or `setup.cfg` files in the project directory are modified, i.e.:
6969

70-
For example, if a project uses dynamic metadata to read its dependencies from a
71-
`requirements.txt` file, you can specify `cache-keys = [{ file = "requirements.txt" }]` to
72-
ensure that the project is rebuilt whenever the `requirements.txt` file is modified.
70+
```toml
71+
cache-keys = [{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]
72+
```
73+
74+
As an example: if a project uses dynamic metadata to read its dependencies from a
75+
`requirements.txt` file, you can specify `cache-keys = [{ file = "requirements.txt" }, { file = "pyproject.toml" }]`
76+
to ensure that the project is rebuilt whenever the `requirements.txt` file is modified (in
77+
addition to watching the `pyproject.toml`).
7378

7479
Cache keys can also include version control information. For example, if a project uses
75-
`setuptools_scm` to read its version from a Git tag, you can specify
76-
`cache-keys = [{ git = true }]` to include the current Git commit hash in the cache key.
80+
`setuptools_scm` to read its version from a Git tag, you can specify `cache-keys = [{ git = true }, { file = "pyproject.toml" }]`
81+
to include the current Git commit hash in the cache key (in addition to the
82+
`pyproject.toml`).
7783

7884
Cache keys only affect the project defined by the `pyproject.toml` in which they're
7985
specified (as opposed to, e.g., affecting all members in a workspace).
8086

81-
**Default value**: `[]`
87+
**Default value**: `[{ file = "pyproject.toml" }, { file = "setup.py" }, { file = "setup.cfg" }]`
8288

8389
**Type**: `list[dict]`
8490

@@ -88,13 +94,13 @@ specified (as opposed to, e.g., affecting all members in a workspace).
8894

8995
```toml
9096
[tool.uv]
91-
cache-keys = [{ file = "requirements.txt" }, { git = true }]
97+
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]
9298
```
9399
=== "uv.toml"
94100

95101
```toml
96102

97-
cache-keys = [{ file = "requirements.txt" }, { git = true }]
103+
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]
98104
```
99105

100106
---

uv.schema.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)