Skip to content

Commit 91d39d9

Browse files
refactor yaml loading to use importlib.resources
1 parent 2382a1f commit 91d39d9

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

src/pygambit/catalog.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import sys
3+
from importlib.resources import files
34
from pathlib import Path
45

56
import yaml
@@ -248,12 +249,8 @@ def get_all_subclasses(cls):
248249
return sorted(get_all_subclasses(CatalogGame))
249250

250251

251-
_CATALOG_YAML = Path(__file__).parent / "catalog.yml"
252-
253-
254-
def _load_catalog_from_yaml(path: Path) -> dict[str, dict]:
255-
if not path.exists():
256-
raise FileNotFoundError(f"Catalog YAML not found: {path}")
252+
def _load_catalog_from_yaml() -> dict[str, dict]:
253+
path = files(__package__) / "catalog.yml"
257254
with path.open("r", encoding="utf-8") as f:
258255
return yaml.safe_load(f) or {}
259256

@@ -318,7 +315,7 @@ def _generate_contrib_game_classes(catalog: dict[str, dict]) -> None:
318315

319316

320317
# Generate classes at import time
321-
_catalog_data = _load_catalog_from_yaml(_CATALOG_YAML)
318+
_catalog_data = _load_catalog_from_yaml()
322319
_generate_contrib_game_classes(_catalog_data)
323320
# _load_coded_games()
324321

0 commit comments

Comments
 (0)