_manage_module
Manage brmspy runtimes and R environments.
This module defines the surface returned by brmspy.brms.manage().
The file is safe to import in the main Python process (no top-level
rpy2.robjects imports). In normal use these methods are invoked through the
manage() context, and the actual work executes in the worker process that
hosts the embedded R session.
Example:
env = "mrp"
if not brms.environment_exists(env):
with brms.manage(environment_name=env) as ctx:
ctx.install_brms(use_prebuilt=True)
ctx.install_rpackage("MCMCglmm")
else:
brms.environment_activate(env)
Notes
- Use the context manager to ensure the worker (and its embedded R session) is started with the desired environment configuration.
- Calling these methods directly in the main process is unsupported and may reintroduce the same stability issues that the worker isolation is designed to avoid.
Attributes¶
__all__ = ['ManageModule']
module-attribute
¶
Classes¶
ManageModule
¶
Management surface returned by brmspy.brms.manage().
The returned object is a proxy that executes these methods inside the worker process. Use it to install brms/toolchains, manage R packages in the active environment, and query basic runtime state.
Notes
The worker process must be able to run R and (depending on the installation mode) may require an OS toolchain for compiling packages / CmdStan.
Source code in brmspy/brms/_manage_module.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | |
Functions¶
install_runtime(*, install_rtools=False)
staticmethod
¶
Install the prebuilt brmspy runtime bundle.
This is a convenience wrapper around install_brms(use_prebuilt=True).
It downloads (if necessary) a precompiled runtime and optionally activates it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
install_rtools
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Path or None
|
Path to the installed runtime directory (prebuilt mode). Returns |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If no compatible prebuilt runtime exists for the current platform. |
Examples:
>>> from brmspy import brms
>>> with brms.manage(environment_name="default") as ctx:
... runtime = ctx.install_runtime()
Source code in brmspy/brms/_manage_module.py
install_brms(*, use_prebuilt=False, install_rtools=False, brms_version=None, cmdstanr_version=None, install_rstan=True, install_cmdstanr=True, rstan_version=None, activate=True)
staticmethod
¶
Install brms and its toolchain dependencies.
In traditional mode (use_prebuilt=False), this installs into the active R
library (typically the active brmspy environment) and may build CmdStan from
source.
In prebuilt mode (use_prebuilt=True), this downloads a brmspy runtime
bundle (R packages + CmdStan) and can activate it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_prebuilt
|
bool
|
If |
False
|
install_rtools
|
bool
|
If |
False
|
brms_version
|
str or None
|
Version spec for the brms R package (traditional mode only). |
None
|
cmdstanr_version
|
str or None
|
Version spec for cmdstanr (traditional mode only). |
None
|
install_rstan
|
bool
|
If |
True
|
install_cmdstanr
|
bool
|
If |
True
|
rstan_version
|
str or None
|
Version spec for rstan (traditional mode only). |
None
|
activate
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
Path or None
|
If |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If installation fails (for example missing toolchain, or no compatible prebuilt runtime exists). |
Examples:
Prebuilt (fast) install:
>>> from brmspy import brms
>>> with brms.manage(environment_name="default") as ctx:
... ctx.install_brms(use_prebuilt=True)
Traditional (R installs + builds CmdStan):
>>> from brmspy import brms
>>> with brms.manage(environment_name="default") as ctx:
... ctx.install_brms(use_prebuilt=False, install_cmdstanr=True, install_rstan=False)
Source code in brmspy/brms/_manage_module.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
install_rpackage(name, version=None, repos_extra=None)
staticmethod
¶
Install an R package into the active environment library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name (e.g. |
required |
version
|
str or None
|
Optional version spec. |
None
|
repos_extra
|
list[str] or None
|
Extra repositories to add (for example R-universe URLs). |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Notes
This installs into the active R library path (usually the brmspy environment library), not into the system R library tree.
Examples:
>>> from brmspy import brms
>>> with brms.manage(environment_name="mrp") as ctx:
... ctx.install_rpackage("MCMCglmm")
Source code in brmspy/brms/_manage_module.py
uninstall_rpackage(name)
staticmethod
¶
Uninstall an R package from the active library paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Notes
Package unloading/removal can be OS-dependent (especially on Windows where DLLs may be locked). This function makes a best effort.
Examples:
>>> from brmspy import brms
>>> with brms.manage(environment_name="mrp") as ctx:
... ok = ctx.uninstall_rpackage("MCMCglmm")
Source code in brmspy/brms/_manage_module.py
import_rpackages(*names)
staticmethod
¶
Import (load) one or more R packages into the worker's embedded R session.
This does not install packages. Use install_rpackage() first if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*names
|
str
|
One or more package names. |
()
|
Returns:
| Type | Description |
|---|---|
None
|
|
Examples:
>>> from brmspy import brms
>>> with brms.manage(environment_name="default") as ctx:
... ctx.import_rpackages("brms", "cmdstanr")
Source code in brmspy/brms/_manage_module.py
is_rpackage_loaded(name)
staticmethod
¶
Check whether an R package is loaded in the current R session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in brmspy/brms/_manage_module.py
get_rpackage_version(name)
staticmethod
¶
Get installed version of an R package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
str or None
|
Installed version string, or |
Source code in brmspy/brms/_manage_module.py
is_rpackage_installed(name)
staticmethod
¶
Check whether an R package is installed in the active library paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in brmspy/brms/_manage_module.py
_unload_rpackage(name)
staticmethod
¶
Attempt to unload an R package from the current session (advanced).
This is intentionally private: unloading packages at runtime can be fragile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
R package name. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in brmspy/brms/_manage_module.py
get_lib_paths()
staticmethod
¶
Get the current R .libPaths() search paths.
Returns:
| Type | Description |
|---|---|
list[str]
|
R library search paths (highest priority first). |
Source code in brmspy/brms/_manage_module.py
get_cmdstan_path()
staticmethod
¶
Get the current CmdStan path configured in cmdstanr.
Returns:
| Type | Description |
|---|---|
str or None
|
CmdStan directory path, or |