Skip to content

Commit 71b92b8

Browse files
comment out update.py
1 parent 8c679ef commit 71b92b8

1 file changed

Lines changed: 120 additions & 120 deletions

File tree

src/pygambit/catalog/update.py

Lines changed: 120 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,128 @@
1-
#!/usr/bin/env python3
1+
# #!/usr/bin/env python3
22

3-
import sys
4-
from pathlib import Path
3+
# import sys
4+
# from pathlib import Path
55

6-
from ruamel.yaml import YAML
6+
# from ruamel.yaml import YAML
77

8-
from pygambit.catalog import games
8+
# from pygambit.catalog import games
99

10-
_CATALOG_YAML = Path(__file__).parent / "catalog.yml"
11-
_GAMEFILES_DIR = Path(__file__).parent.parent.parent.parent / "contrib/games"
12-
_API_RST = Path(__file__).parent.parent.parent.parent / "doc/pygambit.api.rst"
10+
# _CATALOG_YAML = Path(__file__).parent / "catalog.yml"
11+
# _GAMEFILES_DIR = Path(__file__).parent.parent.parent.parent / "contrib/games"
12+
# _API_RST = Path(__file__).parent.parent.parent.parent / "doc/pygambit.api.rst"
1313

1414

15-
def make_class_name(filename: str) -> str:
16-
"""
17-
Convert a filename (without extension) into a class name.
18-
- Replace hyphens with underscores
19-
- Capitalise
20-
- Prepend 'Game' if it starts with a digit
21-
"""
22-
name = filename.replace("-", "_")
15+
# def make_class_name(filename: str) -> str:
16+
# """
17+
# Convert a filename (without extension) into a class name.
18+
# - Replace hyphens with underscores
19+
# - Capitalise
20+
# - Prepend 'Game' if it starts with a digit
21+
# """
22+
# name = filename.replace("-", "_")
2323

24-
# Capitalise in a simple, predictable way
25-
name = name[0].upper() + name[1:] if name else name
24+
# # Capitalise in a simple, predictable way
25+
# name = name[0].upper() + name[1:] if name else name
2626

27-
if name and name[0].isdigit():
28-
name = f"Game{name}"
29-
30-
return name
31-
32-
33-
def update_api_rst() -> None:
34-
"""Update the Game catalog section in pygambit.api.rst with all class names."""
35-
_all_catalog_classes = games()
36-
with open(_API_RST, encoding="utf-8") as f:
37-
content = f.read()
38-
39-
# Find the Game catalog section
40-
game_catalog_start = content.find("Game catalog\n~~~~~~~~~~~~")
41-
if game_catalog_start == -1:
42-
print("Warning: 'Game catalog' section not found in pygambit.api.rst")
43-
return
44-
45-
# Find the autosummary block
46-
autosummary_start = content.find(".. autosummary::", game_catalog_start)
47-
toctree_start = content.find(":toctree: api/", autosummary_start)
48-
49-
# Find the next section (starts with ~~)
50-
next_section = content.find("\n~~", toctree_start)
51-
if next_section == -1:
52-
next_section = len(content)
53-
54-
# Build the new toctree content
55-
new_toctree = ".. autosummary::\n :toctree: api/\n\n games\n"
56-
for class_name in _all_catalog_classes:
57-
cls = getattr(sys.modules[__name__], class_name, None)
58-
if cls is not None and hasattr(cls, "valid_game") and cls.valid_game is False:
59-
pass # Marked as invalid game, do not add class to toctree
60-
else:
61-
new_toctree += f" {class_name}\n"
62-
63-
# Replace the old toctree with the new one
64-
old_toctree_start = content.rfind(".. autosummary::", game_catalog_start, toctree_start + 100)
65-
old_toctree_end = next_section
66-
67-
new_content = (
68-
content[:old_toctree_start]
69-
+ new_toctree
70-
+ content[old_toctree_end:]
71-
)
72-
73-
with open(_API_RST, "w", encoding="utf-8") as f:
74-
f.write(new_content)
75-
76-
print(f"Updated {_API_RST} with new catalog game names")
77-
78-
79-
if __name__ == "__main__":
80-
# Use ruamel.yaml to preserve comments
81-
yaml = YAML()
82-
yaml.preserve_quotes = True
83-
yaml.default_flow_style = False
84-
85-
efg_files = list(_GAMEFILES_DIR.rglob("*.efg"))
86-
nfg_files = list(_GAMEFILES_DIR.rglob("*.nfg"))
87-
88-
print(f"Found {len(efg_files)} .efg files in contrib/games")
89-
print(f"Found {len(nfg_files)} .nfg files in contrib/games")
90-
91-
all_files = sorted(efg_files + nfg_files)
92-
93-
# Get the current class names from the catalog
94-
with open(_CATALOG_YAML, encoding="utf-8") as f:
95-
catalog = yaml.load(f) or {}
96-
file_names = [entry["file"] for entry in catalog.values() if "file" in entry]
97-
98-
# Iterate through contrib/games and update the catalog
99-
# with new/missing entries
100-
new_entries_counter = 0
101-
new_entries = {}
102-
for path in all_files:
103-
stem = path.stem
104-
class_name = make_class_name(stem)
105-
106-
# Avoid duplicates by appending EFG or NFG
107-
if class_name in new_entries:
108-
class_name += path.suffix.split(".")[-1].upper()
109-
110-
if path.name not in file_names:
111-
new_entries[class_name] = {
112-
"file": path.name,
113-
"metadata": {},
114-
}
115-
new_entries_counter += 1
116-
117-
# Update the catalog
118-
catalog.update(new_entries)
119-
with _CATALOG_YAML.open("w", encoding="utf-8") as f:
120-
yaml.dump(catalog, f)
121-
122-
# Update the RST documentation with the new full catalog
123-
# This includes games from coded_games.py as well as catalog.yml
124-
update_api_rst()
125-
126-
print(f"Added {new_entries_counter} new entries to the catalog")
127-
print(f"Output written to: {_CATALOG_YAML}")
128-
print("Done.")
27+
# if name and name[0].isdigit():
28+
# name = f"Game{name}"
29+
30+
# return name
31+
32+
33+
# def update_api_rst() -> None:
34+
# """Update the Game catalog section in pygambit.api.rst with all class names."""
35+
# _all_catalog_classes = games()
36+
# with open(_API_RST, encoding="utf-8") as f:
37+
# content = f.read()
38+
39+
# # Find the Game catalog section
40+
# game_catalog_start = content.find("Game catalog\n~~~~~~~~~~~~")
41+
# if game_catalog_start == -1:
42+
# print("Warning: 'Game catalog' section not found in pygambit.api.rst")
43+
# return
44+
45+
# # Find the autosummary block
46+
# autosummary_start = content.find(".. autosummary::", game_catalog_start)
47+
# toctree_start = content.find(":toctree: api/", autosummary_start)
48+
49+
# # Find the next section (starts with ~~)
50+
# next_section = content.find("\n~~", toctree_start)
51+
# if next_section == -1:
52+
# next_section = len(content)
53+
54+
# # Build the new toctree content
55+
# new_toctree = ".. autosummary::\n :toctree: api/\n\n games\n"
56+
# for class_name in _all_catalog_classes:
57+
# cls = getattr(sys.modules[__name__], class_name, None)
58+
# if cls is not None and hasattr(cls, "valid_game") and cls.valid_game is False:
59+
# pass # Marked as invalid game, do not add class to toctree
60+
# else:
61+
# new_toctree += f" {class_name}\n"
62+
63+
# # Replace the old toctree with the new one
64+
# old_toctree_start = content.rfind(".. autosummary::", game_catalog_start, toctree_start + 100)
65+
# old_toctree_end = next_section
66+
67+
# new_content = (
68+
# content[:old_toctree_start]
69+
# + new_toctree
70+
# + content[old_toctree_end:]
71+
# )
72+
73+
# with open(_API_RST, "w", encoding="utf-8") as f:
74+
# f.write(new_content)
75+
76+
# print(f"Updated {_API_RST} with new catalog game names")
77+
78+
79+
# if __name__ == "__main__":
80+
# # Use ruamel.yaml to preserve comments
81+
# yaml = YAML()
82+
# yaml.preserve_quotes = True
83+
# yaml.default_flow_style = False
84+
85+
# efg_files = list(_GAMEFILES_DIR.rglob("*.efg"))
86+
# nfg_files = list(_GAMEFILES_DIR.rglob("*.nfg"))
87+
88+
# print(f"Found {len(efg_files)} .efg files in contrib/games")
89+
# print(f"Found {len(nfg_files)} .nfg files in contrib/games")
90+
91+
# all_files = sorted(efg_files + nfg_files)
92+
93+
# # Get the current class names from the catalog
94+
# with open(_CATALOG_YAML, encoding="utf-8") as f:
95+
# catalog = yaml.load(f) or {}
96+
# file_names = [entry["file"] for entry in catalog.values() if "file" in entry]
97+
98+
# # Iterate through contrib/games and update the catalog
99+
# # with new/missing entries
100+
# new_entries_counter = 0
101+
# new_entries = {}
102+
# for path in all_files:
103+
# stem = path.stem
104+
# class_name = make_class_name(stem)
105+
106+
# # Avoid duplicates by appending EFG or NFG
107+
# if class_name in new_entries:
108+
# class_name += path.suffix.split(".")[-1].upper()
109+
110+
# if path.name not in file_names:
111+
# new_entries[class_name] = {
112+
# "file": path.name,
113+
# "metadata": {},
114+
# }
115+
# new_entries_counter += 1
116+
117+
# # Update the catalog
118+
# catalog.update(new_entries)
119+
# with _CATALOG_YAML.open("w", encoding="utf-8") as f:
120+
# yaml.dump(catalog, f)
121+
122+
# # Update the RST documentation with the new full catalog
123+
# # This includes games from coded_games.py as well as catalog.yml
124+
# update_api_rst()
125+
126+
# print(f"Added {new_entries_counter} new entries to the catalog")
127+
# print(f"Output written to: {_CATALOG_YAML}")
128+
# print("Done.")

0 commit comments

Comments
 (0)