marimo-dev 0.3.2__tar.gz → 0.3.4__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.
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/PKG-INFO +3 -9
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/pyproject.toml +13 -24
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/__init__.py +5 -3
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/build.py +2 -2
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/core.py +1 -0
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/docs.py +118 -112
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/pkg.py +33 -3
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/README.md +0 -0
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/cli.py +0 -0
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/publish.py +0 -0
- {marimo_dev-0.3.2 → marimo_dev-0.3.4}/src/marimo_dev/read.py +0 -0
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: marimo-dev
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Build and publish python packages from marimo notebooks
|
|
5
5
|
Author: Deufel
|
|
6
6
|
Author-email: Deufel <MDeufel13@gmail.com>
|
|
7
7
|
License: MIT
|
|
8
|
-
|
|
9
|
-
Requires-Dist:
|
|
10
|
-
Requires-Dist: ipython>=9.8.0
|
|
11
|
-
Requires-Dist: marimo>=0.19.7
|
|
12
|
-
Requires-Dist: mohtml>=0.1.11
|
|
13
|
-
Requires-Dist: pydantic-ai-slim>=1.50.0
|
|
14
|
-
Requires-Dist: pytest>=9.0.2
|
|
15
|
-
Requires-Dist: python-fasthtml>=0.12.37
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Requires-Dist: html-tags>=0.0.18
|
|
16
10
|
Requires-Python: >=3.12
|
|
17
11
|
Project-URL: PyPI, https://pypi.org/project/marimo-dev/
|
|
18
12
|
Project-URL: Repository, https://github.com/deufel/m-dev
|
|
@@ -4,19 +4,22 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "marimo-dev"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.4"
|
|
8
8
|
description = "Build and publish python packages from marimo notebooks"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
11
|
+
classifiers = ["Development Status :: 3 - Alpha"]
|
|
11
12
|
dependencies = [
|
|
13
|
+
"html-tags>=0.0.18",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
12
18
|
"anthropic>=0.84.0",
|
|
13
|
-
"fastcore>=1.10.0",
|
|
14
19
|
"ipython>=9.8.0",
|
|
15
20
|
"marimo>=0.19.7",
|
|
16
|
-
"mohtml>=0.1.11",
|
|
17
21
|
"pydantic-ai-slim>=1.50.0",
|
|
18
22
|
"pytest>=9.0.2",
|
|
19
|
-
"python-fasthtml>=0.12.37",
|
|
20
23
|
]
|
|
21
24
|
|
|
22
25
|
[project.license]
|
|
@@ -29,28 +32,14 @@ email = "MDeufel13@gmail.com"
|
|
|
29
32
|
[project.scripts]
|
|
30
33
|
md = "marimo_dev.cli:main"
|
|
31
34
|
|
|
32
|
-
# not really required with a_module.py imports
|
|
33
|
-
[tool.marimo.runtime]
|
|
34
|
-
pythonpath = ["src"]
|
|
35
|
-
|
|
36
|
-
classifiers = [
|
|
37
|
-
"Development Status :: 3 - Alpha"
|
|
38
|
-
]
|
|
39
|
-
|
|
40
35
|
[project.urls]
|
|
41
36
|
Repository = "https://github.com/deufel/m-dev"
|
|
42
37
|
PyPI = "https://pypi.org/project/marimo-dev/"
|
|
43
38
|
|
|
44
|
-
|
|
45
|
-
# Marimo-Dev settings
|
|
46
39
|
[tool.marimo-dev]
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# Remove this when ready to upload this is a saftey net for not accidentally uploading
|
|
54
|
-
# classifiers = ["Private :: Do Not Upload"]
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
nbs = "notebooks"
|
|
41
|
+
out = "src"
|
|
42
|
+
docs = "docs"
|
|
43
|
+
decorators = ["app.function", "app.class_definition"]
|
|
44
|
+
skip_prefixes = ["XX_", "test_", "tests"]
|
|
45
|
+
renames = {dunder_ = "__", internal_ = "_"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""Build and publish python packages from marimo notebooks"""
|
|
2
|
-
__version__ = '0.3.
|
|
2
|
+
__version__ = '0.3.4'
|
|
3
3
|
__author__ = 'Deufel'
|
|
4
4
|
from .core import Config, read_config, Kind, Param, Node
|
|
5
5
|
from .read import inline_doc, parse_params, parse_hash_pipe, parse_class_params, parse_class_methods, parse_ret, src_with_decs, is_export, parse_import, parse_const, parse_export, parse_node, parse_file, read_meta, nb_name, scan
|
|
6
|
-
from .pkg import clean, write, write_mod, rewrite_imports, write_init
|
|
7
|
-
from .docs import nb_path, render_node, render_module_page,
|
|
6
|
+
from .pkg import clean, write, write_mod, rename, apply_renames, rewrite_imports, write_init
|
|
7
|
+
from .docs import nb_path, render_node, render_module_page, render_index_page, html_preview, build_docs, export_wasm, write_nojekyll, Icon, write_highlighter
|
|
8
8
|
from .build import build, tidy, nuke, get_pypi_name, extract_import_names, pep723_header, write_llms, bundle, bundle_notebook
|
|
9
9
|
from .publish import check_credentials, check_pypi_auth, publish
|
|
10
10
|
from .cli import main
|
|
@@ -14,6 +14,7 @@ __all__ = [
|
|
|
14
14
|
"Kind",
|
|
15
15
|
"Node",
|
|
16
16
|
"Param",
|
|
17
|
+
"apply_renames",
|
|
17
18
|
"build",
|
|
18
19
|
"build_docs",
|
|
19
20
|
"bundle",
|
|
@@ -45,6 +46,7 @@ __all__ = [
|
|
|
45
46
|
"publish",
|
|
46
47
|
"read_config",
|
|
47
48
|
"read_meta",
|
|
49
|
+
"rename",
|
|
48
50
|
"render_index_page",
|
|
49
51
|
"render_module_page",
|
|
50
52
|
"render_node",
|
|
@@ -18,8 +18,8 @@ def build(
|
|
|
18
18
|
pkg.mkdir(parents=True, exist_ok=True)
|
|
19
19
|
for name, nodes in mods:
|
|
20
20
|
stripped = re.sub(r'^[a-z]_', '', name)
|
|
21
|
-
if stripped != 'index' and any(n.kind == Kind.EXP for n in nodes): write_mod(pkg/f'{stripped}.py', nodes, mod_names)
|
|
22
|
-
write_init(pkg/'__init__.py', meta, mods)
|
|
21
|
+
if stripped != 'index' and any(n.kind == Kind.EXP for n in nodes): write_mod(pkg/f'{stripped}.py', nodes, mod_names, cfg.renames)
|
|
22
|
+
write_init(pkg/'__init__.py', meta, mods, cfg.renames)
|
|
23
23
|
all_exp = [n for _, nodes in mods for n in nodes if n.kind == Kind.EXP]
|
|
24
24
|
if all_exp: write_llms()
|
|
25
25
|
return str(pkg)
|
|
@@ -11,6 +11,7 @@ class Config:
|
|
|
11
11
|
root: str = '.'
|
|
12
12
|
decorators: list[str] = field(default_factory=lambda: ['app.function', 'app.class_definition'])
|
|
13
13
|
skip_prefixes: list[str] = field(default_factory=lambda: ['XX_', 'test_'])
|
|
14
|
+
renames: dict[str,str] = field(default_factory=dict)
|
|
14
15
|
|
|
15
16
|
def read_config(root='.'):
|
|
16
17
|
"Read config from pyproject.toml [tool.marimo-dev] section with defaults"
|
|
@@ -2,16 +2,27 @@ from .core import Kind, Param, Node, Config, read_config
|
|
|
2
2
|
from .read import scan, nb_name, read_meta
|
|
3
3
|
from .pkg import clean
|
|
4
4
|
from .build import bundle_notebook
|
|
5
|
+
import ast, re, tomllib, json
|
|
5
6
|
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
import
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from dataclasses import dataclass, field
|
|
9
|
+
import os, sys, subprocess, configparser, shutil
|
|
8
10
|
from functools import partial
|
|
9
|
-
from
|
|
10
|
-
from fasthtml.components import ft, Html, Head, Script, Body, show, Style, Title
|
|
11
|
+
from html_tags import mktag, setup_svg, Tag
|
|
11
12
|
|
|
13
|
+
Link = mktag('link', self_closing=True)
|
|
12
14
|
icons = {'home': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-house-icon lucide-house"><path d="M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8"/><path d="M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/></svg>', 'pypi': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-blocks-icon lucide-blocks"><path d="M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2"/><rect x="14" y="2" width="8" height="8" rx="1"/></svg>', 'menu': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-menu-icon lucide-menu"><path d="M4 5h16"/><path d="M4 12h16"/><path d="M4 19h16"/></svg>', 'x': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x-icon lucide-x"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>', 'github': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-github-icon lucide-github"><path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4"/><path d="M9 18c-4.51 2-5-2-7-2"/></svg>', 'code': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-code-icon lucide-code"><path d="m16 18 6-6-6-6"/><path d="m8 6-6 6 6 6"/></svg>', 'info': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-info-icon lucide-info"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>', 'calendar': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-calendar1-icon lucide-calendar-1"><path d="M11 14h1v4"/><path d="M16 2v4"/><path d="M3 10h18"/><path d="M8 2v4"/><rect x="3" y="4" width="18" height="18" rx="2"/></svg>', 'circle-x': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-x-icon lucide-circle-x"><circle cx="12" cy="12" r="10"/><path d="m15 9-6 6"/><path d="m9 9 6 6"/></svg>', 'external-link': '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-external-link-icon lucide-external-link"><path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/></svg>'}
|
|
13
15
|
COLORS = {'keyword': '#c792ea', 'string': '#c3e88d', 'builtin': '#82aaff', 'decorator': '#f78c6c', 'comment': '#546e7a', 'number': '#f78c6c', 'punctuation': '#89ddff', 'defname': '#82aaff', 'classname': '#ffcb6b', 'operator': '#89ddff', 'call': '#82aaff', 'fstring': '#c3e88d', 'type': '#ffcb6b'}
|
|
14
16
|
|
|
17
|
+
Div, Span, P, A, Button, Pre, Code, Li, Ul = (mktag(t) for t in
|
|
18
|
+
'div span p a button pre code li ul'.split())
|
|
19
|
+
H1, H2, H3, Nav, Article, Header, Main, Aside = (mktag(t) for t in
|
|
20
|
+
'h1 h2 h3 nav article header main aside'.split())
|
|
21
|
+
Html, Head, Body, Title, Input, Strong = (mktag(t) for t in
|
|
22
|
+
'html head body title input strong'.split())
|
|
23
|
+
Script, Style, Iframe = (mktag(t, mode='raw') for t in
|
|
24
|
+
'script style iframe'.split())
|
|
25
|
+
|
|
15
26
|
def nb_path(
|
|
16
27
|
mod_name,
|
|
17
28
|
root='.'
|
|
@@ -30,24 +41,25 @@ def render_node(n, repo_url=None, root='.'):
|
|
|
30
41
|
nb = nb_path(n.module, root)
|
|
31
42
|
tag_colors = {'func': '#10b981', 'async': '#f59e0b', 'class': '#8b5cf6'}
|
|
32
43
|
|
|
33
|
-
code_lines = [Span(
|
|
44
|
+
code_lines = [Span(cls="code-line")(line) for line in signature.split('\n')]
|
|
34
45
|
|
|
35
46
|
def ghbtn(icon, label, url):
|
|
36
47
|
if not url: return None
|
|
37
|
-
return A(
|
|
48
|
+
return A(href=url, target="_blank", cls="gh-link")(
|
|
49
|
+
Button(cls="gh-btn")(Icon(icon, size=16), label))
|
|
38
50
|
|
|
39
|
-
tag = Span(
|
|
40
|
-
mod_name = Span(Span(f"{n.module}."
|
|
51
|
+
tag = Span(cls="tag", style=f"background:{tag_colors.get(t, '#666')};")(t)
|
|
52
|
+
mod_name = Span(cls="full-name")(Span(cls="mod")(f"{n.module}."), Span(cls="name")(n.name)) if n.module else Span(cls="full-name name")(n.name)
|
|
41
53
|
|
|
42
|
-
copy_btn = Button(
|
|
54
|
+
copy_btn = Button(cls="copy-btn", onclick=f"navigator.clipboard.writeText(document.getElementById('{node_id}').textContent).then(() => this.textContent = '✓').then(() => setTimeout(() => this.textContent = '📋', 1500))")("📋")
|
|
43
55
|
source_btn = ghbtn('github', 'Source', f"{repo_url}/blob/master/{nb}#L{n.lineno}" if repo_url and nb and n.lineno else None)
|
|
44
56
|
edit_btn = ghbtn('code', 'Edit', f"{repo_url}/edit/master/{nb}" if repo_url and nb else None)
|
|
45
57
|
blame_btn = ghbtn('info', 'Blame', f"{repo_url}/blame/master/{nb}#L{n.lineno}" if repo_url and nb and n.lineno else None)
|
|
46
58
|
history_btn = ghbtn('calendar', 'History', f"{repo_url}/commits/master/{nb}" if repo_url and nb else None)
|
|
47
59
|
issue_btn = ghbtn('circle-x', 'Issue', f"{repo_url}/issues/new?title=Issue%20with%20{n.name}&body={repo_url}/blob/master/{nb}%23L{n.lineno}" if repo_url and nb and n.lineno else None)
|
|
48
60
|
|
|
49
|
-
return Article(
|
|
50
|
-
Style("""
|
|
61
|
+
return Article()(
|
|
62
|
+
Style()("""
|
|
51
63
|
me { margin-bottom: 0.75rem; border-radius: 8px; overflow: hidden; background: #1e1e1e; max-width: 100%; }
|
|
52
64
|
me .header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; }
|
|
53
65
|
me .header-left { display: flex; align-items: center; }
|
|
@@ -65,11 +77,11 @@ def render_node(n, repo_url=None, root='.'):
|
|
|
65
77
|
me .code-line { display: block; padding-left: 3.5em; white-space: pre-wrap; word-break: break-all; position: relative; }
|
|
66
78
|
me .code-line::before { content: counter(line); counter-increment: line; position: absolute; left: 0; width: 2.5em; text-align: right; color: #555; user-select: none; }
|
|
67
79
|
"""),
|
|
68
|
-
Div(
|
|
69
|
-
Div(
|
|
70
|
-
cls="header"),
|
|
71
|
-
P(
|
|
72
|
-
Pre(Code(
|
|
80
|
+
Div(cls="header")(
|
|
81
|
+
Div(cls="header-left")(tag, mod_name),
|
|
82
|
+
Div(cls="header-right")(copy_btn, source_btn, edit_btn, blame_btn, history_btn, issue_btn)),
|
|
83
|
+
P(cls="doc")(n.doc) if n.doc else None,
|
|
84
|
+
Pre()(Code(cls="language-python", id=node_id)(*code_lines)))
|
|
73
85
|
|
|
74
86
|
def render_module_page(mod_name, mod_nodes, all_mod_names, meta, root='.'):
|
|
75
87
|
'''Builds a Module Page'''
|
|
@@ -77,17 +89,17 @@ def render_module_page(mod_name, mod_nodes, all_mod_names, meta, root='.'):
|
|
|
77
89
|
exp_nodes = [n for n in mod_nodes if n.kind == Kind.EXP]
|
|
78
90
|
|
|
79
91
|
head_elements = [
|
|
80
|
-
Script(type="module", src="https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.8/bundles/datastar.js"),
|
|
81
|
-
|
|
82
|
-
Script(src="js/highlight.js", type="module"),
|
|
83
|
-
Style("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; } code { font-family: 'SF Mono', Consolas, monospace; }"),
|
|
84
|
-
Title(f"{mod_name} - {meta['name']}")]
|
|
92
|
+
Script(type="module", src="https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.8/bundles/datastar.js")(),
|
|
93
|
+
mktag('script', mode='raw')(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")(),
|
|
94
|
+
Script(src="js/highlight.js", type="module")(),
|
|
95
|
+
Style()("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; } code { font-family: 'SF Mono', Consolas, monospace; }"),
|
|
96
|
+
Title()(f"{mod_name} - {meta['name']}")]
|
|
85
97
|
|
|
86
|
-
nav_links = [Li(A(
|
|
87
|
-
Li(A(
|
|
98
|
+
nav_links = [Li()(A(href="index.html", cls="back-link")("← Index"))] + [
|
|
99
|
+
Li()(A(href=f"{m}.html", cls=f"nav-link {'active' if m == mod_name else ''}")(m)) for m in all_mod_names]
|
|
88
100
|
|
|
89
|
-
nav = Nav(
|
|
90
|
-
Style("""
|
|
101
|
+
nav = Nav()(
|
|
102
|
+
Style()("""
|
|
91
103
|
me { padding: 1rem; background: #1a1a1a; min-width: 180px; }
|
|
92
104
|
me h3 { margin: 0 0 1rem 0; color: #fff; }
|
|
93
105
|
me ul { list-style: none; padding: 0; margin: 0; }
|
|
@@ -98,104 +110,65 @@ def render_module_page(mod_name, mod_nodes, all_mod_names, meta, root='.'):
|
|
|
98
110
|
me .nav-link.active { color: #fff; }
|
|
99
111
|
me input { width: 100%; padding: 0.5rem; border: 1px solid #333; border-radius: 4px; background: #252525; color: #fff; margin-bottom: 1rem; box-sizing: border-box; }
|
|
100
112
|
"""),
|
|
101
|
-
H3(meta['name']),
|
|
102
|
-
Input(type="text", placeholder="Search...", **{"data-bind": "search"}),
|
|
103
|
-
Ul(*nav_links))
|
|
113
|
+
H3()(meta['name']),
|
|
114
|
+
Input(type="text", placeholder="Search...", **{"data-bind": "search"})(),
|
|
115
|
+
Ul()(*nav_links))
|
|
104
116
|
|
|
105
|
-
header = Header(
|
|
106
|
-
Style("""
|
|
117
|
+
header = Header()(
|
|
118
|
+
Style()("""
|
|
107
119
|
me { padding: 1rem; background: #1e1e1e; border-bottom: 1px solid #333; }
|
|
108
120
|
me .header-row { display: flex; align-items: center; justify-content: space-between; }
|
|
109
121
|
me h1 { margin: 0; font-size: 1.5rem; color: #fff; }
|
|
110
122
|
me .wasm-btn { display: flex; align-items: center; gap: 0.25rem; background: #333; border: 1px solid #444; color: #ccc; padding: 0.5rem 0.75rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
|
|
111
123
|
me .wasm-link { text-decoration: none; }
|
|
112
124
|
"""),
|
|
113
|
-
Div(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
Div(cls="header-row")(
|
|
126
|
+
H1()(mod_name),
|
|
127
|
+
A(href=f"wasm/{mod_name}/index.html", target="_blank", cls="wasm-link")(
|
|
128
|
+
Button(cls="wasm-btn")(Icon('external-link', size=16), "Run in Browser"))))
|
|
117
129
|
|
|
118
|
-
content = Div(
|
|
119
|
-
Style("""
|
|
130
|
+
content = Div()(
|
|
131
|
+
Style()("""
|
|
120
132
|
me { padding: 1rem; background: #121212; overflow-y: auto; flex: 1; }
|
|
121
133
|
"""),
|
|
122
134
|
*[render_node(n, repo_url, root) for n in exp_nodes])
|
|
123
135
|
|
|
124
|
-
body = Body(
|
|
125
|
-
|
|
126
|
-
style="
|
|
127
|
-
**{"data-signals": "{search: ''}"})
|
|
128
|
-
|
|
129
|
-
return Html(Head(*head_elements), body)
|
|
136
|
+
body = Body(style="display: flex; height: 100vh; margin: 0; background: #121212;", **{"data-signals": "{search: ''}"})(
|
|
137
|
+
nav,
|
|
138
|
+
Div(style="flex: 1; display: flex; flex-direction: column;")(header, content))
|
|
130
139
|
|
|
131
|
-
|
|
132
|
-
root='.' # the project root (this should never really change)
|
|
133
|
-
):
|
|
134
|
-
'''Builds the static documentation website'''
|
|
135
|
-
cfg = read_config(root)
|
|
136
|
-
meta = read_meta(root)
|
|
137
|
-
_, mods = scan(root)
|
|
138
|
-
mod_names = [name for name, _ in mods]
|
|
139
|
-
docs_path = Path(root) / cfg.docs
|
|
140
|
-
docs_path.mkdir(exist_ok=True)
|
|
141
|
-
(docs_path / "index.html").write_text(to_xml(render_index_page(meta, mods)))
|
|
142
|
-
for mod_name, mod_nodes in mods:
|
|
143
|
-
(docs_path / f"{mod_name}.html").write_text(to_xml(render_module_page(mod_name, mod_nodes, mod_names, meta, root)))
|
|
144
|
-
export_wasm(root)
|
|
145
|
-
return f"Generated index + {len(mods)} module pages in {docs_path}"
|
|
146
|
-
|
|
147
|
-
def export_wasm(
|
|
148
|
-
root='.' # Project Root
|
|
149
|
-
):
|
|
150
|
-
"""Uses the bundeled notebook to make a WASM marimo notebook"""
|
|
151
|
-
cfg = read_config(root)
|
|
152
|
-
wasm_dir = Path(root) / cfg.docs / 'wasm'
|
|
153
|
-
wasm_dir.mkdir(parents=True, exist_ok=True)
|
|
154
|
-
bundled = Path(root) / cfg.nbs / '_bundled.py'
|
|
155
|
-
bundle_notebook(root, name=str(bundled))
|
|
156
|
-
os.system(f"marimo export html-wasm {bundled} -o {wasm_dir} --mode edit")
|
|
157
|
-
bundled.unlink()
|
|
158
|
-
|
|
159
|
-
def write_nojekyll(root='.'):
|
|
160
|
-
cfg = read_config(root)
|
|
161
|
-
Path(root, cfg.docs, '.nojekyll').touch()
|
|
162
|
-
|
|
163
|
-
def html_preview(width='100%', height='300px'):
|
|
164
|
-
"Display FT components in an IFrame"
|
|
165
|
-
def _preview(*components): show(Iframe(srcdoc=to_xml(components[0] if len(components) == 1 else Div(*components)), width=width, height=height))
|
|
166
|
-
return _preview
|
|
140
|
+
return Html()(Head()(*head_elements), body)
|
|
167
141
|
|
|
168
142
|
def render_index_page(meta, mods, repo_url=None):
|
|
169
143
|
mod_names = [name for name, _ in mods]
|
|
170
144
|
head_elements = [
|
|
171
|
-
Script(type="module", src="https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.7/bundles/datastar.js"),
|
|
172
|
-
|
|
173
|
-
Script(src="js/highlight.js", type="module"),
|
|
174
|
-
Style("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; } code { font-family: 'SF Mono', Consolas, monospace; }"),
|
|
175
|
-
Title(meta['name'])]
|
|
145
|
+
Script(type="module", src="https://cdn.jsdelivr.net/gh/starfederation/datastar@1.0.0-RC.7/bundles/datastar.js")(),
|
|
146
|
+
mktag('script', mode='raw')(src="https://cdn.jsdelivr.net/gh/gnat/css-scope-inline@main/script.js")(),
|
|
147
|
+
Script(src="js/highlight.js", type="module")(),
|
|
148
|
+
Style()("body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; margin: 0; } code { font-family: 'SF Mono', Consolas, monospace; }"),
|
|
149
|
+
Title()(meta['name'])]
|
|
176
150
|
|
|
177
|
-
nav_links = [Li(A(
|
|
151
|
+
nav_links = [Li()(A(href=f"{m}.html", cls="nav-link")(m)) for m in mod_names]
|
|
178
152
|
|
|
179
|
-
nav = Nav(
|
|
180
|
-
Style("""
|
|
153
|
+
nav = Nav()(
|
|
154
|
+
Style()("""
|
|
181
155
|
me { padding: 1rem; background: #1a1a1a; min-width: 180px; }
|
|
182
156
|
me h3 { margin: 0 0 1rem 0; color: #fff; }
|
|
183
157
|
me ul { list-style: none; padding: 0; margin: 0; }
|
|
184
158
|
me .nav-link { color: #aaa; text-decoration: none; }
|
|
185
159
|
me .nav-link:hover { color: #fff; }
|
|
186
160
|
"""),
|
|
187
|
-
H3(meta['name']),
|
|
188
|
-
Ul(*nav_links))
|
|
189
|
-
|
|
190
|
-
module_cards = [A(
|
|
191
|
-
Div(
|
|
192
|
-
|
|
193
|
-
cls="card")
|
|
194
|
-
href=f"{name}.html", cls="card-link")
|
|
161
|
+
H3()(meta['name']),
|
|
162
|
+
Ul()(*nav_links))
|
|
163
|
+
|
|
164
|
+
module_cards = [A(href=f"{name}.html", cls="card-link")(
|
|
165
|
+
Div(cls="card")(
|
|
166
|
+
H3(cls="card-title")(name),
|
|
167
|
+
P(cls="card-count")(f"{len([n for n in nodes if n.kind == Kind.EXP])} exports")))
|
|
195
168
|
for name, nodes in mods]
|
|
196
169
|
|
|
197
|
-
content = Div(
|
|
198
|
-
Style("""
|
|
170
|
+
content = Div()(
|
|
171
|
+
Style()("""
|
|
199
172
|
me { padding: 2rem; flex: 1; }
|
|
200
173
|
me h1 { margin: 0 0 0.5rem 0; color: #fff; }
|
|
201
174
|
me .desc { color: #888; margin: 0 0 2rem 0; }
|
|
@@ -208,36 +181,69 @@ def render_index_page(meta, mods, repo_url=None):
|
|
|
208
181
|
me .card-title { margin: 0 0 0.5rem 0; color: #fff; }
|
|
209
182
|
me .card-count { margin: 0; color: #888; }
|
|
210
183
|
"""),
|
|
211
|
-
H1(meta['name']),
|
|
212
|
-
P(meta['desc']
|
|
213
|
-
P(f"Version {meta['version']}"
|
|
214
|
-
H2("Modules"),
|
|
215
|
-
Div(
|
|
184
|
+
H1()(meta['name']),
|
|
185
|
+
P(cls="desc")(meta['desc']),
|
|
186
|
+
P(cls="version")(f"Version {meta['version']}"),
|
|
187
|
+
H2()("Modules"),
|
|
188
|
+
Div(cls="grid")(*module_cards))
|
|
189
|
+
|
|
190
|
+
body = Body(style="display: flex; min-height: 100vh; margin: 0; background: #121212;")(nav, content)
|
|
191
|
+
return Html()(Head()(*head_elements), body)
|
|
192
|
+
|
|
193
|
+
def html_preview(width='100%', height='300px'):
|
|
194
|
+
"Display FT components in an IFrame"
|
|
195
|
+
from IPython.display import display, HTML
|
|
196
|
+
def _preview(*components):
|
|
197
|
+
html = str(components[0]) if len(components) == 1 else str(Div()(*components))
|
|
198
|
+
display(HTML(f'<iframe srcdoc="{html}" width="{width}" height="{height}"></iframe>'))
|
|
199
|
+
return _preview
|
|
200
|
+
|
|
201
|
+
def build_docs(root='.'):
|
|
202
|
+
'''Builds the static documentation website'''
|
|
203
|
+
cfg = read_config(root)
|
|
204
|
+
meta = read_meta(root)
|
|
205
|
+
_, mods = scan(root)
|
|
206
|
+
mod_names = [name for name, _ in mods]
|
|
207
|
+
docs_path = Path(root) / cfg.docs
|
|
208
|
+
docs_path.mkdir(exist_ok=True)
|
|
209
|
+
(docs_path / "index.html").write_text(str(render_index_page(meta, mods)))
|
|
210
|
+
for mod_name, mod_nodes in mods:
|
|
211
|
+
(docs_path / f"{mod_name}.html").write_text(str(render_module_page(mod_name, mod_nodes, mod_names, meta, root)))
|
|
212
|
+
export_wasm(root)
|
|
213
|
+
return f"Generated index + {len(mods)} module pages in {docs_path}"
|
|
214
|
+
|
|
215
|
+
def export_wasm(
|
|
216
|
+
root='.' # Project Root
|
|
217
|
+
):
|
|
218
|
+
"""Uses the bundeled notebook to make a WASM marimo notebook"""
|
|
219
|
+
cfg = read_config(root)
|
|
220
|
+
wasm_dir = Path(root) / cfg.docs / 'wasm'
|
|
221
|
+
wasm_dir.mkdir(parents=True, exist_ok=True)
|
|
222
|
+
bundled = Path(root) / cfg.nbs / '_bundled.py'
|
|
223
|
+
bundle_notebook(root, name=str(bundled))
|
|
224
|
+
os.system(f"marimo export html-wasm {bundled} -o {wasm_dir} --mode edit")
|
|
225
|
+
bundled.unlink()
|
|
216
226
|
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
def write_nojekyll(root='.'):
|
|
228
|
+
cfg = read_config(root)
|
|
229
|
+
Path(root, cfg.docs, '.nojekyll').touch()
|
|
219
230
|
|
|
220
231
|
def Icon(name: str, # name of the icon MUST be in icon_dict
|
|
221
232
|
size=24, # value to be passed to height and width of the icon
|
|
222
233
|
stroke=1.5, # stroke width
|
|
223
234
|
cls=None, # css class
|
|
224
235
|
icon_dict:dict=icons, # Dict of icons {"name":"<svg...>"}
|
|
225
|
-
**kwargs # passed
|
|
226
|
-
)
|
|
227
|
-
'''
|
|
228
|
-
Creates a custom html compliant <icon-{name}>...
|
|
229
|
-
Intended to be used with a Global Dict of icons {"home": "<svg...", "info": "<svg..."}
|
|
230
|
-
Icon('home') -> <icon-home> .... </icon-home>
|
|
231
|
-
'''
|
|
236
|
+
**kwargs # passed through to tag
|
|
237
|
+
):
|
|
238
|
+
'''Creates a custom html compliant <icon-{name}>...'''
|
|
232
239
|
if name not in icon_dict: raise ValueError(f"Icon '{name}' not found")
|
|
233
240
|
|
|
234
|
-
# count=1 Replace only the first occurrence of width & height 99% of time this is what you want
|
|
235
241
|
svg_string = icon_dict[name]
|
|
236
242
|
svg_string = re.sub(r'width="\d+"', f'width="{size}"', svg_string, count=1)
|
|
237
243
|
svg_string = re.sub(r'height="\d+"', f'height="{size}"', svg_string, count=1)
|
|
238
244
|
svg_string = re.sub(r'stroke-width="\d+"', f'stroke-width="{stroke}"', svg_string)
|
|
239
245
|
|
|
240
|
-
return
|
|
246
|
+
return mktag(f'icon-{name}', mode='raw')(cls=cls, **kwargs)(svg_string)
|
|
241
247
|
|
|
242
248
|
def write_highlighter(root='.'):
|
|
243
249
|
"Write Python syntax highlighter JS to docs folder."
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from .core import Kind, Param, Node, Config
|
|
1
|
+
from .core import Kind, Param, Node, Config, read_config
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
import ast, re
|
|
4
4
|
|
|
@@ -19,13 +19,42 @@ def write_mod(
|
|
|
19
19
|
path, # output file path
|
|
20
20
|
nodes:list, # list of Node objects to write
|
|
21
21
|
mod_names:list, # list of module names for import rewriting
|
|
22
|
+
renames:dict=None, # prefix substitution map
|
|
22
23
|
):
|
|
23
24
|
"Write module file with imports, constants, and exports."
|
|
24
25
|
g = {k: [n for n in nodes if n.kind == k] for k in Kind}
|
|
25
26
|
imports = '\n'.join(rewrite_imports(n.src, mod_names) for n in g[Kind.IMP])
|
|
26
|
-
|
|
27
|
+
exp_src = '\n\n'.join(apply_renames(clean(n.src), n.name, renames) for n in g[Kind.EXP])
|
|
28
|
+
|
|
29
|
+
# Second pass: fix cross-references to renamed symbols
|
|
30
|
+
rename_map = {n.name: rename(n.name, renames) for n in g[Kind.EXP] if rename(n.name, renames) != n.name}
|
|
31
|
+
for old, new in rename_map.items():
|
|
32
|
+
exp_src = re.sub(rf'\b{re.escape(old)}\b', new, exp_src)
|
|
33
|
+
|
|
34
|
+
parts = [imports, '\n'.join(n.src for n in g[Kind.CONST]), '\n'.join(n.src for n in g[Kind.SETUP]), exp_src, '\n\n'.join(n.src for n in g[Kind.RAW])]
|
|
27
35
|
write(path, *parts)
|
|
28
36
|
|
|
37
|
+
def rename(
|
|
38
|
+
name:str, # original function/class name
|
|
39
|
+
renames:dict=None # prefix substitution map
|
|
40
|
+
)->str: # renamed identifier
|
|
41
|
+
"Apply prefix substitutions to a name. Symmetric prefixes like __ wrap both sides."
|
|
42
|
+
for prefix, replacement in (renames or {}).items():
|
|
43
|
+
if not name.startswith(prefix): continue
|
|
44
|
+
stem = name[len(prefix):]
|
|
45
|
+
if replacement.startswith('__'): return replacement + stem + '__'
|
|
46
|
+
return replacement + stem
|
|
47
|
+
return name
|
|
48
|
+
|
|
49
|
+
def apply_renames(
|
|
50
|
+
src:str, # source code
|
|
51
|
+
name:str, # original function/class name
|
|
52
|
+
renames:dict=None # prefix substitution map
|
|
53
|
+
)->str: # source with renamed identifier
|
|
54
|
+
"Replace function/class name in source code using prefix substitution."
|
|
55
|
+
new = rename(name, renames)
|
|
56
|
+
return src.replace(name, new, 1) if new != name else src
|
|
57
|
+
|
|
29
58
|
def rewrite_imports(
|
|
30
59
|
src:str, # source code to rewrite
|
|
31
60
|
mod_names:list # list of module names
|
|
@@ -44,6 +73,7 @@ def write_init(
|
|
|
44
73
|
path:str|Path, # path to write __init__.py file
|
|
45
74
|
meta:dict, # metadata dict with desc, version, author
|
|
46
75
|
mods:list, # list of (name, nodes) tuples
|
|
76
|
+
renames:dict=None, # prefix substitution map
|
|
47
77
|
):
|
|
48
78
|
"Generate and write __init__.py file with metadata and exports."
|
|
49
79
|
lines = [f'"""{meta["desc"]}"""', f"__version__ = '{meta['version']}'"]
|
|
@@ -51,7 +81,7 @@ def write_init(
|
|
|
51
81
|
exports = []
|
|
52
82
|
for name, nodes in mods:
|
|
53
83
|
if name.startswith('00_'): continue
|
|
54
|
-
pub = [n.name for n in nodes if n.kind == Kind.EXP and not n.name.startswith('__') and 'internal' not in n.hash_pipes]
|
|
84
|
+
pub = [rename(n.name, renames) for n in nodes if n.kind == Kind.EXP and not n.name.startswith('__') and 'internal' not in n.hash_pipes]
|
|
55
85
|
if pub: lines.append(f"from .{name} import {', '.join(pub)}"); exports.extend(pub)
|
|
56
86
|
if exports: lines.append('__all__ = [\n' + '\n'.join(f' "{n}",' for n in sorted(exports)) + '\n]')
|
|
57
87
|
write(path, '\n'.join(lines))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|