Skip to content
ocx
install

ComposedEnv, ConfigOverrides

ComposedEnvclassdataclass#

Re-exported from ocx_sdk._envmodelView source
class ComposedEnv(_values: Mapping[str, str])

A merged environment, ready for a child process.

Build one with merge(); EnvReport.compose() is the caller-facing route.

The values stay off every human-readable surface: a composed environment inherits whatever OCX_AUTH_* its base carried, and a repr is exactly what a traceback or a pytest diff prints (CWE-532). __repr__ names the keys and masks every value, the same shape SpawnEnv uses.

mappingproperty#

mapping: dict[str, str]

Return the merged environment as a fresh dict.

The non-invasive form, and the documented default: pass it as subprocess.run(..., env=...) instead of mutating the process.

activatemethod#

def activate() -> Generator[None]

Apply this environment to os.environ for the duration of the block.

Process-global and single-owner: it changes what every thread and every subprocess sees, and a second, overlapping activate() raises instead of nesting. Concurrent code passes mapping to the subprocess call.

The revert is diff-based — only the keys this environment sets are recorded on entry and restored on exit, keys that were absent are deleted again, and unrelated changes made inside the block survive. It runs in finally; os._exit, execve, and SIGKILL leave no chance to run it at all.

Raises

RuntimeError
Another activate() block already owns os.environ.

ConfigOverridesclass#

Re-exported from ocx_sdk._configView source
class ConfigOverrides(TypedDict)

Bases: TypedDict

The OcxConfig fields a with_config call may replace, all optional.

What makes Ocx.with_config(...) and Project.with_config(...) check their keyword arguments instead of accepting **overrides: Any, so a misspelled field is a type error rather than a TypeError at runtime. Public for the same reason MaybeRetry is: a wrapper around this SDK can forward a caller’s overrides with **overrides: Unpack[ConfigOverrides] rather than re-declaring the field list itself.

Mirrors OcxConfig field for field — a field added there and not here is a field with_config would refuse.

Optional at the class level rather than per field: this module postpones annotation evaluation, and a NotRequired[...] inside a string annotation is invisible to __required_keys__, so anything introspecting the type at runtime would be told every field was mandatory. Every field is optional here anyway, which is exactly what total=False says.