Skip to content

Commit 052014d

Browse files
use update script to update api reference doc
1 parent bf9f013 commit 052014d

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

doc/pygambit.api.rst

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,148 @@ Game catalog
336336
:toctree: api/
337337

338338
games
339+
Artist1
340+
Artist2
341+
Badgame1
342+
Badgame2
343+
Bagwell
344+
Bayes1a
345+
Bayes2a
346+
Bcp2
347+
Bcp3
348+
Bcp4
349+
Bhg1
350+
Bhg2
351+
Bhg3
352+
Bhg4
353+
Bhg5
354+
Caro2
355+
Cent2
356+
Cent2NFG
357+
Cent3
358+
Cent4
359+
Cent6
360+
Centcs10
361+
Centcs6
362+
Condjury
363+
Coord2
364+
Coord2NFG
365+
Coord2ts
366+
Coord3
367+
Coord333
368+
Coord3NFG
369+
Coord4
370+
Coord4NFG
371+
Cross
372+
Cs
373+
Csg1
374+
Csg2
375+
Csg3
376+
Csg4
377+
Deg1
378+
Deg2
379+
E01
380+
E01NFG
381+
E02
382+
E02NFG
383+
E03
384+
E04
385+
E04NFG
386+
E05
387+
E06
388+
E07
389+
E07NFG
390+
E08
391+
E09
392+
E10
393+
E10a
394+
E13
395+
E16
396+
E17
397+
E18
398+
G1
399+
G1NFG
400+
G2
401+
G2NFG
402+
G3
403+
G3NFG
404+
Game2s2x2x2
405+
Game2smp
406+
Game2x2
407+
Game2x2a
408+
Game2x2const
409+
Game2x2x2
410+
Game2x2x2NFG
411+
Game2x2x2_nau
412+
Game2x2x2x2
413+
Game2x2x2x2x2
414+
Game3x3x3
415+
Game4cards
416+
Game5x4x3
417+
Game8x2x2
418+
Game8x8
419+
Holdout
420+
Holdout7
421+
Hs1
422+
Jury_mr
423+
Jury_un
424+
Km1
425+
Km2
426+
Km3
427+
Km6
428+
Loopback
429+
Mixdom
430+
Mixdom2
431+
Montyhal
432+
My_2_1
433+
My_2_4
434+
My_2_8
435+
My_3_3a
436+
My_3_3b
437+
My_3_3c
438+
My_3_3d
439+
My_3_3e
440+
My_3_4
441+
Myerson
442+
Myerson_fig_4_2
443+
Nim
444+
Nim7
445+
Oneill
446+
Palf
447+
Palf2
448+
Palf3
449+
Pbride
450+
Perfect1
451+
Perfect2
452+
Perfect3
453+
Poker
454+
Poker2
455+
PokerNFG
456+
PrisonersDilemma
457+
Pvw
458+
Pvw2
459+
Sh3
460+
Sh3NFG
461+
Spence
462+
Stengel
463+
Sww1
464+
Sww1NFG
465+
Sww2
466+
Sww3
467+
Tim
468+
Todd1
469+
Todd2
470+
Todd3
471+
Ttt
472+
Vd
473+
VdNFG
474+
W_ex1
475+
W_ex2
476+
Wilson1
477+
Wink3
478+
Winkels
479+
Work1
480+
Work2
481+
Work3
482+
Yamamoto
483+
Zero

src/pygambit/catalog/update.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
_CATALOG_YAML = Path(__file__).parent / "catalog.yml"
88
_GAMEFILES_DIR = Path(__file__).parent.parent.parent.parent / "contrib/games"
9+
_API_RST = Path(__file__).parent.parent.parent.parent / "doc/pygambit.api.rst"
910

1011

1112
def make_class_name(filename: str) -> str:
@@ -26,6 +27,48 @@ def make_class_name(filename: str) -> str:
2627
return name
2728

2829

30+
def update_api_rst(catalog: dict[str, dict]) -> None:
31+
"""Update the Game catalog section in pygambit.api.rst with all class names."""
32+
with open(_API_RST, encoding="utf-8") as f:
33+
content = f.read()
34+
35+
# Find the Game catalog section
36+
game_catalog_start = content.find("Game catalog\n~~~~~~~~~~~~")
37+
if game_catalog_start == -1:
38+
print("Warning: 'Game catalog' section not found in pygambit.api.rst")
39+
return
40+
41+
# Find the autosummary block
42+
autosummary_start = content.find(".. autosummary::", game_catalog_start)
43+
toctree_start = content.find(":toctree: api/", autosummary_start)
44+
45+
# Find the next section (starts with ~~)
46+
next_section = content.find("\n~~", toctree_start)
47+
if next_section == -1:
48+
next_section = len(content)
49+
50+
# Build the new toctree content
51+
class_names = sorted(catalog.keys())
52+
new_toctree = ".. autosummary::\n :toctree: api/\n\n games\n"
53+
for class_name in class_names:
54+
new_toctree += f" {class_name}\n"
55+
56+
# Replace the old toctree with the new one
57+
old_toctree_start = content.rfind(".. autosummary::", game_catalog_start, toctree_start + 100)
58+
old_toctree_end = next_section
59+
60+
new_content = (
61+
content[:old_toctree_start]
62+
+ new_toctree
63+
+ content[old_toctree_end:]
64+
)
65+
66+
with open(_API_RST, "w", encoding="utf-8") as f:
67+
f.write(new_content)
68+
69+
print(f"Updated {_API_RST} with {len(class_names)} catalog games")
70+
71+
2972
if __name__ == "__main__":
3073
# Use ruamel.yaml to preserve comments
3174
yaml = YAML()
@@ -69,6 +112,9 @@ def make_class_name(filename: str) -> str:
69112
with _CATALOG_YAML.open("w", encoding="utf-8") as f:
70113
yaml.dump(catalog, f)
71114

115+
# Update the RST documentation
116+
update_api_rst(catalog)
117+
72118
print(f"Added {new_entries_counter} new entries to the catalog")
73119
print(f"Output written to: {_CATALOG_YAML}")
74120
print("Done.")

0 commit comments

Comments
 (0)