Skip to content

Commit 3e4bdb9

Browse files
committed
add build context
1 parent 9d40146 commit 3e4bdb9

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

python-build/build_site.py

+36-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import contextlib
2+
import json
13
import pathlib
24
import shutil
3-
from datetime import datetime
5+
import subprocess
6+
from datetime import datetime, timezone
47

58
PYTHON_BUILD_DIR = pathlib.Path(__file__).parent
69
WHEEL_DIR = PYTHON_BUILD_DIR / "wheels"
@@ -19,6 +22,33 @@ def package_name(wheel_file: pathlib.Path) -> str:
1922
return wheel_file.name.split("-")[0].replace("_", "-")
2023

2124

25+
# Get some extra context about the build
26+
ts = datetime.now(timezone.utc).isoformat()
27+
context_info: dict = {
28+
"timestamp": ts,
29+
}
30+
with contextlib.suppress(Exception):
31+
branch_info = subprocess.check_output(
32+
["git", "branch", "--show-current"], text=True
33+
)
34+
context_info["branch"] = branch_info.strip()
35+
with contextlib.suppress(Exception):
36+
commit_info = subprocess.check_output(
37+
["git", "log", "-1", "--pretty=%H%n%B"], text=True
38+
)
39+
commit_hash, commit_msg = commit_info.strip().split("\n", 1)
40+
context_info["commit"] = {
41+
"hash": commit_hash,
42+
"message": commit_msg.strip(),
43+
}
44+
with contextlib.suppress(Exception):
45+
pr_info = subprocess.check_output(
46+
["gh", "pr", "view", "--json", "title,number,url"], text=True
47+
)
48+
pr_info = json.loads(pr_info)
49+
context_info["pr"] = pr_info
50+
51+
2252
newline = "\n"
2353
(SITE_OUTPUT_DIR / "index.html").write_text(
2454
f"""
@@ -36,8 +66,11 @@ def package_name(wheel_file: pathlib.Path) -> str:
3666
<p>
3767
These prebuilt wheel files can be used to install our Python packages as of a specific commit.
3868
</p>
39-
<p>Built at {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}.</p>
4069
70+
<h2>Build context</h2>
71+
<pre id="context-info">{json.dumps(context_info, indent=2)}</pre>
72+
73+
<h2>Usage</h2>
4174
<p>
4275
Current base URL: <span class="base-url">unknown</span>
4376
</p>
@@ -57,7 +90,7 @@ def package_name(wheel_file: pathlib.Path) -> str:
5790
<tr>
5891
<td><code>{package_name(wheel_file)}</code></td>
5992
<td>{wheel_file.stat().st_size / 1024 / 1024:.3f} MB</td>
60-
<td><code>pip install '{package_name(wheel_file)} @ <span class="base-url">&lt;base-url&gt;</span>/artifacts/wheels/{wheel_file.name}'</code></td>
93+
<td><code>uv pip install '{package_name(wheel_file)} @ <span class="base-url">&lt;base-url&gt;</span>/artifacts/wheels/{wheel_file.name}'</code></td>
6194
</tr>
6295
'''
6396
for wheel_file in sorted(WHEEL_DIR.glob("*.whl"))

0 commit comments

Comments
 (0)