Skip to content

Commit 34c9455

Browse files
committed
move device sorting into python script
1 parent 6f6bd1c commit 34c9455

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

.github/scripts/library_doc/update_library_files.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,31 @@
77
from pytablewriter import MarkdownTableWriter
88

99

10-
def generate_device_list():
10+
def get_device_list() -> None:
11+
"""Sort the device library JSON file."""
12+
# Load the existing JSON library file
13+
with open(
14+
file="library/library.json",
15+
encoding="UTF-8",
16+
) as f:
17+
devices_json = json.loads(f.read())
18+
devices = devices_json.get("devices")
19+
20+
# Sort the devices by manufacturer and model
21+
devices.sort(
22+
key=lambda k: (
23+
k["manufacturer"].lower(),
24+
k.get("model_match_method", "").lower(),
25+
k["model"].lower(),
26+
k.get("model_id", "").lower(),
27+
k.get("hw_version", "").lower(),
28+
)
29+
)
30+
with open("library/library.json", "w", encoding="UTF-8") as f:
31+
f.write(json.dumps(devices_json, indent=4))
32+
33+
34+
def regenerate_device_list() -> None:
1135
"""Generate static file containing the device library."""
1236

1337
# Load the existing JSON library file
@@ -67,4 +91,6 @@ def generate_device_list():
6791
md_file.close()
6892

6993

70-
generate_device_list()
94+
if __name__ == "__main__":
95+
get_device_list()
96+
regenerate_device_list()

.github/workflows/json_librarian.yaml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,11 @@ jobs:
1919
steps:
2020
- name: Checkout repository
2121
uses: actions/checkout@v5
22-
23-
- name: Clean up JSON library file
24-
id: update-json
25-
uses: jannekem/run-python-script-action@v1
26-
with:
27-
script: |
28-
import json
29-
30-
# Load the existing JSON library file
31-
with open("library/library.json", "r", encoding="UTF-8") as f:
32-
devices_json = json.loads(f.read())
33-
devices = devices_json.get("devices")
34-
35-
# Sort the devices by manufacturer and model
36-
devices.sort(key=lambda k: (k["manufacturer"].lower(), k.get("model_match_method", "").lower(), k["model"].lower(), k.get("model_id", "").lower(), k.get("hw_version", "").lower()))
37-
with open("library/library.json", "w", encoding="UTF-8") as f:
38-
f.write(json.dumps(devices_json, indent=4))
3922

4023
- name: Install uv
4124
uses: astral-sh/setup-uv@v7
4225

43-
- name: Update Library Files
26+
- name: Sort and Update Library Files
4427
run: |
4528
uv run --only-group library .github/scripts/library_doc/update_library_files.py
4629

0 commit comments

Comments
 (0)