afterpython 0.5.0__tar.gz → 0.5.2__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.
- {afterpython-0.5.0 → afterpython-0.5.2}/PKG-INFO +1 -1
- {afterpython-0.5.0 → afterpython-0.5.2}/pyproject.toml +1 -1
- {afterpython-0.5.0 → afterpython-0.5.2}/pyproject.toml.orig +1 -1
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/jupyter_notebook.py +64 -17
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/marimo_content.py +30 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/build.py +7 -8
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/afterpython-template.toml +1 -1
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/_afterpython.py +2 -2
- {afterpython-0.5.0 → afterpython-0.5.2}/README.md +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/__init__.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/_io/toml.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/_io/yaml.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/_paths.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/_typing.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/__init__.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/build_pdoc.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/comments_json.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/content_json.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/faq_json.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/index_md.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/llms_txt.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/marimo_notebook.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/markdown.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/metadata.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/seo.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/site_data.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/builders/url_md.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/__init__.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/add.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/bump.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/changelog.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/check.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/clean.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/commit_msg.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/dev.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/format.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/init.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/init_branch_rules.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/install.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/lint.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/lock.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/prek.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/preview.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/release.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/remove.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/serve.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/start.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/sync.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/commands/update.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/cli/main.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/const.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/main.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/pcu.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/py.typed +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/ci-workflow-template.yml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/cliff-template.toml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/dependabot-template.yml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/deploy-workflow-template.yml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/custom.css +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/frame.html.jinja2 +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/module.html.jinja2 +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/syntax-highlighting.css +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/theme.css +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pre-commit-config-template.yaml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/release-workflow-template.yml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/ruff-template.toml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/ty-template.toml +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/_git.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/branch_rules.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/github_actions.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/myst.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/prek.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/tools/pyproject.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/utils.py +0 -0
- {afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/version.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: afterpython
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: CLI tool to streamline Python package maintenance and generate a dedicated project website
|
|
5
5
|
Keywords: package-maintenance,project-website,static-site-generator,developer-tools,documentation,cli-tool,ci/cd,mystmd,semantic-release,python-packaging
|
|
6
6
|
Author: Stephen Yau
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import json
|
|
2
|
-
import
|
|
2
|
+
import re
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
5
|
import click
|
|
6
|
+
from ruamel.yaml import YAML
|
|
7
|
+
from ruamel.yaml.error import YAMLError
|
|
6
8
|
|
|
7
9
|
import afterpython as ap
|
|
8
10
|
from afterpython.builders.marimo_notebook import _create_molab_url, _get_molab_badge
|
|
@@ -178,6 +180,43 @@ def _add_thumbnail_to_notebook(
|
|
|
178
180
|
return True
|
|
179
181
|
|
|
180
182
|
|
|
183
|
+
def _wants_molab_badge(notebook: dict) -> bool:
|
|
184
|
+
"""True if the notebook's frontmatter sets `molab_badge: true`, or a
|
|
185
|
+
generated notebook already had it moved into its metadata."""
|
|
186
|
+
if notebook.get("metadata", {}).get("afterpython", {}).get("molab_badge"):
|
|
187
|
+
return True
|
|
188
|
+
content = _read_frontmatter(notebook)
|
|
189
|
+
if content is None:
|
|
190
|
+
return False
|
|
191
|
+
match = re.match(r"^---\s*\n(.*?)\n---", content, re.DOTALL)
|
|
192
|
+
if not match:
|
|
193
|
+
return False
|
|
194
|
+
try:
|
|
195
|
+
data = YAML(typ="safe").load(match.group(1))
|
|
196
|
+
except YAMLError:
|
|
197
|
+
return False
|
|
198
|
+
return isinstance(data, dict) and data.get("molab_badge") is True
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def _remove_frontmatter_key(notebook: dict, key: str):
|
|
202
|
+
content = _read_frontmatter(notebook)
|
|
203
|
+
if content is None:
|
|
204
|
+
return
|
|
205
|
+
lines = [line for line in content.split("\n") if not line.startswith(f"{key}:")]
|
|
206
|
+
_write_frontmatter(notebook, "\n".join(lines))
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _remove_molab_badge_from_notebook(notebook: dict) -> bool:
|
|
210
|
+
"""Remove a badge cell left by an earlier build, e.g. after `molab_badge`
|
|
211
|
+
was turned off in a committed notebook. Returns True if one was removed."""
|
|
212
|
+
cells = notebook["cells"]
|
|
213
|
+
kept = [cell for cell in cells if cell.get("id") != "molab-badge-cell"]
|
|
214
|
+
if len(kept) == len(cells):
|
|
215
|
+
return False
|
|
216
|
+
notebook["cells"] = kept
|
|
217
|
+
return True
|
|
218
|
+
|
|
219
|
+
|
|
181
220
|
def _add_molab_badge_to_notebook(notebook: dict, github_url: str, content_path: Path):
|
|
182
221
|
"""Add a molab badge markdown cell to a single notebook.
|
|
183
222
|
|
|
@@ -224,20 +263,9 @@ def build_jupyter_notebooks():
|
|
|
224
263
|
"""Build Jupyter notebooks for all content types"""
|
|
225
264
|
from afterpython.tools._afterpython import get_default_thumbnail
|
|
226
265
|
|
|
227
|
-
#
|
|
228
|
-
add_molab_badge = os.getenv("AP_MOLAB_BADGE", "0") == "1"
|
|
229
|
-
|
|
230
|
-
# Get GitHub URL once if needed for molab badges
|
|
266
|
+
# read pyproject.toml only once a notebook wants a badge
|
|
231
267
|
github_url = None
|
|
232
|
-
|
|
233
|
-
metadata = read_metadata()
|
|
234
|
-
if "repository" in metadata.urls:
|
|
235
|
-
github_url = metadata.urls["repository"]
|
|
236
|
-
else:
|
|
237
|
-
click.echo(
|
|
238
|
-
"⚠ Repository URL not found in [project.urls] in pyproject.toml, skipping molab badge"
|
|
239
|
-
)
|
|
240
|
-
add_molab_badge = False
|
|
268
|
+
github_url_read = False
|
|
241
269
|
|
|
242
270
|
for content_type in CONTENT_TYPES:
|
|
243
271
|
click.echo(f"Building Jupyter notebooks for {content_type}/...")
|
|
@@ -269,9 +297,18 @@ def build_jupyter_notebooks():
|
|
|
269
297
|
# Track if notebook was modified
|
|
270
298
|
modified = False
|
|
271
299
|
|
|
272
|
-
# Add molab badge if
|
|
273
|
-
#
|
|
274
|
-
|
|
300
|
+
# Add a molab badge if the notebook opts in with `molab_badge: true`
|
|
301
|
+
# in its frontmatter. A notebook generated from a marimo .py isn't
|
|
302
|
+
# committed, so the badge must open the .py instead.
|
|
303
|
+
wants_badge = _wants_molab_badge(notebook)
|
|
304
|
+
if wants_badge and not github_url_read:
|
|
305
|
+
github_url = read_metadata().urls.get("repository")
|
|
306
|
+
github_url_read = True
|
|
307
|
+
if wants_badge and not github_url:
|
|
308
|
+
click.echo(
|
|
309
|
+
f"⚠ Repository URL not found in [project.urls] in pyproject.toml, skipping molab badge in {content_path}"
|
|
310
|
+
)
|
|
311
|
+
if wants_badge and github_url:
|
|
275
312
|
generated_from = (
|
|
276
313
|
notebook.get("metadata", {})
|
|
277
314
|
.get("afterpython", {})
|
|
@@ -284,6 +321,16 @@ def build_jupyter_notebooks():
|
|
|
284
321
|
)
|
|
285
322
|
_add_molab_badge_to_notebook(notebook, github_url, molab_path)
|
|
286
323
|
modified = True
|
|
324
|
+
# MyST warns about unknown frontmatter keys. A generated notebook is
|
|
325
|
+
# a build output, so move the key into its metadata, where a cached
|
|
326
|
+
# rebuild still finds it; a hand-written notebook is the source and
|
|
327
|
+
# must keep it.
|
|
328
|
+
afterpython_metadata = notebook.get("metadata", {}).get("afterpython")
|
|
329
|
+
if wants_badge and afterpython_metadata is not None:
|
|
330
|
+
afterpython_metadata["molab_badge"] = True
|
|
331
|
+
_remove_frontmatter_key(notebook, "molab_badge")
|
|
332
|
+
elif _remove_molab_badge_from_notebook(notebook):
|
|
333
|
+
modified = True
|
|
287
334
|
|
|
288
335
|
# Add thumbnail to frontmatter
|
|
289
336
|
if content_type != "doc" and _add_thumbnail_to_notebook(
|
|
@@ -333,12 +333,42 @@ def _rewrite_cell_ids(notebook: dict, prefix: str):
|
|
|
333
333
|
cell["id"] = cell_id
|
|
334
334
|
|
|
335
335
|
|
|
336
|
+
def _markdown_output_to_markdown_cell(notebook: dict):
|
|
337
|
+
"""A static `mo.md("...")` cell exports as a markdown cell, but a dynamic one
|
|
338
|
+
(e.g. an f-string) stays a code cell with a `text/markdown` output, and MyST
|
|
339
|
+
renders that output as raw text instead of markdown. When the code is hidden,
|
|
340
|
+
only the output is shown anyway, so turn the cell into a markdown cell with
|
|
341
|
+
the output as its source."""
|
|
342
|
+
for index, cell in enumerate(notebook["cells"]):
|
|
343
|
+
if cell.get("cell_type") != "code":
|
|
344
|
+
continue
|
|
345
|
+
hide_code = (
|
|
346
|
+
cell.get("metadata", {})
|
|
347
|
+
.get("marimo", {})
|
|
348
|
+
.get("config", {})
|
|
349
|
+
.get("hide_code", False)
|
|
350
|
+
)
|
|
351
|
+
outputs = cell.get("outputs", [])
|
|
352
|
+
if not hide_code or len(outputs) != 1:
|
|
353
|
+
continue
|
|
354
|
+
data = outputs[0].get("data", {})
|
|
355
|
+
if "text/markdown" not in data or set(data) - {"text/markdown", "text/plain"}:
|
|
356
|
+
continue
|
|
357
|
+
notebook["cells"][index] = {
|
|
358
|
+
"cell_type": "markdown",
|
|
359
|
+
"id": cell.get("id", ""),
|
|
360
|
+
"metadata": {},
|
|
361
|
+
"source": _as_lines(data["text/markdown"]),
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
|
|
336
365
|
def _postprocess(
|
|
337
366
|
notebook: dict, source: Path, content_path: Path, marimo_version: str
|
|
338
367
|
) -> dict:
|
|
339
368
|
for cell in notebook["cells"]:
|
|
340
369
|
cell["source"] = _as_lines(cell.get("source", ""))
|
|
341
370
|
_check_no_errors(notebook, source)
|
|
371
|
+
_markdown_output_to_markdown_cell(notebook)
|
|
342
372
|
_check_frontmatter_first(notebook, source)
|
|
343
373
|
_warn_heading_not_first(notebook, source)
|
|
344
374
|
# outputs come from the sandbox, `myst build --execute` must not redo them
|
|
@@ -191,14 +191,13 @@ def postbuild(dev_build: bool = False):
|
|
|
191
191
|
website_static / content_type,
|
|
192
192
|
is_copy=True,
|
|
193
193
|
)
|
|
194
|
-
# for
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
)
|
|
194
|
+
# for both builds, copy the files (mainly images, e.g. thumbnails) in site/public/ to afterpython/_website/static/{content_type}/build,
|
|
195
|
+
# where convert_paths() points the listings' thumbnails. The html export keeps its own copies in _public/, which its pages use
|
|
196
|
+
_move_files(
|
|
197
|
+
afterpython_content_build / "site" / "public",
|
|
198
|
+
website_static / content_type / "build",
|
|
199
|
+
is_copy=True,
|
|
200
|
+
)
|
|
202
201
|
|
|
203
202
|
# Copy all files (e.g. metadata.json, blog.json etc.) from afterpython/_build to afterpython/_website/static/
|
|
204
203
|
_move_files(
|
|
@@ -10,7 +10,7 @@ google_analytics_id = "" # e.g. "G-XXXXXXXXXX"; empty disables Google Analytics
|
|
|
10
10
|
favicon = "favicon.ico"
|
|
11
11
|
logo = "logo.svg"
|
|
12
12
|
logo_dark = "logo.svg"
|
|
13
|
-
thumbnail = "thumbnail.png" # thumbnail for the website,
|
|
13
|
+
thumbnail = "thumbnail.png" # thumbnail for the website itself, not used for content; set [website.<content_type>].thumbnail for a default per content type
|
|
14
14
|
announcement = ""
|
|
15
15
|
readme_py = "wasm" # marimo html export format: "wasm" or "static"
|
|
16
16
|
execute_readme_py = false # execute README.py cells at build time and embed outputs as a preview (wasm mode only)
|
|
@@ -24,7 +24,6 @@ def get_default_thumbnail(
|
|
|
24
24
|
|
|
25
25
|
Reads default thumbnail configuration from afterpython.toml:
|
|
26
26
|
- Content type specific thumbnail: [website.{content_type}.thumbnail]
|
|
27
|
-
- Website-wide default thumbnail: [website.thumbnail]
|
|
28
27
|
- Falls back to empty string if no default is configured
|
|
29
28
|
|
|
30
29
|
Args:
|
|
@@ -39,6 +38,7 @@ def get_default_thumbnail(
|
|
|
39
38
|
|
|
40
39
|
afterpython = read_afterpython()
|
|
41
40
|
try:
|
|
41
|
+
# DEPRECATED: [website].thumbnail is not a default for content types
|
|
42
42
|
# website_default_thumbnail = normalize_static_path(
|
|
43
43
|
# str(_from_tomlkit(afterpython.get("website", {})).get("thumbnail", ""))
|
|
44
44
|
# )
|
|
@@ -62,7 +62,7 @@ def get_default_thumbnail(
|
|
|
62
62
|
|
|
63
63
|
if content_type_default_thumbnail:
|
|
64
64
|
return f"{static_prefix}static{content_type_default_thumbnail}"
|
|
65
|
-
# use "thumbnail" set in afterpython.toml [website]
|
|
65
|
+
# DEPRECATED: use "thumbnail" set in afterpython.toml [website]
|
|
66
66
|
# elif website_default_thumbnail:
|
|
67
67
|
# Website-wide static is one level up from content_type folder
|
|
68
68
|
# return f"{static_prefix}../static{website_default_thumbnail}"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/deploy-workflow-template.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pdoc/syntax-highlighting.css
RENAMED
|
File without changes
|
|
File without changes
|
{afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/pre-commit-config-template.yaml
RENAMED
|
File without changes
|
{afterpython-0.5.0 → afterpython-0.5.2}/src/afterpython/templates/release-workflow-template.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|