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 |
connect |
Log in to a machine once with its password, so that from then on |
exits |
What a tool's exit code means: its recipe's |
host |
A host: where commands run. This machine, or another reached with the system's |
locking |
A short filesystem lock on an environment prefix, for the installs and removals of every client. |
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 |
|---|---|
ToolFailed |
|
Install |
|
Recipe |
|
RecipeStep |
|
ToolSpec |
|
Step |
One named unit of work: a command line, or an in-process call. |
StepFailed |
|
Host |
A machine, known by what running a command on it gives back: |
HostError |
|
Locked |
The prefix is another client's now: |
Functions:
| Name | Description |
|---|---|
app_recipe |
The recipe that gives a host the environment |
meaning |
What exit |
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 |
|
conda_platform |
|
prefix_lock |
Fail closed ( |
unlock |
Remove the lock of |
Attributes:
| Name | Type | Description |
|---|---|---|
MISSING |
|
|
READY |
|
|
STAMP |
|
|
UNREACHABLE |
|
|
LOCAL |
|
ToolFailed
¶
ToolFailed(tool: str, code: int, output: str = '', codes: dict | None = None)
Bases: RuntimeError
tool exited with code: what that means, and the last of what it said (output).
Methods:
| Name | Description |
|---|---|
__reduce__ |
|
Source code in src/ms_env/exits.py
40 41 42 43 44 | |
__reduce__
¶
__reduce__()
Source code in src/ms_env/exits.py
46 47 | |
Install
dataclass
¶
Install(key: str, future: Future = Future(), lines: list[str] = list(), done: int = 0, total: int = 1, step: str = '')
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 = '', platform: str = '', unsupported: 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
|
|
platform |
str
|
|
unsupported |
str
|
|
RecipeStep
dataclass
¶
RecipeStep(name: str, argv: tuple[str, ...] = (), timeout: float = 1800.0, send: tuple[str, ...] = (), url: str = '', sha256: str = '', to: str = '', downloads: tuple[tuple[str, str, str], ...] = (), local: Callable[[Callable[[str], None]], None] | None = None)
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
argv |
tuple[str, ...]
|
|
timeout |
float
|
|
send |
tuple[str, ...]
|
|
url |
str
|
|
sha256 |
str
|
|
to |
str
|
|
downloads |
tuple[tuple[str, str, str], ...]
|
|
local |
Callable[[Callable[[str], None]], None] | None
|
|
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, ...] = (), exit_codes: dict[int, str] = dict())
Methods:
| Name | Description |
|---|---|
failed |
The error to raise when the tool exited with |
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, ...]
|
|
exit_codes |
dict[int, str]
|
|
exit_codes
class-attribute
instance-attribute
¶
exit_codes: dict[int, str] = field(default_factory=dict)
failed
¶
failed(code: int, output: str = '') -> ToolFailed
The error to raise when the tool exited with code: says what that code means.
Source code in src/ms_env/recipes.py
150 151 152 | |
load
classmethod
¶
load(path: Path | str) -> 'ToolSpec'
Source code in src/ms_env/recipes.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
recipe
¶
recipe(tools_home: str, *, prefix: str = '', extra_paths: Iterable[str] = (), manager: str = '', platform: 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. platform is the host's (Host.platform()); this machine's by default.
Source code in src/ms_env/recipes.py
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 | |
Step
dataclass
¶
Step(name: str, argv: Optional[list[str]] = None, call: Optional[Callable[[], str]] = None, timeout: float = DEFAULT_TIMEOUT, run: Optional[Callable[[Callable[[str], None]], None]] = None)
One named unit of work: a command line, or an in-process call. run is a call that
prints as it goes: it gets the function each line goes to.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
|
argv |
Optional[list[str]]
|
|
call |
Optional[Callable[[], str]]
|
|
timeout |
float
|
|
run |
Optional[Callable[[Callable[[str], None]], None]]
|
|
run
class-attribute
instance-attribute
¶
run: Optional[Callable[[Callable[[str], None]], None]] = None
StepFailed
¶
Bases: RuntimeError
Host
¶
Host(address: str | None = None, ssh=('ssh', '-o', 'BatchMode=yes', *_SHARED))
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. |
platform |
The platform there, as conda names it (see |
Source code in src/ms_env/host.py
42 43 44 45 | |
__repr__
¶
__repr__() -> str
Source code in src/ms_env/host.py
47 48 | |
argv
¶
argv(command: str) -> list[str]
What to execute here for sh to run command there. This machine needs an sh for
that, which Windows lacks: what ms_env does here it does in Python, not through this.
Source code in src/ms_env/host.py
50 51 52 53 | |
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
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
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
69 70 71 72 73 | |
platform
¶
platform() -> str
The platform there, as conda names it (see conda_platform).
Source code in src/ms_env/host.py
75 76 77 78 79 | |
HostError
¶
Bases: RuntimeError
Locked
¶
Locked(prefix: str, host: Host, lock: str, owner: dict)
Bases: RuntimeError
The prefix is another client's now: owner is what it wrote (client, pid, since);
unlock(prefix, host) removes the lock once that client is known to have stopped.
Source code in src/ms_env/locking.py
27 28 29 30 31 | |
app_recipe
¶
app_recipe(name: str, requirements: Iterable[str], imports: Iterable[str], *, prefix: str, tools_home: str, cache: Path | str, manager: str = '', leave_out: Iterable[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.
leave_out names what the host goes without, though the packages ask for it (a GUI where
only their jobs run): what only those would bring is left out too.
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
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 | |
meaning
¶
meaning(code: int, codes: dict | None = None) -> str
What exit code means: codes (a recipe's [exit_codes], keyed by the code as text or
number) first; a signal (Python's negative code, or the shell's 128 + n); "" when unknown.
Source code in src/ms_env/exits.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
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
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
locate
¶
(READY, executable) or (MISSING | UNREACHABLE, ""). Blocks on a subprocess: keep it off UI threads.
A candidate counts when it is there and its check passes; on Windows, path.exe for path.
Source code in src/ms_env/recipes.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
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
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
remove
¶
Delete the prefix when ms_env installed it. False: nothing of ours there, nothing deleted.
Source code in src/ms_env/recipes.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 | |
status
¶
READY, MISSING or UNREACHABLE. Blocks like locate, which also says where the tool is.
Source code in src/ms_env/recipes.py
585 586 587 | |
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
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
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
87 88 89 90 91 92 93 94 95 96 97 98 | |
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
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 67 68 69 70 71 72 73 | |
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
76 77 78 79 80 81 82 83 84 | |
conda_platform
¶
conda_platform(system: str, machine: str) -> str
linux-64, osx-arm64, win-64...; system-machine for one conda has no name for.
Source code in src/ms_env/host.py
23 24 25 26 | |
prefix_lock
¶
Fail closed (Locked) when another client owns this prefix; no background service.
A lock left by a client of this machine that stopped (killed, crashed) is removed and taken
again. One of another machine is never guessed at, by age or else, as that is unsafe on a
cluster: unlock removes it once its owner is known to have stopped.
Source code in src/ms_env/locking.py
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 | |
unlock
¶
Remove the lock of prefix, whoever took it, and return what its owner wrote ({} for no lock).
Only once that owner is known to have stopped: else two clients change one environment.
Source code in src/ms_env/locking.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |