marimo-dev 0.3.6__tar.gz → 0.3.8__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.6 → marimo_dev-0.3.8}/PKG-INFO +23 -1
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/README.md +22 -0
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/pyproject.toml +2 -1
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/__init__.py +3 -2
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/build.py +22 -21
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/core.py +1 -0
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/pkg.py +10 -4
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/cli.py +0 -0
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/docs.py +0 -0
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/publish.py +0 -0
- {marimo_dev-0.3.6 → marimo_dev-0.3.8}/src/marimo_dev/read.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: marimo-dev
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.8
|
|
4
4
|
Summary: Build and publish python packages from marimo notebooks
|
|
5
5
|
Author: Deufel
|
|
6
6
|
Author-email: Deufel <MDeufel13@gmail.com>
|
|
@@ -28,6 +28,28 @@ Marimo notebooks are excellent for development - they manage dependencies automa
|
|
|
28
28
|
|
|
29
29
|
marimo-dev bridges this gap. It extracts decorated functions and classes from your notebooks and writes them to clean Python modules, leaving behind the exploratory code, UI elements, and notebook-specific logic.
|
|
30
30
|
|
|
31
|
+
## Limitations
|
|
32
|
+
|
|
33
|
+
Unlike [nbdev](https://nbdev.fast.ai/) (which this project was heavily inspired by) from we rely on the marimo DAG to identify the functions that will be exported into the final function. This means you really have to write things functionaly. For myself this constraint has helped out a lot. but because of this marimo has its own enforced naming limitations mainly `_foo()` stays local to the cell; cannot use `app()` and another few random reserved function names. The workaround currently is a bit ugly but it seems to be working. we allow the user to specify a dict of renameing conventions (these are replaced globaly so be weary of this but the regx should be safe that it does not match unintented tagets `internal_foo` WILL not match `internal_foobar`). Id the replacement is a "dunder" it is both prepended and appended to the stem.
|
|
34
|
+
|
|
35
|
+
```toml
|
|
36
|
+
[tool.marimo-dev]
|
|
37
|
+
renames = {
|
|
38
|
+
dunder_ = "__", # __stem__
|
|
39
|
+
internal_ = "_", # _stem
|
|
40
|
+
app_ = "app" # exact substitution (empty stem)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Application [beta]
|
|
45
|
+
|
|
46
|
+
add to toml and a __main__ will be included
|
|
47
|
+
|
|
48
|
+
```toml
|
|
49
|
+
[tool.marimo-dev]
|
|
50
|
+
application = "todo:app"
|
|
51
|
+
```
|
|
52
|
+
|
|
31
53
|
## Quick start
|
|
32
54
|
|
|
33
55
|
```bash
|
|
@@ -14,6 +14,28 @@ Marimo notebooks are excellent for development - they manage dependencies automa
|
|
|
14
14
|
|
|
15
15
|
marimo-dev bridges this gap. It extracts decorated functions and classes from your notebooks and writes them to clean Python modules, leaving behind the exploratory code, UI elements, and notebook-specific logic.
|
|
16
16
|
|
|
17
|
+
## Limitations
|
|
18
|
+
|
|
19
|
+
Unlike [nbdev](https://nbdev.fast.ai/) (which this project was heavily inspired by) from we rely on the marimo DAG to identify the functions that will be exported into the final function. This means you really have to write things functionaly. For myself this constraint has helped out a lot. but because of this marimo has its own enforced naming limitations mainly `_foo()` stays local to the cell; cannot use `app()` and another few random reserved function names. The workaround currently is a bit ugly but it seems to be working. we allow the user to specify a dict of renameing conventions (these are replaced globaly so be weary of this but the regx should be safe that it does not match unintented tagets `internal_foo` WILL not match `internal_foobar`). Id the replacement is a "dunder" it is both prepended and appended to the stem.
|
|
20
|
+
|
|
21
|
+
```toml
|
|
22
|
+
[tool.marimo-dev]
|
|
23
|
+
renames = {
|
|
24
|
+
dunder_ = "__", # __stem__
|
|
25
|
+
internal_ = "_", # _stem
|
|
26
|
+
app_ = "app" # exact substitution (empty stem)
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Application [beta]
|
|
31
|
+
|
|
32
|
+
add to toml and a __main__ will be included
|
|
33
|
+
|
|
34
|
+
```toml
|
|
35
|
+
[tool.marimo-dev]
|
|
36
|
+
application = "todo:app"
|
|
37
|
+
```
|
|
38
|
+
|
|
17
39
|
## Quick start
|
|
18
40
|
|
|
19
41
|
```bash
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "marimo-dev"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.8"
|
|
8
8
|
description = "Build and publish python packages from marimo notebooks"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -43,3 +43,4 @@ docs = "docs"
|
|
|
43
43
|
decorators = ["app.function", "app.class_definition"]
|
|
44
44
|
skip_prefixes = ["XX_", "test_", "tests"]
|
|
45
45
|
renames = {dunder_ = "__", internal_ = "_"}
|
|
46
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""Build and publish python packages from marimo notebooks"""
|
|
2
|
-
__version__ = '0.3.
|
|
2
|
+
__version__ = '0.3.8'
|
|
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
6
|
from .pkg import clean, write, write_mod, rename, apply_renames, rewrite_imports, write_init
|
|
7
7
|
from .docs import sanitize_for_js, render_node_with_search, render_module_page_datastar, nb_path, render_index_page, html_preview, build_docs, export_wasm, write_nojekyll, Icon, write_highlighter
|
|
8
|
-
from .build import build, tidy, nuke, get_pypi_name, extract_import_names, pep723_header, write_llms, bundle, bundle_notebook
|
|
8
|
+
from .build import build, write_main, 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
|
|
11
11
|
__all__ = [
|
|
@@ -59,6 +59,7 @@ __all__ = [
|
|
|
59
59
|
"write_highlighter",
|
|
60
60
|
"write_init",
|
|
61
61
|
"write_llms",
|
|
62
|
+
"write_main",
|
|
62
63
|
"write_mod",
|
|
63
64
|
"write_nojekyll",
|
|
64
65
|
]
|
|
@@ -9,7 +9,7 @@ IMPORT_TO_PYPI = {'bs4': 'beautifulsoup4', 'PIL': 'pillow', 'cv2': 'opencv-pytho
|
|
|
9
9
|
def build(
|
|
10
10
|
root='.', # root directory containing pyproject.toml
|
|
11
11
|
)->str: # path to built package
|
|
12
|
-
"Build a Python package from notebooks."
|
|
12
|
+
"""Build a Python package from notebooks."""
|
|
13
13
|
cfg = read_config(root)
|
|
14
14
|
meta, mods = scan(root)
|
|
15
15
|
mod_names = [name for name, _ in mods]
|
|
@@ -20,10 +20,20 @@ def build(
|
|
|
20
20
|
stripped = re.sub(r'^[a-z]_', '', name)
|
|
21
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
22
|
write_init(pkg/'__init__.py', meta, mods, cfg.renames)
|
|
23
|
+
if cfg.application: write_main(pkg, cfg.application)
|
|
23
24
|
all_exp = [n for _, nodes in mods for n in nodes if n.kind == Kind.EXP]
|
|
24
25
|
if all_exp: write_llms()
|
|
25
26
|
return str(pkg)
|
|
26
27
|
|
|
28
|
+
def write_main(
|
|
29
|
+
pkg,
|
|
30
|
+
application
|
|
31
|
+
):
|
|
32
|
+
"""Writes the __main__ from the toml settings when --application flag is passed to build"""
|
|
33
|
+
mod, obj = application.split(":")
|
|
34
|
+
code = f"from .{mod} import {obj}\nfrom py_sse import serve\nserve({obj})\n"
|
|
35
|
+
(pkg / '__main__.py').write_text(code)
|
|
36
|
+
|
|
27
37
|
def tidy():
|
|
28
38
|
"Remove cache and temporary files (__pycache__, __marimo__, .pytest_cache, etc)."
|
|
29
39
|
import shutil
|
|
@@ -103,50 +113,41 @@ def bundle(root='.', name=None):
|
|
|
103
113
|
cfg = read_config(root)
|
|
104
114
|
meta, mods = scan(root)
|
|
105
115
|
|
|
106
|
-
# Get notebook filenames to filter out local imports
|
|
107
116
|
nbs_dir = Path(root) / cfg.nbs
|
|
108
117
|
nb_names = {f.stem for f in nbs_dir.glob('*.py')}
|
|
118
|
+
mod_names = {re.sub(r'^[a-z]_', '', n) for n in nb_names}
|
|
109
119
|
|
|
110
|
-
# Collect all nodes
|
|
111
120
|
all_nodes = [n for _, nodes in mods for n in nodes]
|
|
112
121
|
|
|
113
|
-
# Extract dependencies
|
|
114
122
|
import_names = extract_import_names(all_nodes)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# Filter out local modules, notebook names, and stdlib
|
|
118
|
-
external = {get_pypi_name(n) for n in import_names
|
|
119
|
-
if n not in mod_names
|
|
120
|
-
and n not in nb_names
|
|
121
|
-
and n not in sys.stdlib_module_names}
|
|
123
|
+
external = {get_pypi_name(n) for n in import_names
|
|
124
|
+
if n not in mod_names and n not in sys.stdlib_module_names}
|
|
122
125
|
|
|
123
|
-
# Build output
|
|
124
126
|
header = pep723_header(external)
|
|
125
127
|
|
|
126
|
-
# Filter out local imports, dedupe externals
|
|
127
128
|
seen = set()
|
|
128
129
|
filtered_imports = []
|
|
129
130
|
for n in all_nodes:
|
|
130
131
|
if n.kind != Kind.IMP: continue
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
tree = ast.parse(n.src)
|
|
133
|
+
is_local = False
|
|
134
|
+
for stmt in ast.walk(tree):
|
|
135
|
+
if isinstance(stmt, ast.ImportFrom) and stmt.module:
|
|
136
|
+
if stmt.module.split('.')[0] in mod_names: is_local = True
|
|
137
|
+
if is_local: continue
|
|
133
138
|
if n.src not in seen:
|
|
134
139
|
seen.add(n.src)
|
|
135
140
|
filtered_imports.append(n.src)
|
|
136
141
|
|
|
137
142
|
imports = '\n'.join(filtered_imports)
|
|
138
|
-
|
|
139
143
|
consts = '\n'.join(n.src for n in all_nodes if n.kind == Kind.CONST)
|
|
140
144
|
setup = '\n'.join(n.src for n in all_nodes if n.kind == Kind.SETUP)
|
|
141
145
|
exports = '\n\n'.join(clean(n.src) for n in all_nodes if n.kind == Kind.EXP)
|
|
142
146
|
|
|
143
147
|
content = '\n\n'.join(p for p in [header, imports, consts, setup, exports] if p.strip())
|
|
144
148
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
out_path = Path(root) / name
|
|
148
|
-
else:
|
|
149
|
-
out_path = Path(root) / cfg.out / meta['name'].replace('-', '_') / '__init__.py'
|
|
149
|
+
if name: out_path = Path(root) / name
|
|
150
|
+
else: out_path = Path(root) / cfg.out / meta['name'].replace('-', '_') / '__init__.py'
|
|
150
151
|
|
|
151
152
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
152
153
|
out_path.write_text(content)
|
|
@@ -12,6 +12,7 @@ class Config:
|
|
|
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
14
|
renames: dict[str,str] = field(default_factory=dict)
|
|
15
|
+
application: str | None = None # e.g. "todo:app"
|
|
15
16
|
|
|
16
17
|
def read_config(root='.'):
|
|
17
18
|
"Read config from pyproject.toml [tool.marimo-dev] section with defaults"
|
|
@@ -25,12 +25,12 @@ def write_mod(
|
|
|
25
25
|
g = {k: [n for n in nodes if n.kind == k] for k in Kind}
|
|
26
26
|
imports = '\n'.join(rewrite_imports(n.src, mod_names) for n in g[Kind.IMP])
|
|
27
27
|
exp_src = '\n\n'.join(apply_renames(clean(n.src), n.name, renames) for n in g[Kind.EXP])
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
# Second pass: fix cross-references to renamed symbols
|
|
30
30
|
rename_map = {n.name: rename(n.name, renames) for n in g[Kind.EXP] if rename(n.name, renames) != n.name}
|
|
31
31
|
for old, new in rename_map.items():
|
|
32
32
|
exp_src = re.sub(rf'\b{re.escape(old)}\b', new, exp_src)
|
|
33
|
-
|
|
33
|
+
|
|
34
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])]
|
|
35
35
|
write(path, *parts)
|
|
36
36
|
|
|
@@ -51,9 +51,15 @@ def apply_renames(
|
|
|
51
51
|
name:str, # original function/class name
|
|
52
52
|
renames:dict=None # prefix substitution map
|
|
53
53
|
)->str: # source with renamed identifier
|
|
54
|
-
"Replace function/class name in source
|
|
54
|
+
"Replace function/class definition name in source using prefix substitution."
|
|
55
55
|
new = rename(name, renames)
|
|
56
|
-
|
|
56
|
+
if new == name: return src
|
|
57
|
+
# Target only the def/class line, not the first arbitrary occurrence
|
|
58
|
+
return re.sub(
|
|
59
|
+
rf'(?m)^(\s*(?:async\s+)?(?:def|class)\s+){re.escape(name)}\b',
|
|
60
|
+
rf'\g<1>{new}',
|
|
61
|
+
src, count=1
|
|
62
|
+
)
|
|
57
63
|
|
|
58
64
|
def rewrite_imports(
|
|
59
65
|
src:str, # source code to rewrite
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|