Skip to navigation

nemo_gym.orchestration.server_venv

View as Markdown

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.
_legacy_setup_env_command-
_local_nemo_gym_extrasThe extras a server requests on its local Gym requirement, 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

_LOCAL_NEMO_GYM_REQUIREMENT_RE

API

nemo_gym.orchestration.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.orchestration.server_venv._get_nemo_gym_version_spec(
is_editable_install: bool
) -> str

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

Parameters:

is_editable_install
bool

Whether nemo-gym is installed in editable mode in parent venv

Returns: str

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

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

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

Installs from PyPI replace the server’s nemo-gym[...] @ ../../ line with a nemo-gym requirement, so its extras must be carried over or their dependencies are never installed.

nemo_gym.orchestration.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.orchestration.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.orchestration.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.orchestration.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.orchestration.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.orchestration.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.orchestration.server_venv.NEMO_GYM_ALLOWED_COMPONENT_ROOTS_ENV_VAR_NAME = 'NEMO_GYM_ALLOWED_COMPONENT_ROOTS'
nemo_gym.orchestration.server_venv._LOCAL_NEMO_GYM_REQUIREMENT_RE = re.compile('^\\s*(?:-e\\s+)?nemo[-_]gym\\s*(?:\\[(?P<extras>[^\\]]*)\\])?\\s*@\\...