Customization
QR code & watermarks
You can customize the QR code (or disable it altogether) by specifying
a custom watermark in the call to gofigr.jupyter.configure()
. See gofigr.watermarks.DefaultWatermark
for other parameters.
%reload_ext gofigr
from gofigr.jupyter import *
configure(analysis=FindByName("Documentation examples", create=True),
auto_publish=True,
watermark=DefaultWatermark(show_qr_code=False))
Annotators
GoFigr implements Annotators
, an extensible framework for automatically including relevant
data when publishing revisions. You can use this mechanism to automatically
attach the output of pip freeze
, for example.
Out of the box, GoFigr includes the following annotators:
gofigr.jupyter.NotebookNameAnnotator
: annotates revisions with the name & path of the current notebookgofigr.jupyter.CellCodeAnnotator
: annotates revisions with the code of the Jupyter cellgofigr.jupyter.CellIdAnnotator
: annotates revisions with the Jupyter Cell ID (only available in Jupyter Lab)gofigr.jupyter.PipFreezeAnnotator
: annotates revisions with the output of pip freezegofigr.jupyter.SystemAnnotator
: annotates revisions with uname -a
Notebook name & path
GoFigr uses ipynbname to infer the name & path of the currently running notebook. While this works well most of the time, it may not work in certain configurations. For example, it doesn’t work if the notebook is executed programmatically with nbconvert. Other exceptions may exist, as well.
GoFigr will show a warning if the notebook name or path cannot be obtained. To fix, you can specify them in the call to configure:
%reload_ext gofigr
from gofigr.jupyter import *
configure(analysis=FindByName("Documentation examples", create=True),
auto_publish=True,
notebook_name="my notebook",
notebook_path="/path/to/notebook.ipynb")
Implementing custom annotators
To implement a custom annotator, simply subclass gofigr.jupyter.Annotator
. For example, here’s how pip freeze
is implemented:
class PipFreezeAnnotator(Annotator):
"""Annotates revisions with the output of pip freeze"""
def annotate(self, revision):
try:
output = subprocess.check_output(["pip", "freeze"]).decode('ascii')
except subprocess.CalledProcessError as e:
output = e.output
revision.data.append(_GF_EXTENSION.gf.TextData(name="pip freeze", contents=output))
return revision
You can annotate revisions with:
Specifying annotators
You can override the default annotators in the call to gofigr.jupyter.configure()
:
%reload_ext gofigr
from gofigr.jupyter import *
from gofigr.watermarks import DefaultWatermark
configure(..., annotators=DEFAULT_ANNOTATORS)