Skip to content

Commit 99165ca

Browse files
committed
py cli
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 6a693bd commit 99165ca

5 files changed

Lines changed: 21 additions & 18 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ rustc-hash = "2.1"
216216
serde = "1.0.220"
217217
serde_json = "1.0.138"
218218
serde_test = "1.0.176"
219+
sha2 = "0.10"
219220
simdutf8 = "0.1.5"
220221
similar = "2.7.0"
221222
sketches-ddsketch = "0.3.0"

vortex-test/compat-gen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ reqwest = { workspace = true }
4747
clap = { workspace = true, features = ["derive"] }
4848
serde = { workspace = true, features = ["derive"] }
4949
serde_json = { workspace = true }
50+
sha2 = { workspace = true }

vortex-test/compat-gen/scripts/compat.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,10 @@ def _version_from_ref(git_ref: str | None = None) -> str:
253253
"type": "array",
254254
"items": {
255255
"type": "object",
256-
"required": ["name", "since"],
256+
"required": ["name"],
257257
"properties": {
258258
"name": {"type": "string"},
259259
"description": {"type": "string"},
260-
"since": {"type": "string"},
261260
"sha256": {"type": "string"},
262261
},
263262
},
@@ -288,7 +287,7 @@ def _read_manifest(store: Store, version: str) -> dict | None:
288287
# Upgrade legacy format: flat list of filenames -> new object format.
289288
if isinstance(manifest.get("fixtures"), list) and manifest["fixtures"] and isinstance(manifest["fixtures"][0], str):
290289
_info(f" upgrading legacy manifest format for v{version}")
291-
manifest["fixtures"] = [{"name": n, "description": "", "since": version} for n in manifest["fixtures"]]
290+
manifest["fixtures"] = [{"name": n, "description": "", "sha256": ""} for n in manifest["fixtures"]]
292291

293292
_validate_manifest(manifest, version)
294293
# Stash the prefix so callers know where to fetch fixture files.
@@ -298,26 +297,22 @@ def _read_manifest(store: Store, version: str) -> dict | None:
298297

299298
def _merge_manifest(
300299
store: Store, fixtures_json: dict, version: str, prev_version: str | None,
301-
output: Path,
302300
) -> dict:
303-
"""Build a manifest for `version`, carrying forward `since` from prev_version."""
301+
"""Build a manifest for `version`, using sha256 from Rust-generated fixtures.json."""
304302
entries = []
305-
prev_since: dict[str, str] = {}
303+
prev_names: set[str] = set()
306304

307305
if prev_version:
308306
prev_manifest = _read_manifest(store, prev_version)
309307
if prev_manifest:
310-
prev_since = {e["name"]: e["since"] for e in prev_manifest["fixtures"]}
308+
prev_names = {e["name"] for e in prev_manifest["fixtures"]}
311309

312310
for f in fixtures_json["fixtures"]:
313-
name = f["name"]
314-
since = prev_since.get(name, version)
315-
sha = hashlib.sha256((output / name).read_bytes()).hexdigest()
316-
entries.append({"name": name, "description": f["description"], "since": since, "sha256": sha})
311+
entries.append({"name": f["name"], "description": f["description"], "sha256": f["sha256"]})
317312

318313
# Additive-only enforcement.
319314
current_names = {e["name"] for e in entries}
320-
missing = [n for n in prev_since if n not in current_names]
315+
missing = [n for n in prev_names if n not in current_names]
321316
if missing:
322317
print(
323318
f"error: fixtures removed since v{prev_version}: {', '.join(missing)}",
@@ -345,12 +340,11 @@ def cmd_generate(args: argparse.Namespace) -> None:
345340

346341
_run_rust_generate(output)
347342

348-
# Read fixtures.json and write a versioned manifest.
343+
# Read fixtures.json (with sha256 from Rust) and write a versioned manifest.
349344
fixtures_json = json.loads((output / "fixtures.json").read_text())
350345
entries = []
351346
for f in fixtures_json["fixtures"]:
352-
sha = hashlib.sha256((output / f["name"]).read_bytes()).hexdigest()
353-
entries.append({"name": f["name"], "description": f["description"], "since": version, "sha256": sha})
347+
entries.append({"name": f["name"], "description": f["description"], "sha256": f["sha256"]})
354348
manifest = {
355349
"version": version,
356350
"generated_at": datetime.now(timezone.utc).isoformat(),
@@ -398,7 +392,7 @@ def _publish_full(
398392
if prev:
399393
_info(f"previous version: {prev}")
400394

401-
manifest = _merge_manifest(store, fixtures_json, version, prev, output)
395+
manifest = _merge_manifest(store, fixtures_json, version, prev)
402396
manifest_json = json.dumps(manifest, indent=2) + "\n"
403397

404398
if args.dry_run:
@@ -541,8 +535,7 @@ def _publish_update(
541535
new_entries = existing_manifest["fixtures"][:]
542536
for f in fixtures_json["fixtures"]:
543537
if f["name"] in new_fixture_names:
544-
sha = hashlib.sha256((output / f["name"]).read_bytes()).hexdigest()
545-
new_entries.append({"name": f["name"], "description": f["description"], "since": version, "sha256": sha})
538+
new_entries.append({"name": f["name"], "description": f["description"], "sha256": f["sha256"]})
546539

547540
updated_manifest = {
548541
"version": version,

vortex-test/compat-gen/src/generate.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::path::Path;
55
use std::thread;
66

77
use serde::Serialize;
8+
use sha2::Digest;
9+
use sha2::Sha256;
810
use vortex_array::ArrayRef;
911
use vortex_error::VortexResult;
1012
use vortex_error::vortex_bail;
@@ -24,6 +26,7 @@ struct FixturesJson {
2426
struct FixtureInfo {
2527
name: String,
2628
description: String,
29+
sha256: String,
2730
}
2831

2932
/// Generate all fixtures into `output_dir`.
@@ -68,9 +71,13 @@ pub fn generate(output_dir: &Path, exclude: &[String]) -> VortexResult<()> {
6871
check_expected_encodings(array, *fixture)?;
6972
let path = output_dir.join(fixture.name());
7073
adapter::write_file(&path, array.clone())?;
74+
let file_bytes = std::fs::read(&path)
75+
.map_err(|e| vortex_err!("failed to read back {}: {e}", path.display()))?;
76+
let sha256 = format!("{:x}", Sha256::digest(&file_bytes));
7177
infos.push(FixtureInfo {
7278
name: fixture.name().to_string(),
7379
description: fixture.description().to_string(),
80+
sha256,
7481
});
7582
eprintln!(" wrote {}", fixture.name());
7683
}

0 commit comments

Comments
 (0)