nemo_gym

View as Markdown

Subpackages

Submodules

Package Contents

Functions

NameDescription
_augment_sys_pathPut the artifact roots on sys.path so plugin modules (e.g. a benchmark’s prepare.py) import.
_extra_roots-
_resolve_under_cwd_or_installResolve a possibly-relative path for reading a built-in or user-supplied file against the ordered
component_search_rootsOrdered, de-duplicated roots to look for a Gym component/artifact under: the NEMO_GYM_EXTRA_ROOTS
print_always_flushes-

Data

CACHE_DIR

NEMO_GYM_EXTRA_ROOTS_ENV_VAR_NAME

OLD_PRINT

PARENT_DIR

RESULTS_DIR

ROOT_DIR

WORKING_DIR

_is_editable_install

API

nemo_gym._augment_sys_path() -> None

Put the artifact roots on sys.path so plugin modules (e.g. a benchmark’s prepare.py) import.

Extra roots go to the front and cwd/PARENT_DIR (the built-ins) to the end, so import precedence matches file resolution under :func:component_search_roots (a plugin shadows a same-named Gym module). Idempotent; reads NEMO_GYM_EXTRA_ROOTS at call time, so it can be re-run after --search-dir folds roots into the env (see nemo_gym.cli.main).

nemo_gym._extra_roots() -> typing.List[pathlib.Path]
nemo_gym._resolve_under_cwd_or_install(
rel_path: typing.Union[str, pathlib.Path],
validator: typing.Optional[typing.Callable[[Path], bool]] = None
) -> pathlib.Path

Resolve a possibly-relative path for reading a built-in or user-supplied file against the ordered :func:component_search_roots.

Absolute paths are returned unchanged. A relative path is returned rooted at the first root where it exists (earliest-wins: extra roots > cwd > install root), so a repo-relative path like benchmarks/<name>/config.yaml or resources_servers/<env>/data/example.jsonl resolves by name from any cwd or plugin root. validator overrides the default Path.exists check — pass it when a candidate is valid only if specific markers are present (e.g. a server dir must ship requirements.txt or pyproject.toml). If nothing matches, the path under the highest-priority root is returned so error messages point at the user’s own location.

Use this for read paths only — never for write targets (e.g. metrics written next to a dataset), which must stay relative to the user’s writable cwd rather than the install root.

nemo_gym.component_search_roots(
sys_path: typing.List[pathlib.Path] | None = None
) -> typing.List[pathlib.Path]

Ordered, de-duplicated roots to look for a Gym component/artifact under: the NEMO_GYM_EXTRA_ROOTS roots first, then cwd and the install root (PARENT_DIR, the built-ins) last.

Earlier roots win on a name collision, so user components shadow built-ins. De-duplicated by resolved path, since cwd/install root coincide in an editable checkout. The single source of truth for where Gym looks for components — used by path resolution (:func:_resolve_under_cwd_or_install), module imports (:func:_augment_sys_path) and the gym list/gym search discovery functions.

sys_path weaves existing sys.path entries in for import precedence: they slot in after the extra roots but before cwd/built-ins. Any entry that is itself cwd or the install root is dropped so those two always stay last — matching the file-lookup order even in a wheel install, where the install root is already on sys.path as site-packages.

nemo_gym.print_always_flushes(
args = (),
kwargs = {}
) -> None
nemo_gym.CACHE_DIR = WORKING_DIR / 'cache'
nemo_gym.NEMO_GYM_EXTRA_ROOTS_ENV_VAR_NAME = 'NEMO_GYM_EXTRA_ROOTS'
nemo_gym.OLD_PRINT = print
nemo_gym.PARENT_DIR = ROOT_DIR.parent
nemo_gym.RESULTS_DIR = WORKING_DIR / 'results'
nemo_gym.ROOT_DIR = Path(__file__).absolute().parent
nemo_gym.WORKING_DIR = PARENT_DIR if _is_editable_install else Path.cwd()
nemo_gym._is_editable_install = (PARENT_DIR / 'pyproject.toml').exists()