mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-14 20:39:37 +00:00
minify and filter embed managed pythons json on compile time (#12967)
## 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? -->
This commit is contained in:
parent
481d05d8df
commit
5ee54b4fa3
6 changed files with 45 additions and 45 deletions
1
.github/workflows/sync-python-releases.yml
vendored
1
.github/workflows/sync-python-releases.yml
vendored
|
@ -24,7 +24,6 @@ jobs:
|
||||||
- name: Sync Python Releases
|
- name: Sync Python Releases
|
||||||
run: |
|
run: |
|
||||||
uv run -- fetch-download-metadata.py
|
uv run -- fetch-download-metadata.py
|
||||||
uv run -- minify-download-metadata.py
|
|
||||||
working-directory: ./crates/uv-python
|
working-directory: ./crates/uv-python
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
1
crates/uv-python/.gitignore
vendored
Normal file
1
crates/uv-python/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
download-metadata-minified.json
|
|
@ -80,3 +80,6 @@ itertools = { version = "0.14.0" }
|
||||||
temp-env = { version = "0.3.6" }
|
temp-env = { version = "0.3.6" }
|
||||||
tempfile = { workspace = true }
|
tempfile = { workspace = true }
|
||||||
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
|
test-log = { version = "0.2.16", features = ["trace"], default-features = false }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
|
41
crates/uv-python/build.rs
Normal file
41
crates/uv-python/build.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
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");
|
||||||
|
}
|
|
@ -1,43 +0,0 @@
|
||||||
# /// script
|
|
||||||
# requires-python = ">=3.12"
|
|
||||||
# ///
|
|
||||||
"""
|
|
||||||
Generate minified Python version download metadata json to embed in the binary.
|
|
||||||
|
|
||||||
Generates the `download-metadata-minified.json` file from the `download-metadata.json` file.
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
|
|
||||||
uv run -- crates/uv-python/minify-download-metadata.py
|
|
||||||
"""
|
|
||||||
|
|
||||||
import json
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
CRATE_ROOT = Path(__file__).parent
|
|
||||||
VERSION_METADATA = CRATE_ROOT / "download-metadata.json"
|
|
||||||
TARGET = CRATE_ROOT / "src" / "download-metadata-minified.json"
|
|
||||||
|
|
||||||
|
|
||||||
def process_json(data: dict) -> dict:
|
|
||||||
out_data = {}
|
|
||||||
|
|
||||||
for key, value in data.items():
|
|
||||||
# Exclude debug variants for now, we don't support them in the Rust side
|
|
||||||
if value["variant"] == "debug":
|
|
||||||
continue
|
|
||||||
|
|
||||||
out_data[key] = value
|
|
||||||
|
|
||||||
return out_data
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
json_data = json.loads(Path(VERSION_METADATA).read_text())
|
|
||||||
json_data = process_json(json_data)
|
|
||||||
json_string = json.dumps(json_data, separators=(",", ":"))
|
|
||||||
TARGET.write_text(json_string)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue