mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00

## Summary Implementation referenced in https://github.com/astral-sh/uv/pull/12239#issuecomment-2744880003 Closes #12919 #12901 This makes the sysconfig replacements mappings dynamically generated from https://github.com/astral-sh/python-build-standalone/blob/main/cpython-unix/targets.yml ## Test Plan cargo dev tests, and tested scenario from https://github.com/astral-sh/uv/issues/12901#issuecomment-2822107454
27 lines
807 B
Rust
27 lines
807 B
Rust
/// Replacement mode for sysconfig values.
|
|
#[derive(Debug)]
|
|
pub(crate) enum ReplacementMode {
|
|
Partial { from: String },
|
|
Full,
|
|
}
|
|
|
|
/// A replacement entry to patch in sysconfig data.
|
|
#[derive(Debug)]
|
|
pub(crate) struct ReplacementEntry {
|
|
pub(crate) mode: ReplacementMode,
|
|
pub(crate) to: String,
|
|
}
|
|
|
|
impl ReplacementEntry {
|
|
/// Patches a sysconfig value either partially (replacing a specific word) or fully.
|
|
pub(crate) fn patch(&self, entry: &str) -> String {
|
|
match &self.mode {
|
|
ReplacementMode::Partial { from } => entry
|
|
.split_whitespace()
|
|
.map(|word| if word == from { &self.to } else { word })
|
|
.collect::<Vec<_>>()
|
|
.join(" "),
|
|
ReplacementMode::Full => self.to.clone(),
|
|
}
|
|
}
|
|
}
|