marimo-dev 0.3.5__tar.gz → 0.3.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: marimo-dev
3
- Version: 0.3.5
3
+ Version: 0.3.7
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,19 @@ 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
+
31
44
  ## Quick start
32
45
 
33
46
  ```bash
@@ -14,6 +14,19 @@ 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
+
17
30
  ## Quick start
18
31
 
19
32
  ```bash
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "marimo-dev"
7
- version = "0.3.5"
7
+ version = "0.3.7"
8
8
  description = "Build and publish python packages from marimo notebooks"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -1,5 +1,5 @@
1
1
  """Build and publish python packages from marimo notebooks"""
2
- __version__ = '0.3.5'
2
+ __version__ = '0.3.7'
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
@@ -7,6 +7,7 @@ from .pkg import clean, write, write_mod, rename, apply_renames, rewrite_imports
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
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
+ from .cli import main
10
11
  __all__ = [
11
12
  "Config",
12
13
  "Icon",
@@ -27,6 +28,7 @@ __all__ = [
27
28
  "html_preview",
28
29
  "inline_doc",
29
30
  "is_export",
31
+ "main",
30
32
  "nb_name",
31
33
  "nb_path",
32
34
  "nuke",
@@ -0,0 +1,27 @@
1
+ from .build import build, tidy, nuke, bundle
2
+ from .publish import publish
3
+ from .docs import build_docs, write_highlighter
4
+ import sys, subprocess
5
+ from pathlib import Path
6
+
7
+ def main():
8
+ if len(sys.argv) < 2: print("Usage: md [build|publish|docs|tidy|nuke]"); sys.exit(1)
9
+ cmd = sys.argv[1]
10
+ if cmd == 'build':
11
+ print(f"Built package at: {build()}")
12
+ print(build_docs())
13
+ elif cmd == 'publish':
14
+ test = '--test' in sys.argv or '-t' in sys.argv
15
+ target = "TestPyPI" if test else "PyPI"
16
+ if input(f"Publish to {target}? [y/N] ").lower() != 'y': print("Aborted"); sys.exit(0)
17
+ publish(test=test)
18
+ elif cmd == 'docs':
19
+ write_highlighter()
20
+ build_docs()
21
+ elif cmd == 'tidy': tidy()
22
+ elif cmd == 'nuke': nuke()
23
+ elif cmd == 'bundle':
24
+ name = sys.argv[2] if len(sys.argv) > 2 else None
25
+ print(bundle(name=name))
26
+
27
+ else: print(f"Unknown command: {cmd}"); sys.exit(1)
@@ -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 code using prefix substitution."
54
+ "Replace function/class definition name in source using prefix substitution."
55
55
  new = rename(name, renames)
56
- return src.replace(name, new, 1) if new != name else src
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