Skip to navigation

nemo_gym.server_runtime.entrypoint_flags

View as Markdown

Reading literal class flags, such as ray_enabled, from a server entrypoint’s source without importing it.

Module Contents

Functions

NameDescription
_declared_class_flagThe literal boolean assigned to name in a class body, annotated or not, or None when there is none.
_parse_entrypoint-
_run_webserver_class_names-
entrypoint_class_flagThe boolean class attribute name declared by the server an entrypoint starts, read from source.
entrypoint_server_class_namesThe names of the classes an entrypoint calls run_webserver() on, read from source; empty if unreadable.

API

nemo_gym.server_runtime.entrypoint_flags._declared_class_flag(
class_node: ast.ClassDef,
name: str
) -> bool | None

The literal boolean assigned to name in a class body, annotated or not, or None when there is none.

nemo_gym.server_runtime.entrypoint_flags._parse_entrypoint(
entrypoint_fpath: pathlib.Path
) -> ast.Module | None
nemo_gym.server_runtime.entrypoint_flags._run_webserver_class_names(
tree: ast.Module
) -> set[str]
nemo_gym.server_runtime.entrypoint_flags.entrypoint_class_flag(
entrypoint_fpath: pathlib.Path,
name: str
) -> bool | None

The boolean class attribute name declared by the server an entrypoint starts, read from source.

Gym settles some things before any server exists, and each server runs in its own venv, so this reads the source instead of importing it. It finds the classes the entrypoint calls run_webserver() on and checks their literal name declarations (name = True or name: ClassVar[bool] = True in the class body).

Returns True when any of them declares True, False when all of them declare False, and None when that can’t be settled from the source alone, such as an inherited declaration, a class imported from another module, or an unreadable entrypoint.

nemo_gym.server_runtime.entrypoint_flags.entrypoint_server_class_names(
entrypoint_fpath: pathlib.Path
) -> set[str]

The names of the classes an entrypoint calls run_webserver() on, read from source; empty if unreadable.