mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-08 04:48:02 +00:00

## Summary In #10939 I added the generated `crates/uv-python/src/download-metadata-minified.json` file which is a minified version of `crates/uv-python/download-metadata.json`. The main reason for this PR is to avoid bloating the git objects as this is a single-line file. As a bonus, I also filtered the embed json to include only the versions for the compiled target. Which should improve the binary size and performance by a bit. ## Test Plan <!-- How was it tested? -->
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn process_json(data: &serde_json::Value) -> serde_json::Value {
|
|
let mut out_data = serde_json::Map::new();
|
|
|
|
if let Some(obj) = data.as_object() {
|
|
for (key, value) in obj {
|
|
if let Some(variant) = value.get("variant") {
|
|
// Exclude debug variants for now, we don't support them
|
|
if variant == "debug" {
|
|
continue;
|
|
}
|
|
}
|
|
|
|
out_data.insert(key.clone(), value.clone());
|
|
}
|
|
}
|
|
|
|
serde_json::Value::Object(out_data)
|
|
}
|
|
|
|
fn main() {
|
|
let version_metadata = Path::new("download-metadata.json");
|
|
let target = Path::new("src/download-metadata-minified.json");
|
|
|
|
let json_data: serde_json::Value = serde_json::from_str(
|
|
#[allow(clippy::disallowed_methods)]
|
|
&fs::read_to_string(version_metadata).expect("Failed to read download-metadata.json"),
|
|
)
|
|
.expect("Failed to parse JSON");
|
|
|
|
let filtered_data = process_json(&json_data);
|
|
|
|
#[allow(clippy::disallowed_methods)]
|
|
fs::write(
|
|
target,
|
|
serde_json::to_string(&filtered_data).expect("Failed to serialize JSON"),
|
|
)
|
|
.expect("Failed to write minified JSON");
|
|
}
|