Coverage for adaro_rl / zoo / registry.py: 92%
13 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 07:50 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 07:50 +0000
1import os
2import importlib
5IS_SPHINX_BUILD = (
6 os.getenv("READTHEDOCS") == "True" or os.getenv("SPHINX_BUILD") == "1"
7)
10def import_configs(pkg_dir: str, pkg_name: str):
11 """
12 Internally collect *zoo* configurations (environments + agents).
14 The helper scans the given ``pkg_dir`` for sub-packages that define a
15 particular benchmark (e.g. ``Enduro-v5``, ``HalfCheetah-v5``), imports
16 each of them, and returns a dictionary that maps the folder name to the
17 imported module. The function is called automatically when
18 `adaro_rl.zoo` is imported; end-users normally never invoke it
19 directly.
21 During a Sphinx/Read-the-Docs build the import pass is skipped so the
22 documentation process remains lightweight.
24 Parameters
25 ----------
26 pkg_dir : str
27 Absolute path to the directory that contains the configuration
28 folders.
29 pkg_name : str
30 Fully-qualified parent package name (usually ``"adaro_rl.zoo"``).
32 Returns
33 -------
34 dict[str, module]
35 Mapping ``{config_name: module}`` with one entry for every valid
36 configuration found in *pkg_dir*. An empty dictionary is returned
37 when the build runs under Sphinx.
38 """
39 if IS_SPHINX_BUILD:
40 return {}
42 cfgs = {}
43 for entry in os.listdir(pkg_dir):
44 p = os.path.join(pkg_dir, entry)
45 if os.path.isdir(p) and "__init__.py" in os.listdir(p):
46 mod = importlib.import_module(f".{entry}", package=pkg_name)
47 cfgs[entry] = mod
48 return cfgs