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 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_hu3xrtc8

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-beta.14.tgz 8MB
    output:          /tmp/_my_lite_dir_hu3xrtc8/_output
    lite dir:        /tmp/_my_lite_dir_hu3xrtc8
    apps:            
    sourcemaps:      True
    unused packages: True
lite_archive:archive
lite_contents:contents
lite_lite:jupyter-lite.json
lite_mathjax:status
lite_mimetypes:jupyter-lite.json
lite_pyodide:pyodide
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_mathjax:status
     jupyter-server-mathjax: /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/latest/lib/python3.10/site-packages/jupyter_server_mathjax/static 
     configured MathJax dir: /tmp/_my_lite_dir_hu3xrtc8/traitlets.Undefined
     effective MathJax dir: /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/latest/lib/python3.10/site-packages/jupyter_server_mathjax/static
.  lite_status:lite_mimetypes:jupyter-lite.json
    filetypes:         26 
.  lite_status:lite_pyodide:pyodide
     URL: None
 archive: []
   cache: 0 files
   local: 0 files
.  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.1.0-beta.14.tgz 8MB
    output:          /tmp/_my_lite_dir_hu3xrtc8/_output
    lite dir:        /tmp/_my_lite_dir_hu3xrtc8
    apps:            
    sourcemaps:      True
    unused packages: True
lite_archive:archive
lite_contents:contents
lite_lite:jupyter-lite.json
lite_mathjax:status
lite_mimetypes:jupyter-lite.json
lite_pyodide:pyodide
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_mathjax:status
     jupyter-server-mathjax: /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/latest/lib/python3.10/site-packages/jupyter_server_mathjax/static 
     configured MathJax dir: /tmp/_my_lite_dir_hu3xrtc8/traitlets.Undefined
     effective MathJax dir: /home/docs/checkouts/readthedocs.org/user_builds/jupyterlite/conda/latest/lib/python3.10/site-packages/jupyter_server_mathjax/static
.  lite_status:lite_mimetypes:jupyter-lite.json
    filetypes:         26 
.  lite_status:lite_pyodide:pyodide
     URL: None
 archive: []
   cache: 0 files
   local: 0 files
.  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!