Skip to navigation

nemo_gym.server_runtime.supervisor.server_venv

View as MarkdownOpen in Claude

Module Contents

Functions

NameDescription
_get_nemo_gym_install_flagsBuild uv pip install flags for nemo-gym in sub-venvs.
_get_nemo_gym_version_specDetect nemo-gym version from parent venv and return version specifier.
_is_complete_venvWhether skip_venv_if_present may reuse venv_path: it needs the marker written after a successful setup.
_is_external_serverA server outside Gym’s own servers: in no Gym checkout, and not shipped inside the installed wheel.
_is_gym_checkoutWhether root is a NeMo Gym source checkout, not just any project with a pyproject.toml.
_legacy_setup_env_command-
_local_nemo_gym_extrasThe extras a server requests on its Gym requirement lines, formatted as [a,b], or "" for none.
_nemo_gym_extrasThe extras requested on the Gym requirements among requirements, formatted as [a,b], or "" for none.
_python_request_admitsWhether a uv Python request admits version.
_server_python_requestThe interpreter a server venv is built with: the parent’s, unless the server’s .python-version excludes it.
_validate_component_working_dirReject a server resolved outside scheduler-approved component roots.
get_venv_pathResolve the venv a server runs from: uv_venv_dir/<type>/<name>/.venv, else <server dir>/.venv.
run_command-
setup_env_commandPrepare a component from its lock, or retain custom component setup.

Data

NEMO_GYM_ALLOWED_COMPONENT_ROOTS_ENV_VAR_NAME

_NEMO_GYM_REQUIREMENT_ERE

_NEMO_GYM_REQUIREMENT_RE

__getattr__

API

nemo_gym.server_runtime.supervisor.server_venv._get_nemo_gym_install_flags() -> str

Build uv pip install flags for nemo-gym in sub-venvs.

Supports:

  • Pre-release versions via NEMO_GYM_ALLOW_PRERELEASE=true
  • Custom PyPI indexes via UV_INDEX_URL, UV_EXTRA_INDEX_URL, UV_INDEX_STRATEGY
  • Auto-detection of parent venv version for consistency

Returns: str

String of flags to add to ‘uv pip install nemo-gym’

nemo_gym.server_runtime.supervisor.server_venv._get_nemo_gym_version_spec() -> str

Detect nemo-gym version from parent venv and return version specifier.

Returns: str

Version specifier string (e.g., “==0.2.1rc0”) or empty string

nemo_gym.server_runtime.supervisor.server_venv._is_complete_venv(
venv_path: pathlib.Path
) -> bool

Whether skip_venv_if_present may reuse venv_path: it needs the marker written after a successful setup.

A cancelled install leaves bin/python and bin/activate without its packages, so those alone are not enough.

nemo_gym.server_runtime.supervisor.server_venv._is_external_server(
dir_path: pathlib.Path
) -> bool

A server outside Gym’s own servers: in no Gym checkout, and not shipped inside the installed wheel.

Its lock pins its own Gym source, so the locked installer would skip the parent’s Gym; the legacy installer gives it the parent’s editable checkout or the parent’s published version instead.

nemo_gym.server_runtime.supervisor.server_venv._is_gym_checkout(
root: pathlib.Path
) -> bool

Whether root is a NeMo Gym source checkout, not just any project with a pyproject.toml.

A server directory two levels below a Gym checkout installs Gym from that checkout. An external repository that keeps its own servers in resources_servers/<name> has a pyproject.toml of its own and gets Gym from the parent installation instead.

nemo_gym.server_runtime.supervisor.server_venv._legacy_setup_env_command(
dir_path: pathlib.Path,
global_config_dict: omegaconf.DictConfig,
prefix: str
) -> str
nemo_gym.server_runtime.supervisor.server_venv._local_nemo_gym_extras(
requirements_fpath: pathlib.Path
) -> str

The extras a server requests on its Gym requirement lines, formatted as [a,b], or "" for none.

A server outside a Gym checkout gets Gym from its parent installation instead of its own nemo-gym[...] line, so the line’s extras must be carried over or their dependencies are never installed.

nemo_gym.server_runtime.supervisor.server_venv._nemo_gym_extras(
requirements: typing.Iterable[str]
) -> str

The extras requested on the Gym requirements among requirements, formatted as [a,b], or "" for none.

nemo_gym.server_runtime.supervisor.server_venv._python_request_admits(
request: str,
version: str
) -> bool

Whether a uv Python request admits version.

The request is a specifier such as >=3.13,<3.14 or a version such as 3.13, optionally prefixed with cpython@ or cpython. Requests this cannot interpret, such as pypy@3.10 or the free-threaded 3.13+freethreaded, admit nothing and are left to uv.

nemo_gym.server_runtime.supervisor.server_venv._server_python_request(
dir_path: pathlib.Path,
parent_python: str
) -> str

The interpreter a server venv is built with: the parent’s, unless the server’s .python-version excludes it.

A range such as >=3.13.14,<3.14 would otherwise let uv pick a different patch release than the parent’s, and Ray refuses to connect processes whose Python patch versions differ.

nemo_gym.server_runtime.supervisor.server_venv._validate_component_working_dir(
working_dir_path: pathlib.Path,
server_name: str,
environment: dict[str, str]
) -> None

Reject a server resolved outside scheduler-approved component roots.

nemo_gym.server_runtime.supervisor.server_venv.get_venv_path(
dir_path: pathlib.Path,
global_config_dict: omegaconf.DictConfig
) -> pathlib.Path

Resolve the venv a server runs from: uv_venv_dir/<type>/<name>/.venv, else <server dir>/.venv.

Callers need this to launch a server with the venv’s own interpreter rather than trusting whatever bin/activate puts on PATH. A venv copied or moved after creation keeps the original prefix hard-coded in bin/activate, so sourcing it silently hands the server a different interpreter than the one uv_venv_dir asked for.

nemo_gym.server_runtime.supervisor.server_venv.run_command(
command: str,
working_dir_path: pathlib.Path,
server_name: str = '',
project_root: pathlib.Path | None = None,
global_config_dict: omegaconf.DictConfig | None = None,
stdout_target: typing.IO[typing.Any] | None = None,
stderr_target: typing.IO[typing.Any] | None = None,
extra_env: typing.Mapping[str, str] | None = None,
start_new_session: bool = False
) -> subprocess.Popen
nemo_gym.server_runtime.supervisor.server_venv.setup_env_command(
dir_path: pathlib.Path,
global_config_dict: omegaconf.DictConfig,
prefix: str
) -> str

Prepare a component from its lock, or retain custom component setup.

nemo_gym.server_runtime.supervisor.server_venv.NEMO_GYM_ALLOWED_COMPONENT_ROOTS_ENV_VAR_NAME = 'NEMO_GYM_ALLOWED_COMPONENT_ROOTS'
nemo_gym.server_runtime.supervisor.server_venv._NEMO_GYM_REQUIREMENT_ERE = '^[[:space:]]*(-e[[:space:]]+)?nemo[-_.]+gym([^A-Za-z0-9_.-]|$)'
nemo_gym.server_runtime.supervisor.server_venv._NEMO_GYM_REQUIREMENT_RE = re.compile('^\\s*(?:-e\\s+)?nemo[-_.]+gym(?![A-Za-z0-9_.-])\\s*(?:\\[(?P<extras>...
nemo_gym.server_runtime.supervisor.server_venv.__getattr__ = moved_names_getattr(__name__)