API reference¶
Every name is imported from ms_env.
ms_env
¶
Environments for MolSuite apps: a recipe says how to tell that a tool works and how to
install it, a host says where, and ensure applies one to the other.
The lowest layer of MolSuite: the standard library, no Qt, and nothing of ms_flow.
Modules:
| Name | Description |
|---|---|
app |
The environment of an app on a host: the Python that runs here, with the same versions of |
host |
A host: where commands run. This machine, or another reached with the system's |
recipes |
External tools: find one that already works, or install it -- driven by a TOML file. |
steps |
Steps: named units of work that run one after another, their output read line by line. |
Classes:
| Name | Description |
|---|---|
Install |
|
Recipe |
|
RecipeStep |
|
ToolSpec |
|
Step |
One named unit of work: either a command line or an in-process call. |
StepFailed |
|
Host |
A machine, known by what running a command on it gives back: |
HostError |
|
Functions:
| Name | Description |
|---|---|
app_recipe |
The recipe that gives a host the environment |
ensure |
Make sure the tool is there: start installing it, or join the install already running. |
locate |
(READY, executable) or (MISSING | UNREACHABLE, ""). Blocks on a subprocess: keep it off UI threads. |
recipe_steps |
The whole install: clear what ms_env left at the prefix, run the recipe, stamp it. |
remove |
Delete the prefix when ms_env installed it. False: nothing of ours there, nothing deleted. |
status |
READY, MISSING or UNREACHABLE. Blocks like |
verify |
What the environment at the recipe's prefix lacks of what the recipe asks for; [] when it meets it. |
find_environment_manager |
The program that creates environments here: micromamba, unless a variable names another. |
run_step |
Run one step, streaming its output. Raises StepFailed on failure. |
run_steps |
|
Attributes:
| Name | Type | Description |
|---|---|---|
MISSING |
|
|
READY |
|
|
STAMP |
|
|
UNREACHABLE |
|
|
LOCAL |
|
Install
dataclass
¶
Install(key: str, future: Future = Future(), lines: list[str] = list())
Recipe
dataclass
¶
Recipe(name: str, prefix: str, candidates: tuple[str, ...], commands: tuple[str, ...], check: tuple[str, ...], steps: tuple[RecipeStep, ...], conda: tuple[str, ...] = (), pip: tuple[str, ...] = (), stamp: str = '', refresh: tuple[RecipeStep, ...] = (), base: str = '')
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
prefix |
str
|
|
candidates |
tuple[str, ...]
|
|
commands |
tuple[str, ...]
|
|
check |
tuple[str, ...]
|
|
steps |
tuple[RecipeStep, ...]
|
|
conda |
tuple[str, ...]
|
|
pip |
tuple[str, ...]
|
|
stamp |
str
|
|
refresh |
tuple[RecipeStep, ...]
|
|
base |
str
|
|
RecipeStep
dataclass
¶
RecipeStep(name: str, argv: tuple[str, ...], timeout: float = 1800.0, send: tuple[str, ...] = ())
ToolSpec
dataclass
¶
ToolSpec(name: str, version: str, info: dict[str, Any], prefix: str, paths: tuple[str, ...], commands: tuple[str, ...], check: tuple[str, ...], conda: tuple[str, ...] = (), pip: tuple[str, ...] = (), channels: tuple[str, ...] = ('conda-forge',), steps: tuple[RecipeStep, ...] = ())
Methods:
| Name | Description |
|---|---|
load |
|
recipe |
Bind the templates to one host. |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
version |
str
|
|
info |
dict[str, Any]
|
|
prefix |
str
|
|
paths |
tuple[str, ...]
|
|
commands |
tuple[str, ...]
|
|
check |
tuple[str, ...]
|
|
conda |
tuple[str, ...]
|
|
pip |
tuple[str, ...]
|
|
channels |
tuple[str, ...]
|
|
steps |
tuple[RecipeStep, ...]
|
|
load
classmethod
¶
load(path: Path | str) -> 'ToolSpec'
Source code in src/ms_env/recipes.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
recipe
¶
recipe(tools_home: str, *, prefix: str = '', extra_paths: Iterable[str] = (), manager: str = '') -> Recipe
Bind the templates to one host. tools_home/prefix are paths on that host.
prefix is a location the user chose instead of the managed one: an environment of
their own (checked, never changed) or a place to install into. extra_paths are
user-registered executables; manager is a conda-type program to use there instead
of micromamba.
Source code in src/ms_env/recipes.py
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 | |
Step
dataclass
¶
Step(name: str, argv: Optional[list[str]] = None, call: Optional[Callable[[], str]] = None, timeout: float = DEFAULT_TIMEOUT)
StepFailed
¶
Bases: RuntimeError
Host
¶
Host(address: str | None = None, ssh=('ssh', '-o', 'BatchMode=yes'))
A machine, known by what running a command on it gives back: address as ssh knows it (its
keys, users and jumps are in ~/.ssh/config), or None for this one.
Methods:
| Name | Description |
|---|---|
__repr__ |
|
argv |
What to execute here for |
run |
What |
home |
The home of the account there: where a path of ours on that machine starts. |
Source code in src/ms_env/host.py
19 20 | |
__repr__
¶
__repr__() -> str
Source code in src/ms_env/host.py
22 23 | |
argv
¶
argv(command: str) -> list[str]
What to execute here for sh to run command there.
Source code in src/ms_env/host.py
25 26 27 | |
run
¶
run(command: str, data=b'', timeout: float = 600) -> bytes
What command printed there, given data (bytes, or an open file) to read.
Source code in src/ms_env/host.py
29 30 31 32 33 34 35 36 37 38 39 40 41 | |
home
¶
home() -> str
The home of the account there: where a path of ours on that machine starts.
Source code in src/ms_env/host.py
43 44 45 | |
HostError
¶
Bases: RuntimeError
app_recipe
¶
app_recipe(name: str, requirements: Iterable[str], imports: Iterable[str], *, prefix: str, tools_home: str, cache: Path | str, manager: str = '') -> Recipe
The recipe that gives a host the environment requirements run in here.
requirements are the packages of the app, each name or name[extras]: one imported
from a source checkout goes as a wheel of its code as it is now, one that is installed is
asked for in the version it has. imports are the modules that have to import there for
the environment to count as usable. prefix and tools_home are paths on the host (see
Host.home); cache is a directory of this machine for the wheels.
The environment is updated where it stands for as long as the Python is the same. Builds wheels the first time, and after the code changes: keep it off UI threads.
Source code in src/ms_env/app.py
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 | |
ensure
¶
Make sure the tool is there: start installing it, or join the install already running.
Returns at once: wait on future and read lines for the log. Nothing is installed
where the tool is already usable. An install of ours made from another recipe is made
again, or brought up to this one where it stands when the recipe says how (that is the
update); an environment of the user is verified and left as it is.
busy is asked only before an install of ours is changed: what it returns is why that
cannot be done now (something is running from it), and the install fails saying so.
Source code in src/ms_env/recipes.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |
locate
¶
(READY, executable) or (MISSING | UNREACHABLE, ""). Blocks on a subprocess: keep it off UI threads.
Source code in src/ms_env/recipes.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
recipe_steps
¶
The whole install: clear what ms_env left at the prefix, run the recipe, stamp it.
The first step fails on a prefix that holds something ms_env did not install. With
refresh the prefix stays and only recipe.refresh runs before the stamp.
Source code in src/ms_env/recipes.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
remove
¶
Delete the prefix when ms_env installed it. False: nothing of ours there, nothing deleted.
Source code in src/ms_env/recipes.py
384 385 386 387 388 389 390 391 392 393 394 395 | |
status
¶
READY, MISSING or UNREACHABLE. Blocks like locate, which also says where the tool is.
Source code in src/ms_env/recipes.py
315 316 317 | |
verify
¶
What the environment at the recipe's prefix lacks of what the recipe asks for; [] when it meets it.
The way to take an environment the user already has instead of installing one: every
pinned conda package (looked up in conda-meta), every pinned pip package (asked to the
python of the prefix) and the recipe's check on the executables of that prefix. Reads
only. ponytail: a pip URL or path is not looked up, and >= counts as "is there".
Source code in src/ms_env/recipes.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
find_environment_manager
¶
find_environment_manager(*extra_variables: str) -> Path | None
The program that creates environments here: micromamba, unless a variable names another.
extra_variables are app-specific overrides, read before MOLSUITE_ENV_MANAGER; any
of them may name a conda or a mamba. None: the recipe downloads its own micromamba.
Source code in src/ms_env/steps.py
80 81 82 83 84 85 86 87 88 89 90 91 | |
run_step
¶
run_step(step: Step, on_line: Callable[[str], None] | None = None) -> None
Run one step, streaming its output. Raises StepFailed on failure.
Source code in src/ms_env/steps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
run_steps
¶
run_steps(steps: Iterable[Step], on_line: Callable[[str], None] | None = None, on_step: Callable[[int, Step], None] | None = None) -> None
Source code in src/ms_env/steps.py
69 70 71 72 73 74 75 76 77 | |