environment
Environment store helpers (internal).
This module provides small filesystem helpers for brmspy "environments", which
are named directories under ~/.brmspy/environment/<name>/ containing:
config.json(serializedEnvironmentConfig)Rlib/(user-managed R library for that environment)
The session layer uses these helpers when entering/leaving context-managed tools
(e.g. manage()), and for convenience methods like environment existence checks.
Classes¶
EnvironmentConfig
dataclass
¶
Worker environment configuration.
This configuration is applied in the worker before importing/using brms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_home
|
str or None
|
Override for |
None
|
startup_scripts
|
list[str]
|
R code snippets executed in the worker after initialization. |
list()
|
environment_name
|
str
|
brmspy environment name (used to determine |
'default'
|
runtime_path
|
str or None
|
Path to a brmspy runtime bundle to activate in the worker. |
None
|
env
|
dict[str, str]
|
Extra environment variables applied when spawning the worker. |
dict()
|
Source code in brmspy/types/session.py
Attributes¶
r_home = None
class-attribute
instance-attribute
¶
startup_scripts = field(default_factory=list)
class-attribute
instance-attribute
¶
environment_name = 'default'
class-attribute
instance-attribute
¶
runtime_path = None
class-attribute
instance-attribute
¶
env = field(default_factory=dict)
class-attribute
instance-attribute
¶
Functions¶
to_dict()
¶
Serialize configuration for persistence to JSON.
Source code in brmspy/types/session.py
from_dict(obj)
classmethod
¶
Deserialize configuration from a JSON object.
Source code in brmspy/types/session.py
from_obj(obj)
classmethod
¶
Normalize None | dict | EnvironmentConfig into an EnvironmentConfig.
Source code in brmspy/types/session.py
__init__(r_home=None, startup_scripts=list(), environment_name='default', runtime_path=None, env=dict())
¶
Functions¶
get_environment_base_dir()
¶
Return the base directory for brmspy environments, creating it if needed.
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in brmspy/_session/environment.py
get_environment_dir(name)
¶
Return the directory for a named environment (may or may not exist).
get_environments_state_path()
¶
Return the path to environment_state.json (stores last active environment name).
get_environment_userlibs_dir(name)
¶
get_environment_exists(name)
¶
Return True if an environment exists (determined by presence of config.json).
Source code in brmspy/_session/environment.py
get_environment_config(name)
¶
Load an environment configuration from disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Environment name. |
required |
Returns:
| Type | Description |
|---|---|
EnvironmentConfig
|
Loaded configuration. If no config file exists, returns a default config
with |