From 339475fa08c39a0680bc77c8899ce12c5ce82920 Mon Sep 17 00:00:00 2001 From: Dane Freeman Date: Fri, 22 Jan 2021 20:01:08 -0500 Subject: [PATCH 1/4] scrips to migrate elk-models to fixtures --- .gitmodules | 3 ++ .prettierignore | 7 +++ MANIFEST.in | 2 +- dodo.py | 8 ++++ py_src/ipyelk/tests/elk-models | 1 + scripts/migrate_models.py | 86 ++++++++++++++++++++++++++++++++++ scripts/project.py | 4 +- 7 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 100644 .prettierignore create mode 160000 py_src/ipyelk/tests/elk-models create mode 100644 scripts/migrate_models.py diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..bd337d77 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "py_src/ipyelk/tests/elk-models"] + path = py_src/ipyelk/tests/elk-models + url = https://github.com/eclipse/elk-models.git diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..fb94b153 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,7 @@ +build +dist +envs +lib +node_modules +py_src/ipyelk/tests/elk-models +py_src/ipyelk/tests/fixtures \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index e3329cbd..7ad4a113 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,7 @@ recursive-include third-party *.html recursive-exclude scripts *.* exclude src lib docs examples package.json scripts - +prune py_src/ipyelk/tests/elk-models global-exclude *~ global-exclude *.pyc global-exclude *.pyo diff --git a/dodo.py b/dodo.py index f9bde2aa..3ff11c4c 100644 --- a/dodo.py +++ b/dodo.py @@ -21,6 +21,7 @@ from scripts import project as P from scripts import reporter from scripts import utils as U +from scripts import migrate_models as M os.environ.update(PYTHONIOENCODING="utf-8", PIP_DISABLE_PIP_VERSION_CHECK="1") @@ -207,6 +208,13 @@ def task_setup(): targets=[P.YARN_INTEGRITY], ) +def task_fixtures(): + """migrate elk-models to fixtures""" + return dict( + file_dep=[*M.ELKMODEL_ELKT, *M.ELKMODEL_JSON], + actions=[M.migrate], + targets=[*M.ELKMODEL_FIXTURES], + ) def task_build(): """build packages""" diff --git a/py_src/ipyelk/tests/elk-models b/py_src/ipyelk/tests/elk-models new file mode 160000 index 00000000..e46a263a --- /dev/null +++ b/py_src/ipyelk/tests/elk-models @@ -0,0 +1 @@ +Subproject commit e46a263a86fbde594d8eb25374b0852117a0d94e diff --git a/scripts/migrate_models.py b/scripts/migrate_models.py new file mode 100644 index 00000000..32e44e1b --- /dev/null +++ b/scripts/migrate_models.py @@ -0,0 +1,86 @@ +""" Convert [Elk Model Repository](https://github.com/eclipse/elk-models) into ElkJSON +""" + +# Copyright (c) 2021 Dane Freeman. +# Distributed under the terms of the Modified BSD License. + +import json +import requests + +from itertools import chain +from pathlib import Path +from typing import Dict + +from .project import ELKMODELS, ELKFIXTURES + + +ELKMODEL_ELKT = [f for f in ELKMODELS.rglob("*.elkt")] +ELKMODEL_JSON = [f for f in ELKMODELS.rglob("*.json")] + + +def fixture(model:Path)->Path: + """Get mapped fixture target + + :param model: model path + :return: Elk fixture that should exist after migrating models + """ + return ELKFIXTURES / model.relative_to(ELKMODELS).with_suffix(".json") + +ELKMODEL_FIXTURES = [fixture(f) for f in chain(ELKMODEL_ELKT, ELKMODEL_JSON)] + + +def migrate_layout_options(data:Dict)->Dict: + """The older klayjs json uses the `properties` key which needs to be + remapped to `layoutOptions` + + :param data: klayjs JSON + :return: Updated ElkJSON + """ + data = {**data} + layout_options = data.pop("properties", None) + if layout_options: + data["layoutOptions"] = layout_options + + for prop in ["ports", "children", "labels"]: + value = [migrate_layout_options(d) for d in data.get(prop, [])] + if value: + data[prop] = value + return data + + +def elkt_to_elkjson(data:str)->Dict: + """Uses public server to convert elkt to elk json + + :param data: elkt text + :return: ElkJSON + """ + #TODO maybe this url can be configured elsewhere but it isn't immediately discoverable + url = "https://rtsys.informatik.uni-kiel.de/elklive/conversion?inFormat=elkt&outFormat=json" + headers = { + 'Content-Type': 'text/plain', + } + resp = requests.post(url, data=data.encode("utf-8"), headers=headers) + if resp.status_code == 200: + return json.loads(resp.content.decode("utf-8")) + + +def migrate(): + """Migrate elk-models' elkt and older json formats to fixtures""" + ELKFIXTURES.mkdir(parents=True, exist_ok=True) + + def save(model, elkjson): + path = fixture(model) + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(elkjson)) + + for model in ELKMODEL_JSON: + elkjson = migrate_layout_options(json.loads(model.read_text())) + save(model, elkjson) + + for model in ELKMODEL_ELKT: + path = fixture(model) + if not path.exists(): + elkjson = elkt_to_elkjson(model.read_text()) + + save(model, elkjson) + diff --git a/scripts/project.py b/scripts/project.py index f77ca3c5..f2816f62 100644 --- a/scripts/project.py +++ b/scripts/project.py @@ -136,9 +136,11 @@ EXAMPLE_PY = [*EXAMPLES.rglob("*.py")] EXAMPLE_INDEX = EXAMPLES / "_index.ipynb" BUILD_NBHTML = BUILD / "nbsmoke" +ELKMODELS = PY_SRC / "tests" / "elk-models" +ELKFIXTURES = PY_SRC / "tests" / "fixtures" # mostly linting -ALL_PY_SRC = [*PY_SRC.rglob("*.py")] +ALL_PY_SRC = [p for p in PY_SRC.rglob("*.py") if str(ELKMODELS) not in str(p)] ALL_PY = [DODO, DOCS_CONF, *ALL_PY_SRC, *EXAMPLE_PY, *SCRIPTS.rglob("*.py")] ALL_YML = [*ROOT.glob("*.yml"), *CI.rglob("*.yml")] ALL_JSON = [*ROOT.glob("*.json"), *EXAMPLE_JSON, PY_SCHEMA] From cccf8532e2e920715585c16b21a504559ec5e162 Mon Sep 17 00:00:00 2001 From: Dane Freeman Date: Sat, 23 Jan 2021 10:15:12 -0500 Subject: [PATCH 2/4] update elk model migration to account for missing label ids. adding example fixture explorer --- dodo.py | 6 +- examples/14_elk_model_explorer.ipynb | 123 +++++++++++++++++++++++++++ examples/_index.ipynb | 3 +- scripts/migrate_models.py | 27 +++++- 4 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 examples/14_elk_model_explorer.ipynb diff --git a/dodo.py b/dodo.py index 3ff11c4c..4ccb7838 100644 --- a/dodo.py +++ b/dodo.py @@ -211,9 +211,11 @@ def task_setup(): def task_fixtures(): """migrate elk-models to fixtures""" return dict( - file_dep=[*M.ELKMODEL_ELKT, *M.ELKMODEL_JSON], + file_dep=[P.SCRIPTS / "migrate_models.py", *M.ELKMODEL_ELKT, *M.ELKMODEL_JSON], actions=[M.migrate], - targets=[*M.ELKMODEL_FIXTURES], + uptodate=[False], + targets=["fake_target_since_somehow_duplicating_doit_task"], + # targets=[f for f in M.ELKMODEL_FIXTURES], ) def task_build(): diff --git a/examples/14_elk_model_explorer.ipynb b/examples/14_elk_model_explorer.ipynb new file mode 100644 index 00000000..e211afd0 --- /dev/null +++ b/examples/14_elk_model_explorer.ipynb @@ -0,0 +1,123 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 🦌 Elk Model Explorer ⚡\n", + "\n", + "The [Elk Model Repositoy](https://github.com/eclipse/elk-models) was converted to elk json and included as a set of fixtures to test against. This notebook loads those fixtures for users to explore to understand what kinds of layout variety possible as well and see the originating elk json." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "\n", + "from pathlib import Path\n", + "from IPython.display import display, JSON\n", + "from ipyelk import ElkDiagram, tests" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def fixture_explorer():\n", + " #TODO some labels do not have a width / height provided ... could use the text sizer widget and size labels accordingly\n", + " #TODO some nodes do not have a specified width / height ... set a default\n", + " fixtures = Path(tests.__file__).parent / \"fixtures\"\n", + " fixtures\n", + "\n", + " options = [f.relative_to(fixtures) for f in fixtures.rglob(\"*.json\")]\n", + " len(options)\n", + " import ipywidgets as W\n", + " diagram = ElkDiagram(layout={\"flex\":\"1\"})\n", + " selector = W.Dropdown(options=options)\n", + " err_btn = W.Button()\n", + " output = W.Output()\n", + "\n", + " def set_err(message):\n", + " if message:\n", + " err_btn.icon = \"warning\"\n", + " err_btn.tooltip = message\n", + " else:\n", + " err_btn.icon = \"check\"\n", + " err_btn.tooltip = \"\"\n", + "\n", + " def _load(change=None):\n", + " data = json.loads((fixtures / selector.value).read_text())\n", + " try:\n", + " output.clear_output()\n", + " with output:\n", + " display(JSON(data))\n", + " diagram.value = {\"id\":\"root\"} # needed for now to clear sprotty diagram. until fixed https://github.com/jupyrdf/ipyelk/issues/17\n", + " diagram.value = data\n", + " set_err(\"\")\n", + " except Exception as e:\n", + " diagram.value = {\"id\":\"root\"}\n", + " set_err(str(e))\n", + "\n", + "\n", + " model_explorer = W.VBox(children=[\n", + "\n", + " W.HBox(\n", + " children=[\n", + " selector,\n", + " err_btn,\n", + " ]\n", + " ),\n", + " W.HBox(\n", + " children=[\n", + " diagram,\n", + " output,\n", + " ],\n", + " layout={\"flex\":\"1\"})\n", + "\n", + " ],\n", + " layout={\"height\":\"100%\"} \n", + " )\n", + " selector.observe(_load, \"value\")\n", + " _load()\n", + " return model_explorer\n", + "\n", + "if __name__ == \"__main__\":\n", + " explorer = fixture_explorer()\n", + " display(explorer)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.9" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/examples/_index.ipynb b/examples/_index.ipynb index bfa1312f..80051907 100644 --- a/examples/_index.ipynb +++ b/examples/_index.ipynb @@ -14,7 +14,8 @@ "## Basic Examples\n", "\n", "- [🦌 Introducing ELK 👋](./00_Introduction.ipynb)\n", - "- [🦌 Linking ELK Diagrams 🔗](./01_Linking.ipynb)" + "- [🦌 Linking ELK Diagrams 🔗](./01_Linking.ipynb)\n", + "- [🦌 ELK Models Explorer 🔗](./14_elk_model_explorer.ipynb)" ] }, { diff --git a/scripts/migrate_models.py b/scripts/migrate_models.py index 32e44e1b..e44738bf 100644 --- a/scripts/migrate_models.py +++ b/scripts/migrate_models.py @@ -10,6 +10,7 @@ from itertools import chain from pathlib import Path from typing import Dict +from uuid import uuid4 from .project import ELKMODELS, ELKFIXTURES @@ -47,6 +48,27 @@ def migrate_layout_options(data:Dict)->Dict: data[prop] = value return data +def backfill_ids(data:Dict)->Dict: + """Seems like some `id`s are missing. This will backfill as needed + + :param data: JSON + :return: Updated ElkJSON + """ + data = {**data} + data["id"] = data.get("id", str(uuid4())) + + for prop in ["ports", "children", "labels"]: + value = [backfill_ids(d) for d in data.get(prop, [])] + if value: + data[prop] = value + + edges = [] + for edge in data.get("edges", []): + edges.append(backfill_ids(edge)) + if edges: + data["edges"] = edges + return data + def elkt_to_elkjson(data:str)->Dict: """Uses public server to convert elkt to elk json @@ -64,11 +86,12 @@ def elkt_to_elkjson(data:str)->Dict: return json.loads(resp.content.decode("utf-8")) -def migrate(): +def migrate(force=False): """Migrate elk-models' elkt and older json formats to fixtures""" ELKFIXTURES.mkdir(parents=True, exist_ok=True) def save(model, elkjson): + elkjson = backfill_ids(elkjson) path = fixture(model) path.parent.mkdir(parents=True, exist_ok=True) path.write_text(json.dumps(elkjson)) @@ -79,7 +102,7 @@ def save(model, elkjson): for model in ELKMODEL_ELKT: path = fixture(model) - if not path.exists(): + if force or not path.exists(): elkjson = elkt_to_elkjson(model.read_text()) save(model, elkjson) From ca501fb03655892ee38e88140e86ace0b96db422 Mon Sep 17 00:00:00 2001 From: Dane Freeman Date: Sun, 24 Jan 2021 07:58:37 -0500 Subject: [PATCH 3/4] linting and simple default sizes on fixture explorer --- dodo.py | 4 +- examples/14_elk_model_explorer.ipynb | 102 +++++++++++++++++++++++---- scripts/migrate_models.py | 20 +++--- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/dodo.py b/dodo.py index 4ccb7838..315610f9 100644 --- a/dodo.py +++ b/dodo.py @@ -18,10 +18,10 @@ from doit import create_after from doit.action import CmdAction from doit.tools import PythonInteractiveAction, config_changed +from scripts import migrate_models as M from scripts import project as P from scripts import reporter from scripts import utils as U -from scripts import migrate_models as M os.environ.update(PYTHONIOENCODING="utf-8", PIP_DISABLE_PIP_VERSION_CHECK="1") @@ -208,6 +208,7 @@ def task_setup(): targets=[P.YARN_INTEGRITY], ) + def task_fixtures(): """migrate elk-models to fixtures""" return dict( @@ -218,6 +219,7 @@ def task_fixtures(): # targets=[f for f in M.ELKMODEL_FIXTURES], ) + def task_build(): """build packages""" diff --git a/examples/14_elk_model_explorer.ipynb b/examples/14_elk_model_explorer.ipynb index e211afd0..31b370de 100644 --- a/examples/14_elk_model_explorer.ipynb +++ b/examples/14_elk_model_explorer.ipynb @@ -11,23 +11,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import json\n", + "import asyncio\n", "\n", "from pathlib import Path\n", "from IPython.display import display, JSON\n", - "from ipyelk import ElkDiagram, tests" + "from ipyelk import ElkDiagram, tests\n", + "from ipyelk.diagram.elk_text_sizer import size_labels, ElkTextSizer\n", + "from ipyelk.diagram.elk_model import ElkLabel\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "4729124b76a14d45a6c4119b97b25d64", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(HBox(children=(Dropdown(options=(PosixPath('tests/layered/interactive_layout/noDummyNodes.json'…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ + "ran = []\n", + "async def size_labels(text_sizer, labels):\n", + " ran.append(labels)\n", + " sizes = await text_sizer.measure(tuple(ElkLabel.from_dict(l) for l in labels))\n", + " \n", + " for size, label in zip(sizes, labels):\n", + " label[\"width\"] = size.width\n", + " label[\"height\"] = size.height\n", + " \n", + " \n", + "def collect_labels(data):\n", + " \n", + " labels = []\n", + " labels += data.get(\"labels\", [])\n", + " for prop in [\"ports\", \"children\", \"edges\"]:\n", + " for value in data.get(prop, []):\n", + " labels += collect_labels(value)\n", + " return labels\n", + "\n", + "def default_node_size(data, width=40, height=40):\n", + " if \"width\" not in data:\n", + " data[\"width\"] = width\n", + " if \"height\" not in data:\n", + " data[\"height\"] = height\n", + " for child in data.get(\"children\", []):\n", + " default_node_size(child)\n", + "\n", "def fixture_explorer():\n", " #TODO some labels do not have a width / height provided ... could use the text sizer widget and size labels accordingly\n", " #TODO some nodes do not have a specified width / height ... set a default\n", @@ -41,6 +86,7 @@ " selector = W.Dropdown(options=options)\n", " err_btn = W.Button()\n", " output = W.Output()\n", + " text_sizer = ElkTextSizer(max_size=20)\n", "\n", " def set_err(message):\n", " if message:\n", @@ -50,18 +96,35 @@ " err_btn.icon = \"check\"\n", " err_btn.tooltip = \"\"\n", "\n", - " def _load(change=None):\n", + " \n", + " async def _load():\n", + " # load fixture elk json\n", " data = json.loads((fixtures / selector.value).read_text())\n", + " \n", + " # add width and height to labels\n", + " await size_labels(text_sizer, collect_labels(data))\n", + " \n", + " # add default size to nodes\n", + " default_node_size(data)\n", + " \n", " try:\n", - " output.clear_output()\n", - " with output:\n", - " display(JSON(data))\n", " diagram.value = {\"id\":\"root\"} # needed for now to clear sprotty diagram. until fixed https://github.com/jupyrdf/ipyelk/issues/17\n", " diagram.value = data\n", " set_err(\"\")\n", " except Exception as e:\n", " diagram.value = {\"id\":\"root\"}\n", " set_err(str(e))\n", + " \n", + " def update(change=None):\n", + " asyncio.create_task(_load())\n", + " \n", + " def refresh_json_view(change=None):\n", + " output.clear_output()\n", + " with output:\n", + " display(JSON(diagram.value))\n", + " \n", + " \n", + " diagram.observe(refresh_json_view, \"value\")\n", "\n", "\n", " model_explorer = W.VBox(children=[\n", @@ -82,21 +145,32 @@ " ],\n", " layout={\"height\":\"100%\"} \n", " )\n", - " selector.observe(_load, \"value\")\n", - " _load()\n", - " return model_explorer\n", + " selector.observe(update, \"value\")\n", + " update()\n", + " return model_explorer, diagram, output, refresh_json_view\n", "\n", "if __name__ == \"__main__\":\n", - " explorer = fixture_explorer()\n", + " explorer, diagram, output, refresh_json_view = fixture_explorer()\n", " display(explorer)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "# TODO understand why this refresh_json_view function works if called manually but no longer seems to update the output view using the observers" + ] + }, + { + "cell_type": "code", + "execution_count": 6, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "refresh_json_view()" + ] } ], "metadata": { diff --git a/scripts/migrate_models.py b/scripts/migrate_models.py index e44738bf..af078b02 100644 --- a/scripts/migrate_models.py +++ b/scripts/migrate_models.py @@ -5,21 +5,20 @@ # Distributed under the terms of the Modified BSD License. import json -import requests - from itertools import chain from pathlib import Path from typing import Dict from uuid import uuid4 -from .project import ELKMODELS, ELKFIXTURES +import requests +from .project import ELKFIXTURES, ELKMODELS ELKMODEL_ELKT = [f for f in ELKMODELS.rglob("*.elkt")] ELKMODEL_JSON = [f for f in ELKMODELS.rglob("*.json")] -def fixture(model:Path)->Path: +def fixture(model: Path) -> Path: """Get mapped fixture target :param model: model path @@ -27,10 +26,11 @@ def fixture(model:Path)->Path: """ return ELKFIXTURES / model.relative_to(ELKMODELS).with_suffix(".json") + ELKMODEL_FIXTURES = [fixture(f) for f in chain(ELKMODEL_ELKT, ELKMODEL_JSON)] -def migrate_layout_options(data:Dict)->Dict: +def migrate_layout_options(data: Dict) -> Dict: """The older klayjs json uses the `properties` key which needs to be remapped to `layoutOptions` @@ -48,7 +48,8 @@ def migrate_layout_options(data:Dict)->Dict: data[prop] = value return data -def backfill_ids(data:Dict)->Dict: + +def backfill_ids(data: Dict) -> Dict: """Seems like some `id`s are missing. This will backfill as needed :param data: JSON @@ -70,16 +71,16 @@ def backfill_ids(data:Dict)->Dict: return data -def elkt_to_elkjson(data:str)->Dict: +def elkt_to_elkjson(data: str) -> Dict: """Uses public server to convert elkt to elk json :param data: elkt text :return: ElkJSON """ - #TODO maybe this url can be configured elsewhere but it isn't immediately discoverable + # TODO maybe this url can be configured elsewhere but it isn't immediately discoverable url = "https://rtsys.informatik.uni-kiel.de/elklive/conversion?inFormat=elkt&outFormat=json" headers = { - 'Content-Type': 'text/plain', + "Content-Type": "text/plain", } resp = requests.post(url, data=data.encode("utf-8"), headers=headers) if resp.status_code == 200: @@ -106,4 +107,3 @@ def save(model, elkjson): elkjson = elkt_to_elkjson(model.read_text()) save(model, elkjson) - From 5ee78e4cc8c325d8ab134e38934d1551f4bb0b60 Mon Sep 17 00:00:00 2001 From: Dane Freeman Date: Mon, 25 Jan 2021 08:44:36 -0500 Subject: [PATCH 4/4] fixing dodo issue with merge and cleanup line length in fixture migration script --- dodo.py | 27 +++++++++---------- examples/14_elk_model_explorer.ipynb | 40 +++++++++++++--------------- scripts/migrate_models.py | 8 +++--- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/dodo.py b/dodo.py index b8a66137..be318524 100644 --- a/dodo.py +++ b/dodo.py @@ -18,9 +18,8 @@ from doit import create_after from doit.action import CmdAction from doit.tools import LongRunning, PythonInteractiveAction, config_changed -from scripts import migrate_models as M - +from scripts import migrate_models as M from scripts import project as P from scripts import reporter from scripts import utils as U @@ -217,19 +216,6 @@ def task_setup(): yield py_task -def task_fixtures(): - """migrate elk-models to fixtures""" - return dict( - file_dep=[P.SCRIPTS / "migrate_models.py", *M.ELKMODEL_ELKT, *M.ELKMODEL_JSON], - actions=[M.migrate], - uptodate=[False], - targets=["fake_target_since_somehow_duplicating_doit_task"], - # targets=[f for f in M.ELKMODEL_FIXTURES], - ) - - -def task_build(): - """build packages""" if not P.TESTING_IN_CI: yield dict( name="js", @@ -247,6 +233,17 @@ def task_build(): ) +def task_fixtures(): + """migrate elk-models to fixtures""" + return dict( + file_dep=[P.SCRIPTS / "migrate_models.py", *M.ELKMODEL_ELKT, *M.ELKMODEL_JSON], + actions=[M.migrate], + uptodate=[False], + targets=["fake_target_since_somehow_duplicating_doit_task"], + # targets=[f for f in M.ELKMODEL_FIXTURES], + ) + + if not P.TESTING_IN_CI: def task_build(): diff --git a/examples/14_elk_model_explorer.ipynb b/examples/14_elk_model_explorer.ipynb index 31b370de..5ad650c3 100644 --- a/examples/14_elk_model_explorer.ipynb +++ b/examples/14_elk_model_explorer.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -27,24 +27,9 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "4729124b76a14d45a6c4119b97b25d64", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "VBox(children=(HBox(children=(Dropdown(options=(PosixPath('tests/layered/interactive_layout/noDummyNodes.json'…" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "ran = []\n", "async def size_labels(text_sizer, labels):\n", @@ -99,7 +84,13 @@ " \n", " async def _load():\n", " # load fixture elk json\n", - " data = json.loads((fixtures / selector.value).read_text())\n", + " if not selector.value:\n", + " return\n", + " \n", + " path = (fixtures / selector.value)\n", + " if not path.exists():\n", + " return\n", + " data = json.loads(path.read_text())\n", " \n", " # add width and height to labels\n", " await size_labels(text_sizer, collect_labels(data))\n", @@ -156,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -165,12 +156,19 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ "refresh_json_view()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/scripts/migrate_models.py b/scripts/migrate_models.py index af078b02..a1c9c493 100644 --- a/scripts/migrate_models.py +++ b/scripts/migrate_models.py @@ -77,12 +77,14 @@ def elkt_to_elkjson(data: str) -> Dict: :param data: elkt text :return: ElkJSON """ - # TODO maybe this url can be configured elsewhere but it isn't immediately discoverable - url = "https://rtsys.informatik.uni-kiel.de/elklive/conversion?inFormat=elkt&outFormat=json" + # TODO maybe this url can be configured elsewhere but it isn't immediately + # discoverable + url = "https://rtsys.informatik.uni-kiel.de/elklive/conversion" + params = {"inFormat": "elkt", "outFormat": "json"} headers = { "Content-Type": "text/plain", } - resp = requests.post(url, data=data.encode("utf-8"), headers=headers) + resp = requests.post(url, params=params, data=data.encode("utf-8"), headers=headers) if resp.status_code == 200: return json.loads(resp.content.decode("utf-8"))