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#

Hide code cell content
import atexit
import os
import pathlib
import shutil
import tempfile

from IPython.display import *

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_x0ybetsf

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_core.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.3.0.tgz 13MB
    output:          /tmp/_my_lite_dir_x0ybetsf/_output
    lite dir:        /tmp/_my_lite_dir_x0ybetsf
    apps:            
    sourcemaps:      True
    unused packages: True
lite_archive:archive
lite_contents:contents
lite_icons:icons
lite_lite:jupyter-lite.json
lite_mimetypes: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_icons:icons
    favicon files: 0 files
.  lite_status:lite_lite:jupyter-lite.json
.  lite_status:lite_mimetypes:jupyter-lite.json
    filetypes:         26 
.  lite_status:lite_serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  lite_status:lite_settings:overrides
    overrides.json: 0
.  lite_status:lite_translation:translation
    translation files: 0 files
0

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.3.0.tgz 13MB
    output:          /tmp/_my_lite_dir_x0ybetsf/_output
    lite dir:        /tmp/_my_lite_dir_x0ybetsf
    apps:            
    sourcemaps:      True
    unused packages: True
lite_archive:archive
lite_contents:contents
lite_icons:icons
lite_lite:jupyter-lite.json
lite_mimetypes: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_icons:icons
    favicon files: 0 files
.  lite_status:lite_lite:jupyter-lite.json
.  lite_status:lite_mimetypes:jupyter-lite.json
    filetypes:         26 
.  lite_status:lite_serve:contents
    url: http://127.0.0.1:8000/
    server: tornado
    headers:
.  lite_status:lite_settings:overrides
    overrides.json: 0
.  lite_status:lite_translation:translation
    translation files: 0 files
.  hello
HELLO!