kenryu 0.2.1__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {kenryu-0.2.1 → kenryu-0.3.0}/PKG-INFO +9 -9
- {kenryu-0.2.1 → kenryu-0.3.0}/README.md +8 -8
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/__init__.py +4 -4
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/__main__.py +8 -8
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/engine.py +2 -2
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/registry.py +2 -2
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/server.py +3 -3
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/app.js +8 -7
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/index.html +2 -2
- {kenryu-0.2.1 → kenryu-0.3.0}/kenryu.egg-info/PKG-INFO +9 -9
- kenryu-0.3.0/kenryu.egg-info/SOURCES.txt +21 -0
- kenryu-0.3.0/kenryu.egg-info/entry_points.txt +2 -0
- kenryu-0.3.0/kenryu.egg-info/top_level.txt +1 -0
- {kenryu-0.2.1 → kenryu-0.3.0}/pyproject.toml +4 -5
- {kenryu-0.2.1 → kenryu-0.3.0}/tests/test_engine.py +7 -7
- kenryu-0.2.1/kenryu.egg-info/SOURCES.txt +0 -21
- kenryu-0.2.1/kenryu.egg-info/entry_points.txt +0 -3
- kenryu-0.2.1/kenryu.egg-info/top_level.txt +0 -1
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/preview.py +0 -0
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/app.css +0 -0
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/vendor/LITEGRAPH-LICENSE +0 -0
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/vendor/litegraph.core.min.js +0 -0
- {kenryu-0.2.1/nagare → kenryu-0.3.0/kenryu}/static/vendor/litegraph.css +0 -0
- {kenryu-0.2.1 → kenryu-0.3.0}/kenryu.egg-info/dependency_links.txt +0 -0
- {kenryu-0.2.1 → kenryu-0.3.0}/kenryu.egg-info/requires.txt +0 -0
- {kenryu-0.2.1 → kenryu-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kenryu
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A node editor for Python functions (prototype)
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -10,13 +10,13 @@ Requires-Dist: numpy; extra == "demo"
|
|
|
10
10
|
Requires-Dist: scipy; extra == "demo"
|
|
11
11
|
Requires-Dist: matplotlib; extra == "demo"
|
|
12
12
|
|
|
13
|
-
#
|
|
13
|
+
# kenryu 流
|
|
14
14
|
|
|
15
15
|
A prototype node editor for Python functions, in the spirit of Blender's node editor. Write ordinary type-hinted functions; each one becomes a node you wire up in the browser, run with caching, preview and export as a plain script.
|
|
16
16
|
|
|
17
17
|
```sh
|
|
18
18
|
pip install git+https://github.com/ShashankRaoCoding/kenryu
|
|
19
|
-
|
|
19
|
+
kenryu path/to/your/nodes # opens http://127.0.0.1:8650/
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
To try the demo, clone the repo and install with the demo extras (pandas, numpy, scipy, matplotlib):
|
|
@@ -24,14 +24,14 @@ To try the demo, clone the repo and install with the demo extras (pandas, numpy,
|
|
|
24
24
|
```sh
|
|
25
25
|
git clone https://github.com/ShashankRaoCoding/kenryu && cd kenryu
|
|
26
26
|
pip install ".[demo]"
|
|
27
|
-
|
|
27
|
+
kenryu examples
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
The RNA-seq demo loads on first start: simulate counts → filter → CPM → PCA and differential expression → plots.
|
|
31
31
|
|
|
32
32
|
## Your own nodes
|
|
33
33
|
|
|
34
|
-
Point
|
|
34
|
+
Point kenryu at any folder of `.py` files. Every public function becomes a node, and its type hints decide the shape:
|
|
35
35
|
|
|
36
36
|
```python
|
|
37
37
|
def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
@@ -47,25 +47,25 @@ def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
|
47
47
|
| return type | the output; `tuple[A, B]` gives two |
|
|
48
48
|
| first paragraph of the docstring | the description |
|
|
49
49
|
|
|
50
|
-
No
|
|
50
|
+
No kenryu import is needed. `from kenryu import node` gives an optional decorator for a title, output names, or turning a `str`/`int` parameter into a socket: `@node(title="PCA", outputs=["pcs"], sockets=["path"])`.
|
|
51
51
|
|
|
52
52
|
## How it behaves
|
|
53
53
|
|
|
54
54
|
- **Live**: change a setting or a connection and the graph re-runs. Each node is cached by its code, its settings and its inputs, so only what changed (and what's downstream) runs again. Its code means its whole file plus any other file of the folder that file imports, so editing a helper function re-runs the nodes that use it. Edit a function in your editor and switch back: it re-runs the nodes from that file.
|
|
55
55
|
- **Previews**: tables, figures and text show in the side panel; figures also show inside the node. Errors show the traceback from your function, and downstream nodes wait.
|
|
56
56
|
- **Save / Open** keep graphs in `FOLDER/graphs/`; the canvas also survives a page reload.
|
|
57
|
-
- **Export .py** writes the graph as a plain Python script that runs without
|
|
57
|
+
- **Export .py** writes the graph as a plain Python script that runs without kenryu.
|
|
58
58
|
|
|
59
59
|
## Inside kenkyu
|
|
60
60
|
|
|
61
|
-
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed
|
|
61
|
+
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed kenryu for its **Flows**: install this package (`pip install git+https://github.com/ShashankRaoCoding/kenryu`) where kenkyu runs. kenkyu starts it as `kenryu FOLDER --port 8650 --kenkyu` (no browser, the address printed once ready, and an exit when kenkyu closes its stdin), or uses a kenryu already running on 8650, and serves the canvas at `/kenryu/?flow=ID`. `GET /api/info` tells kenkyu it is talking to a kenryu that speaks its protocol. In that mode the canvas loads and saves the flow in kenkyu's library instead of local storage and `graphs/`, and tells kenkyu which node is selected so its figure can go into a document. Runs return each node's cache `key`, which kenkyu stores with a figure to notice when the code behind it changes, and take a `dpi` for figures. The page uses relative addresses, so it works the same at `/` and under `/kenryu/`.
|
|
62
62
|
|
|
63
63
|
## Prototype limits
|
|
64
64
|
|
|
65
65
|
- One process and an in-memory cache: restarting loses cached results.
|
|
66
66
|
- Nodes get their inputs by reference: a function that changes its input in place also changes the cached copy. Return new objects.
|
|
67
67
|
- New settings or sockets on a function need a page reload (a banner offers it); changed function bodies don't.
|
|
68
|
-
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart
|
|
68
|
+
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart kenryu to clear it.
|
|
69
69
|
- The server only answers to `localhost` or an IP address, and refuses requests that change things when the browser says they came from another site, so other web pages can't run your nodes.
|
|
70
70
|
- No per-sample "for each" yet, no environments per node, no concurrency.
|
|
71
71
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# kenryu 流
|
|
2
2
|
|
|
3
3
|
A prototype node editor for Python functions, in the spirit of Blender's node editor. Write ordinary type-hinted functions; each one becomes a node you wire up in the browser, run with caching, preview and export as a plain script.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
pip install git+https://github.com/ShashankRaoCoding/kenryu
|
|
7
|
-
|
|
7
|
+
kenryu path/to/your/nodes # opens http://127.0.0.1:8650/
|
|
8
8
|
```
|
|
9
9
|
|
|
10
10
|
To try the demo, clone the repo and install with the demo extras (pandas, numpy, scipy, matplotlib):
|
|
@@ -12,14 +12,14 @@ To try the demo, clone the repo and install with the demo extras (pandas, numpy,
|
|
|
12
12
|
```sh
|
|
13
13
|
git clone https://github.com/ShashankRaoCoding/kenryu && cd kenryu
|
|
14
14
|
pip install ".[demo]"
|
|
15
|
-
|
|
15
|
+
kenryu examples
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
The RNA-seq demo loads on first start: simulate counts → filter → CPM → PCA and differential expression → plots.
|
|
19
19
|
|
|
20
20
|
## Your own nodes
|
|
21
21
|
|
|
22
|
-
Point
|
|
22
|
+
Point kenryu at any folder of `.py` files. Every public function becomes a node, and its type hints decide the shape:
|
|
23
23
|
|
|
24
24
|
```python
|
|
25
25
|
def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
@@ -35,25 +35,25 @@ def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
|
35
35
|
| return type | the output; `tuple[A, B]` gives two |
|
|
36
36
|
| first paragraph of the docstring | the description |
|
|
37
37
|
|
|
38
|
-
No
|
|
38
|
+
No kenryu import is needed. `from kenryu import node` gives an optional decorator for a title, output names, or turning a `str`/`int` parameter into a socket: `@node(title="PCA", outputs=["pcs"], sockets=["path"])`.
|
|
39
39
|
|
|
40
40
|
## How it behaves
|
|
41
41
|
|
|
42
42
|
- **Live**: change a setting or a connection and the graph re-runs. Each node is cached by its code, its settings and its inputs, so only what changed (and what's downstream) runs again. Its code means its whole file plus any other file of the folder that file imports, so editing a helper function re-runs the nodes that use it. Edit a function in your editor and switch back: it re-runs the nodes from that file.
|
|
43
43
|
- **Previews**: tables, figures and text show in the side panel; figures also show inside the node. Errors show the traceback from your function, and downstream nodes wait.
|
|
44
44
|
- **Save / Open** keep graphs in `FOLDER/graphs/`; the canvas also survives a page reload.
|
|
45
|
-
- **Export .py** writes the graph as a plain Python script that runs without
|
|
45
|
+
- **Export .py** writes the graph as a plain Python script that runs without kenryu.
|
|
46
46
|
|
|
47
47
|
## Inside kenkyu
|
|
48
48
|
|
|
49
|
-
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed
|
|
49
|
+
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed kenryu for its **Flows**: install this package (`pip install git+https://github.com/ShashankRaoCoding/kenryu`) where kenkyu runs. kenkyu starts it as `kenryu FOLDER --port 8650 --kenkyu` (no browser, the address printed once ready, and an exit when kenkyu closes its stdin), or uses a kenryu already running on 8650, and serves the canvas at `/kenryu/?flow=ID`. `GET /api/info` tells kenkyu it is talking to a kenryu that speaks its protocol. In that mode the canvas loads and saves the flow in kenkyu's library instead of local storage and `graphs/`, and tells kenkyu which node is selected so its figure can go into a document. Runs return each node's cache `key`, which kenkyu stores with a figure to notice when the code behind it changes, and take a `dpi` for figures. The page uses relative addresses, so it works the same at `/` and under `/kenryu/`.
|
|
50
50
|
|
|
51
51
|
## Prototype limits
|
|
52
52
|
|
|
53
53
|
- One process and an in-memory cache: restarting loses cached results.
|
|
54
54
|
- Nodes get their inputs by reference: a function that changes its input in place also changes the cached copy. Return new objects.
|
|
55
55
|
- New settings or sockets on a function need a page reload (a banner offers it); changed function bodies don't.
|
|
56
|
-
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart
|
|
56
|
+
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart kenryu to clear it.
|
|
57
57
|
- The server only answers to `localhost` or an IP address, and refuses requests that change things when the browser says they came from another site, so other web pages can't run your nodes.
|
|
58
58
|
- No per-sample "for each" yet, no environments per node, no concurrency.
|
|
59
59
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""kenryu: a node editor for Python functions.
|
|
2
2
|
|
|
3
|
-
Write plain, type-hinted functions;
|
|
3
|
+
Write plain, type-hinted functions; kenryu turns each into a node you can
|
|
4
4
|
wire up in the browser, run with caching, preview, and export as a script.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
from .registry import node
|
|
8
8
|
|
|
9
9
|
__all__ = ["node"]
|
|
10
|
-
__version__ = "0.
|
|
10
|
+
__version__ = "0.3.0"
|
|
11
11
|
|
|
12
12
|
# The version of what kenkyu relies on: --kenkyu, cache keys and dpi in
|
|
13
13
|
# runs, relative page addresses and the ?flow= canvas. kenkyu reads it from
|
|
14
|
-
# /api/info before using a
|
|
14
|
+
# /api/info before using a kenryu it finds running.
|
|
15
15
|
KENKYU_PROTOCOL = 1
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""python -m
|
|
1
|
+
"""python -m kenryu [nodes-folder] [--port 8650]"""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -11,10 +11,10 @@ from pathlib import Path
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def _exit_when_stdin_closes() -> None:
|
|
14
|
-
"""kenkyu starts
|
|
14
|
+
"""kenkyu starts kenryu with a pipe on stdin and never writes to it.
|
|
15
15
|
|
|
16
16
|
When kenkyu stops, for any reason, the pipe closes and this read returns,
|
|
17
|
-
so
|
|
17
|
+
so kenryu never outlives the app that started it.
|
|
18
18
|
"""
|
|
19
19
|
try:
|
|
20
20
|
while sys.stdin.buffer.read(4096):
|
|
@@ -25,7 +25,7 @@ def _exit_when_stdin_closes() -> None:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def main(argv=None) -> int:
|
|
28
|
-
ap = argparse.ArgumentParser(prog="
|
|
28
|
+
ap = argparse.ArgumentParser(prog="kenryu", description="A node editor for your Python functions.")
|
|
29
29
|
ap.add_argument("folder", nargs="?", default=".", help="folder of .py files whose functions become nodes")
|
|
30
30
|
ap.add_argument("--port", type=int, default=8650, help="0 picks any free port")
|
|
31
31
|
ap.add_argument("--graphs", help="where graphs are saved (default: FOLDER/graphs)")
|
|
@@ -45,7 +45,7 @@ def main(argv=None) -> int:
|
|
|
45
45
|
|
|
46
46
|
folder = Path(args.folder)
|
|
47
47
|
if not folder.is_dir():
|
|
48
|
-
print(f"
|
|
48
|
+
print(f"kenryu: {folder} is not a folder", file=sys.stderr)
|
|
49
49
|
return 2
|
|
50
50
|
app, httpd = serve(folder, args.port, args.graphs)
|
|
51
51
|
url = f"http://127.0.0.1:{httpd.server_address[1]}/"
|
|
@@ -53,10 +53,10 @@ def main(argv=None) -> int:
|
|
|
53
53
|
print(f" could not load {f}: {err}", file=sys.stderr)
|
|
54
54
|
if args.kenkyu:
|
|
55
55
|
threading.Thread(target=_exit_when_stdin_closes, daemon=True).start()
|
|
56
|
-
print(f"
|
|
56
|
+
print(f"kenryu: ready {url}", flush=True)
|
|
57
57
|
else:
|
|
58
|
-
print(f"
|
|
59
|
-
print(f"
|
|
58
|
+
print(f"kenryu: {len(app.registry.types)} nodes from {app.registry.folder}")
|
|
59
|
+
print(f"kenryu: open {url} (Ctrl-C to stop)")
|
|
60
60
|
if not args.no_browser:
|
|
61
61
|
webbrowser.open(url)
|
|
62
62
|
try:
|
|
@@ -176,7 +176,7 @@ class Engine:
|
|
|
176
176
|
|
|
177
177
|
|
|
178
178
|
def export_script(graph: dict, registry: Registry) -> str:
|
|
179
|
-
"""The graph as a plain Python script that runs without
|
|
179
|
+
"""The graph as a plain Python script that runs without kenryu."""
|
|
180
180
|
registry.refresh()
|
|
181
181
|
nodes = {str(n["id"]): n for n in graph.get("nodes", [])}
|
|
182
182
|
order = topo_order(graph)
|
|
@@ -213,7 +213,7 @@ def export_script(graph: dict, registry: Registry) -> str:
|
|
|
213
213
|
lhs = ", ".join(names) + " = " if nt.outputs else ""
|
|
214
214
|
lines.append(f"{lhs}{call}")
|
|
215
215
|
|
|
216
|
-
head = ["# Generated by
|
|
216
|
+
head = ["# Generated by kenryu. Runs on its own: python this_file.py",
|
|
217
217
|
"import sys",
|
|
218
218
|
f"sys.path.insert(0, {str(registry.folder)!r}) # the folder holding your node functions",
|
|
219
219
|
""]
|
|
@@ -32,7 +32,7 @@ def node(fn: Callable | None = None, *, title: str | None = None, outputs: list[
|
|
|
32
32
|
"""Optional decorator: extra details for a node."""
|
|
33
33
|
|
|
34
34
|
def wrap(f: Callable) -> Callable:
|
|
35
|
-
f.
|
|
35
|
+
f.__kenryu__ = {"title": title, "outputs": outputs, "sockets": set(sockets or []), "category": category}
|
|
36
36
|
return f
|
|
37
37
|
|
|
38
38
|
return wrap(fn) if fn is not None else wrap
|
|
@@ -94,7 +94,7 @@ def _hints(fn: Callable) -> dict[str, Any]:
|
|
|
94
94
|
|
|
95
95
|
|
|
96
96
|
def describe(fn: Callable, module: str) -> NodeType:
|
|
97
|
-
extra = getattr(fn, "
|
|
97
|
+
extra = getattr(fn, "__kenryu__", {})
|
|
98
98
|
hints = _hints(fn)
|
|
99
99
|
sig = inspect.signature(fn)
|
|
100
100
|
inputs, params, required = [], [], set()
|
|
@@ -24,7 +24,7 @@ def local_host(hostport: str) -> bool:
|
|
|
24
24
|
"""Whether a Host header names this machine by "localhost" or an IP address.
|
|
25
25
|
|
|
26
26
|
DNS rebinding (a page on evil.example pointing its own name at 127.0.0.1
|
|
27
|
-
to read
|
|
27
|
+
to read kenryu as if same-origin) always needs a domain name, so those
|
|
28
28
|
requests are refused while IP addresses, LAN ones included, still work.
|
|
29
29
|
"""
|
|
30
30
|
host = hostport.strip()
|
|
@@ -95,7 +95,7 @@ def handler(app: App):
|
|
|
95
95
|
def allowed(self, changes: bool) -> bool:
|
|
96
96
|
host = self.headers.get("Host", "")
|
|
97
97
|
if not local_host(host):
|
|
98
|
-
self.send(421, "
|
|
98
|
+
self.send(421, "kenryu only answers to localhost or an IP address", "text/plain")
|
|
99
99
|
return False
|
|
100
100
|
if changes and cross_site(self.headers, host):
|
|
101
101
|
self.json({"error": "cross-site request refused"}, 403)
|
|
@@ -111,7 +111,7 @@ def handler(app: App):
|
|
|
111
111
|
if path == "/api/info":
|
|
112
112
|
from . import KENKYU_PROTOCOL, __version__
|
|
113
113
|
|
|
114
|
-
return self.json({"name": "
|
|
114
|
+
return self.json({"name": "kenryu", "version": __version__, "kenkyu": KENKYU_PROTOCOL,
|
|
115
115
|
"folder": str(app.registry.folder)})
|
|
116
116
|
if path == "/api/nodes":
|
|
117
117
|
return self.json(app.registry.specs())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//
|
|
1
|
+
// kenryu: the canvas. Node types come from api/nodes (your functions);
|
|
2
2
|
// runs go to api/run, which answers with a status and preview per node.
|
|
3
3
|
// Addresses are relative so the same page works on its own (at /) and inside
|
|
4
|
-
// kenkyu, which serves it at /
|
|
4
|
+
// kenkyu, which serves it at /kenryu/.
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
const $ = (s) => document.querySelector(s);
|
|
@@ -16,7 +16,7 @@ const FLOW_URL = FLOW && `/flows/${FLOW}/graph`;
|
|
|
16
16
|
const tell = (msg) => { if (FLOW && window.parent !== window) window.parent.postMessage({ ...msg, flow: +FLOW }, location.origin); };
|
|
17
17
|
const TYPE_COLOURS = { DataFrame: "#e0a33a", Series: "#d07a45", Figure: "#5b9bd5", ndarray: "#9a7fd6", AnnData: "#4fb07b", str: "#b0b0b0", "*": "#8c8c8c" };
|
|
18
18
|
const STATUS_COLOURS = { ok: "#5fb36b", error: "#e05a4f", waiting: "#c9a640" };
|
|
19
|
-
const STORE = FLOW ? `
|
|
19
|
+
const STORE = FLOW ? `kenryu.flow.${FLOW}` : "kenryu.graph";
|
|
20
20
|
|
|
21
21
|
let specs = {}; // spec id -> spec
|
|
22
22
|
let specsSig = "";
|
|
@@ -140,7 +140,7 @@ function plainGraph() {
|
|
|
140
140
|
function tellSelection() {
|
|
141
141
|
const n = selected;
|
|
142
142
|
const r = n && results[n.id];
|
|
143
|
-
tell({ type: "
|
|
143
|
+
tell({ type: "kenryu:select", node: n ? String(n.id) : null, title: n ? n.title : "",
|
|
144
144
|
figure: !!(r && r.status === "ok" && r.preview && r.preview.kind === "image") });
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -267,7 +267,7 @@ async function saveFlow() {
|
|
|
267
267
|
try {
|
|
268
268
|
const res = await fetch(FLOW_URL, { method: "POST", headers: { "Content-Type": "application/json" }, body });
|
|
269
269
|
if (!res.ok) throw new Error((await res.text()).trim() || res.status);
|
|
270
|
-
tell({ type: "
|
|
270
|
+
tell({ type: "kenryu:saved", ...(await res.json()) });
|
|
271
271
|
} catch (e) {
|
|
272
272
|
$("#status").textContent = "not saved to kenkyu: " + e.message;
|
|
273
273
|
}
|
|
@@ -302,7 +302,7 @@ window.addEventListener("message", async (e) => {
|
|
|
302
302
|
if (e.data.type === "kenkyu:select") focusNode(e.data.node);
|
|
303
303
|
if (e.data.type === "kenkyu:flush") {
|
|
304
304
|
if (flowTimer) await saveFlow(); else if (flowSaving) await flowSaving;
|
|
305
|
-
tell({ type: "
|
|
305
|
+
tell({ type: "kenryu:flushed", id: e.data.id });
|
|
306
306
|
}
|
|
307
307
|
});
|
|
308
308
|
|
|
@@ -466,7 +466,8 @@ window.addEventListener("focus", async () => {
|
|
|
466
466
|
return;
|
|
467
467
|
}
|
|
468
468
|
let saved = null;
|
|
469
|
-
|
|
469
|
+
// Before 0.3 the canvas was saved under "nagare." keys: pick those up once.
|
|
470
|
+
try { saved = JSON.parse(localStorage.getItem(STORE) || localStorage.getItem(STORE.replace(/^kenryu\./, "nagare.")) || "null"); } catch (_) { saved = null; }
|
|
470
471
|
if (saved && saved.nodes && saved.nodes.length) load(saved);
|
|
471
472
|
else if (specs["rnaseq.simulate_counts"]) buildDemo();
|
|
472
473
|
listGraphs();
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title>
|
|
6
|
+
<title>kenryu</title>
|
|
7
7
|
<link rel="stylesheet" href="vendor/litegraph.css">
|
|
8
8
|
<link rel="stylesheet" href="app.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<header class="bar">
|
|
12
|
-
<strong class="brand">流
|
|
12
|
+
<strong class="brand">流 kenryu</strong>
|
|
13
13
|
<span id="flow-name" class="flow-name" hidden></span>
|
|
14
14
|
<button id="run" title="Run everything (R)">Run</button>
|
|
15
15
|
<label class="live" title="Re-run whenever something changes; unchanged nodes come from the cache"><input type="checkbox" id="live" checked> Live</label>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kenryu
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A node editor for Python functions (prototype)
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -10,13 +10,13 @@ Requires-Dist: numpy; extra == "demo"
|
|
|
10
10
|
Requires-Dist: scipy; extra == "demo"
|
|
11
11
|
Requires-Dist: matplotlib; extra == "demo"
|
|
12
12
|
|
|
13
|
-
#
|
|
13
|
+
# kenryu 流
|
|
14
14
|
|
|
15
15
|
A prototype node editor for Python functions, in the spirit of Blender's node editor. Write ordinary type-hinted functions; each one becomes a node you wire up in the browser, run with caching, preview and export as a plain script.
|
|
16
16
|
|
|
17
17
|
```sh
|
|
18
18
|
pip install git+https://github.com/ShashankRaoCoding/kenryu
|
|
19
|
-
|
|
19
|
+
kenryu path/to/your/nodes # opens http://127.0.0.1:8650/
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
To try the demo, clone the repo and install with the demo extras (pandas, numpy, scipy, matplotlib):
|
|
@@ -24,14 +24,14 @@ To try the demo, clone the repo and install with the demo extras (pandas, numpy,
|
|
|
24
24
|
```sh
|
|
25
25
|
git clone https://github.com/ShashankRaoCoding/kenryu && cd kenryu
|
|
26
26
|
pip install ".[demo]"
|
|
27
|
-
|
|
27
|
+
kenryu examples
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
The RNA-seq demo loads on first start: simulate counts → filter → CPM → PCA and differential expression → plots.
|
|
31
31
|
|
|
32
32
|
## Your own nodes
|
|
33
33
|
|
|
34
|
-
Point
|
|
34
|
+
Point kenryu at any folder of `.py` files. Every public function becomes a node, and its type hints decide the shape:
|
|
35
35
|
|
|
36
36
|
```python
|
|
37
37
|
def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
@@ -47,25 +47,25 @@ def normalise_cpm(counts: pd.DataFrame, log: bool = True) -> pd.DataFrame:
|
|
|
47
47
|
| return type | the output; `tuple[A, B]` gives two |
|
|
48
48
|
| first paragraph of the docstring | the description |
|
|
49
49
|
|
|
50
|
-
No
|
|
50
|
+
No kenryu import is needed. `from kenryu import node` gives an optional decorator for a title, output names, or turning a `str`/`int` parameter into a socket: `@node(title="PCA", outputs=["pcs"], sockets=["path"])`.
|
|
51
51
|
|
|
52
52
|
## How it behaves
|
|
53
53
|
|
|
54
54
|
- **Live**: change a setting or a connection and the graph re-runs. Each node is cached by its code, its settings and its inputs, so only what changed (and what's downstream) runs again. Its code means its whole file plus any other file of the folder that file imports, so editing a helper function re-runs the nodes that use it. Edit a function in your editor and switch back: it re-runs the nodes from that file.
|
|
55
55
|
- **Previews**: tables, figures and text show in the side panel; figures also show inside the node. Errors show the traceback from your function, and downstream nodes wait.
|
|
56
56
|
- **Save / Open** keep graphs in `FOLDER/graphs/`; the canvas also survives a page reload.
|
|
57
|
-
- **Export .py** writes the graph as a plain Python script that runs without
|
|
57
|
+
- **Export .py** writes the graph as a plain Python script that runs without kenryu.
|
|
58
58
|
|
|
59
59
|
## Inside kenkyu
|
|
60
60
|
|
|
61
|
-
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed
|
|
61
|
+
[kenkyu](https://github.com/ShashankRaoCoding/kenkyu) uses an installed kenryu for its **Flows**: install this package (`pip install git+https://github.com/ShashankRaoCoding/kenryu`) where kenkyu runs. kenkyu starts it as `kenryu FOLDER --port 8650 --kenkyu` (no browser, the address printed once ready, and an exit when kenkyu closes its stdin), or uses a kenryu already running on 8650, and serves the canvas at `/kenryu/?flow=ID`. `GET /api/info` tells kenkyu it is talking to a kenryu that speaks its protocol. In that mode the canvas loads and saves the flow in kenkyu's library instead of local storage and `graphs/`, and tells kenkyu which node is selected so its figure can go into a document. Runs return each node's cache `key`, which kenkyu stores with a figure to notice when the code behind it changes, and take a `dpi` for figures. The page uses relative addresses, so it works the same at `/` and under `/kenryu/`.
|
|
62
62
|
|
|
63
63
|
## Prototype limits
|
|
64
64
|
|
|
65
65
|
- One process and an in-memory cache: restarting loses cached results.
|
|
66
66
|
- Nodes get their inputs by reference: a function that changes its input in place also changes the cached copy. Return new objects.
|
|
67
67
|
- New settings or sockets on a function need a page reload (a banner offers it); changed function bodies don't.
|
|
68
|
-
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart
|
|
68
|
+
- The cache knows about the files in your nodes folder, not installed packages: after upgrading a library your nodes use, restart kenryu to clear it.
|
|
69
69
|
- The server only answers to `localhost` or an IP address, and refuses requests that change things when the browser says they came from another site, so other web pages can't run your nodes.
|
|
70
70
|
- No per-sample "for each" yet, no environments per node, no concurrency.
|
|
71
71
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
kenryu/__init__.py
|
|
4
|
+
kenryu/__main__.py
|
|
5
|
+
kenryu/engine.py
|
|
6
|
+
kenryu/preview.py
|
|
7
|
+
kenryu/registry.py
|
|
8
|
+
kenryu/server.py
|
|
9
|
+
kenryu.egg-info/PKG-INFO
|
|
10
|
+
kenryu.egg-info/SOURCES.txt
|
|
11
|
+
kenryu.egg-info/dependency_links.txt
|
|
12
|
+
kenryu.egg-info/entry_points.txt
|
|
13
|
+
kenryu.egg-info/requires.txt
|
|
14
|
+
kenryu.egg-info/top_level.txt
|
|
15
|
+
kenryu/static/app.css
|
|
16
|
+
kenryu/static/app.js
|
|
17
|
+
kenryu/static/index.html
|
|
18
|
+
kenryu/static/vendor/LITEGRAPH-LICENSE
|
|
19
|
+
kenryu/static/vendor/litegraph.core.min.js
|
|
20
|
+
kenryu/static/vendor/litegraph.css
|
|
21
|
+
tests/test_engine.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
kenryu
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "kenryu"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "A node editor for Python functions (prototype)"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
@@ -10,15 +10,14 @@ dependencies = []
|
|
|
10
10
|
demo = ["pandas", "numpy", "scipy", "matplotlib"]
|
|
11
11
|
|
|
12
12
|
[project.scripts]
|
|
13
|
-
|
|
14
|
-
kenryu = "nagare.__main__:main"
|
|
13
|
+
kenryu = "kenryu.__main__:main"
|
|
15
14
|
|
|
16
15
|
[build-system]
|
|
17
16
|
requires = ["setuptools>=68"]
|
|
18
17
|
build-backend = "setuptools.build_meta"
|
|
19
18
|
|
|
20
19
|
[tool.setuptools.packages.find]
|
|
21
|
-
include = ["
|
|
20
|
+
include = ["kenryu*"]
|
|
22
21
|
|
|
23
22
|
[tool.setuptools.package-data]
|
|
24
|
-
|
|
23
|
+
kenryu = ["static/*", "static/vendor/*"]
|
|
@@ -9,8 +9,8 @@ import matplotlib
|
|
|
9
9
|
|
|
10
10
|
matplotlib.use("Agg")
|
|
11
11
|
|
|
12
|
-
from
|
|
13
|
-
from
|
|
12
|
+
from kenryu.engine import Engine, GraphError, export_script, topo_order
|
|
13
|
+
from kenryu.registry import Registry
|
|
14
14
|
|
|
15
15
|
EXAMPLES = Path(__file__).resolve().parents[1] / "examples"
|
|
16
16
|
|
|
@@ -151,15 +151,15 @@ def test_kenkyu_mode_prints_its_address_and_stops_with_stdin(tmp_path):
|
|
|
151
151
|
import urllib.request
|
|
152
152
|
|
|
153
153
|
env = {**os.environ, "PYTHONPATH": str(Path(__file__).resolve().parents[1])}
|
|
154
|
-
proc = subprocess.Popen([sys.executable, "-m", "
|
|
154
|
+
proc = subprocess.Popen([sys.executable, "-m", "kenryu", str(EXAMPLES), "--port", "0", "--kenkyu"],
|
|
155
155
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, env=env)
|
|
156
156
|
try:
|
|
157
157
|
line = proc.stdout.readline().strip()
|
|
158
|
-
assert line.startswith("
|
|
158
|
+
assert line.startswith("kenryu: ready http://127.0.0.1:"), line
|
|
159
159
|
url = line.split()[-1]
|
|
160
160
|
with urllib.request.urlopen(url + "api/info", timeout=30) as r:
|
|
161
161
|
info = json.load(r)
|
|
162
|
-
assert info["name"] == "
|
|
162
|
+
assert info["name"] == "kenryu" and info["kenkyu"] >= 1
|
|
163
163
|
with urllib.request.urlopen(url + "api/nodes", timeout=30) as r:
|
|
164
164
|
assert any(t["id"] == "rnaseq.pca" for t in json.load(r)["types"])
|
|
165
165
|
with urllib.request.urlopen(url, timeout=30) as r: # the page uses relative addresses
|
|
@@ -210,7 +210,7 @@ def test_server_refuses_rebinding_and_cross_site_writes(tmp_path):
|
|
|
210
210
|
import http.client
|
|
211
211
|
import threading
|
|
212
212
|
|
|
213
|
-
from
|
|
213
|
+
from kenryu.server import serve
|
|
214
214
|
|
|
215
215
|
app, httpd = serve(EXAMPLES, 0, graphs=tmp_path)
|
|
216
216
|
threading.Thread(target=httpd.serve_forever, daemon=True).start()
|
|
@@ -242,7 +242,7 @@ def test_server_refuses_rebinding_and_cross_site_writes(tmp_path):
|
|
|
242
242
|
assert req("POST", "/api/graphs/a", headers={"Sec-Fetch-Site": "same-origin", "Origin": own}, body=save) == 200
|
|
243
243
|
assert req("POST", "/api/graphs/b", headers={"Origin": own}, body=save) == 200
|
|
244
244
|
assert req("POST", "/api/graphs/c", body=save) == 200 # curl, kenkyu's server
|
|
245
|
-
# Through kenkyu's proxy: the page is on :8406,
|
|
245
|
+
# Through kenkyu's proxy: the page is on :8406, kenryu sees Host :8650.
|
|
246
246
|
assert req("POST", "/api/graphs/d", headers={"Sec-Fetch-Site": "same-origin",
|
|
247
247
|
"Origin": "http://127.0.0.1:8406"}, body=save) == 200
|
|
248
248
|
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
README.md
|
|
2
|
-
pyproject.toml
|
|
3
|
-
kenryu.egg-info/PKG-INFO
|
|
4
|
-
kenryu.egg-info/SOURCES.txt
|
|
5
|
-
kenryu.egg-info/dependency_links.txt
|
|
6
|
-
kenryu.egg-info/entry_points.txt
|
|
7
|
-
kenryu.egg-info/requires.txt
|
|
8
|
-
kenryu.egg-info/top_level.txt
|
|
9
|
-
nagare/__init__.py
|
|
10
|
-
nagare/__main__.py
|
|
11
|
-
nagare/engine.py
|
|
12
|
-
nagare/preview.py
|
|
13
|
-
nagare/registry.py
|
|
14
|
-
nagare/server.py
|
|
15
|
-
nagare/static/app.css
|
|
16
|
-
nagare/static/app.js
|
|
17
|
-
nagare/static/index.html
|
|
18
|
-
nagare/static/vendor/LITEGRAPH-LICENSE
|
|
19
|
-
nagare/static/vendor/litegraph.core.min.js
|
|
20
|
-
nagare/static/vendor/litegraph.css
|
|
21
|
-
tests/test_engine.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
nagare
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|