ocracy.kit.install#
Install plans: what a backend needs on this OS, as data an agent can act on.
Many backends are not one pip install away: a system binary (brew install
tesseract), a GPU wheel, first-run model weights, a credential. A package keeps
that knowledge as a recipes table (backend id -> recipe) and this module turns
one recipe into a Requirements whose instructions() is a
copy-pasteable plan:
>>> req = build_requirements(
... "tess", package="ocracy", implemented=True, available=False,
... recipe={"system": {"linux": ["apt-get install tesseract-ocr"]}},
... platform="linux",
... )
>>> req.pip_command
'pip install "ocracy[tess]"'
>>> req.system
['apt-get install tesseract-ocr']
A recipe needs only the fields that differ from the trivial
pip install "<package>[<id>]": extra (the pyproject extra, when it differs
from the id), system (platform -> shell commands), system_note, gpu (an
alternative pip line), weights (first-run downloads), heavy, alt (a
lighter backend) and notes.
run_install() executes the pip part of a plan (yes=True only) and verifies
it in a fresh interpreter. System commands and GPU wheels are surfaced, never run:
they need sudo, brew, or a CUDA choice only the user can make.
The registry and ledger lookups stay in the package (they are the package’s
knowledge); ocracy.install is the worked example. Stdlib only; imports
nothing else from ocracy.
Functions
|
|
|
Build |
|
Plan (default) or run ( |
Classes
|
What a backend needs to run, structured for an agent to act on. |
- class ocracy.kit.install.Requirements(backend_id, implemented, available, is_local, is_remote, pip_command, extra=None, system=<factory>, system_note=None, gpu=None, weights=None, heavy=False, alternative=None, credentials=<factory>, notes=<factory>, verify_command=None, alternative_label='Lighter alternative')[source]#
Bases:
objectWhat a backend needs to run, structured for an agent to act on.
- ocracy.kit.install.build_requirements(backend_id, *, package, implemented, available, recipe=None, is_local=False, is_remote=False, ledger_pip='', credentials=(), platform=None, verify_command=None, unimplemented_note=None, alternative_label='Lighter alternative')[source]#
Build
Requirementsforbackend_idfrom its recipe and known facts.- Parameters:
backend_id (
str) – The backend’s id.package (
str) – The distribution whose extra installs it (pip install "pkg[x]").implemented (
bool) – Whether the package ships a facade for it.available (
bool) – Whether it is usable right now (the package’s own probe).recipe (
Optional[Mapping]) – Its row of the package’s recipes table (see the module docstring).is_remote (
bool) – From the backend’s config or ledger record.ledger_pip (
str) – The ledger’s install line, used for a backend not implemented.credentials (
Iterable[str]) –exportlines (seecredential_lines()).platform (
Optional[str]) – Overridecurrent_platform()(for tests and docs).verify_command (
Optional[str]) – The shell line shown asVerify:.unimplemented_note (
Optional[str]) – Appended tonoteswhen not implemented.alternative_label (
str) – The wording beforealtin the instructions.
- Return type:
- ocracy.kit.install.current_platform()[source]#
'darwin','linux','windows', orsys.platformfor anything else.- Return type:
- ocracy.kit.install.run_install(req, *, package, yes=False, verify_code=None, upgrade=False)[source]#
Plan (default) or run (
yes=True) the pip install thatreqdescribes.- Parameters:
req (
Requirements) – The plan, frombuild_requirements().package (
str) – The distribution whose extra to install.yes (
bool) – Actually run pip; otherwise a dry run that changes nothing.verify_code (
Optional[str]) – Python source run in a fresh interpreter after a successful install;available_afteris whether it printedTrue.upgrade (
bool) – Pass--upgradeto pip.
- Return type:
- Returns:
{backend, requirements, ran, available_before, message?, pip_argv?, returncode?, stdout_tail?, stderr_tail?, available_after?, system_todo?}.