Skip to content

Commit a058c3f

Browse files
Dynamically generate CatalogGameFromContrib subclasses from YAML
1 parent b832ec4 commit a058c3f

4 files changed

Lines changed: 48 additions & 598 deletions

File tree

doc/tutorials/01_quickstart.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@
495495
},
496496
{
497497
"cell_type": "code",
498-
"execution_count": 15,
498+
"execution_count": 14,
499499
"id": "6db7a29a",
500500
"metadata": {},
501501
"outputs": [
@@ -509,7 +509,7 @@
509509
"Game(title='Two person Prisoner's Dilemma game')"
510510
]
511511
},
512-
"execution_count": 15,
512+
"execution_count": 14,
513513
"metadata": {},
514514
"output_type": "execute_result"
515515
}
@@ -535,7 +535,7 @@
535535
},
536536
{
537537
"cell_type": "code",
538-
"execution_count": 16,
538+
"execution_count": 15,
539539
"id": "f58eaa77",
540540
"metadata": {},
541541
"outputs": [],
@@ -553,7 +553,7 @@
553553
},
554554
{
555555
"cell_type": "code",
556-
"execution_count": 17,
556+
"execution_count": 16,
557557
"id": "4119a2ac",
558558
"metadata": {},
559559
"outputs": [],

src/pygambit/catalog/__init__.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1+
from . import catalog
12
from .catalog import games
23

3-
# Dynamically import all catalog games
4+
# Ensure catalog module is fully imported including all YAML-generated classes exist
45
_all_games = games()
56
_game_classes = {}
67

78
for game_name in _all_games:
8-
# Import each game class from catalog module
9-
from . import catalog
10-
_game_classes[game_name] = getattr(catalog, game_name)
9+
try:
10+
_game_classes[game_name] = getattr(catalog, game_name)
11+
except AttributeError as e:
12+
raise ImportError(
13+
f"Catalog game '{game_name}' listed but not found in catalog module"
14+
) from e
1115

1216
# Add to module namespace
1317
globals().update(_game_classes)
1418

1519
# Build __all__ dynamically
16-
__all__ = ["games"] + list(_all_games) # type: ignore[assignment]
17-
18-
# from .catalog import (
19-
# OneShotTrust,
20-
# PrisonersDilemma,
21-
# TwoStageMatchingPennies,
22-
# games,
23-
# )
24-
25-
# __all__ = [
26-
# "games",
27-
# "PrisonersDilemma",
28-
# "TwoStageMatchingPennies",
29-
# "OneShotTrust",
30-
# ]
20+
__all__ = ["games", *list(_all_games)]

0 commit comments

Comments
 (0)