{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Exploring `doit` graphs with `ipywidgets`" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipywidgets as W, traitlets as T, doit, graphviz, jinja2, textwrap, re; ui = W.VBox([W.HTML('restart and run all to see something here')]); ui" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class Doit(W.Widget):\n", " doit_ = T.Instance(doit.doit_cmd.DoitMain)\n", " tasks = W.trait_types.TypedTuple(trait=T.Instance(doit.task.Task))\n", " \n", " @T.observe(\"doit_\")\n", " def on_doit_change(self, change):\n", " cmds = self.doit_.get_cmds()\n", " tasks, _ = self.doit_.task_loader.load_tasks(cmds['list'], None, None)\n", " tc = doit.control.TaskControl(tasks)\n", " self.tasks = tuple(tc.tasks.values())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class FileDoit(Doit):\n", " path = T.Unicode(\"dodo.py\").tag(sync=True)\n", " \n", " def __init__(self, *args, **kwargs):\n", " super().__init__(*args, **kwargs)\n", " self.on_path_change(T.Bunch(new=self.path))\n", " \n", " @T.observe(\"path\")\n", " def _on_path_change(self, change):\n", " self.on_path_change(change) \n", " \n", " def on_path_change(self, change):\n", " pass" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class PyFileDoit(FileDoit): \n", " def on_path_change(self, change=None):\n", " self.doit_ = doit.doit_cmd.DoitMain(doit.cmd_base.ModuleTaskLoader(doit.loader.get_module(self.path)))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "it = PyFileDoit(path = \"dodo.py\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class TaskGraph(W.HTML):\n", " tasks = W.trait_types.TypedTuple(trait=T.Instance(doit.task.Task))\n", " graph = T.Instance(graphviz.Digraph)\n", " node_template = T.Unicode(\"\"\"<\n", "
{{t.name}} |
{{wrap(t.doc)}} |