doit

The use of doit is an implementation detail, and is subject to change!

Under the hood, the CLI is powered by doit, a lightweight task engine in python comparable to make.

Using Tasks with the API

import os, pathlib, tempfile, shutil, atexit, hashlib
from IPython.display import *
from IPython import get_ipython # needed for `jupyter_execute` because magics?
import IPython
if "TMP_DIR" not in globals():
    TMP_DIR = pathlib.Path(tempfile.mkdtemp(prefix="_my_lite_dir_"))
    def clean():
        shutil.rmtree(TMP_DIR)
    atexit.register(clean)
os.chdir(TMP_DIR)
print(pathlib.Path.cwd())
/tmp/_my_lite_dir_lrjxn14u

The LiteManager collects all the tasks from Addons, and can optionally accept a task_prefix in case you need to integrate with existing tasks.

from jupyterlite.manager import LiteManager
manager = LiteManager(
    task_prefix="lite_"
)
manager.initialize()
manager.doit_run("lite_status")
lite_static:jupyter-lite.json
.  lite_pre_status:lite_static:jupyter-lite.json
    tarball:  jupyterlite-app-0.1.0-alpha.14.tgz 16MB
    output:   /tmp/_my_lite_dir_lrjxn14u/_output
    lite dir: /tmp/_my_lite_dir_lrjxn14u
    apps:     ('lab', 'retro')
lite_archive:archive
lite_contents:contents
lite_lite:jupyter-lite.json
lite_serve:contents
lite_settings:overrides
lite_translation:translation
.  lite_status:lite_archive:archive
.  lite_status:lite_contents:contents
    contents: 0 files
.  lite_status:lite_lite:jupyter-lite.json
.  lite_status:lite_serve:contents
    will serve 8000 with: tornado
.  lite_status:lite_settings:overrides
    overrides.json: 0
.  lite_status:lite_translation:translation
    translation files: 0 files

Custom Tasks and %doit

doit offers an IPython magic, enabled with an extension. This can be combined to create highly reactive build tools for creating very custom sites.

%reload_ext doit

It works against the __main__ namespace, which won’t have anything by default.

%doit list

All the JupyterLite tasks can be added by updating __main__ via globals

globals().update(manager._doit_tasks)

Now when a new task is created, it can reference other tasks and targets.

def task_hello():
    return dict(
        actions=[lambda: print("HELLO!")],
        task_dep=["lite_post_status"]
    )
%doit -v2 hello
lite_static:jupyter-lite.json
.  lite_pre_status:lite_static:jupyter-lite.json
    tarball:  jupyterlite-app-0.1.0-alpha.14.tgz 16MB
    output:   /tmp/_my_lite_dir_lrjxn14u/_output
    lite dir: /tmp/_my_lite_dir_lrjxn14u
    apps:     ('lab', 'retro')
.  hello
HELLO!