marimo-dev 0.3.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: marimo-dev
3
- Version: 0.3.7
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>
@@ -41,6 +41,15 @@ Unlike [nbdev](https://nbdev.fast.ai/) (which this project was heavily inspired
41
41
  }
42
42
  ```
43
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
+
44
53
  ## Quick start
45
54
 
46
55
  ```bash
@@ -27,6 +27,15 @@ Unlike [nbdev](https://nbdev.fast.ai/) (which this project was heavily inspired
27
27
  }
28
28
  ```
29
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
+
30
39
  ## Quick start
31
40
 
32
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"
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.7'
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
- mod_names = [m for m, _ in mods]
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
- # Skip if it's a local notebook import
132
- if any(nb in n.src for nb in nb_names): continue
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
- # Determine output path
146
- if name:
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"