User defined reports#
canary can write output in a number of formats: JSON, HTML, Markdown, among others (see canary report for additional formats). User defined report formats can be created by returning an instance of canary.CanaryReporter from a _canary.plugins.hookspec.canary_session_reporter() plugin hook. For example, the following will write a custom plain text report.
import os
import canary
@canary.hookimpl
def canary_session_reporter():
return TxtReporter()
class TxtReporter(canary.CanaryReporter)
type = "txt"
description = "Create a plain text report"
def create(self, output: str | None = None) -> None:
"""Create a plain text output
"""
output = output or "canary-report.txt"
workspace = canary.Workspace.load()
with open(output, "w") as fh:
for job in workspace.load_jobs():
fh.write("====\n")
fh.write(f"Name: {job.spec.name}\n")
fh.write(f"Start: {job.timekeeper.started_on}\n")
fh.write(f"Finish: {job.timekeeper.finished_on}\n")
fh.write(f"Status: {job.status.name}\n")
$ canary report txt -h
usage: canary report txt [-h] ...
positional arguments:
create Create plain text report
options:
-h, --help show this help message and exit
$ canary report txt create -h
usage: canary report txt create [-h] [-o O]
options:
-h, --help show this help message and exit
-o O Output file name [default: ./output.txt]