Skip to content

Commit 295d7d5

Browse files
committed
Enables Python checkers black and ruff and applies "nix fmt"
1 parent 4e6ed1c commit 295d7d5

File tree

4 files changed

+55
-38
lines changed

4 files changed

+55
-38
lines changed

antithesis/entrypoint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env -S python3 -u
22

3-
# This file serves as the client's entrypoint. It:
3+
# This file serves as the client's entrypoint. It:
44
# 1. Confirms that all nodes in the cluster are available
55
# 2. Signals "setupComplete" using the Antithesis SDK
66

@@ -15,7 +15,7 @@
1515
print("Client [entrypoint]: running...")
1616

1717
# Here is the python format for setup_complete. At this point, our system is fully initialized and ready to test.
18-
setup_complete({"Message":"sim-rs cluster is healthy"})
18+
setup_complete({"Message": "sim-rs cluster is healthy"})
1919

2020
# sleep infinity
2121
time.sleep(31536000)

crypto-benchmarks.rs/demo/ui/server.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
from flask import Flask, send_from_directory, jsonify, render_template, abort, redirect, url_for
1+
from flask import (
2+
Flask,
3+
send_from_directory,
4+
jsonify,
5+
render_template,
6+
abort,
7+
redirect,
8+
url_for,
9+
)
210
import json
311
import subprocess
412
from pathlib import Path
@@ -22,7 +30,9 @@ def committee(run):
2230
abort(500, f"extract_committee.py not found at {script}")
2331

2432
try:
25-
out = subprocess.check_output(["python3", str(script), str(rdir)], cwd=ROOT, text=True)
33+
out = subprocess.check_output(
34+
["python3", str(script), str(rdir)], cwd=ROOT, text=True
35+
)
2636
data = json.loads(out)
2737
return jsonify(data)
2838
except subprocess.CalledProcessError as e:
@@ -48,11 +58,10 @@ def registry(run):
4858
pools.append({"id": pid, "stake": s})
4959
total_stake += s
5060

51-
return jsonify({
52-
"pools": pools,
53-
"total_pools": len(pools),
54-
"total_stake": total_stake
55-
})
61+
return jsonify(
62+
{"pools": pools, "total_pools": len(pools), "total_stake": total_stake}
63+
)
64+
5665

5766
@app.route("/demo/<run>")
5867
def demo_for_run(run):
@@ -63,6 +72,7 @@ def demo_for_run(run):
6372
return send_from_directory(str(run_dir), "demo.json")
6473
abort(404, f"demo.json not found in {run_dir}")
6574

75+
6676
@app.route("/demo/<run>/<path:filename>")
6777
def demo_asset(run, filename):
6878
"""Serve auxiliary files (eid.txt, ebhash.txt, etc.) from the run directory."""
@@ -72,15 +82,18 @@ def demo_asset(run, filename):
7282
return send_from_directory(str(run_dir), filename)
7383
abort(404, f"{filename} not found in {run_dir}")
7484

85+
7586
# === UI endpoint ===
7687
@app.route("/ui")
7788
def ui():
7889
return render_template("index.html")
7990

91+
8092
# Small helper route to redirect `/` to `/ui`
8193
@app.route("/")
8294
def root():
8395
return redirect(url_for("ui"))
8496

97+
8598
if __name__ == "__main__":
8699
app.run(host="0.0.0.0", port=5050, debug=True)

pre-commit-hooks.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Sourced by build.nix
12
# https://github.com/cachix/git-hooks.nix?tab=readme-ov-file#hooks
23
{
34
# Nix
@@ -8,4 +9,8 @@
89
# Haskell
910
fourmolu.enable = true;
1011
hlint.enable = true;
12+
13+
# Python
14+
black.enable = true;
15+
ruff.enable = true;
1116
}

scripts/trace-translator/trace-translator.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
in the format expected by the Leios trace verifier.
66
"""
77

8-
import json, sys
8+
import json
9+
import sys
910
from datetime import datetime, timezone
1011

12+
1113
def log_message(message, time):
1214
print(json.dumps({"message": message, "time_s": time.total_seconds()}))
1315

16+
1417
fmt = "%Y-%m-%dT%H:%M:%S.%fZ"
1518
last_at = None
1619
last_SLC_slot = None
@@ -23,43 +26,39 @@ def log_message(message, time):
2326
exit(127)
2427

2528
if last_at is None:
26-
last_at = obj['at']
29+
last_at = obj["at"]
2730

28-
curr_at = obj['at']
29-
time = datetime.strptime(curr_at, fmt).replace(tzinfo=timezone.utc) \
30-
- \
31-
datetime.strptime(last_at, fmt).replace(tzinfo=timezone.utc)
31+
curr_at = obj["at"]
32+
time = datetime.strptime(curr_at, fmt).replace(
33+
tzinfo=timezone.utc
34+
) - datetime.strptime(last_at, fmt).replace(tzinfo=timezone.utc)
3235
last_at = curr_at
3336

34-
if obj['ns'] == "Forge.Loop.AdoptedBlock":
37+
if obj["ns"] == "Forge.Loop.AdoptedBlock":
3538
message = {
36-
"type": "RBGenerated",
37-
"producer": obj['host'],
38-
"slot": last_SLC_slot,
39-
"id": obj['data']['blockHash'],
40-
"endorsement": None,
41-
"parent": None, # FIXME: This is not available
42-
"size": obj['data']['blockSize'],
43-
"tx_payload_bytes": None, # FIXME: This is not available
44-
}
45-
elif obj['ns'] == "BlockFetch.Client.CompletedBlockFetch":
39+
"type": "RBGenerated",
40+
"producer": obj["host"],
41+
"slot": last_SLC_slot,
42+
"id": obj["data"]["blockHash"],
43+
"endorsement": None,
44+
"parent": None, # FIXME: This is not available
45+
"size": obj["data"]["blockSize"],
46+
"tx_payload_bytes": None, # FIXME: This is not available
47+
}
48+
elif obj["ns"] == "BlockFetch.Client.CompletedBlockFetch":
4649
message = {
47-
"type": "RBReceived",
48-
"recipient": obj['host'],
49-
"id": obj['data']['block']
50-
}
50+
"type": "RBReceived",
51+
"recipient": obj["host"],
52+
"id": obj["data"]["block"],
53+
}
5154
else:
52-
if obj['ns'] == "Forge.Loop.StartLeadershipCheck":
55+
if obj["ns"] == "Forge.Loop.StartLeadershipCheck":
5356
if last_SLC_slot is None:
54-
last_SLC_slot = obj['data']['slot']
57+
last_SLC_slot = obj["data"]["slot"]
5558
else:
56-
message = {
57-
"type": "Slot",
58-
"node": obj['host'],
59-
"slot": last_SLC_slot
60-
}
59+
message = {"type": "Slot", "node": obj["host"], "slot": last_SLC_slot}
6160
log_message(message, time)
62-
last_SLC_slot = obj['data']['slot']
61+
last_SLC_slot = obj["data"]["slot"]
6362
continue
6463

6564
log_message(message, time)

0 commit comments

Comments
 (0)