gvn.console
The gvn command line and the Project it loads: what one codebase offers to gvn's tools.
The ideas behind it are explained in Writing the project, Your first eval. This page is generated from the source, so it lists every public name with its signature and docstring. Python API has the other packages and an index of every name.
Modules
| Module | What it holds | Names |
|---|---|---|
gvn.console.cli |
The gvn command line |
junit, main, run |
gvn.console.project |
Project: what one codebase offers to gvn's tools, written once by its developers | NotOffered, Project, load_project |
gvn.console.cli
The gvn command line.
Standard library only (argparse). Read by product managers and QA engineers as
well as developers: every message is a plain sentence that says what happened and
what to do next; no tracebacks for mistakes a person can fix (a missing file, a
name the project does not offer, a FileProblem). Any ValueError or
LookupError that reaches the command line is such a refusal (gvn refuses a wrong
value with the one and an unknown name with the other), so it is printed as one
sentence with exit status 2; any other exception is a defect and keeps its
traceback.
The project comes from --project package.module:attribute, else from the
environment variable GVN_PROJECT, else from project = "..." under
[tool.gvn] in a pyproject.toml: the one in the current directory or in the
nearest parent whose pyproject.toml has that setting (files without it are
passed over). Beside project that file may say pythonpath = ["src"]: folders,
relative to it, put on sys.path in place of the folder itself, for a project in the
src/ layout. It applies only to a project named this way.
::
gvn eval list
The eval files of the project, the versions and criteria it offers, and
recorded eval runs.
gvn eval run FILE --version NAME [--name RUN] [--trials N] [--only TAGS_OR_IDS]
[--budget AMOUNT] [--concurrency N] [--junit PATH]
[--at-least CRITERION=RATE ...] [--allow-could-not-run N]
Run an eval against a version (continuing a run of that name if one was
started) and print the report's summary. --trials and --only replace the
eval file's trials and only (tags or case ids, separated by commas); the run's
default name is EVAL.VERSION, followed by .only-<what was chosen> and
.<N>-trials when they differ from the file, so a smaller run is never taken
for the whole one. With --junit, also write a JUnit XML
file: one test suite, one test case per case of the eval, failed when the
case is failing or flaky (the message lists the failing criteria and their
explanations), errored when its trials errored, skipped when unjudged.
With --at-least, apply that gate (see ``gate``).
gvn eval show RUN
The summary of a recorded eval run, then the trials that could not run (case
and trial, counted from 1, and why), the trials another gvn eval run is
running or scoring right now, and the reviews waiting for a reviewer (case and
trial, and criterion).
gvn eval compare CANDIDATE BASELINE [--margin POINTS] [--min-cases N]
Is the candidate run better than the baseline run? Prints the verdict in
words (with why, when there is not enough data to tell because a case was
not judged in a run or fewer than N cases, default 6, were judged in both),
which version each run is of and what each cost, what else differs between
the two runs, and the differences.
gvn eval gate RUN --at-least CRITERION=RATE [--at-least ...] [--allow-could-not-run N]
For CI: exit 1 unless each named criterion's pass rate (``passed`` for the
trial as a whole) is at least RATE (0.9 or 90%) and was judged in every trial
that ran, no more than N trials (default 0) could not run, and the run is
complete (``Report.gate``).
gvn eval regrade FILE --version NAME [--name RUN] [--trials N] [--only TAGS_OR_IDS]
Score a recorded run again with the eval file's current criteria, running
no trial. --trials and --only name the run as ``run`` does.
gvn eval review [RUN]
The reviews waiting for a reviewer, in every recorded run (or in RUN): the
run, the case, the trial (counted from 1), the criterion, its question, its
verdicts and the command that records an answer.
gvn eval review RUN CASE TRIAL CRITERION VERDICT --by NAME [--note TEXT]
Record one person's verdict on a waiting review, as the web page does
(``Runner.review``). TRIAL is counted from 1, as ``show`` and ``review``
print it. NAME is who answers; TEXT is kept with the verdict.
gvn eval serve [--port N] [--open]
Start the Workbench (``gvn_workbench.app``, the separate ``gvn-workbench``
package) on this computer and print the address of its eval page. The
Workbench is told how the project was found here (its
``package.module:attribute`` and the ``pythonpath`` folders), so that it can
load the project again after a save changes its files.
Wherever gvn's own sentences point to gvn eval regrade (trials that wait to be
scored again, two runs compared under criteria that changed, a review asked under
other criteria), the command line prints the exact command for that run: its eval
file, --version, and the --only, --trials and --name that find it.
Exit status: 0 done; 1 a gate failed, a comparison is worse under
--fail-if-worse, or the run stopped at its budget; 2 the command or a file is
wrong.
junit
from gvn.console.cli import junit
junit(report_plain: dict[str, typing.Any]) -> str
The JUnit XML text of a Report.to_plain() dict, as eval run --junit
writes it.
One <testsuite> (named after the eval run) inside <testsuites>, one
<testcase> per case (classname: the eval, name: the case id), in
reading order of the case ids (case2 before case10), as the report lists
them. A failing or flaky case holds a <failure> naming the failing
criteria, with one line per failing score as its text (and, when some of its
trials could not run, how many in the message and why in the text); otherwise a
case with an errored trial holds an <error> with the reasons; otherwise an
unjudged case is <skipped>. No time attributes.
main
from gvn.console.cli import main
main(
argv: Sequence[str] | None = None,
project: Project | None = None,
out: typing.TextIO | None = None,
err: typing.TextIO | None = None,
) -> int
Run the command line and return its exit status (never calls sys.exit).
argv: None for sys.argv[1:]. project: None to load it as the module
docstring says; given, it is used as is (how tests and embedding programs call
this). out / err: None for sys.stdout / sys.stderr.
run
from gvn.console.cli import run
run() -> None
The console script gvn: main() as the process's exit status.
gvn.console.project
Project: what one codebase offers to gvn's tools, written once by its developers.
A Project holds its harnesses and, for evals, its versions, environments, criteria
and stand-ins. Eval files name things; a Project is where those names mean
something. It is built explicitly and passed in (there is no registry): the command
line and the web page load it from module:attribute.
NotOffered
from gvn.console.project import NotOffered
An eval file names a version, environment, stand-in or criterion the project does not offer; the message lists what it does offer.
Project
from gvn.console.project import Project
Project(
root: Path,
versions: Mapping[str, Subject],
environments: Mapping[str, Environments],
journal: Journal,
results: Results,
model: Model,
clock: Clock,
criteria: Mapping[str, Criterion] | None = None,
stand_ins: Mapping[str, StandIn] | None = None,
model_roles: Mapping[str, Model] | None = None,
rates: Rates | None = None,
currency: str | None = None,
harnesses: Iterable[Harness] | None = None,
) -> None
root: the directory holding the eval and cases files (searched
recursively for *.eval.toml and *.cases.csv / *.cases.jsonl).
versions: name -> Subject, at least one. environments: name ->
Environments, at least one. criteria: key -> Criterion (or Check) offered
to eval files under use = "<key>"; the key is a short word for the file, and
reports call the criterion by the name the file gives it, else by its own
name(). stand_ins: name -> StandIn. journal, results, model,
model_roles, clock, rates: as gvn.evals.running.Runner takes.
currency: None, or what the amounts of rates are in ("USD"), passed to
the Runner for reports to name. harnesses: None (none), or an iterable of
gvn.runtime.harnesses.Harness, each known by its own name(), so two of one
name are refused. Names are non-empty strs. Immutable.
Project.root
root() -> Path
Project.versions
versions() -> tuple[str, ...]
The names of the versions offered, sorted.
Project.version
version(name: str) -> Subject
NotOffered when absent.
Project.harnesses
harnesses() -> tuple[str, ...]
The names of the harnesses offered, sorted.
Project.harness
harness(name: str) -> Harness
NotOffered when absent.
Project.offered
offered() -> dict[str, tuple[str, ...]]
{"versions", "environments", "criteria", "stand_ins"} -> sorted names.
Project.criteria
criteria() -> dict[str, str]
Key -> the criterion's own name, for every criterion offered (sorted by
key): what use = "<key>" brings in and what reports call it when the eval
file gives it no name.
Project.currency
currency() -> str | None
Project.eval_files
eval_files() -> tuple[Path, ...]
Every *.eval.toml under the root, sorted.
Project.cases_files
cases_files() -> tuple[Path, ...]
Every *.cases.csv and *.cases.jsonl under the root, sorted.
Project.within
within(relative: str) -> Path
The path of relative under the root. ValueError when it would leave the
root (.., an absolute path, a symbolic link out of it).
Project.eval
eval(
eval_file: EvalFile,
trials: int | None = None,
only: Sequence[str] | None = None,
) -> Eval
The Eval an eval file describes: its cases read (only applied), each
use criterion looked up by its key, each spends, judge and
review entry built (gvn.evals.criteria.Spends, gvn.evals.judging),
the environment and stand-in looked up. A use or spends entry with a
name is reported under that name.
trials / only: None to keep what the file says, else what to run
instead: the number of trials (an int >= 1), the tags or case ids whose cases
run (a non-empty collection of non-empty str; a case runs when it has one of
the tags or one of the ids).
NotOffered for a name the project lacks, listing what it offers (a judge
entry also needs a model under the role "judge"); FileProblem from the
cases file, for an eval name that cannot name a run, or for a use entry
without a name whose criterion is itself called "passed" (taken by the
overall result; the file must give it another name); ValueError when an
entry of only is neither a tag nor a case id, or when two criteria end up
with one name.
Project.runner
runner(
budget: float | None = None,
concurrency: int = 4,
per_trial: float | None = None,
) -> Runner
A Runner over this project's journal, results, models and clock.
budget / per_trial: None, or a cost limit in the currency of
rates for the whole eval run / for each trial (ValueError when given
without rates).
Project.results
results() -> Results
Project.journal
journal() -> Journal
Project.model
model() -> Model
The model the project's runs use when they name no role.
Project.clock
clock() -> Clock
Project.model_role
model_role(name: str) -> Model
The model offered under the role name. NotOffered when absent, naming the
roles offered.
load_project
from gvn.console.project import load_project
load_project(spec: str) -> Project
The Project named by "package.module:attribute": the attribute is a Project,
or a function of no arguments returning one. ValueError saying what is wrong
(no colon, module not importable, attribute missing, not a Project) otherwise.