marimo-dev 0.4.3__tar.gz → 0.5.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.
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/PKG-INFO +7 -6
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/README.md +3 -1
- marimo_dev-0.5.0/pyproject.toml +42 -0
- marimo_dev-0.4.3/pyproject.toml → marimo_dev-0.5.0/pyproject.toml.orig +6 -11
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/__init__.py +13 -3
- marimo_dev-0.5.0/src/marimo_dev/_html.py +59 -0
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/build_docs.py +2 -2
- marimo_dev-0.5.0/src/marimo_dev/build_docs_html.py +413 -0
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/build_pkg.py +50 -43
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/cli.py +3 -0
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/parse.py +5 -5
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/types.py +24 -5
- {marimo_dev-0.4.3 → marimo_dev-0.5.0}/src/marimo_dev/publish.py +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: marimo-dev
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Build and publish python packages from marimo notebooks
|
|
5
|
-
Author: Deufel
|
|
6
|
-
Author-email: Deufel <MDeufel13@gmail.com>
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Build and publish (functional/immutable) python packages from marimo notebooks
|
|
5
|
+
Author: Mike Deufel
|
|
6
|
+
Author-email: Mike Deufel <MDeufel13@gmail.com>
|
|
7
7
|
License: MIT
|
|
8
8
|
Classifier: Development Status :: 3 - Alpha
|
|
9
|
-
Requires-Dist: html-tags>=0.0.18
|
|
10
9
|
Requires-Python: >=3.12
|
|
11
10
|
Project-URL: Repository, https://github.com/deufel/m-dev
|
|
12
11
|
Project-URL: PyPI, https://pypi.org/project/marimo-dev/
|
|
@@ -43,7 +42,7 @@ skip_prefixes = ["XX_", "test_"] # default
|
|
|
43
42
|
application = "server:app:py_sse.serve" # optional, enables __main__.py
|
|
44
43
|
|
|
45
44
|
[tool.marimo-dev.renames]
|
|
46
|
-
internal_ = "_" # internal_foo → _foo (private)
|
|
45
|
+
internal_ = "_" # internal_foo → _foo (private); also file names
|
|
47
46
|
dunder_ = "__" # dunder_init → __init__
|
|
48
47
|
```
|
|
49
48
|
|
|
@@ -51,6 +50,8 @@ dunder_ = "__" # dunder_init → __init__
|
|
|
51
50
|
notebooks/
|
|
52
51
|
├─ a_utils.py → exported as "utils" (letter prefix stripped)
|
|
53
52
|
├─ b_database.py → exported as "database"
|
|
53
|
+
├─ c_internal_html.py → built as "_html": private module, usable by the
|
|
54
|
+
│ others, not re-exported, not in the docs
|
|
54
55
|
├─ XX_scratch.py → skipped (XX_ prefix)
|
|
55
56
|
├─ test_stuff.py → skipped (test_ prefix)
|
|
56
57
|
|
|
@@ -29,7 +29,7 @@ skip_prefixes = ["XX_", "test_"] # default
|
|
|
29
29
|
application = "server:app:py_sse.serve" # optional, enables __main__.py
|
|
30
30
|
|
|
31
31
|
[tool.marimo-dev.renames]
|
|
32
|
-
internal_ = "_" # internal_foo → _foo (private)
|
|
32
|
+
internal_ = "_" # internal_foo → _foo (private); also file names
|
|
33
33
|
dunder_ = "__" # dunder_init → __init__
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -37,6 +37,8 @@ dunder_ = "__" # dunder_init → __init__
|
|
|
37
37
|
notebooks/
|
|
38
38
|
├─ a_utils.py → exported as "utils" (letter prefix stripped)
|
|
39
39
|
├─ b_database.py → exported as "database"
|
|
40
|
+
├─ c_internal_html.py → built as "_html": private module, usable by the
|
|
41
|
+
│ others, not re-exported, not in the docs
|
|
40
42
|
├─ XX_scratch.py → skipped (XX_ prefix)
|
|
41
43
|
├─ test_stuff.py → skipped (test_ prefix)
|
|
42
44
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.13.10,<0.14"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "marimo-dev"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "Build and publish (functional/immutable) python packages from marimo notebooks"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
classifiers = ["Development Status :: 3 - Alpha"]
|
|
12
|
+
dependencies = []
|
|
13
|
+
|
|
14
|
+
[project.license]
|
|
15
|
+
text = "MIT"
|
|
16
|
+
|
|
17
|
+
[[project.authors]]
|
|
18
|
+
name = "Mike Deufel"
|
|
19
|
+
email = "MDeufel13@gmail.com"
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
md = "marimo_dev.cli:main"
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Repository = "https://github.com/deufel/m-dev"
|
|
26
|
+
PyPI = "https://pypi.org/project/marimo-dev/"
|
|
27
|
+
|
|
28
|
+
[dependency-groups]
|
|
29
|
+
dev = ["marimo>=0.23"]
|
|
30
|
+
|
|
31
|
+
[tool.marimo-dev]
|
|
32
|
+
nbs = "notebooks"
|
|
33
|
+
out = "src"
|
|
34
|
+
docs = "docs"
|
|
35
|
+
skip_prefixes = [
|
|
36
|
+
"XX_",
|
|
37
|
+
"test_",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.marimo-dev.renames]
|
|
41
|
+
dunder_ = "__"
|
|
42
|
+
internal_ = "_"
|
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["uv_build>=0.
|
|
2
|
+
requires = ["uv_build>=0.13.10,<0.14"]
|
|
3
3
|
build-backend = "uv_build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "marimo-dev"
|
|
7
|
-
version = "0.
|
|
8
|
-
description = "Build and publish python packages from marimo notebooks"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
description = "Build and publish (functional/immutable) python packages from marimo notebooks"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
11
11
|
classifiers = ["Development Status :: 3 - Alpha"]
|
|
12
|
-
dependencies = [
|
|
13
|
-
"html-tags>=0.0.18",
|
|
14
|
-
]
|
|
12
|
+
dependencies = []
|
|
15
13
|
|
|
16
14
|
[dependency-groups]
|
|
17
15
|
dev = [
|
|
18
|
-
"marimo>=0.
|
|
19
|
-
"pydantic-ai-slim>=1.50.0",
|
|
20
|
-
"pytest>=9.0.2",
|
|
16
|
+
"marimo>=0.23", # only needed to edit the notebooks
|
|
21
17
|
]
|
|
22
18
|
|
|
23
19
|
[project.license]
|
|
24
20
|
text = "MIT"
|
|
25
21
|
|
|
26
22
|
[[project.authors]]
|
|
27
|
-
name = "Deufel"
|
|
23
|
+
name = "Mike Deufel"
|
|
28
24
|
email = "MDeufel13@gmail.com"
|
|
29
25
|
|
|
30
26
|
[project.scripts]
|
|
@@ -34,7 +30,6 @@ md = "marimo_dev.cli:main"
|
|
|
34
30
|
Repository = "https://github.com/deufel/m-dev"
|
|
35
31
|
PyPI = "https://pypi.org/project/marimo-dev/"
|
|
36
32
|
|
|
37
|
-
|
|
38
33
|
[tool.marimo-dev]
|
|
39
34
|
nbs = "notebooks" # where notebooks live (default: "notebooks")
|
|
40
35
|
out = "src" # package output dir (default: "src")
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"""Build and publish python packages from marimo notebooks"""
|
|
2
|
-
__version__ = '0.
|
|
3
|
-
__author__ = 'Deufel'
|
|
1
|
+
"""Build and publish (functional/immutable) python packages from marimo notebooks"""
|
|
2
|
+
__version__ = '0.5.0'
|
|
3
|
+
__author__ = 'Mike Deufel'
|
|
4
4
|
from .types import rename, Config, Param, Return, Method, Import, Const, Setup, ExportKind, Export, ParsedFile, Module, Meta, Project
|
|
5
5
|
from .parse import read_config, read_project
|
|
6
6
|
from .build_pkg import build, bundle
|
|
7
7
|
from .build_docs import render_llms, render_llms_full, build_docs
|
|
8
8
|
from .publish import publish
|
|
9
9
|
from .cli import tidy, nuke, main
|
|
10
|
+
from .build_docs_html import signature_text, method_signature_text, render_export, render_module_setup, render_module, render_sidebar, render_header, render_page, build_docs_html
|
|
10
11
|
__all__ = [
|
|
11
12
|
"Config",
|
|
12
13
|
"Const",
|
|
@@ -23,14 +24,23 @@ __all__ = [
|
|
|
23
24
|
"Setup",
|
|
24
25
|
"build",
|
|
25
26
|
"build_docs",
|
|
27
|
+
"build_docs_html",
|
|
26
28
|
"bundle",
|
|
27
29
|
"main",
|
|
30
|
+
"method_signature_text",
|
|
28
31
|
"nuke",
|
|
29
32
|
"publish",
|
|
30
33
|
"read_config",
|
|
31
34
|
"read_project",
|
|
32
35
|
"rename",
|
|
36
|
+
"render_export",
|
|
37
|
+
"render_header",
|
|
33
38
|
"render_llms",
|
|
34
39
|
"render_llms_full",
|
|
40
|
+
"render_module",
|
|
41
|
+
"render_module_setup",
|
|
42
|
+
"render_page",
|
|
43
|
+
"render_sidebar",
|
|
44
|
+
"signature_text",
|
|
35
45
|
"tidy",
|
|
36
46
|
]
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from html import escape
|
|
2
|
+
from types import SimpleNamespace
|
|
3
|
+
|
|
4
|
+
VOID = frozenset('area base br col embed hr img input link meta source track wbr'.split())
|
|
5
|
+
|
|
6
|
+
def esc(
|
|
7
|
+
s, # any value; stringified
|
|
8
|
+
) -> str: # text safe to place inside an element
|
|
9
|
+
"Escape `&`, `<` and `>` in text content."
|
|
10
|
+
return escape(str(s), quote=False)
|
|
11
|
+
|
|
12
|
+
def _attrs(
|
|
13
|
+
d: dict, # attribute name → value, keys in final HTML form
|
|
14
|
+
) -> str: # ' k="v" ...' with a leading space per attribute, or ''
|
|
15
|
+
"Serialize attributes. `True` is a bare attribute; `None` and `False` are omitted."
|
|
16
|
+
return ''.join(
|
|
17
|
+
f' {k}' if v is True else f' {k}="{escape(str(v), quote=True)}"'
|
|
18
|
+
for k, v in d.items()
|
|
19
|
+
if v is not None and v is not False
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def _join(
|
|
23
|
+
xs, # children: strings, nested lists / tuples / generators, None, False
|
|
24
|
+
) -> str: # one concatenated string
|
|
25
|
+
"Concatenate children, flattening nested iterables and dropping `None` / `False`."
|
|
26
|
+
return ''.join(
|
|
27
|
+
str(x) if isinstance(x, str) or not hasattr(x, '__iter__') else _join(x)
|
|
28
|
+
for x in xs
|
|
29
|
+
if x is not None and x is not False
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
def tag(
|
|
33
|
+
name: str, # element name, e.g. 'div'
|
|
34
|
+
): # closure `el(*children_or_attr_dicts, **attrs) -> str`
|
|
35
|
+
"Make an element function for one tag name."
|
|
36
|
+
void = name in VOID
|
|
37
|
+
|
|
38
|
+
def el(*args, **kw):
|
|
39
|
+
attrs = {k: v for a in args if isinstance(a, dict) for k, v in a.items()}
|
|
40
|
+
attrs.update(('class' if k == 'cls' else k.rstrip('_').replace('_', '-'), v) for k, v in kw.items())
|
|
41
|
+
if void: return f'<{name}{_attrs(attrs)}>'
|
|
42
|
+
inner = _join(a for a in args if not isinstance(a, dict))
|
|
43
|
+
return f'<{name}{_attrs(attrs)}>{inner}</{name}>'
|
|
44
|
+
|
|
45
|
+
return el
|
|
46
|
+
|
|
47
|
+
def tags(
|
|
48
|
+
names: str, # space separated tag names, e.g. 'div p a'
|
|
49
|
+
) -> SimpleNamespace: # namespace with one element function per name
|
|
50
|
+
"Make several element functions at once: `h = tags('div p'); h.div(h.p('hi'))`."
|
|
51
|
+
return SimpleNamespace(**{n: tag(n) for n in names.split()})
|
|
52
|
+
|
|
53
|
+
def page(
|
|
54
|
+
head: str, # rendered <head> element
|
|
55
|
+
body: str, # rendered <body> element
|
|
56
|
+
lang: str = 'en', # value of <html lang>
|
|
57
|
+
) -> str: # complete HTML document
|
|
58
|
+
"Wrap head and body in a full HTML document."
|
|
59
|
+
return f'<!DOCTYPE html>\n<html lang="{lang}">{head}{body}</html>\n'
|
|
@@ -7,7 +7,7 @@ def render_llms(
|
|
|
7
7
|
) -> str: # llms.txt content
|
|
8
8
|
"Render llms.txt — module index with export names."
|
|
9
9
|
lines = [f"# {proj.meta.name}\n", f"> {proj.meta.desc}\n"]
|
|
10
|
-
for mod in proj.
|
|
10
|
+
for mod in proj.documented_modules:
|
|
11
11
|
names = ', '.join(e.final_name for e in mod.documented_exports)
|
|
12
12
|
if names:
|
|
13
13
|
lines.append(f"- [{mod.name}](/{mod.name}): {names}")
|
|
@@ -19,7 +19,7 @@ def render_llms_full(
|
|
|
19
19
|
) -> str: # llms-full.txt content
|
|
20
20
|
"Render llms-full.txt — complete cleaned source."
|
|
21
21
|
parts = [f"# {proj.meta.name}\n\n> {proj.meta.desc}\n"]
|
|
22
|
-
for mod in proj.
|
|
22
|
+
for mod in proj.documented_modules:
|
|
23
23
|
documented = mod.documented_exports
|
|
24
24
|
if not documented: continue
|
|
25
25
|
parts.append(f"## {mod.name}\n")
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
from urllib.parse import quote
|
|
2
|
+
from ._html import tags, esc, page
|
|
3
|
+
from .types import Project, Module, Export, Param, Return, ExportKind
|
|
4
|
+
|
|
5
|
+
h = tags('head meta title link style body header main aside nav section article address div h1 h2 h3 h4 p a small span ul li details summary pre code')
|
|
6
|
+
|
|
7
|
+
# ── Signature rendering ──────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
def _fmt_param(
|
|
10
|
+
p, # a Param dataclass instance
|
|
11
|
+
): # a single line like " name: str = default, # doc" (leading 4-space indent)
|
|
12
|
+
"Format one parameter line in the docments style."
|
|
13
|
+
line = f" {p.name}"
|
|
14
|
+
if p.anno: line += f": {p.anno}"
|
|
15
|
+
if p.default: line += f" = {p.default}"
|
|
16
|
+
line += ","
|
|
17
|
+
if p.doc: line += f" # {p.doc}"
|
|
18
|
+
return line
|
|
19
|
+
|
|
20
|
+
def _fmt_return(
|
|
21
|
+
ret, # a Return dataclass instance or None
|
|
22
|
+
): # a string like ") -> Type: # doc" or just "):"
|
|
23
|
+
"Format the closing line of a signature including return type and doc."
|
|
24
|
+
if ret is None: return "):"
|
|
25
|
+
line = f") -> {ret.anno}:"
|
|
26
|
+
if ret.doc: line += f" # {ret.doc}"
|
|
27
|
+
return line
|
|
28
|
+
|
|
29
|
+
def signature_text(
|
|
30
|
+
exp, # Export dataclass
|
|
31
|
+
): # full signature as plain text (ready for a <pre><code>)
|
|
32
|
+
"Build a docments-style signature reconstruction from an Export."
|
|
33
|
+
kw = 'async def' if exp.kind == ExportKind.ASYNC else \
|
|
34
|
+
'class' if exp.kind == ExportKind.CLASS else 'def'
|
|
35
|
+
lines = [f"{kw} {exp.final_name}("]
|
|
36
|
+
for p in exp.params:
|
|
37
|
+
lines.append(_fmt_param(p))
|
|
38
|
+
lines.append(_fmt_return(exp.ret))
|
|
39
|
+
if exp.doc:
|
|
40
|
+
# Render docstring inside the signature block so it highlights as Python
|
|
41
|
+
lines.append(f' """{exp.doc}"""')
|
|
42
|
+
return '\n'.join(lines)
|
|
43
|
+
|
|
44
|
+
def method_signature_text(
|
|
45
|
+
m, # Method dataclass
|
|
46
|
+
): # signature reconstruction, indented as a class method
|
|
47
|
+
"Build a docments-style signature for a method (used inside classes)."
|
|
48
|
+
lines = [f"def {m.name}("]
|
|
49
|
+
for p in m.params:
|
|
50
|
+
lines.append(_fmt_param(p))
|
|
51
|
+
lines.append(_fmt_return(m.ret))
|
|
52
|
+
if m.doc:
|
|
53
|
+
lines.append(f' """{m.doc}"""')
|
|
54
|
+
return '\n'.join(lines)
|
|
55
|
+
|
|
56
|
+
# ── Styles (plain strings: no interpolation, so CSS braces stay readable) ────
|
|
57
|
+
|
|
58
|
+
def _css_base() -> str: # document-level CSS for the <head>
|
|
59
|
+
"Page baseline: grey desk, white sheet, serif text, monospace code, print rules."
|
|
60
|
+
return """
|
|
61
|
+
html { background: #f0f0f0; }
|
|
62
|
+
body {
|
|
63
|
+
margin: 0;
|
|
64
|
+
font-family: "Times New Roman", Times, serif;
|
|
65
|
+
font-size: 1.0625rem;
|
|
66
|
+
line-height: 1.4;
|
|
67
|
+
color: black;
|
|
68
|
+
}
|
|
69
|
+
.sheet {
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
max-inline-size: 70rem;
|
|
72
|
+
margin: 2rem auto;
|
|
73
|
+
padding: 3rem;
|
|
74
|
+
background: white;
|
|
75
|
+
box-shadow: 0 0.15rem 0.6rem rgba(0, 0, 0, 0.15);
|
|
76
|
+
}
|
|
77
|
+
a { color: inherit; }
|
|
78
|
+
code, pre {
|
|
79
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
80
|
+
font-size: 0.8em;
|
|
81
|
+
font-variant-ligatures: none;
|
|
82
|
+
}
|
|
83
|
+
pre {
|
|
84
|
+
margin: 0;
|
|
85
|
+
padding: 0.5rem 0.8rem;
|
|
86
|
+
border-inline-start: 1px solid black;
|
|
87
|
+
line-height: 1.35;
|
|
88
|
+
overflow-x: auto;
|
|
89
|
+
}
|
|
90
|
+
pre code { font-size: inherit; }
|
|
91
|
+
@media (max-width: 48rem) {
|
|
92
|
+
html { background: white; }
|
|
93
|
+
.sheet { margin: 0; padding: 1.25rem; box-shadow: none; }
|
|
94
|
+
}
|
|
95
|
+
@media print {
|
|
96
|
+
html { background: white; }
|
|
97
|
+
.sheet { max-inline-size: none; margin: 0; padding: 0; box-shadow: none; }
|
|
98
|
+
details > summary { display: none; }
|
|
99
|
+
}
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def _css_sheet() -> str: # scoped CSS for the sheet (header / main / aside grid)
|
|
103
|
+
"Sheet layout: header on top, main and table of contents below."
|
|
104
|
+
return """
|
|
105
|
+
@scope {
|
|
106
|
+
:scope {
|
|
107
|
+
display: grid;
|
|
108
|
+
grid-template:
|
|
109
|
+
"header header" auto
|
|
110
|
+
"main aside" 1fr
|
|
111
|
+
/ minmax(0, 3fr) minmax(0, 1fr);
|
|
112
|
+
column-gap: 2rem;
|
|
113
|
+
row-gap: 1.5rem;
|
|
114
|
+
}
|
|
115
|
+
> header {
|
|
116
|
+
grid-area: header;
|
|
117
|
+
padding-block-end: 1rem;
|
|
118
|
+
border-block-end: 1px solid black;
|
|
119
|
+
display: grid;
|
|
120
|
+
grid-template-columns: 1fr auto;
|
|
121
|
+
column-gap: 2rem;
|
|
122
|
+
align-items: end;
|
|
123
|
+
}
|
|
124
|
+
> main { grid-area: main; }
|
|
125
|
+
> aside {
|
|
126
|
+
grid-area: aside;
|
|
127
|
+
padding-inline-start: 1.5rem;
|
|
128
|
+
border-inline-start: 1px solid black;
|
|
129
|
+
}
|
|
130
|
+
> header h1 { margin: 0 0 0.25rem; font-size: 2rem; line-height: 1.1; }
|
|
131
|
+
> header h1 small { margin-inline-start: 0.4em; font-size: 0.5em; font-weight: 400; opacity: 0.7; }
|
|
132
|
+
> header p { margin: 0; font-size: 1.15rem; opacity: 0.8; }
|
|
133
|
+
> header address {
|
|
134
|
+
font-style: normal;
|
|
135
|
+
text-align: end;
|
|
136
|
+
font-size: 0.95rem;
|
|
137
|
+
line-height: 1.35;
|
|
138
|
+
display: flex;
|
|
139
|
+
flex-direction: column;
|
|
140
|
+
}
|
|
141
|
+
> header address a { text-decoration: none; }
|
|
142
|
+
> header address a:hover { text-decoration: underline; }
|
|
143
|
+
|
|
144
|
+
@media (max-width: 48rem) {
|
|
145
|
+
:scope {
|
|
146
|
+
grid-template:
|
|
147
|
+
"header" auto
|
|
148
|
+
"aside" auto
|
|
149
|
+
"main" 1fr
|
|
150
|
+
/ minmax(0, 1fr);
|
|
151
|
+
}
|
|
152
|
+
> header { grid-template-columns: minmax(0, 1fr); row-gap: 0.5rem; }
|
|
153
|
+
> header address { text-align: start; }
|
|
154
|
+
> aside {
|
|
155
|
+
padding-inline-start: 0;
|
|
156
|
+
padding-block-end: 1rem;
|
|
157
|
+
border-inline-start: 0;
|
|
158
|
+
border-block-end: 1px solid black;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
@media print {
|
|
162
|
+
:scope { display: block; }
|
|
163
|
+
> aside { display: none; }
|
|
164
|
+
> header { margin-block-end: 1.5rem; }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
def _css_main() -> str: # scoped CSS for <main> (modules and exports)
|
|
170
|
+
"Module sections stack vertically; each export is a small grid: name, kind chip, body."
|
|
171
|
+
return """
|
|
172
|
+
@scope {
|
|
173
|
+
:scope { display: flex; flex-direction: column; gap: 2.5rem; }
|
|
174
|
+
section { display: flex; flex-direction: column; gap: 1.5rem; scroll-margin-block-start: 1rem; }
|
|
175
|
+
section > h2 {
|
|
176
|
+
margin: 0;
|
|
177
|
+
padding-block-end: 0.3rem;
|
|
178
|
+
border-block-end: 1px solid rgba(0, 0, 0, 0.4);
|
|
179
|
+
font-size: 1.5rem;
|
|
180
|
+
line-height: 1.1;
|
|
181
|
+
}
|
|
182
|
+
article {
|
|
183
|
+
display: grid;
|
|
184
|
+
grid-template:
|
|
185
|
+
"name kind" auto
|
|
186
|
+
"body body" auto
|
|
187
|
+
/ minmax(0, 1fr) auto;
|
|
188
|
+
column-gap: 1rem;
|
|
189
|
+
row-gap: 0.45rem;
|
|
190
|
+
scroll-margin-block-start: 1rem;
|
|
191
|
+
}
|
|
192
|
+
article > h3 { grid-area: name; margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.1; }
|
|
193
|
+
article > span {
|
|
194
|
+
grid-area: kind;
|
|
195
|
+
align-self: baseline;
|
|
196
|
+
padding: 0.1em 0.5em;
|
|
197
|
+
border: 1px solid rgba(0, 0, 0, 0.4);
|
|
198
|
+
border-radius: 999px;
|
|
199
|
+
font-size: 0.8rem;
|
|
200
|
+
white-space: nowrap;
|
|
201
|
+
}
|
|
202
|
+
article > div { grid-area: body; display: flex; flex-direction: column; gap: 0.5rem; }
|
|
203
|
+
article:target > h3 { text-decoration: underline; }
|
|
204
|
+
small { opacity: 0.7; }
|
|
205
|
+
h4 {
|
|
206
|
+
margin: 0.3rem 0 0;
|
|
207
|
+
font-size: 0.85rem;
|
|
208
|
+
font-weight: 600;
|
|
209
|
+
opacity: 0.6;
|
|
210
|
+
text-transform: uppercase;
|
|
211
|
+
letter-spacing: 0.08em;
|
|
212
|
+
}
|
|
213
|
+
details > summary { cursor: pointer; font-size: 0.9rem; opacity: 0.7; }
|
|
214
|
+
details[open] > summary { margin-block-end: 0.4rem; }
|
|
215
|
+
details > div { display: flex; flex-direction: column; gap: 0.5rem; }
|
|
216
|
+
}
|
|
217
|
+
"""
|
|
218
|
+
|
|
219
|
+
def _css_aside() -> str: # scoped CSS for <aside> (table of contents)
|
|
220
|
+
"Table of contents: one small uppercase heading per module, export links below."
|
|
221
|
+
return """
|
|
222
|
+
@scope {
|
|
223
|
+
nav {
|
|
224
|
+
position: sticky;
|
|
225
|
+
inset-block-start: 1rem;
|
|
226
|
+
max-block-size: calc(100dvh - 2rem);
|
|
227
|
+
overflow-y: auto;
|
|
228
|
+
display: flex;
|
|
229
|
+
flex-direction: column;
|
|
230
|
+
gap: 1.2rem;
|
|
231
|
+
}
|
|
232
|
+
section { display: flex; flex-direction: column; gap: 0.3rem; }
|
|
233
|
+
h2 {
|
|
234
|
+
margin: 0;
|
|
235
|
+
font-size: 0.85rem;
|
|
236
|
+
font-weight: 600;
|
|
237
|
+
opacity: 0.6;
|
|
238
|
+
text-transform: uppercase;
|
|
239
|
+
letter-spacing: 0.08em;
|
|
240
|
+
}
|
|
241
|
+
ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 0.15rem; }
|
|
242
|
+
li { font-size: 0.95rem; line-height: 1.25; overflow-wrap: anywhere; }
|
|
243
|
+
a { text-decoration: none; }
|
|
244
|
+
a:hover { text-decoration: underline; }
|
|
245
|
+
|
|
246
|
+
/* Narrow screens: the contents become one wrapping row of module links. */
|
|
247
|
+
@media (max-width: 48rem) {
|
|
248
|
+
nav { position: static; max-block-size: none; flex-direction: row; flex-wrap: wrap; gap: 0.4rem 1rem; }
|
|
249
|
+
ul { display: none; }
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
"""
|
|
253
|
+
|
|
254
|
+
# ── Export rendering ─────────────────────────────────────────────────────────
|
|
255
|
+
|
|
256
|
+
def _export_id(
|
|
257
|
+
mod, # Module
|
|
258
|
+
exp, # Export
|
|
259
|
+
): # anchor id like "utils_rename"
|
|
260
|
+
"Compute the DOM id for an export (module-scoped so names can collide)."
|
|
261
|
+
return f"{mod.name}_{exp.final_name}"
|
|
262
|
+
|
|
263
|
+
def _code(
|
|
264
|
+
src: str, # source text
|
|
265
|
+
) -> str: # <pre><code> block
|
|
266
|
+
"A code block. The one place text is escaped: source contains `<`, `>` and `&`."
|
|
267
|
+
return h.pre(h.code(esc(src)))
|
|
268
|
+
|
|
269
|
+
def render_export(
|
|
270
|
+
mod, # parent Module (for anchor id)
|
|
271
|
+
exp, # Export to render
|
|
272
|
+
): # an <article> for this export
|
|
273
|
+
"Render one export: name, kind chip, signature block, methods (if class), full source disclosure."
|
|
274
|
+
body = []
|
|
275
|
+
|
|
276
|
+
# If the final name differs from the original, show that
|
|
277
|
+
if exp.final_name != exp.name:
|
|
278
|
+
body.append(h.small("originally ", h.code(esc(exp.name))))
|
|
279
|
+
|
|
280
|
+
# Signature + docstring as one code block
|
|
281
|
+
body.append(_code(signature_text(exp)))
|
|
282
|
+
|
|
283
|
+
# For classes: each method as its own signature block (private ones skipped, except __init__)
|
|
284
|
+
methods = [m for m in exp.methods if not m.name.startswith('_') or m.name == '__init__']
|
|
285
|
+
if methods:
|
|
286
|
+
body.append(h.h4("Methods"))
|
|
287
|
+
body.extend(_code(method_signature_text(m)) for m in methods)
|
|
288
|
+
|
|
289
|
+
# Full source, collapsed by default
|
|
290
|
+
body.append(h.details(h.summary("Source"), _code(exp.clean_src)))
|
|
291
|
+
|
|
292
|
+
return h.article(
|
|
293
|
+
h.h3(esc(exp.final_name)),
|
|
294
|
+
h.span(exp.kind.value),
|
|
295
|
+
h.div(body),
|
|
296
|
+
id=_export_id(mod, exp),
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
# ── Module rendering (one <section> per module) ──────────────────────────────
|
|
300
|
+
|
|
301
|
+
def render_module_setup(
|
|
302
|
+
mod, # Module containing imports/consts/setup lists
|
|
303
|
+
): # a <details> element if there's setup content, else None
|
|
304
|
+
"Render the module's imports / consts / setup inside a collapsed <details>."
|
|
305
|
+
blocks = [
|
|
306
|
+
(label, '\n'.join(x.src for x in items))
|
|
307
|
+
for label, items in (('Imports', mod.imports), ('Constants', mod.consts), ('Setup', mod.setup))
|
|
308
|
+
if items
|
|
309
|
+
]
|
|
310
|
+
if not blocks: return None
|
|
311
|
+
return h.details(
|
|
312
|
+
h.summary("Module setup"),
|
|
313
|
+
h.div([(h.h4(label), _code(src)) for label, src in blocks]),
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
def render_module(
|
|
317
|
+
mod, # Module to render
|
|
318
|
+
): # a <section> with the module heading, setup disclosure and exports
|
|
319
|
+
"Render one module: heading, collapsed setup, then every public export."
|
|
320
|
+
return h.section(
|
|
321
|
+
h.h2(esc(mod.name)),
|
|
322
|
+
render_module_setup(mod),
|
|
323
|
+
[render_export(mod, exp) for exp in mod.public_exports],
|
|
324
|
+
id=mod.name,
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
# ── Table of contents ────────────────────────────────────────────────────────
|
|
328
|
+
|
|
329
|
+
def render_sidebar(
|
|
330
|
+
proj, # Project
|
|
331
|
+
): # <nav> with one linked list per module
|
|
332
|
+
"Render the table of contents: every module with links to its exports."
|
|
333
|
+
return h.nav(
|
|
334
|
+
h.section(
|
|
335
|
+
h.h2(h.a(esc(mod.name), href=f"#{mod.name}")),
|
|
336
|
+
h.ul(
|
|
337
|
+
h.li(h.a(esc(exp.final_name), href=f"#{_export_id(mod, exp)}"))
|
|
338
|
+
for exp in mod.public_exports
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
for mod in proj.documented_modules
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
# ── Header ───────────────────────────────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
def render_header(
|
|
347
|
+
proj, # Project
|
|
348
|
+
): # (title block, links block) — the two children of <header>
|
|
349
|
+
"Render the page header: name, version and description on the left, project links on the right."
|
|
350
|
+
meta = proj.meta
|
|
351
|
+
links = [
|
|
352
|
+
h.a(esc(url.split('://', 1)[-1].rstrip('/')), href=url)
|
|
353
|
+
for url in meta.urls.values()
|
|
354
|
+
] + [h.a("llms.txt", href="llms.txt"), h.a("llms-full.txt", href="llms-full.txt")]
|
|
355
|
+
return (
|
|
356
|
+
h.div(
|
|
357
|
+
h.h1(esc(meta.name or 'Untitled'), meta.version and h.small(f"v{esc(meta.version)}")),
|
|
358
|
+
meta.desc and h.p(esc(meta.desc)),
|
|
359
|
+
),
|
|
360
|
+
h.address(links),
|
|
361
|
+
)
|
|
362
|
+
|
|
363
|
+
def _favicon(
|
|
364
|
+
letter: str, # single character drawn on the icon
|
|
365
|
+
) -> str: # <link rel="icon"> with an inline SVG data URI
|
|
366
|
+
"Favicon built from an inline SVG — no image file, no request."
|
|
367
|
+
svg = (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">'
|
|
368
|
+
f'<rect width="32" height="32" rx="6" fill="white"/>'
|
|
369
|
+
f'<text x="16" y="24" text-anchor="middle" font-family="Times New Roman, serif" '
|
|
370
|
+
f'font-weight="700" font-size="28" fill="black">{esc(letter)}</text></svg>')
|
|
371
|
+
return h.link(rel='icon', type='image/svg+xml', href=f'data:image/svg+xml,{quote(svg, safe=":/@!,")}')
|
|
372
|
+
|
|
373
|
+
# ── Full page ────────────────────────────────────────────────────────────────
|
|
374
|
+
|
|
375
|
+
def render_page(
|
|
376
|
+
proj, # the complete parsed Project
|
|
377
|
+
): # the complete HTML document as a string
|
|
378
|
+
"Assemble the full single-page HTML document for a Project. Self-contained: inline CSS, no scripts."
|
|
379
|
+
modules = proj.documented_modules
|
|
380
|
+
if not modules:
|
|
381
|
+
return page(h.head(h.title("No modules")), h.body(h.p("Empty project")))
|
|
382
|
+
|
|
383
|
+
name = proj.meta.name or 'Documentation'
|
|
384
|
+
head_content = h.head(
|
|
385
|
+
h.meta(charset="utf-8"),
|
|
386
|
+
h.meta(name="viewport", content="width=device-width, initial-scale=1"),
|
|
387
|
+
proj.meta.desc and h.meta(name="description", content=proj.meta.desc),
|
|
388
|
+
h.title(esc(f"{name} docs" if proj.meta.name else name)),
|
|
389
|
+
_favicon(name[0].upper()),
|
|
390
|
+
h.style(_css_base()),
|
|
391
|
+
)
|
|
392
|
+
body_content = h.body(
|
|
393
|
+
h.div(
|
|
394
|
+
h.style(_css_sheet()),
|
|
395
|
+
h.header(render_header(proj)),
|
|
396
|
+
h.main(h.style(_css_main()), [render_module(m) for m in modules]),
|
|
397
|
+
h.aside(h.style(_css_aside()), render_sidebar(proj)),
|
|
398
|
+
cls="sheet",
|
|
399
|
+
),
|
|
400
|
+
)
|
|
401
|
+
return page(head_content, body_content)
|
|
402
|
+
|
|
403
|
+
def build_docs_html(
|
|
404
|
+
proj, # complete parsed Project
|
|
405
|
+
path=None, # output path, defaults to {root}/{docs}/index.html
|
|
406
|
+
): # status message
|
|
407
|
+
"Write index.html alongside the existing llms.* files."
|
|
408
|
+
from pathlib import Path
|
|
409
|
+
docs = Path(proj.config.root) / proj.config.docs
|
|
410
|
+
docs.mkdir(parents=True, exist_ok=True)
|
|
411
|
+
out = Path(path) if path else docs / 'index.html'
|
|
412
|
+
out.write_text(str(render_page(proj)))
|
|
413
|
+
return f"Wrote HTML docs to {out}"
|
|
@@ -15,20 +15,29 @@ def _apply_renames(
|
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
def _rewrite_import(
|
|
18
|
-
src: str,
|
|
19
|
-
|
|
20
|
-
) -> str:
|
|
21
|
-
"Rewrite cross-notebook imports to relative package imports."
|
|
18
|
+
src: str, # import statement source
|
|
19
|
+
mod_map: dict[str, str], # notebook stem → module name
|
|
20
|
+
) -> str: # rewritten import with relative path
|
|
21
|
+
"Rewrite cross-notebook imports (`from a_types import X`) to relative package imports."
|
|
22
22
|
if not src.strip().startswith('from '): return src
|
|
23
23
|
parts = src.split()
|
|
24
24
|
if len(parts) < 2: return src
|
|
25
25
|
module = parts[1]
|
|
26
|
-
if module
|
|
27
|
-
|
|
28
|
-
if stripped in mod_names:
|
|
29
|
-
return src.replace(f'from {module}', f'from .{stripped}')
|
|
26
|
+
if module in mod_map:
|
|
27
|
+
return src.replace(f'from {module}', f'from .{mod_map[module]}', 1)
|
|
30
28
|
return src
|
|
31
29
|
|
|
30
|
+
def _import_roots(
|
|
31
|
+
src: str, # import statement source
|
|
32
|
+
) -> list[str]: # top-level module names it imports, e.g. ['ast', 're']
|
|
33
|
+
"Top-level module names of an import statement."
|
|
34
|
+
parts = src.split(None, 1)
|
|
35
|
+
if len(parts) < 2: return []
|
|
36
|
+
if parts[0] == 'from': roots = [parts[1].split()[0]]
|
|
37
|
+
elif parts[0] == 'import': roots = [p.split()[0] for p in parts[1].split(',') if p.strip()]
|
|
38
|
+
else: return []
|
|
39
|
+
return [r.split('.')[0] for r in roots if r.split('.')[0]]
|
|
40
|
+
|
|
32
41
|
def _write(
|
|
33
42
|
path: Path, # file path to write
|
|
34
43
|
*parts: str, # content parts to join with blank lines
|
|
@@ -37,12 +46,12 @@ def _write(
|
|
|
37
46
|
path.write_text('\n\n'.join(p for p in parts if p and p.strip()) + '\n')
|
|
38
47
|
|
|
39
48
|
def _write_module(
|
|
40
|
-
path: Path,
|
|
41
|
-
mod: Module,
|
|
42
|
-
|
|
49
|
+
path: Path, # output .py file path
|
|
50
|
+
mod: Module, # parsed module data
|
|
51
|
+
mod_map: dict[str, str], # notebook stem → module name, for import rewriting
|
|
43
52
|
):
|
|
44
53
|
"Write a single .py module file from a Module."
|
|
45
|
-
imports = '\n'.join(_rewrite_import(i.src,
|
|
54
|
+
imports = '\n'.join(_rewrite_import(i.src, mod_map) for i in mod.imports)
|
|
46
55
|
consts = '\n'.join(c.src for c in mod.consts)
|
|
47
56
|
setup = '\n'.join(s.src for s in mod.setup)
|
|
48
57
|
|
|
@@ -81,9 +90,12 @@ def _write_init(
|
|
|
81
90
|
if all_exports:
|
|
82
91
|
entries = '\n'.join(f' "{n}",' for n in sorted(all_exports))
|
|
83
92
|
lines.append(f'__all__ = [\n{entries}\n]')
|
|
84
|
-
|
|
85
|
-
if proj.init_extras:
|
|
86
|
-
lines.append('\n'.join(s.src for s in proj.init_extras))
|
|
93
|
+
|
|
94
|
+
if proj.init_extras.consts:
|
|
95
|
+
lines.append('\n'.join(s.src for s in proj.init_extras.consts))
|
|
96
|
+
|
|
97
|
+
if proj.init_extras.setup:
|
|
98
|
+
lines.append('\n'.join(s.src for s in proj.init_extras.setup))
|
|
87
99
|
|
|
88
100
|
_write(path, '\n'.join(lines))
|
|
89
101
|
|
|
@@ -120,10 +132,10 @@ def build(
|
|
|
120
132
|
if pkg.exists(): shutil.rmtree(pkg)
|
|
121
133
|
pkg.mkdir(parents=True, exist_ok=True)
|
|
122
134
|
|
|
123
|
-
|
|
135
|
+
mod_map = proj.mod_map
|
|
124
136
|
for mod in proj.modules:
|
|
125
137
|
if mod.name != 'index' and mod.has_exports:
|
|
126
|
-
_write_module(pkg / f'{mod.name}.py', mod,
|
|
138
|
+
_write_module(pkg / f'{mod.name}.py', mod, mod_map)
|
|
127
139
|
|
|
128
140
|
_write_init(pkg / '__init__.py', proj)
|
|
129
141
|
if cfg.app_parts:
|
|
@@ -137,31 +149,19 @@ def bundle(
|
|
|
137
149
|
) -> str: # path to bundled file
|
|
138
150
|
"Bundle all modules into a single Python file with PEP 723 deps."
|
|
139
151
|
cfg, meta = proj.config, proj.meta
|
|
140
|
-
|
|
152
|
+
nb_stems = set(proj.mod_map)
|
|
141
153
|
|
|
142
|
-
# Collect external imports, deduplicate
|
|
154
|
+
# Collect external imports, deduplicate; cross-notebook imports are dropped
|
|
143
155
|
seen_imports: set[str] = set()
|
|
144
156
|
external_imports: list[str] = []
|
|
145
157
|
dep_modules: set[str] = set()
|
|
146
158
|
|
|
147
159
|
for mod in proj.modules:
|
|
148
160
|
for imp in mod.imports:
|
|
149
|
-
|
|
150
|
-
if
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
root_mod = re.sub(r'^[a-z]_', '', parts[1]).split('.')[0]
|
|
154
|
-
if root_mod in mod_names: is_local = True
|
|
155
|
-
elif parts[1].split('.')[0] not in sys.stdlib_module_names:
|
|
156
|
-
dep_modules.add(parts[1].split('.')[0])
|
|
157
|
-
elif imp.src.startswith('import '):
|
|
158
|
-
parts = imp.src.split()
|
|
159
|
-
if len(parts) >= 2:
|
|
160
|
-
root_mod = parts[1].split('.')[0]
|
|
161
|
-
if root_mod not in sys.stdlib_module_names:
|
|
162
|
-
dep_modules.add(root_mod)
|
|
163
|
-
|
|
164
|
-
if not is_local and imp.src not in seen_imports:
|
|
161
|
+
roots = _import_roots(imp.src)
|
|
162
|
+
if any(r in nb_stems for r in roots): continue
|
|
163
|
+
dep_modules.update(r for r in roots if r not in sys.stdlib_module_names)
|
|
164
|
+
if imp.src not in seen_imports:
|
|
165
165
|
seen_imports.add(imp.src)
|
|
166
166
|
external_imports.append(imp.src)
|
|
167
167
|
|
|
@@ -170,23 +170,30 @@ def bundle(
|
|
|
170
170
|
header = f'# /// script\n# dependencies = [{deps_str}]\n# ///'
|
|
171
171
|
|
|
172
172
|
imports = '\n'.join(external_imports)
|
|
173
|
-
consts = '\n'.join(c.src for m in proj.modules for c in m.consts)
|
|
174
|
-
setup = '\n'.join(s.src for m in proj.modules for s in m.setup)
|
|
175
173
|
|
|
176
|
-
#
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
174
|
+
# Modules in build order, each as consts → setup → exports, so a module's
|
|
175
|
+
# setup code can use anything defined by the modules before it.
|
|
176
|
+
body = '\n\n'.join(
|
|
177
|
+
part
|
|
178
|
+
for m in proj.modules
|
|
179
|
+
for part in (
|
|
180
|
+
'\n'.join(c.src for c in m.consts),
|
|
181
|
+
'\n'.join(s.src for s in m.setup),
|
|
182
|
+
'\n\n'.join(_apply_renames(e.clean_src, e.name, e.final_name) for e in m.exports),
|
|
183
|
+
)
|
|
184
|
+
if part.strip()
|
|
180
185
|
)
|
|
186
|
+
|
|
187
|
+
# Fix cross-references to renamed symbols
|
|
181
188
|
rename_map = {
|
|
182
189
|
e.name: e.final_name
|
|
183
190
|
for m in proj.modules for e in m.exports
|
|
184
191
|
if e.final_name != e.name
|
|
185
192
|
}
|
|
186
193
|
for old, new in rename_map.items():
|
|
187
|
-
|
|
194
|
+
body = re.sub(rf'\b{re.escape(old)}\b', new, body)
|
|
188
195
|
|
|
189
|
-
sections = [header, imports,
|
|
196
|
+
sections = [header, imports, body]
|
|
190
197
|
|
|
191
198
|
if cfg.app_parts:
|
|
192
199
|
sections.append(_entry_point_src(cfg.app_parts))
|
|
@@ -4,6 +4,7 @@ from .parse import read_project
|
|
|
4
4
|
from .build_pkg import build, bundle
|
|
5
5
|
from .build_docs import build_docs
|
|
6
6
|
from .publish import publish
|
|
7
|
+
from .build_docs_html import build_docs_html
|
|
7
8
|
|
|
8
9
|
def tidy():
|
|
9
10
|
"Remove cache and temporary files."
|
|
@@ -33,6 +34,7 @@ def main():
|
|
|
33
34
|
# Everything else needs the project
|
|
34
35
|
proj = read_project()
|
|
35
36
|
|
|
37
|
+
|
|
36
38
|
if cmd == 'build':
|
|
37
39
|
pkg = build(proj)
|
|
38
40
|
build_docs(proj)
|
|
@@ -40,6 +42,7 @@ def main():
|
|
|
40
42
|
|
|
41
43
|
elif cmd == 'docs':
|
|
42
44
|
print(build_docs(proj))
|
|
45
|
+
print(build_docs_html(proj))
|
|
43
46
|
|
|
44
47
|
elif cmd == 'bundle':
|
|
45
48
|
name = sys.argv[2] if len(sys.argv) > 2 else None
|
|
@@ -212,13 +212,13 @@ def _module_name(
|
|
|
212
212
|
f: Path, # notebook file path
|
|
213
213
|
cfg: Config, # project configuration
|
|
214
214
|
) -> str | None: # module name or None to skip
|
|
215
|
-
"Extract module name from file path, or None to skip."
|
|
215
|
+
"Extract module name from file path, or None to skip. Renames apply, so `x_internal_foo.py` → `_foo`."
|
|
216
216
|
if f.name.startswith('.'):
|
|
217
217
|
return None
|
|
218
218
|
if any(f.stem.startswith(p) for p in cfg.skip_prefixes):
|
|
219
219
|
return None
|
|
220
220
|
name = re.sub(r'^[a-z]_(\w+)', r'\1', f.stem)
|
|
221
|
-
return None if name.startswith('test') else name
|
|
221
|
+
return None if name.startswith('test') else rename(name, cfg.renames)
|
|
222
222
|
|
|
223
223
|
def read_project(
|
|
224
224
|
root: str = '.', # project root containing pyproject.toml and notebooks
|
|
@@ -232,10 +232,10 @@ def read_project(
|
|
|
232
232
|
meta = _read_meta(root)
|
|
233
233
|
nbs = Path(root) / cfg.nbs
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
init_extras, modules = ParsedFile([], [], [], []), []
|
|
236
236
|
for f in sorted(nbs.glob('*.py')):
|
|
237
237
|
if f.name == cfg.init:
|
|
238
|
-
|
|
238
|
+
init_extras = _parse_file(f, cfg)
|
|
239
239
|
continue
|
|
240
240
|
name = _module_name(f, cfg)
|
|
241
241
|
if name is None: continue
|
|
@@ -249,4 +249,4 @@ def read_project(
|
|
|
249
249
|
exports = parsed.exports,
|
|
250
250
|
))
|
|
251
251
|
|
|
252
|
-
return Project(meta=meta, config=cfg, init_extras=
|
|
252
|
+
return Project(meta=meta, config=cfg, init_extras=init_extras, modules=modules)
|
|
@@ -108,7 +108,7 @@ class ParsedFile:
|
|
|
108
108
|
@dataclass
|
|
109
109
|
class Module:
|
|
110
110
|
"A parsed notebook file containing imports, setup, and exports."
|
|
111
|
-
name: str # e.g. 'core' (prefix stripped)
|
|
111
|
+
name: str # e.g. 'core' (prefix stripped, renames applied)
|
|
112
112
|
nb_stem: str = '' # e.g. 'a_core' (original filename stem)
|
|
113
113
|
imports: list[Import] = field(default_factory=list)
|
|
114
114
|
consts: list[Const] = field(default_factory=list)
|
|
@@ -120,19 +120,24 @@ class Module:
|
|
|
120
120
|
"True if module contains any exported definitions."
|
|
121
121
|
return len(self.exports) > 0
|
|
122
122
|
|
|
123
|
+
@property
|
|
124
|
+
def internal(self) -> bool:
|
|
125
|
+
"True for a private module (name starts with `_`): built, but not re-exported or documented."
|
|
126
|
+
return self.name.startswith('_')
|
|
127
|
+
|
|
123
128
|
@property
|
|
124
129
|
def public_exports(
|
|
125
130
|
self, # Module instance
|
|
126
131
|
) -> list[Export]: # exports visible in __init__.py
|
|
127
|
-
"Exports that are part of the public API."
|
|
128
|
-
return [e for e in self.exports if e.public]
|
|
132
|
+
"Exports that are part of the public API. Always empty for an internal module."
|
|
133
|
+
return [] if self.internal else [e for e in self.exports if e.public]
|
|
129
134
|
|
|
130
135
|
@property
|
|
131
136
|
def documented_exports(
|
|
132
137
|
self, # Module instance
|
|
133
138
|
) -> list[Export]: # exports included in documentation
|
|
134
139
|
"Exports that should appear in docs."
|
|
135
|
-
return
|
|
140
|
+
return self.public_exports
|
|
136
141
|
|
|
137
142
|
@dataclass
|
|
138
143
|
class Meta:
|
|
@@ -159,7 +164,7 @@ class Project:
|
|
|
159
164
|
"A complete parsed marimo-dev project."
|
|
160
165
|
meta: Meta
|
|
161
166
|
config: Config
|
|
162
|
-
init_extras:
|
|
167
|
+
init_extras: ParsedFile = field(default_factory=lambda: ParsedFile([], [], [], []))
|
|
163
168
|
modules: list[Module] = field(default_factory=list)
|
|
164
169
|
|
|
165
170
|
@property
|
|
@@ -169,6 +174,20 @@ class Project:
|
|
|
169
174
|
"All module names in build order."
|
|
170
175
|
return [m.name for m in self.modules]
|
|
171
176
|
|
|
177
|
+
@property
|
|
178
|
+
def mod_map(
|
|
179
|
+
self, # Project instance
|
|
180
|
+
) -> dict[str, str]: # notebook stem → module name, e.g. {'a_types': 'types'}
|
|
181
|
+
"Map each notebook file stem to the module it builds to."
|
|
182
|
+
return {m.nb_stem: m.name for m in self.modules}
|
|
183
|
+
|
|
184
|
+
@property
|
|
185
|
+
def documented_modules(
|
|
186
|
+
self, # Project instance
|
|
187
|
+
) -> list[Module]: # modules that appear in the docs
|
|
188
|
+
"Modules with at least one documented export (internal modules never qualify)."
|
|
189
|
+
return [m for m in self.modules if m.documented_exports]
|
|
190
|
+
|
|
172
191
|
@property
|
|
173
192
|
def nonempty_modules(
|
|
174
193
|
self, # Project instance
|
|
File without changes
|