doit#
使用
doit
是一个实现细节,可能会发生变化!
在幕后,CLI 由 doit 提供支持,这是一个轻量级的 Python 任务引擎,类似于 make
。
使用 API 中的任务#
显示代码单元格内容
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_kdqfaoi2
LiteManager
从附加组件中收集所有任务,并且可以选择接受一个 task_prefix
,以防您需要与现有任务集成。
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_kdqfaoi2/_output
lite dir: /tmp/_my_lite_dir_kdqfaoi2
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
自定义任务和 %doit
#
doit
提供了一个 IPython 魔法,通过扩展启用。这可以结合起来为创建非常自定义的网站创建高度反应式构建工具。
%reload_ext doit
它针对 __main__
命名空间工作,默认情况下该命名空间将没有任何内容。
%doit list
所有 JupyterLite 任务都可以通过 globals
更新 __main__
来添加。
globals().update(manager._doit_tasks)
现在,当创建新任务时,它可以引用其他任务和目标。
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_kdqfaoi2/_output
lite dir: /tmp/_my_lite_dir_kdqfaoi2
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!