marimo-dev 0.3.8__tar.gz → 0.4.1__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.1/PKG-INFO +85 -0
- marimo_dev-0.4.1/README.md +71 -0
- {marimo_dev-0.3.8 → marimo_dev-0.4.1}/pyproject.toml +11 -8
- marimo_dev-0.4.1/src/marimo_dev/__init__.py +35 -0
- marimo_dev-0.4.1/src/marimo_dev/build_docs.py +40 -0
- marimo_dev-0.4.1/src/marimo_dev/build_pkg.py +200 -0
- marimo_dev-0.4.1/src/marimo_dev/cli.py +57 -0
- marimo_dev-0.4.1/src/marimo_dev/parse.py +248 -0
- marimo_dev-0.4.1/src/marimo_dev/publish.py +77 -0
- marimo_dev-0.4.1/src/marimo_dev/types.py +167 -0
- marimo_dev-0.3.8/PKG-INFO +0 -231
- marimo_dev-0.3.8/README.md +0 -217
- marimo_dev-0.3.8/src/marimo_dev/__init__.py +0 -65
- marimo_dev-0.3.8/src/marimo_dev/build.py +0 -227
- marimo_dev-0.3.8/src/marimo_dev/cli.py +0 -27
- marimo_dev-0.3.8/src/marimo_dev/core.py +0 -51
- marimo_dev-0.3.8/src/marimo_dev/docs.py +0 -383
- marimo_dev-0.3.8/src/marimo_dev/pkg.py +0 -93
- marimo_dev-0.3.8/src/marimo_dev/publish.py +0 -105
- marimo_dev-0.3.8/src/marimo_dev/read.py +0 -211
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: marimo-dev
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: Build and publish python packages from marimo notebooks
|
|
5
|
+
Author: Deufel
|
|
6
|
+
Author-email: Deufel <MDeufel13@gmail.com>
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Requires-Dist: html-tags>=0.0.18
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Project-URL: PyPI, https://pypi.org/project/marimo-dev/
|
|
12
|
+
Project-URL: Repository, https://github.com/deufel/m-dev
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> This project is under active development and is not an official marimo tool - Mar 2026
|
|
20
|
+
|
|
21
|
+
# marimo-dev
|
|
22
|
+
|
|
23
|
+
```md
|
|
24
|
+
types.py → what things are
|
|
25
|
+
parse.py → read notebooks into types
|
|
26
|
+
build_pkg.py → Project → Python package
|
|
27
|
+
build_docs.py → Project → documentation
|
|
28
|
+
publish.py → Project → PyPI
|
|
29
|
+
cli.py → dispatch
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```toml
|
|
33
|
+
[project]
|
|
34
|
+
name = "my-project"
|
|
35
|
+
version = "0.1.0"
|
|
36
|
+
description = "A cool library"
|
|
37
|
+
|
|
38
|
+
[tool.marimo-dev]
|
|
39
|
+
nbs = "notebooks" # default
|
|
40
|
+
out = "src" # default
|
|
41
|
+
docs = "docs" # default
|
|
42
|
+
skip_prefixes = ["XX_", "test_"] # default
|
|
43
|
+
application = "server:app:py_sse.serve" # optional, enables __main__.py
|
|
44
|
+
|
|
45
|
+
[tool.marimo-dev.renames]
|
|
46
|
+
internal_ = "_" # internal_foo → _foo (private)
|
|
47
|
+
dunder_ = "__" # dunder_init → __init__
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```md
|
|
51
|
+
notebooks/
|
|
52
|
+
├─ a_utils.py → exported as "utils" (letter prefix stripped)
|
|
53
|
+
├─ b_database.py → exported as "database"
|
|
54
|
+
├─ XX_scratch.py → skipped (XX_ prefix)
|
|
55
|
+
├─ test_stuff.py → skipped (test_ prefix)
|
|
56
|
+
|
|
57
|
+
$ md build
|
|
58
|
+
src/my_project/
|
|
59
|
+
├─ __init__.py # re-exports public symbols, __version__, __all__
|
|
60
|
+
├─ utils.py # from a_utils.py (imports rewritten to relative)
|
|
61
|
+
├─ database.py # from b_database.py
|
|
62
|
+
└─ __main__.py # only when application is set in config
|
|
63
|
+
docs/
|
|
64
|
+
├─ llms.txt # module index with export names
|
|
65
|
+
└─ llms-full.txt # complete cleaned source for LLM consumption
|
|
66
|
+
|
|
67
|
+
$ md bundle app.py
|
|
68
|
+
app.py # single file, PEP 723 deps header, entry point appended
|
|
69
|
+
# → uv run app.py just works
|
|
70
|
+
|
|
71
|
+
$ md docs
|
|
72
|
+
docs/
|
|
73
|
+
├─ llms.txt # module index with export names
|
|
74
|
+
└─ llms-full.txt # complete cleaned source
|
|
75
|
+
|
|
76
|
+
$ md publish [--test]
|
|
77
|
+
builds package, then uploads to PyPI (or TestPyPI with --test)
|
|
78
|
+
requires ~/.pypirc with token
|
|
79
|
+
|
|
80
|
+
$ md tidy
|
|
81
|
+
removes __pycache__/, __marimo__/, .pytest_cache/, *.pyc
|
|
82
|
+
|
|
83
|
+
$ md nuke
|
|
84
|
+
tidy + removes dist/, docs/, src/, temp/
|
|
85
|
+
```
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> This project is under active development and is not an official marimo tool - Mar 2026
|
|
6
|
+
|
|
7
|
+
# marimo-dev
|
|
8
|
+
|
|
9
|
+
```md
|
|
10
|
+
types.py → what things are
|
|
11
|
+
parse.py → read notebooks into types
|
|
12
|
+
build_pkg.py → Project → Python package
|
|
13
|
+
build_docs.py → Project → documentation
|
|
14
|
+
publish.py → Project → PyPI
|
|
15
|
+
cli.py → dispatch
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```toml
|
|
19
|
+
[project]
|
|
20
|
+
name = "my-project"
|
|
21
|
+
version = "0.1.0"
|
|
22
|
+
description = "A cool library"
|
|
23
|
+
|
|
24
|
+
[tool.marimo-dev]
|
|
25
|
+
nbs = "notebooks" # default
|
|
26
|
+
out = "src" # default
|
|
27
|
+
docs = "docs" # default
|
|
28
|
+
skip_prefixes = ["XX_", "test_"] # default
|
|
29
|
+
application = "server:app:py_sse.serve" # optional, enables __main__.py
|
|
30
|
+
|
|
31
|
+
[tool.marimo-dev.renames]
|
|
32
|
+
internal_ = "_" # internal_foo → _foo (private)
|
|
33
|
+
dunder_ = "__" # dunder_init → __init__
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```md
|
|
37
|
+
notebooks/
|
|
38
|
+
├─ a_utils.py → exported as "utils" (letter prefix stripped)
|
|
39
|
+
├─ b_database.py → exported as "database"
|
|
40
|
+
├─ XX_scratch.py → skipped (XX_ prefix)
|
|
41
|
+
├─ test_stuff.py → skipped (test_ prefix)
|
|
42
|
+
|
|
43
|
+
$ md build
|
|
44
|
+
src/my_project/
|
|
45
|
+
├─ __init__.py # re-exports public symbols, __version__, __all__
|
|
46
|
+
├─ utils.py # from a_utils.py (imports rewritten to relative)
|
|
47
|
+
├─ database.py # from b_database.py
|
|
48
|
+
└─ __main__.py # only when application is set in config
|
|
49
|
+
docs/
|
|
50
|
+
├─ llms.txt # module index with export names
|
|
51
|
+
└─ llms-full.txt # complete cleaned source for LLM consumption
|
|
52
|
+
|
|
53
|
+
$ md bundle app.py
|
|
54
|
+
app.py # single file, PEP 723 deps header, entry point appended
|
|
55
|
+
# → uv run app.py just works
|
|
56
|
+
|
|
57
|
+
$ md docs
|
|
58
|
+
docs/
|
|
59
|
+
├─ llms.txt # module index with export names
|
|
60
|
+
└─ llms-full.txt # complete cleaned source
|
|
61
|
+
|
|
62
|
+
$ md publish [--test]
|
|
63
|
+
builds package, then uploads to PyPI (or TestPyPI with --test)
|
|
64
|
+
requires ~/.pypirc with token
|
|
65
|
+
|
|
66
|
+
$ md tidy
|
|
67
|
+
removes __pycache__/, __marimo__/, .pytest_cache/, *.pyc
|
|
68
|
+
|
|
69
|
+
$ md nuke
|
|
70
|
+
tidy + removes dist/, docs/, src/, temp/
|
|
71
|
+
```
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "marimo-dev"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.1"
|
|
8
8
|
description = "Build and publish python packages from marimo notebooks"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -36,11 +36,14 @@ md = "marimo_dev.cli:main"
|
|
|
36
36
|
Repository = "https://github.com/deufel/m-dev"
|
|
37
37
|
PyPI = "https://pypi.org/project/marimo-dev/"
|
|
38
38
|
|
|
39
|
-
[tool.marimo-dev]
|
|
40
|
-
nbs = "notebooks"
|
|
41
|
-
out = "src"
|
|
42
|
-
docs = "docs"
|
|
43
|
-
decorators = ["app.function", "app.class_definition"]
|
|
44
|
-
skip_prefixes = ["XX_", "test_", "tests"]
|
|
45
|
-
renames = {dunder_ = "__", internal_ = "_"}
|
|
46
39
|
|
|
40
|
+
[tool.marimo-dev]
|
|
41
|
+
nbs = "notebooks" # where notebooks live (default: "notebooks")
|
|
42
|
+
out = "src" # package output dir (default: "src")
|
|
43
|
+
docs = "docs" # docs output dir (default: "docs")
|
|
44
|
+
skip_prefixes = ["XX_", "test_"] # ignore these filename prefixes
|
|
45
|
+
|
|
46
|
+
# Name substitutions for marimo naming constraints
|
|
47
|
+
[tool.marimo-dev.renames]
|
|
48
|
+
dunder_ = "__" # dunder_init → __init__
|
|
49
|
+
internal_ = "_" # internal_helper → _helper
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Build and publish python packages from marimo notebooks"""
|
|
2
|
+
__version__ = '0.4.1'
|
|
3
|
+
__author__ = 'Deufel'
|
|
4
|
+
from .types import rename, Config, Param, Return, Method, Import, Const, Setup, ExportKind, Export, Module, Meta, Project
|
|
5
|
+
from .parse import read_config, read_project
|
|
6
|
+
from .build_pkg import build, bundle
|
|
7
|
+
from .build_docs import render_llms, render_llms_full, build_docs
|
|
8
|
+
from .publish import publish
|
|
9
|
+
from .cli import tidy, nuke, main
|
|
10
|
+
__all__ = [
|
|
11
|
+
"Config",
|
|
12
|
+
"Const",
|
|
13
|
+
"Export",
|
|
14
|
+
"ExportKind",
|
|
15
|
+
"Import",
|
|
16
|
+
"Meta",
|
|
17
|
+
"Method",
|
|
18
|
+
"Module",
|
|
19
|
+
"Param",
|
|
20
|
+
"Project",
|
|
21
|
+
"Return",
|
|
22
|
+
"Setup",
|
|
23
|
+
"build",
|
|
24
|
+
"build_docs",
|
|
25
|
+
"bundle",
|
|
26
|
+
"main",
|
|
27
|
+
"nuke",
|
|
28
|
+
"publish",
|
|
29
|
+
"read_config",
|
|
30
|
+
"read_project",
|
|
31
|
+
"rename",
|
|
32
|
+
"render_llms",
|
|
33
|
+
"render_llms_full",
|
|
34
|
+
"tidy",
|
|
35
|
+
]
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from .types import Project
|
|
3
|
+
|
|
4
|
+
def render_llms(
|
|
5
|
+
proj: Project, # complete parsed project
|
|
6
|
+
base_url: str = '', # base URL for links
|
|
7
|
+
) -> str: # llms.txt content
|
|
8
|
+
"Render llms.txt — module index with export names."
|
|
9
|
+
lines = [f"# {proj.meta.name}\n", f"> {proj.meta.desc}\n"]
|
|
10
|
+
for mod in proj.nonempty_modules:
|
|
11
|
+
names = ', '.join(e.final_name for e in mod.documented_exports)
|
|
12
|
+
if names:
|
|
13
|
+
lines.append(f"- [{mod.name}](/{mod.name}): {names}")
|
|
14
|
+
lines.append(f"\n- [llms-full.txt](/llms-full.txt): Complete source code")
|
|
15
|
+
return '\n'.join(lines) + '\n'
|
|
16
|
+
|
|
17
|
+
def render_llms_full(
|
|
18
|
+
proj: Project, # complete parsed project
|
|
19
|
+
) -> str: # llms-full.txt content
|
|
20
|
+
"Render llms-full.txt — complete cleaned source."
|
|
21
|
+
parts = [f"# {proj.meta.name}\n\n> {proj.meta.desc}\n"]
|
|
22
|
+
for mod in proj.nonempty_modules:
|
|
23
|
+
documented = mod.documented_exports
|
|
24
|
+
if not documented: continue
|
|
25
|
+
parts.append(f"## {mod.name}\n")
|
|
26
|
+
for exp in documented:
|
|
27
|
+
parts.append(exp.clean_src)
|
|
28
|
+
return '\n\n'.join(parts) + '\n'
|
|
29
|
+
|
|
30
|
+
def build_docs(
|
|
31
|
+
proj: Project, # complete parsed project
|
|
32
|
+
) -> str: # status message
|
|
33
|
+
"Write all documentation files."
|
|
34
|
+
docs = Path(proj.config.root) / proj.config.docs
|
|
35
|
+
docs.mkdir(parents=True, exist_ok=True)
|
|
36
|
+
|
|
37
|
+
(docs / 'llms.txt').write_text(render_llms(proj))
|
|
38
|
+
(docs / 'llms-full.txt').write_text(render_llms_full(proj))
|
|
39
|
+
|
|
40
|
+
return f"Wrote docs to {docs}"
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import re, shutil, sys
|
|
3
|
+
from .types import Project, Module
|
|
4
|
+
|
|
5
|
+
def _apply_renames(
|
|
6
|
+
src: str, # source code text
|
|
7
|
+
name: str, # original function/class name
|
|
8
|
+
final_name: str, # resolved name from parser
|
|
9
|
+
) -> str: # source with def/class name replaced
|
|
10
|
+
"Rename a function/class definition in source."
|
|
11
|
+
if final_name == name: return src
|
|
12
|
+
return re.sub(
|
|
13
|
+
rf'(?m)^(\s*(?:async\s+)?(?:def|class)\s+){re.escape(name)}\b',
|
|
14
|
+
rf'\g<1>{final_name}', src, count=1
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def _rewrite_import(
|
|
18
|
+
src: str, # import statement source
|
|
19
|
+
mod_names: list[str], # module names in this project
|
|
20
|
+
) -> str: # rewritten import with relative path
|
|
21
|
+
"Rewrite cross-notebook imports to relative package imports."
|
|
22
|
+
if not src.strip().startswith('from '): return src
|
|
23
|
+
parts = src.split()
|
|
24
|
+
if len(parts) < 2: return src
|
|
25
|
+
module = parts[1]
|
|
26
|
+
if module.startswith('.'): return src
|
|
27
|
+
stripped = re.sub(r'^[a-z]_', '', module)
|
|
28
|
+
if stripped in mod_names:
|
|
29
|
+
return src.replace(f'from {module}', f'from .{stripped}')
|
|
30
|
+
return src
|
|
31
|
+
|
|
32
|
+
def _write(
|
|
33
|
+
path: Path, # file path to write
|
|
34
|
+
*parts: str, # content parts to join with blank lines
|
|
35
|
+
):
|
|
36
|
+
"Write non-empty parts joined by blank lines."
|
|
37
|
+
path.write_text('\n\n'.join(p for p in parts if p and p.strip()) + '\n')
|
|
38
|
+
|
|
39
|
+
def _write_module(
|
|
40
|
+
path: Path, # output .py file path
|
|
41
|
+
mod: Module, # parsed module data
|
|
42
|
+
mod_names: list[str], # all module names for import rewriting
|
|
43
|
+
):
|
|
44
|
+
"Write a single .py module file from a Module."
|
|
45
|
+
imports = '\n'.join(_rewrite_import(i.src, mod_names) for i in mod.imports)
|
|
46
|
+
consts = '\n'.join(c.src for c in mod.consts)
|
|
47
|
+
setup = '\n'.join(s.src for s in mod.setup)
|
|
48
|
+
|
|
49
|
+
exp_src = '\n\n'.join(
|
|
50
|
+
_apply_renames(e.clean_src, e.name, e.final_name) for e in mod.exports
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
# Fix cross-references to renamed symbols
|
|
54
|
+
rename_map = {
|
|
55
|
+
e.name: e.final_name
|
|
56
|
+
for e in mod.exports
|
|
57
|
+
if e.final_name != e.name
|
|
58
|
+
}
|
|
59
|
+
for old, new in rename_map.items():
|
|
60
|
+
exp_src = re.sub(rf'\b{re.escape(old)}\b', new, exp_src)
|
|
61
|
+
|
|
62
|
+
_write(path, imports, consts, setup, exp_src)
|
|
63
|
+
|
|
64
|
+
def _write_init(
|
|
65
|
+
path: Path, # path to write __init__.py
|
|
66
|
+
proj: Project, # complete parsed project
|
|
67
|
+
):
|
|
68
|
+
"Generate __init__.py with metadata and re-exports."
|
|
69
|
+
meta = proj.meta
|
|
70
|
+
lines = [f'"""{meta.desc}"""', f"__version__ = '{meta.version}'"]
|
|
71
|
+
if meta.author:
|
|
72
|
+
lines.append(f"__author__ = '{meta.author.split('<')[0].strip()}'")
|
|
73
|
+
|
|
74
|
+
all_exports = []
|
|
75
|
+
for mod in proj.modules:
|
|
76
|
+
pub = [e.final_name for e in mod.public_exports]
|
|
77
|
+
if pub:
|
|
78
|
+
lines.append(f"from .{mod.name} import {', '.join(pub)}")
|
|
79
|
+
all_exports.extend(pub)
|
|
80
|
+
|
|
81
|
+
if all_exports:
|
|
82
|
+
entries = '\n'.join(f' "{n}",' for n in sorted(all_exports))
|
|
83
|
+
lines.append(f'__all__ = [\n{entries}\n]')
|
|
84
|
+
|
|
85
|
+
_write(path, '\n'.join(lines))
|
|
86
|
+
|
|
87
|
+
def _write_main(
|
|
88
|
+
path: Path, # path to write __main__.py
|
|
89
|
+
app_parts: tuple[str, str, str|None], # (module, object, optional runner)
|
|
90
|
+
):
|
|
91
|
+
"Generate __main__.py entry point for application mode."
|
|
92
|
+
mod, obj, runner = app_parts
|
|
93
|
+
if runner:
|
|
94
|
+
pkg, func = runner.rsplit('.', 1)
|
|
95
|
+
code = f"from .{mod} import {obj}\nfrom {pkg} import {func}\n{func}({obj})\n"
|
|
96
|
+
else:
|
|
97
|
+
code = f"from .{mod} import {obj}\n{obj}()\n"
|
|
98
|
+
path.write_text(code)
|
|
99
|
+
|
|
100
|
+
def _entry_point_src(
|
|
101
|
+
app_parts: tuple[str, str, str|None], # (module, object, optional runner)
|
|
102
|
+
) -> str: # source code for entry point block
|
|
103
|
+
"Generate entry point source for bundle mode (no relative imports)."
|
|
104
|
+
_, obj, runner = app_parts
|
|
105
|
+
if runner:
|
|
106
|
+
_, func = runner.rsplit('.', 1)
|
|
107
|
+
return f"\n{func}({obj})\n"
|
|
108
|
+
else:
|
|
109
|
+
return f"\n{obj}()\n"
|
|
110
|
+
|
|
111
|
+
def build(
|
|
112
|
+
proj: Project, # complete parsed project
|
|
113
|
+
) -> str: # path to built package directory
|
|
114
|
+
"Build a Python package from a parsed Project."
|
|
115
|
+
cfg, meta = proj.config, proj.meta
|
|
116
|
+
pkg = Path(cfg.root) / cfg.out / meta.pkg_name
|
|
117
|
+
if pkg.exists(): shutil.rmtree(pkg)
|
|
118
|
+
pkg.mkdir(parents=True, exist_ok=True)
|
|
119
|
+
|
|
120
|
+
mod_names = proj.mod_names
|
|
121
|
+
for mod in proj.modules:
|
|
122
|
+
if mod.name != 'index' and mod.has_exports:
|
|
123
|
+
_write_module(pkg / f'{mod.name}.py', mod, mod_names)
|
|
124
|
+
|
|
125
|
+
_write_init(pkg / '__init__.py', proj)
|
|
126
|
+
if cfg.app_parts:
|
|
127
|
+
_write_main(pkg / '__main__.py', cfg.app_parts)
|
|
128
|
+
|
|
129
|
+
return str(pkg)
|
|
130
|
+
|
|
131
|
+
def bundle(
|
|
132
|
+
proj: Project, # complete parsed project
|
|
133
|
+
name: str | None = None, # output filename (None for default)
|
|
134
|
+
) -> str: # path to bundled file
|
|
135
|
+
"Bundle all modules into a single Python file with PEP 723 deps."
|
|
136
|
+
cfg, meta = proj.config, proj.meta
|
|
137
|
+
mod_names = set(proj.mod_names)
|
|
138
|
+
|
|
139
|
+
# Collect external imports, deduplicate
|
|
140
|
+
seen_imports: set[str] = set()
|
|
141
|
+
external_imports: list[str] = []
|
|
142
|
+
dep_modules: set[str] = set()
|
|
143
|
+
|
|
144
|
+
for mod in proj.modules:
|
|
145
|
+
for imp in mod.imports:
|
|
146
|
+
is_local = False
|
|
147
|
+
if imp.src.startswith('from '):
|
|
148
|
+
parts = imp.src.split()
|
|
149
|
+
if len(parts) >= 2:
|
|
150
|
+
root_mod = re.sub(r'^[a-z]_', '', parts[1]).split('.')[0]
|
|
151
|
+
if root_mod in mod_names: is_local = True
|
|
152
|
+
elif parts[1].split('.')[0] not in sys.stdlib_module_names:
|
|
153
|
+
dep_modules.add(parts[1].split('.')[0])
|
|
154
|
+
elif imp.src.startswith('import '):
|
|
155
|
+
parts = imp.src.split()
|
|
156
|
+
if len(parts) >= 2:
|
|
157
|
+
root_mod = parts[1].split('.')[0]
|
|
158
|
+
if root_mod not in sys.stdlib_module_names:
|
|
159
|
+
dep_modules.add(root_mod)
|
|
160
|
+
|
|
161
|
+
if not is_local and imp.src not in seen_imports:
|
|
162
|
+
seen_imports.add(imp.src)
|
|
163
|
+
external_imports.append(imp.src)
|
|
164
|
+
|
|
165
|
+
# PEP 723 header
|
|
166
|
+
deps_str = ', '.join(f'"{d}"' for d in sorted(dep_modules))
|
|
167
|
+
header = f'# /// script\n# dependencies = [{deps_str}]\n# ///'
|
|
168
|
+
|
|
169
|
+
imports = '\n'.join(external_imports)
|
|
170
|
+
consts = '\n'.join(c.src for m in proj.modules for c in m.consts)
|
|
171
|
+
setup = '\n'.join(s.src for m in proj.modules for s in m.setup)
|
|
172
|
+
|
|
173
|
+
# Apply renames to exports and fix cross-references
|
|
174
|
+
exports = '\n\n'.join(
|
|
175
|
+
_apply_renames(e.clean_src, e.name, e.final_name)
|
|
176
|
+
for m in proj.modules for e in m.exports
|
|
177
|
+
)
|
|
178
|
+
rename_map = {
|
|
179
|
+
e.name: e.final_name
|
|
180
|
+
for m in proj.modules for e in m.exports
|
|
181
|
+
if e.final_name != e.name
|
|
182
|
+
}
|
|
183
|
+
for old, new in rename_map.items():
|
|
184
|
+
exports = re.sub(rf'\b{re.escape(old)}\b', new, exports)
|
|
185
|
+
|
|
186
|
+
sections = [header, imports, consts, setup, exports]
|
|
187
|
+
|
|
188
|
+
if cfg.app_parts:
|
|
189
|
+
sections.append(_entry_point_src(cfg.app_parts))
|
|
190
|
+
|
|
191
|
+
content = '\n\n'.join(p for p in sections if p.strip())
|
|
192
|
+
|
|
193
|
+
if name:
|
|
194
|
+
out = Path(cfg.root) / name
|
|
195
|
+
else:
|
|
196
|
+
out = Path(cfg.root) / cfg.out / meta.pkg_name / '__init__.py'
|
|
197
|
+
|
|
198
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
199
|
+
out.write_text(content)
|
|
200
|
+
return str(out)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import sys, shutil
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from .parse import read_project
|
|
4
|
+
from .build_pkg import build, bundle
|
|
5
|
+
from .build_docs import build_docs
|
|
6
|
+
from .publish import publish
|
|
7
|
+
|
|
8
|
+
def tidy():
|
|
9
|
+
"Remove cache and temporary files."
|
|
10
|
+
for pattern in ('__pycache__', '__marimo__', '.pytest_cache'):
|
|
11
|
+
for p in Path('.').rglob(pattern): shutil.rmtree(p, ignore_errors=True)
|
|
12
|
+
for p in Path('.').rglob('*.pyc'): p.unlink(missing_ok=True)
|
|
13
|
+
print("Cleaned cache files")
|
|
14
|
+
|
|
15
|
+
def nuke():
|
|
16
|
+
"Remove all build artifacts and cache files."
|
|
17
|
+
tidy()
|
|
18
|
+
for d in ('dist', 'docs', 'src', 'temp'):
|
|
19
|
+
shutil.rmtree(d, ignore_errors=True)
|
|
20
|
+
print("Nuked build artifacts")
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
"Entry point for the md command."
|
|
24
|
+
if len(sys.argv) < 2:
|
|
25
|
+
print("Usage: md [build|docs|bundle|publish|tidy|nuke]")
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
|
|
28
|
+
cmd = sys.argv[1]
|
|
29
|
+
|
|
30
|
+
if cmd == 'tidy': tidy(); return
|
|
31
|
+
if cmd == 'nuke': nuke(); return
|
|
32
|
+
|
|
33
|
+
# Everything else needs the project
|
|
34
|
+
proj = read_project()
|
|
35
|
+
|
|
36
|
+
if cmd == 'build':
|
|
37
|
+
pkg = build(proj)
|
|
38
|
+
build_docs(proj)
|
|
39
|
+
print(f"Built package at: {pkg}")
|
|
40
|
+
|
|
41
|
+
elif cmd == 'docs':
|
|
42
|
+
print(build_docs(proj))
|
|
43
|
+
|
|
44
|
+
elif cmd == 'bundle':
|
|
45
|
+
name = sys.argv[2] if len(sys.argv) > 2 else None
|
|
46
|
+
print(bundle(proj, name=name))
|
|
47
|
+
|
|
48
|
+
elif cmd == 'publish':
|
|
49
|
+
test = '--test' in sys.argv or '-t' in sys.argv
|
|
50
|
+
target = "TestPyPI" if test else "PyPI"
|
|
51
|
+
if input(f"Publish to {target}? [y/N] ").lower() != 'y':
|
|
52
|
+
print("Aborted"); sys.exit(0)
|
|
53
|
+
publish(proj, test=test)
|
|
54
|
+
|
|
55
|
+
else:
|
|
56
|
+
print(f"Unknown command: {cmd}")
|
|
57
|
+
sys.exit(1)
|