Skip to content

Commit 8ced25c

Browse files
committed
Revert build config
1 parent e7c1524 commit 8ced25c

File tree

18 files changed

+86
-176
lines changed

18 files changed

+86
-176
lines changed

Cargo.lock

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

crates/install-wheel-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "install-wheel-rs"
33
version = "0.0.1"
44
publish = false
5-
description = "Takes a wheel and installs it, either in a venv or for monotrail"
5+
description = "Takes a wheel and installs it."
66
keywords = ["wheel", "python"]
77

88
edition = { workspace = true }

crates/install-wheel-rs/Readme.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

crates/uv-cache-info/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ workspace = true
1616
fs-err = { workspace = true }
1717
schemars = { workspace = true, optional = true }
1818
serde = { workspace = true, features = ["derive"] }
19+
thiserror = { workspace = true }
1920
toml = { workspace = true }
21+
tracing = { workspace = true }

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
1-
use crate::commit_info::Commit;
1+
use crate::commit_info::CacheCommit;
22
use crate::timestamp::Timestamp;
33

44
use serde::Deserialize;
55
use std::cmp::max;
66
use std::io;
77
use std::path::{Path, PathBuf};
8+
use tracing::debug;
89

10+
/// The information used to determine whether a built distribution is up-to-date, based on the
11+
/// timestamps of relevant files, the current commit of a repository, etc.
912
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
1013
#[serde(rename_all = "kebab-case")]
1114
#[serde(try_from = "CacheInfoWire")]
1215
pub struct CacheInfo {
16+
/// The timestamp of the most recent `ctime` of any relevant files, at the time of the build.
17+
/// The timestamp will typically be the maximum of the `ctime` values of the `pyproject.toml`,
18+
/// `setup.py`, and `setup.cfg` files, if they exist; however, users can provide additional
19+
/// files to timestamp via the `cache-keys` field.
1320
timestamp: Option<Timestamp>,
14-
commit: Option<Commit>,
21+
/// The commit at which the distribution was built.
22+
commit: Option<CacheCommit>,
1523
}
1624

1725
impl CacheInfo {
26+
/// Return the [`CacheInfo`] for a given timestamp.
1827
pub fn from_timestamp(timestamp: Timestamp) -> Self {
1928
Self {
2029
timestamp: Some(timestamp),
2130
..Self::default()
2231
}
2332
}
2433

34+
/// Compute the cache info for a given path, which may be a file or a directory.
2535
pub fn from_path(path: &Path) -> io::Result<Self> {
2636
let metadata = fs_err::metadata(path)?;
2737
if metadata.is_file() {
@@ -31,6 +41,7 @@ impl CacheInfo {
3141
}
3242
}
3343

44+
/// Compute the cache info for a given directory.
3445
pub fn from_directory(directory: &Path) -> io::Result<Self> {
3546
let mut commit = None;
3647

@@ -93,16 +104,21 @@ impl CacheInfo {
93104
.map(Timestamp::from_metadata),
94105
);
95106
}
96-
CacheKey::Git { git: true } => {
97-
commit = Commit::from_repository(directory);
98-
}
107+
CacheKey::Git { git: true } => match CacheCommit::from_repository(directory) {
108+
Ok(commit_info) => commit = Some(commit_info),
109+
Err(err) => {
110+
debug!("Failed to read the current commit: {err}");
111+
}
112+
},
99113
CacheKey::Git { git: false } => {}
100114
}
101115
}
102116

103117
Ok(Self { timestamp, commit })
104118
}
105119

120+
/// Compute the cache info for a given file, assumed to be a binary or source distribution
121+
/// represented as (e.g.) a `.whl` or `.tar.gz` archive.
106122
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, io::Error> {
107123
let metadata = fs_err::metadata(path.as_ref())?;
108124
let timestamp = Timestamp::from_metadata(&metadata);
@@ -120,13 +136,16 @@ impl CacheInfo {
120136
#[derive(Debug, serde::Deserialize)]
121137
struct TimestampCommit {
122138
timestamp: Option<Timestamp>,
123-
commit: Option<Commit>,
139+
commit: Option<CacheCommit>,
124140
}
125141

126142
#[derive(Debug, serde::Deserialize)]
127143
#[serde(untagged)]
128144
enum CacheInfoWire {
145+
/// For backwards-compatibility, enable deserializing [`CacheInfo`] structs that are solely
146+
/// represented by a timestamp.
129147
Timestamp(Timestamp),
148+
/// A [`CacheInfo`] struct that includes both a timestamp and a commit.
130149
TimestampCommit(TimestampCommit),
131150
}
132151

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

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,64 @@
11
use std::path::{Path, PathBuf};
22

3-
/// The current commit for a repository.
3+
#[derive(Debug, thiserror::Error)]
4+
pub(crate) enum CacheCommitError {
5+
#[error("The repository at {0} is missing a `.git` directory")]
6+
MissingGitDir(PathBuf),
7+
#[error("The repository at {0} is missing a `HEAD` file")]
8+
MissingHead(PathBuf),
9+
#[error("The repository at {0} has an invalid reference: `{1}`")]
10+
InvalidRef(PathBuf, String),
11+
#[error("The discovered commit has an invalid length (expected 40 characters): `{0}`")]
12+
WrongLength(String),
13+
#[error("The discovered commit has an invalid character (expected hexadecimal): `{0}`")]
14+
WrongDigit(String),
15+
#[error(transparent)]
16+
Io(#[from] std::io::Error),
17+
}
18+
19+
/// The current commit for a repository (i.e., a 40-character hexadecimal string).
420
#[derive(Default, Debug, Clone, Hash, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
5-
pub(crate) struct Commit(String);
21+
pub(crate) struct CacheCommit(String);
622

7-
impl Commit {
8-
/// Return the [`Commit`] for the repository at the given path.
9-
pub(crate) fn from_repository(path: &Path) -> Option<Self> {
23+
impl CacheCommit {
24+
/// Return the [`CacheCommit`] for the repository at the given path.
25+
pub(crate) fn from_repository(path: &Path) -> Result<Self, CacheCommitError> {
1026
// Find the `.git` directory, searching through parent directories if necessary.
1127
let git_dir = path
1228
.ancestors()
1329
.map(|ancestor| ancestor.join(".git"))
14-
.find(|git_dir| git_dir.exists())?;
30+
.find(|git_dir| git_dir.exists())
31+
.ok_or_else(|| CacheCommitError::MissingGitDir(path.to_path_buf()))?;
1532

16-
let git_head_path = git_head(&git_dir)?;
17-
let git_head_contents = fs_err::read_to_string(git_head_path).ok()?;
33+
let git_head_path =
34+
git_head(&git_dir).ok_or_else(|| CacheCommitError::MissingHead(git_dir.clone()))?;
35+
let git_head_contents = fs_err::read_to_string(git_head_path)?;
1836

1937
// The contents are either a commit or a reference in the following formats
2038
// - "<commit>" when the head is detached
2139
// - "ref <ref>" when working on a branch
2240
// If a commit, checking if the HEAD file has changed is sufficient
2341
// If a ref, we need to add the head file for that ref to rebuild on commit
2442
let mut git_ref_parts = git_head_contents.split_whitespace();
25-
let commit_or_ref = git_ref_parts.next()?;
26-
if let Some(git_ref) = git_ref_parts.next() {
43+
let commit_or_ref = git_ref_parts.next().ok_or_else(|| {
44+
CacheCommitError::InvalidRef(git_dir.clone(), git_head_contents.clone())
45+
})?;
46+
let commit = if let Some(git_ref) = git_ref_parts.next() {
2747
let git_ref_path = git_dir.join(git_ref);
28-
let commit = fs_err::read_to_string(git_ref_path).ok()?;
29-
Some(Self(commit))
48+
fs_err::read_to_string(git_ref_path)?
3049
} else {
31-
Some(Self(commit_or_ref.to_string()))
50+
commit_or_ref.to_string()
51+
};
52+
53+
// The commit should be 40 hexadecimal characters.
54+
if commit.len() != 40 {
55+
return Err(CacheCommitError::WrongLength(commit));
3256
}
57+
if commit.chars().any(|c| !c.is_ascii_hexdigit()) {
58+
return Err(CacheCommitError::WrongDigit(commit));
59+
}
60+
61+
Ok(Self(commit))
3362
}
3463
}
3564

crates/uv-dispatch/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ impl<'a> BuildContext for BuildDispatch<'a> {
223223
&BuildOptions::default(),
224224
self.hasher,
225225
self.index_locations,
226-
self.config_settings,
227226
self.cache(),
228227
venv,
229228
&markers,

crates/uv-distribution/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ license = { workspace = true }
1313
workspace = true
1414

1515
[dependencies]
16-
cache-key = { workspace = true }
1716
distribution-filename = { workspace = true }
1817
distribution-types = { workspace = true }
1918
install-wheel-rs = { workspace = true }

crates/uv-distribution/src/index/built_wheel_index.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use distribution_types::{
77
use platform_tags::Tags;
88
use uv_cache::{Cache, CacheBucket, CacheShard, WheelCache};
99
use uv_cache_info::CacheInfo;
10-
use uv_configuration::ConfigSettings;
1110
use uv_fs::symlinks;
1211
use uv_types::HashStrategy;
1312

@@ -17,22 +16,15 @@ pub struct BuiltWheelIndex<'a> {
1716
cache: &'a Cache,
1817
tags: &'a Tags,
1918
hasher: &'a HashStrategy,
20-
build_configuration: &'a ConfigSettings,
2119
}
2220

2321
impl<'a> BuiltWheelIndex<'a> {
2422
/// Initialize an index of built distributions.
25-
pub fn new(
26-
cache: &'a Cache,
27-
tags: &'a Tags,
28-
hasher: &'a HashStrategy,
29-
build_configuration: &'a ConfigSettings,
30-
) -> Self {
23+
pub fn new(cache: &'a Cache, tags: &'a Tags, hasher: &'a HashStrategy) -> Self {
3124
Self {
3225
cache,
3326
tags,
3427
hasher,
35-
build_configuration,
3628
}
3729
}
3830

@@ -61,13 +53,6 @@ impl<'a> BuiltWheelIndex<'a> {
6153

6254
let cache_shard = cache_shard.shard(revision.id());
6355

64-
// If there are build settings, we need to scope to a cache shard.
65-
let cache_shard = if self.build_configuration.is_empty() {
66-
cache_shard
67-
} else {
68-
cache_shard.shard(cache_key::cache_digest(self.build_configuration))
69-
};
70-
7156
Ok(self.find(&cache_shard))
7257
}
7358
/// Return the most compatible [`CachedWheel`] for a given source distribution at a local path.
@@ -98,13 +83,6 @@ impl<'a> BuiltWheelIndex<'a> {
9883

9984
let cache_shard = cache_shard.shard(revision.id());
10085

101-
// If there are build settings, we need to scope to a cache shard.
102-
let cache_shard = if self.build_configuration.is_empty() {
103-
cache_shard
104-
} else {
105-
cache_shard.shard(cache_key::cache_digest(self.build_configuration))
106-
};
107-
10886
Ok(self
10987
.find(&cache_shard)
11088
.map(|wheel| wheel.with_cache_info(cache_info)))
@@ -147,13 +125,6 @@ impl<'a> BuiltWheelIndex<'a> {
147125

148126
let cache_shard = cache_shard.shard(revision.id());
149127

150-
// If there are build settings, we need to scope to a cache shard.
151-
let cache_shard = if self.build_configuration.is_empty() {
152-
cache_shard
153-
} else {
154-
cache_shard.shard(cache_key::cache_digest(self.build_configuration))
155-
};
156-
157128
Ok(self
158129
.find(&cache_shard)
159130
.map(|wheel| wheel.with_cache_info(cache_info)))
@@ -173,13 +144,6 @@ impl<'a> BuiltWheelIndex<'a> {
173144
WheelCache::Git(&source_dist.url, &git_sha.to_short_string()).root(),
174145
);
175146

176-
// If there are build settings, we need to scope to a cache shard.
177-
let cache_shard = if self.build_configuration.is_empty() {
178-
cache_shard
179-
} else {
180-
cache_shard.shard(cache_key::cache_digest(self.build_configuration))
181-
};
182-
183147
self.find(&cache_shard)
184148
}
185149

0 commit comments

Comments
 (0)