marimo-dev 0.4.1__tar.gz → 0.4.3__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.4.1
3
+ Version: 0.4.3
4
4
  Summary: Build and publish python packages from marimo notebooks
5
5
  Author: Deufel
6
6
  Author-email: Deufel <MDeufel13@gmail.com>
@@ -8,8 +8,8 @@ License: MIT
8
8
  Classifier: Development Status :: 3 - Alpha
9
9
  Requires-Dist: html-tags>=0.0.18
10
10
  Requires-Python: >=3.12
11
- Project-URL: PyPI, https://pypi.org/project/marimo-dev/
12
11
  Project-URL: Repository, https://github.com/deufel/m-dev
12
+ Project-URL: PyPI, https://pypi.org/project/marimo-dev/
13
13
  Description-Content-Type: text/markdown
14
14
 
15
15
 
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["uv_build>=0.9.15,<0.10.0"]
2
+ requires = ["uv_build>=0.11.2,<0.12"]
3
3
  build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "marimo-dev"
7
- version = "0.4.1"
7
+ version = "0.4.3"
8
8
  description = "Build and publish python packages from marimo notebooks"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -15,8 +15,6 @@ dependencies = [
15
15
 
16
16
  [dependency-groups]
17
17
  dev = [
18
- "anthropic>=0.84.0",
19
- "ipython>=9.8.0",
20
18
  "marimo>=0.19.7",
21
19
  "pydantic-ai-slim>=1.50.0",
22
20
  "pytest>=9.0.2",
@@ -1,7 +1,7 @@
1
1
  """Build and publish python packages from marimo notebooks"""
2
- __version__ = '0.4.1'
2
+ __version__ = '0.4.3'
3
3
  __author__ = 'Deufel'
4
- from .types import rename, Config, Param, Return, Method, Import, Const, Setup, ExportKind, Export, Module, Meta, Project
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
@@ -17,6 +17,7 @@ __all__ = [
17
17
  "Method",
18
18
  "Module",
19
19
  "Param",
20
+ "ParsedFile",
20
21
  "Project",
21
22
  "Return",
22
23
  "Setup",
@@ -81,6 +81,9 @@ def _write_init(
81
81
  if all_exports:
82
82
  entries = '\n'.join(f' "{n}",' for n in sorted(all_exports))
83
83
  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))
84
87
 
85
88
  _write(path, '\n'.join(lines))
86
89
 
@@ -135,12 +138,12 @@ def bundle(
135
138
  "Bundle all modules into a single Python file with PEP 723 deps."
136
139
  cfg, meta = proj.config, proj.meta
137
140
  mod_names = set(proj.mod_names)
138
-
141
+
139
142
  # Collect external imports, deduplicate
140
143
  seen_imports: set[str] = set()
141
144
  external_imports: list[str] = []
142
145
  dep_modules: set[str] = set()
143
-
146
+
144
147
  for mod in proj.modules:
145
148
  for imp in mod.imports:
146
149
  is_local = False
@@ -157,19 +160,19 @@ def bundle(
157
160
  root_mod = parts[1].split('.')[0]
158
161
  if root_mod not in sys.stdlib_module_names:
159
162
  dep_modules.add(root_mod)
160
-
163
+
161
164
  if not is_local and imp.src not in seen_imports:
162
165
  seen_imports.add(imp.src)
163
166
  external_imports.append(imp.src)
164
-
167
+
165
168
  # PEP 723 header
166
169
  deps_str = ', '.join(f'"{d}"' for d in sorted(dep_modules))
167
170
  header = f'# /// script\n# dependencies = [{deps_str}]\n# ///'
168
-
171
+
169
172
  imports = '\n'.join(external_imports)
170
173
  consts = '\n'.join(c.src for m in proj.modules for c in m.consts)
171
174
  setup = '\n'.join(s.src for m in proj.modules for s in m.setup)
172
-
175
+
173
176
  # Apply renames to exports and fix cross-references
174
177
  exports = '\n\n'.join(
175
178
  _apply_renames(e.clean_src, e.name, e.final_name)
@@ -182,19 +185,19 @@ def bundle(
182
185
  }
183
186
  for old, new in rename_map.items():
184
187
  exports = re.sub(rf'\b{re.escape(old)}\b', new, exports)
185
-
188
+
186
189
  sections = [header, imports, consts, setup, exports]
187
-
190
+
188
191
  if cfg.app_parts:
189
192
  sections.append(_entry_point_src(cfg.app_parts))
190
-
193
+
191
194
  content = '\n\n'.join(p for p in sections if p.strip())
192
-
195
+
193
196
  if name:
194
197
  out = Path(cfg.root) / name
195
198
  else:
196
199
  out = Path(cfg.root) / cfg.out / meta.pkg_name / '__init__.py'
197
-
200
+
198
201
  out.parent.mkdir(parents=True, exist_ok=True)
199
202
  out.write_text(content)
200
203
  return str(out)
@@ -1,6 +1,6 @@
1
1
  from pathlib import Path
2
2
  import ast, re, tomllib
3
- from .types import Config, Meta, Project, Module, Import, Const, Setup, Export, Param, Method, Return, ExportKind, EXPORT_DECORATORS, rename
3
+ from .types import Config, Meta, Project, Module, Import, Const, Setup, Export, ParsedFile, Param, Method, Return, ExportKind, EXPORT_DECORATORS, rename
4
4
 
5
5
  def read_config(
6
6
  root: str = '.', # project root containing pyproject.toml
@@ -140,9 +140,9 @@ def _classify(
140
140
  def _parse_file(
141
141
  path: Path, # path to notebook .py file
142
142
  cfg: Config, # project configuration (for renames)
143
- ) -> tuple[list[Import], list[Const], list[Setup], list[Export]]: # four typed lists
143
+ ) -> ParsedFile: # custom dataclass
144
144
  """Parse a single notebook file into its constituent parts.
145
-
145
+
146
146
  Three branches:
147
147
  1. ast.With → imports, consts, setup
148
148
  2. Decorated → exports (final_name and public resolved here)
@@ -151,11 +151,11 @@ def _parse_file(
151
151
  src = path.read_text()
152
152
  tree = ast.parse(src)
153
153
  lines = src.splitlines()
154
-
154
+
155
155
  imports, consts, setup, exports = [], [], [], []
156
-
156
+
157
157
  for n in tree.body:
158
-
158
+
159
159
  # ── Branch 1: Setup cells (with app.setup:) ──────────
160
160
  if isinstance(n, ast.With):
161
161
  for s in n.body:
@@ -169,18 +169,18 @@ def _parse_file(
169
169
  code = ast.get_source_segment(src, s) or ast.unparse(s)
170
170
  setup.append(Setup(src=code))
171
171
  continue
172
-
172
+
173
173
  # ── Branch 2: Decorated exports ──────────────────────
174
174
  if not isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
175
175
  continue
176
176
  dec = next((d for d in n.decorator_list if _is_export_dec(d)), None)
177
177
  if not dec or n.name.startswith('test_'):
178
178
  continue
179
-
179
+
180
180
  kind = _classify(n)
181
181
  full_src = _src_with_decs(n, lines)
182
182
  final_name = rename(n.name, cfg.renames)
183
-
183
+
184
184
  if kind == ExportKind.CLASS:
185
185
  params = _parse_class_params(n, lines)
186
186
  methods = _parse_methods(n, lines)
@@ -189,7 +189,7 @@ def _parse_file(
189
189
  params = _parse_params(n, lines)
190
190
  methods = []
191
191
  ret = _parse_return(n, lines)
192
-
192
+
193
193
  exports.append(Export(
194
194
  name = n.name,
195
195
  final_name = final_name,
@@ -203,10 +203,10 @@ def _parse_file(
203
203
  ret = ret,
204
204
  lineno = n.lineno,
205
205
  ))
206
-
206
+
207
207
  # ── Branch 3: everything else → skip (implicit) ─────
208
-
209
- return imports, consts, setup, exports
208
+
209
+ return ParsedFile(imports, consts, setup, exports)
210
210
 
211
211
  def _module_name(
212
212
  f: Path, # notebook file path
@@ -224,25 +224,29 @@ def read_project(
224
224
  root: str = '.', # project root containing pyproject.toml and notebooks
225
225
  ) -> Project: # complete parsed project
226
226
  """Read an entire marimo-dev project into a Project.
227
-
227
+
228
228
  Single entry point. Call once, get everything.
229
229
  """
230
+
230
231
  cfg = read_config(root)
231
232
  meta = _read_meta(root)
232
233
  nbs = Path(root) / cfg.nbs
233
-
234
- modules = []
234
+
235
+ init_setup, modules = [], []
235
236
  for f in sorted(nbs.glob('*.py')):
237
+ if f.name == cfg.init:
238
+ init_setup = _parse_file(f, cfg).setup
239
+ continue
236
240
  name = _module_name(f, cfg)
237
241
  if name is None: continue
238
- imports, consts, setup, exports = _parse_file(f, cfg)
242
+ parsed = _parse_file(f, cfg)
239
243
  modules.append(Module(
240
244
  name = name,
241
245
  nb_stem = f.stem,
242
- imports = imports,
243
- consts = consts,
244
- setup = setup,
245
- exports = exports,
246
+ imports = parsed.imports,
247
+ consts = parsed.consts,
248
+ setup = parsed.setup,
249
+ exports = parsed.exports,
246
250
  ))
247
-
248
- return Project(meta=meta, config=cfg, modules=modules)
251
+
252
+ return Project(meta=meta, config=cfg, init_extras=init_setup, modules=modules)
@@ -23,10 +23,11 @@ class Config:
23
23
  out: str = 'src' # package output directory
24
24
  docs: str = 'docs' # documentation output directory
25
25
  root: str = '.' # project root
26
+ init: str = '_init.py' # setup block added to package __init__
26
27
  skip_prefixes: tuple = ('XX_', 'test_') # filename prefixes to ignore
27
28
  renames: dict = field(default_factory=dict) # name prefix substitutions
28
29
  application: str|None = None # entry point e.g. "module:obj" or "module:obj:runner"
29
-
30
+
30
31
  @property
31
32
  def app_parts(
32
33
  self, # Config instance
@@ -43,13 +44,13 @@ class Param:
43
44
  name: str # parameter name
44
45
  anno: str = '' # type annotation
45
46
  default: str = '' # default value
46
- doc: str = '' # inline comment
47
+ doc: str = ''
47
48
 
48
49
  @dataclass
49
50
  class Return:
50
51
  "A return annotation with optional inline documentation."
51
52
  anno: str # return type
52
- doc: str = '' # inline comment after ->
53
+ doc: str = ''
53
54
 
54
55
  @dataclass
55
56
  class Method:
@@ -62,18 +63,18 @@ class Method:
62
63
  @dataclass
63
64
  class Import:
64
65
  "An import statement from a setup cell."
65
- src: str # e.g. "from pathlib import Path"
66
+ src: str
66
67
 
67
68
  @dataclass
68
69
  class Const:
69
70
  "A constant assignment from a setup cell."
70
71
  name: str # variable name
71
- src: str # e.g. "MAX_SIZE = 1024"
72
+ src: str
72
73
 
73
74
  @dataclass
74
75
  class Setup:
75
76
  "Arbitrary setup code that is not an import or constant."
76
- src: str # source text
77
+ src: str
77
78
 
78
79
  class ExportKind(Enum):
79
80
  "Classification of an exported definition."
@@ -96,6 +97,14 @@ class Export:
96
97
  ret: Return|None = None
97
98
  lineno: int = 0
98
99
 
100
+ @dataclass
101
+ class ParsedFile:
102
+ "A parsed notebook file mostly ergonomic class for handeling returns more robustly"
103
+ imports: list[Import]
104
+ consts: list[Const]
105
+ setup: list[Setup]
106
+ exports: list[Export]
107
+
99
108
  @dataclass
100
109
  class Module:
101
110
  "A parsed notebook file containing imports, setup, and exports."
@@ -105,19 +114,19 @@ class Module:
105
114
  consts: list[Const] = field(default_factory=list)
106
115
  setup: list[Setup] = field(default_factory=list)
107
116
  exports: list[Export] = field(default_factory=list)
108
-
117
+
109
118
  @property
110
119
  def has_exports(self) -> bool:
111
120
  "True if module contains any exported definitions."
112
121
  return len(self.exports) > 0
113
-
122
+
114
123
  @property
115
124
  def public_exports(
116
125
  self, # Module instance
117
126
  ) -> list[Export]: # exports visible in __init__.py
118
127
  "Exports that are part of the public API."
119
128
  return [e for e in self.exports if e.public]
120
-
129
+
121
130
  @property
122
131
  def documented_exports(
123
132
  self, # Module instance
@@ -134,12 +143,12 @@ class Meta:
134
143
  license: str = ''
135
144
  author: str = ''
136
145
  urls: dict = field(default_factory=dict)
137
-
146
+
138
147
  @property
139
148
  def repo_url(self) -> str:
140
149
  "Repository URL from project.urls."
141
150
  return self.urls.get('Repository', '')
142
-
151
+
143
152
  @property
144
153
  def pkg_name(self) -> str:
145
154
  "Python package name (hyphens replaced with underscores)."
@@ -150,15 +159,16 @@ class Project:
150
159
  "A complete parsed marimo-dev project."
151
160
  meta: Meta
152
161
  config: Config
162
+ init_extras: list[Setup] = field(default_factory=list)
153
163
  modules: list[Module] = field(default_factory=list)
154
-
164
+
155
165
  @property
156
166
  def mod_names(
157
167
  self, # Project instance
158
168
  ) -> list[str]: # list of module names
159
169
  "All module names in build order."
160
170
  return [m.name for m in self.modules]
161
-
171
+
162
172
  @property
163
173
  def nonempty_modules(
164
174
  self, # Project instance
File without changes