-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-nix-buck2-prelude_hash.py
executable file
·41 lines (37 loc) · 1.46 KB
/
get-nix-buck2-prelude_hash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env -S uv run
# quick and dirty Python/UV script to get the prelude_hash corresponding to the
# nix-managed `buck2` release
#
# pre-req: this script assumes `buck2` was installed with
# [`nix`](https://github.com/NixOS/nixpkgs/tree/nixpkgs-unstable/pkgs/development/tools/build-managers/buck2)
# pre-req: this script requires [uv](https://github.com/astral-sh/uv) in order
# to run (and install dependencies)
# *********************************************************
# ** inline UV dependency install as metadata script ... **
# *********************************************************
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests",
# ]
# ///
import shutil
import pathlib
import re
import requests
if pstr := shutil.which("buck2"):
p = pathlib.Path(pstr)
pabs = p.resolve(strict=True)
nix_store_dir = pabs.parts
calver_re = re.compile(r"\w+-buck2-(un)?stable-(\d\d\d\d-\d\d-\d\d)")
for part in nix_store_dir:
(stable, calver) = m.groups() if (m := calver_re.match(part)) else (None, None)
if calver is not None:
print(
f"nix installed version of {stable}stable 'buck2' is [{calver}] at [{pstr}]"
)
r = requests.get(
f"https://github.com/facebook/buck2/releases/download/{calver}/prelude_hash"
)
prelude_hash_val = r.text.rstrip()
print(f"corresponding 'prelude_hash' is [{prelude_hash_val}]")