afterpython 0.4.0__py3-none-any.whl → 0.4.2__py3-none-any.whl
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/builders/__init__.py +4 -0
- afterpython/builders/build_pdoc.py +7 -0
- afterpython/builders/comments_json.py +107 -0
- afterpython/builders/jupyter_notebook.py +23 -7
- afterpython/builders/marimo_content.py +467 -0
- afterpython/builders/marimo_notebook.py +7 -6
- afterpython/cli/commands/build.py +74 -55
- afterpython/cli/commands/clean.py +6 -0
- afterpython/cli/commands/dev.py +19 -1
- afterpython/cli/commands/init.py +113 -51
- afterpython/cli/main.py +3 -1
- afterpython/const.py +1 -1
- afterpython/templates/afterpython-template.toml +6 -0
- afterpython/templates/ci-workflow-template.yml +10 -10
- afterpython/templates/deploy-workflow-template.yml +2 -2
- afterpython/templates/pdoc/custom.css +37 -0
- afterpython/templates/pdoc/frame.html.jinja2 +15 -1
- afterpython/templates/pdoc/syntax-highlighting.css +155 -0
- afterpython/templates/pdoc/theme.css +44 -0
- afterpython/templates/release-workflow-template.yml +1 -1
- afterpython/templates/ruff-template.toml +1 -1
- afterpython/tools/myst.py +36 -19
- {afterpython-0.4.0.dist-info → afterpython-0.4.2.dist-info}/METADATA +18 -16
- {afterpython-0.4.0.dist-info → afterpython-0.4.2.dist-info}/RECORD +26 -21
- {afterpython-0.4.0.dist-info → afterpython-0.4.2.dist-info}/WHEEL +1 -1
- {afterpython-0.4.0.dist-info → afterpython-0.4.2.dist-info}/entry_points.txt +0 -0
|
@@ -28,18 +28,19 @@ def _create_molab_url(github_url: str, content_path: Path) -> str:
|
|
|
28
28
|
def is_marimo_notebook(path: Path) -> bool:
|
|
29
29
|
"""Check if a Python file is a marimo notebook.
|
|
30
30
|
|
|
31
|
-
Looks for marimo
|
|
32
|
-
`
|
|
33
|
-
|
|
31
|
+
Looks for `marimo.App(`, which every notebook needs and a plain script
|
|
32
|
+
that just `import`s marimo won't have. `__generated_with` isn't required:
|
|
33
|
+
marimo writes it, but hand-written notebooks (e.g. copied from the docs)
|
|
34
|
+
often lack it and marimo runs them fine.
|
|
34
35
|
"""
|
|
35
36
|
if not path.exists() or not path.is_file():
|
|
36
37
|
return False
|
|
37
38
|
try:
|
|
38
|
-
#
|
|
39
|
-
|
|
39
|
+
# whole file: a long PEP 723 header can push `marimo.App(` far down
|
|
40
|
+
text = path.read_text(encoding="utf-8", errors="ignore")
|
|
40
41
|
except OSError:
|
|
41
42
|
return False
|
|
42
|
-
return "
|
|
43
|
+
return "marimo.App(" in text
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
def _export_marimo(
|
|
@@ -17,10 +17,12 @@ from click.exceptions import Exit
|
|
|
17
17
|
|
|
18
18
|
import afterpython as ap
|
|
19
19
|
from afterpython.builders import (
|
|
20
|
+
build_comments_json,
|
|
20
21
|
build_content_json,
|
|
21
22
|
build_faq_json,
|
|
22
23
|
build_jupyter_notebooks,
|
|
23
24
|
build_llms_txt,
|
|
25
|
+
build_marimo_content,
|
|
24
26
|
build_marimo_readme,
|
|
25
27
|
build_markdown,
|
|
26
28
|
build_metadata,
|
|
@@ -83,7 +85,7 @@ def _read_api_reference() -> bool:
|
|
|
83
85
|
return bool(website.get("api_reference", False))
|
|
84
86
|
|
|
85
87
|
|
|
86
|
-
def prebuild():
|
|
88
|
+
def prebuild(dev_build: bool = False):
|
|
87
89
|
def _check_initialized():
|
|
88
90
|
# Check if 'ap init' has been run
|
|
89
91
|
afterpython_toml = ap.paths.afterpython_path / "afterpython.toml"
|
|
@@ -137,8 +139,13 @@ def prebuild():
|
|
|
137
139
|
create_placeholder_index_md_files()
|
|
138
140
|
build_metadata()
|
|
139
141
|
build_faq_json()
|
|
142
|
+
build_comments_json()
|
|
140
143
|
build_marimo_readme(mode=_get_readme_py_mode())
|
|
141
144
|
build_markdown()
|
|
145
|
+
# before build_jupyter_notebooks() so generated notebooks get the same
|
|
146
|
+
# thumbnail/molab post-processing as hand-written ones. Production builds
|
|
147
|
+
# always re-run notebooks (outputs can change without the .py changing).
|
|
148
|
+
build_marimo_content(use_cache=dev_build)
|
|
142
149
|
build_jupyter_notebooks()
|
|
143
150
|
|
|
144
151
|
|
|
@@ -171,7 +178,12 @@ def postbuild(dev_build: bool = False):
|
|
|
171
178
|
print(f"Moved: {source} to {destination}")
|
|
172
179
|
|
|
173
180
|
build_content_json()
|
|
174
|
-
|
|
181
|
+
# In dev, `myst start` is still running and watches myst.yml: removing the
|
|
182
|
+
# placeholder from the TOC now would make the first real page the index,
|
|
183
|
+
# so every later rebuild lands in index.json. `ap dev` deletes the
|
|
184
|
+
# placeholders when its servers stop instead.
|
|
185
|
+
if not dev_build:
|
|
186
|
+
delete_placeholder_index_md_files()
|
|
175
187
|
|
|
176
188
|
website_static = ap.paths.website_path / "static"
|
|
177
189
|
website_static.mkdir(parents=True, exist_ok=True)
|
|
@@ -267,62 +279,69 @@ def build(ctx: click.Context, execute: bool):
|
|
|
267
279
|
return
|
|
268
280
|
|
|
269
281
|
paths = ctx.obj["paths"]
|
|
270
|
-
prebuild()
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
282
|
+
# prebuild() creates placeholder index.md files and edits myst.yml TOCs;
|
|
283
|
+
# remove them even if a later step fails (e.g. a marimo notebook errors)
|
|
284
|
+
try:
|
|
285
|
+
prebuild()
|
|
286
|
+
|
|
287
|
+
# Determine BASE_PATH based on website URL configuration. Computed
|
|
288
|
+
# before build_pdoc() so it can wire pdoc's logo-link back to the
|
|
289
|
+
# project website root.
|
|
290
|
+
base_path = determine_base_path()
|
|
291
|
+
if base_path:
|
|
292
|
+
click.echo(f"Using BASE_PATH: {base_path}")
|
|
293
|
+
else:
|
|
294
|
+
click.echo("Using BASE_PATH: (empty - custom domain)")
|
|
295
|
+
|
|
296
|
+
if _read_api_reference():
|
|
297
|
+
build_pdoc(base_path=base_path)
|
|
298
|
+
|
|
299
|
+
node_env: NodeEnv = find_node_env()
|
|
300
|
+
|
|
301
|
+
# myst's production build
|
|
302
|
+
for content_type in CONTENT_TYPES:
|
|
303
|
+
content_path = ap.paths.afterpython_path / content_type
|
|
304
|
+
myst_yml_path = content_path / "myst.yml"
|
|
305
|
+
|
|
306
|
+
if not content_path.exists():
|
|
307
|
+
click.echo(
|
|
308
|
+
f"{content_path} does not exist, skip building {content_type}/"
|
|
309
|
+
)
|
|
310
|
+
continue
|
|
311
|
+
|
|
312
|
+
if not myst_yml_path.exists():
|
|
313
|
+
click.echo(
|
|
314
|
+
f"No myst.yml found in {content_path}, skip building {content_type}/"
|
|
315
|
+
)
|
|
316
|
+
continue
|
|
317
|
+
|
|
318
|
+
if not has_content_for_myst(content_path):
|
|
319
|
+
click.echo(f"Skipping {content_type}/ (no content files found)")
|
|
320
|
+
continue
|
|
321
|
+
|
|
322
|
+
click.echo(f"Building {content_type}/...")
|
|
323
|
+
# NOTE: needs to set BASE_URL (used by MyST) so that the project website can link to the content pages correctly at e.g. localhost:5173/doc
|
|
324
|
+
base_url = f"{base_path}/{content_type}"
|
|
325
|
+
build_env = {**node_env, "BASE_URL": base_url, "BASE_PATH": base_path}
|
|
326
|
+
result = subprocess.run(
|
|
327
|
+
[
|
|
328
|
+
"myst",
|
|
329
|
+
"build",
|
|
330
|
+
"--html",
|
|
331
|
+
*(["--execute"] if execute else []),
|
|
332
|
+
*ctx.args,
|
|
333
|
+
],
|
|
334
|
+
cwd=content_path,
|
|
335
|
+
env=build_env,
|
|
336
|
+
check=False,
|
|
298
337
|
)
|
|
299
|
-
continue
|
|
300
|
-
|
|
301
|
-
if not has_content_for_myst(content_path):
|
|
302
|
-
click.echo(f"Skipping {content_type}/ (no content files found)")
|
|
303
|
-
continue
|
|
304
|
-
|
|
305
|
-
click.echo(f"Building {content_type}/...")
|
|
306
|
-
# NOTE: needs to set BASE_URL (used by MyST) so that the project website can link to the content pages correctly at e.g. localhost:5173/doc
|
|
307
|
-
base_url = f"{base_path}/{content_type}"
|
|
308
|
-
build_env = {**node_env, "BASE_URL": base_url, "BASE_PATH": base_path}
|
|
309
|
-
result = subprocess.run(
|
|
310
|
-
[
|
|
311
|
-
"myst",
|
|
312
|
-
"build",
|
|
313
|
-
"--html",
|
|
314
|
-
*(["--execute"] if execute else []),
|
|
315
|
-
*ctx.args,
|
|
316
|
-
],
|
|
317
|
-
cwd=content_path,
|
|
318
|
-
env=build_env,
|
|
319
|
-
check=False,
|
|
320
|
-
)
|
|
321
338
|
|
|
322
|
-
|
|
323
|
-
|
|
339
|
+
if result.returncode != 0:
|
|
340
|
+
raise Exit(result.returncode)
|
|
324
341
|
|
|
325
|
-
|
|
342
|
+
postbuild(dev_build=False)
|
|
343
|
+
finally:
|
|
344
|
+
delete_placeholder_index_md_files()
|
|
326
345
|
|
|
327
346
|
click.echo("Building project website...")
|
|
328
347
|
website_env = {**node_env, "BASE_PATH": base_path}
|
|
@@ -42,10 +42,16 @@ def clean(ctx, all: bool):
|
|
|
42
42
|
paths = ctx.obj["paths"]
|
|
43
43
|
node_env: NodeEnv = find_node_env()
|
|
44
44
|
|
|
45
|
+
from afterpython.builders.marimo_content import remove_generated_notebooks
|
|
46
|
+
|
|
45
47
|
# Clean MyST builds for each content type
|
|
46
48
|
for content_type in CONTENT_TYPES:
|
|
47
49
|
content_path = paths.afterpython_path / content_type
|
|
48
50
|
|
|
51
|
+
# .ipynb files generated from marimo notebooks are build artifacts too
|
|
52
|
+
if removed := remove_generated_notebooks(content_path):
|
|
53
|
+
click.echo(f" Removed {removed} generated notebook(s) in {content_type}/")
|
|
54
|
+
|
|
49
55
|
# Skip if no content exists
|
|
50
56
|
if not has_content_for_myst(content_path):
|
|
51
57
|
click.echo(f"Skipping {content_type}/ (no content found)")
|
afterpython/cli/commands/dev.py
CHANGED
|
@@ -230,8 +230,20 @@ def dev(
|
|
|
230
230
|
)
|
|
231
231
|
enabled_content_types = {ct for ct, flag in content_flags.items() if flag}
|
|
232
232
|
|
|
233
|
+
stop_watching = threading.Event()
|
|
234
|
+
|
|
233
235
|
try:
|
|
234
|
-
prebuild()
|
|
236
|
+
prebuild(dev_build=True)
|
|
237
|
+
|
|
238
|
+
# re-export marimo notebooks on save for the content types being served
|
|
239
|
+
if enabled_content_types:
|
|
240
|
+
from afterpython.builders.marimo_content import watch_marimo_content
|
|
241
|
+
|
|
242
|
+
threading.Thread(
|
|
243
|
+
target=watch_marimo_content,
|
|
244
|
+
args=(enabled_content_types, stop_watching),
|
|
245
|
+
daemon=True,
|
|
246
|
+
).start()
|
|
235
247
|
|
|
236
248
|
# Clear .env.development before writing new ports
|
|
237
249
|
env_file = paths.website_path / ".env.development"
|
|
@@ -313,4 +325,10 @@ def dev(
|
|
|
313
325
|
# Handle Ctrl+C during subprocess.run
|
|
314
326
|
pass
|
|
315
327
|
finally:
|
|
328
|
+
stop_watching.set()
|
|
316
329
|
cleanup_processes()
|
|
330
|
+
# runs on shutdown: postbuild() keeps the placeholder index.md files
|
|
331
|
+
# during the session (MyST servers watch myst.yml); clean them up now
|
|
332
|
+
from afterpython.builders import delete_placeholder_index_md_files
|
|
333
|
+
|
|
334
|
+
delete_placeholder_index_md_files()
|
afterpython/cli/commands/init.py
CHANGED
|
@@ -169,14 +169,62 @@ def init_py_typed():
|
|
|
169
169
|
click.echo(f"Created {py_typed_path}")
|
|
170
170
|
|
|
171
171
|
|
|
172
|
-
def _preflight_init(
|
|
172
|
+
def _preflight_init(website: bool) -> None:
|
|
173
173
|
"""Validate external prerequisites before any filesystem writes, so a
|
|
174
174
|
failure aborts cleanly instead of leaving a half-initialized project."""
|
|
175
|
-
if
|
|
176
|
-
from afterpython.tools.myst import
|
|
175
|
+
if website:
|
|
176
|
+
from afterpython.tools.myst import ensure_pnpm_12
|
|
177
177
|
from afterpython.utils import find_node_env
|
|
178
178
|
|
|
179
|
-
|
|
179
|
+
ensure_pnpm_12(find_node_env())
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _select_steps(yes: bool, skip_website: bool, ask_commit_types: bool) -> set[str]:
|
|
183
|
+
"""Ask which optional setup steps to run, as one checkbox list (all checked by default).
|
|
184
|
+
|
|
185
|
+
Without a terminal (CI, piped input) or with --yes, nothing is asked and the defaults are used.
|
|
186
|
+
"""
|
|
187
|
+
import sys
|
|
188
|
+
|
|
189
|
+
import questionary
|
|
190
|
+
|
|
191
|
+
# (step, label, checked by default)
|
|
192
|
+
options = [
|
|
193
|
+
(
|
|
194
|
+
"website",
|
|
195
|
+
"Project website (MyST, template, deploy workflow)",
|
|
196
|
+
not skip_website,
|
|
197
|
+
)
|
|
198
|
+
]
|
|
199
|
+
# only relevant when afterpython.toml is created, it's ignored otherwise
|
|
200
|
+
if ask_commit_types:
|
|
201
|
+
options.append(
|
|
202
|
+
(
|
|
203
|
+
"commit_types",
|
|
204
|
+
"Commit message check (conventional commit types, e.g. 'feat: add X')",
|
|
205
|
+
True,
|
|
206
|
+
)
|
|
207
|
+
)
|
|
208
|
+
options += [
|
|
209
|
+
("prek", "Pre-commit hooks (prek)", True),
|
|
210
|
+
("ruff", "ruff: lint & format", True),
|
|
211
|
+
("ty", "ty: type checking (`ap check`)", True),
|
|
212
|
+
("cliff", "git-cliff: changelog", True),
|
|
213
|
+
("release", "Release workflow (.github/workflows/release.yml)", True),
|
|
214
|
+
("dependabot", "Dependabot (auto-update GitHub Actions versions)", True),
|
|
215
|
+
]
|
|
216
|
+
|
|
217
|
+
if yes or not (sys.stdin.isatty() and sys.stdout.isatty()):
|
|
218
|
+
return {step for step, _, checked in options if checked}
|
|
219
|
+
|
|
220
|
+
choices = [
|
|
221
|
+
questionary.Choice(label, value=step, checked=checked)
|
|
222
|
+
for step, label, checked in options
|
|
223
|
+
]
|
|
224
|
+
selected = questionary.checkbox("Select what to set up", choices=choices).ask()
|
|
225
|
+
if selected is None: # Ctrl-C, before anything was written
|
|
226
|
+
raise click.Abort()
|
|
227
|
+
return set(selected)
|
|
180
228
|
|
|
181
229
|
|
|
182
230
|
@click.group(invoke_without_command=True)
|
|
@@ -184,7 +232,7 @@ def _preflight_init(skip_website: bool) -> None:
|
|
|
184
232
|
"--yes",
|
|
185
233
|
"-y",
|
|
186
234
|
is_flag=True,
|
|
187
|
-
help="
|
|
235
|
+
help="Set up everything without asking",
|
|
188
236
|
)
|
|
189
237
|
@click.option(
|
|
190
238
|
"--skip-website",
|
|
@@ -205,32 +253,27 @@ def init(ctx, yes, skip_website: bool):
|
|
|
205
253
|
from afterpython.tools.prek import init_prek, sync_hooks
|
|
206
254
|
from afterpython.tools.pyproject import init_pyproject
|
|
207
255
|
|
|
208
|
-
_preflight_init(skip_website)
|
|
209
|
-
|
|
210
256
|
paths = ctx.obj["paths"]
|
|
211
|
-
click.echo("Initializing afterpython...")
|
|
212
257
|
afterpython_path = paths.afterpython_path
|
|
213
258
|
static_path = paths.static_path
|
|
214
259
|
|
|
260
|
+
steps = _select_steps(
|
|
261
|
+
yes,
|
|
262
|
+
skip_website,
|
|
263
|
+
ask_commit_types=not (afterpython_path / "afterpython.toml").exists(),
|
|
264
|
+
)
|
|
265
|
+
_preflight_init(website="website" in steps)
|
|
266
|
+
|
|
267
|
+
click.echo("Initializing afterpython...")
|
|
215
268
|
try:
|
|
216
269
|
afterpython_path.mkdir(parents=True, exist_ok=True)
|
|
217
270
|
static_path.mkdir(parents=True, exist_ok=True)
|
|
218
271
|
|
|
219
272
|
init_pyproject()
|
|
220
273
|
|
|
221
|
-
|
|
222
|
-
commit_types = (
|
|
223
|
-
yes
|
|
224
|
-
or (afterpython_path / "afterpython.toml").exists()
|
|
225
|
-
or click.confirm(
|
|
226
|
-
"\nCheck commit messages against conventional commit types "
|
|
227
|
-
"(e.g. 'feat: add X', types listed in afterpython.toml)?",
|
|
228
|
-
default=True,
|
|
229
|
-
)
|
|
230
|
-
)
|
|
231
|
-
init_afterpython(commit_types=commit_types)
|
|
274
|
+
init_afterpython(commit_types="commit_types" in steps)
|
|
232
275
|
|
|
233
|
-
if
|
|
276
|
+
if "website" in steps:
|
|
234
277
|
# check=True so a failure inside `ap init website` aborts the parent
|
|
235
278
|
# run instead of silently continuing to write more files.
|
|
236
279
|
subprocess.run(["ap", "init", "website"], check=True)
|
|
@@ -239,42 +282,20 @@ def init(ctx, yes, skip_website: bool):
|
|
|
239
282
|
|
|
240
283
|
create_workflow("ci")
|
|
241
284
|
|
|
242
|
-
if
|
|
243
|
-
f"\nCreate .pre-commit-config.yaml in {afterpython_path}?", default=True
|
|
244
|
-
):
|
|
285
|
+
if "prek" in steps:
|
|
245
286
|
init_prek()
|
|
246
|
-
|
|
247
|
-
if yes or click.confirm(
|
|
248
|
-
f"\nCreate ruff.toml in {afterpython_path} (and point pyproject.toml's [tool.ruff] to it)?",
|
|
249
|
-
default=True,
|
|
250
|
-
):
|
|
287
|
+
if "ruff" in steps:
|
|
251
288
|
init_ruff()
|
|
252
|
-
|
|
253
|
-
if yes or click.confirm(
|
|
254
|
-
f"\nCreate ty.toml in {afterpython_path} (type checking with `ap check`)?",
|
|
255
|
-
default=True,
|
|
256
|
-
):
|
|
289
|
+
if "ty" in steps:
|
|
257
290
|
init_ty()
|
|
258
|
-
# whatever
|
|
291
|
+
# whatever was selected: keep ruff/ty hooks only for the tools that were set up
|
|
259
292
|
sync_hooks()
|
|
260
293
|
|
|
261
|
-
if
|
|
262
|
-
f"\nCreate cliff.toml in {afterpython_path} (changelog generation with git-cliff)?",
|
|
263
|
-
default=True,
|
|
264
|
-
):
|
|
294
|
+
if "cliff" in steps:
|
|
265
295
|
init_cliff()
|
|
266
|
-
|
|
267
|
-
if yes or click.confirm(
|
|
268
|
-
"\nCreate release workflow in .github/workflows/release.yml?",
|
|
269
|
-
default=True,
|
|
270
|
-
):
|
|
296
|
+
if "release" in steps:
|
|
271
297
|
create_workflow("release")
|
|
272
|
-
|
|
273
|
-
if yes or click.confirm(
|
|
274
|
-
"\nCreate Dependabot configuration (.github/dependabot.yml) "
|
|
275
|
-
"to auto-update GitHub Actions versions?",
|
|
276
|
-
default=True,
|
|
277
|
-
):
|
|
298
|
+
if "dependabot" in steps:
|
|
278
299
|
create_dependabot()
|
|
279
300
|
except BaseException:
|
|
280
301
|
if afterpython_path.exists():
|
|
@@ -327,12 +348,12 @@ def init_website_subcommand():
|
|
|
327
348
|
the website to an existing AfterPython project.
|
|
328
349
|
"""
|
|
329
350
|
from afterpython.tools.github_actions import create_workflow
|
|
330
|
-
from afterpython.tools.myst import
|
|
351
|
+
from afterpython.tools.myst import ensure_pnpm_12, init_myst
|
|
331
352
|
from afterpython.utils import find_node_env
|
|
332
353
|
|
|
333
354
|
# Pre-flight: same rationale as `ap init` — guard the standalone entry too,
|
|
334
355
|
# since this subcommand can be invoked directly via `ap init website`.
|
|
335
|
-
|
|
356
|
+
ensure_pnpm_12(find_node_env())
|
|
336
357
|
|
|
337
358
|
init_faq()
|
|
338
359
|
init_myst()
|
|
@@ -342,3 +363,44 @@ def init_website_subcommand():
|
|
|
342
363
|
# of a broken website install.
|
|
343
364
|
subprocess.run(["ap", "update", "website"], check=True)
|
|
344
365
|
create_workflow("deploy")
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
@init.command("content")
|
|
369
|
+
@click.option("--all", is_flag=True, help="Initialize all content types")
|
|
370
|
+
@click.option("--doc", is_flag=True, help="Initialize afterpython/doc/")
|
|
371
|
+
@click.option("--blog", is_flag=True, help="Initialize afterpython/blog/")
|
|
372
|
+
@click.option("--tutorial", is_flag=True, help="Initialize afterpython/tutorial/")
|
|
373
|
+
@click.option("--example", is_flag=True, help="Initialize afterpython/example/")
|
|
374
|
+
@click.option("--guide", is_flag=True, help="Initialize afterpython/guide/")
|
|
375
|
+
def init_content_subcommand(
|
|
376
|
+
all: bool, doc: bool, blog: bool, tutorial: bool, example: bool, guide: bool
|
|
377
|
+
):
|
|
378
|
+
"""Initialize content directories (MyST config) without touching the website
|
|
379
|
+
|
|
380
|
+
Content types that already have a myst.yml are skipped.
|
|
381
|
+
|
|
382
|
+
Examples:
|
|
383
|
+
ap init content --blog # afterpython/blog/
|
|
384
|
+
ap init content --blog --tutorial # afterpython/blog/ and afterpython/tutorial/
|
|
385
|
+
ap init content --all # every content type that is missing
|
|
386
|
+
"""
|
|
387
|
+
from afterpython._typing import tContentType
|
|
388
|
+
from afterpython.const import CONTENT_TYPES
|
|
389
|
+
from afterpython.tools.myst import init_myst
|
|
390
|
+
|
|
391
|
+
flags: dict[tContentType, bool] = {
|
|
392
|
+
"doc": doc,
|
|
393
|
+
"blog": blog,
|
|
394
|
+
"tutorial": tutorial,
|
|
395
|
+
"example": example,
|
|
396
|
+
"guide": guide,
|
|
397
|
+
}
|
|
398
|
+
if all:
|
|
399
|
+
content_types = CONTENT_TYPES
|
|
400
|
+
else:
|
|
401
|
+
content_types = {content_type for content_type, flag in flags.items() if flag}
|
|
402
|
+
if not content_types:
|
|
403
|
+
raise click.UsageError(
|
|
404
|
+
"Specify one or more of --doc/--blog/--tutorial/--example/--guide, or --all"
|
|
405
|
+
)
|
|
406
|
+
init_myst(content_types)
|
afterpython/cli/main.py
CHANGED
|
@@ -90,7 +90,9 @@ class AliasGroup(click.Group):
|
|
|
90
90
|
@click.version_option(version=__version__)
|
|
91
91
|
def afterpython_group(ctx):
|
|
92
92
|
"""afterpython's CLI"""
|
|
93
|
-
|
|
93
|
+
# usecwd: search from the user's project, not from this file's location
|
|
94
|
+
# (with an editable install that would find afterpython's own .env)
|
|
95
|
+
load_dotenv(find_dotenv(usecwd=True))
|
|
94
96
|
ctx.ensure_object(dict)
|
|
95
97
|
ctx.obj["paths"] = ap.paths
|
|
96
98
|
|
afterpython/const.py
CHANGED
|
@@ -13,6 +13,12 @@ announcement = ""
|
|
|
13
13
|
readme_py = "wasm" # marimo html export format: "wasm" or "static"
|
|
14
14
|
execute_readme_py = false # execute README.py cells at build time and embed outputs as a preview (wasm mode only)
|
|
15
15
|
api_reference = false # set to true to enable the pdoc-generated API reference
|
|
16
|
+
# api_reference_docformat = "google" # docstring format for pdoc: "google", "numpy", "restructuredtext" or "markdown"
|
|
17
|
+
|
|
18
|
+
[website.comments] # giscus comment section on blog posts, tutorials, examples and guides
|
|
19
|
+
enabled = true
|
|
20
|
+
# Discussions category for comments. Announcement format means only maintainers can start discussions there; visitors can only reply.
|
|
21
|
+
category = "Announcements"
|
|
16
22
|
|
|
17
23
|
# [website.blog]
|
|
18
24
|
# thumbnail = "blog_default_thumbnail.png" # inside blog/static/ folder, default thumbnail for blog posts
|
|
@@ -27,7 +27,7 @@ jobs:
|
|
|
27
27
|
uses: actions/checkout@v7
|
|
28
28
|
|
|
29
29
|
- name: Install uv
|
|
30
|
-
uses: astral-sh/setup-uv@v10.
|
|
30
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
31
31
|
|
|
32
32
|
- name: Run ruff
|
|
33
33
|
# fails if ruff-check finds issues or ruff-format would change a file
|
|
@@ -66,7 +66,7 @@ jobs:
|
|
|
66
66
|
runs-on: ubuntu-latest
|
|
67
67
|
strategy:
|
|
68
68
|
matrix:
|
|
69
|
-
python-version: ['3.
|
|
69
|
+
python-version: ['3.13', '3.14', '3.15']
|
|
70
70
|
fail-fast: false
|
|
71
71
|
|
|
72
72
|
env:
|
|
@@ -78,7 +78,7 @@ jobs:
|
|
|
78
78
|
uses: actions/checkout@v7
|
|
79
79
|
|
|
80
80
|
- name: Install uv
|
|
81
|
-
uses: astral-sh/setup-uv@v10.
|
|
81
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
82
82
|
|
|
83
83
|
- name: Install dependencies
|
|
84
84
|
# the package + all [dependency-groups] (e.g. test, dev), at the versions in uv.lock
|
|
@@ -106,7 +106,7 @@ jobs:
|
|
|
106
106
|
runs-on: ubuntu-latest
|
|
107
107
|
strategy:
|
|
108
108
|
matrix:
|
|
109
|
-
environment: ['
|
|
109
|
+
environment: ['py313', 'py314', 'py315']
|
|
110
110
|
fail-fast: false
|
|
111
111
|
|
|
112
112
|
steps:
|
|
@@ -114,9 +114,9 @@ jobs:
|
|
|
114
114
|
uses: actions/checkout@v7
|
|
115
115
|
|
|
116
116
|
- name: Set up pixi
|
|
117
|
-
uses: prefix-dev/setup-pixi@v0.
|
|
117
|
+
uses: prefix-dev/setup-pixi@v0.11.3
|
|
118
118
|
with:
|
|
119
|
-
pixi-version: v0.
|
|
119
|
+
pixi-version: v0.84.1
|
|
120
120
|
cache: true
|
|
121
121
|
# install (and cache) only the environment this matrix run tests
|
|
122
122
|
environments: ${{ matrix.environment }}
|
|
@@ -169,7 +169,7 @@ jobs:
|
|
|
169
169
|
uses: actions/checkout@v7
|
|
170
170
|
|
|
171
171
|
- name: Install uv
|
|
172
|
-
uses: astral-sh/setup-uv@v10.
|
|
172
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
173
173
|
|
|
174
174
|
- name: Build package
|
|
175
175
|
# --no-sources: build like it will be published, ignoring [tool.uv.sources] (local paths, git)
|
|
@@ -228,7 +228,7 @@ jobs:
|
|
|
228
228
|
|
|
229
229
|
- name: Install uv
|
|
230
230
|
if: steps.ty.outputs.enabled == 'true' && hashFiles('pixi.toml') == ''
|
|
231
|
-
uses: astral-sh/setup-uv@v10.
|
|
231
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
232
232
|
|
|
233
233
|
- name: Run ty (uv)
|
|
234
234
|
# the package + all [dependency-groups] (incl. afterpython itself), at the versions in uv.lock
|
|
@@ -239,9 +239,9 @@ jobs:
|
|
|
239
239
|
|
|
240
240
|
- name: Set up pixi
|
|
241
241
|
if: steps.ty.outputs.enabled == 'true' && hashFiles('pixi.toml') != ''
|
|
242
|
-
uses: prefix-dev/setup-pixi@v0.
|
|
242
|
+
uses: prefix-dev/setup-pixi@v0.11.3
|
|
243
243
|
with:
|
|
244
|
-
pixi-version: v0.
|
|
244
|
+
pixi-version: v0.84.1
|
|
245
245
|
cache: true
|
|
246
246
|
environments: default
|
|
247
247
|
|
|
@@ -47,7 +47,7 @@ jobs:
|
|
|
47
47
|
- name: Install pnpm
|
|
48
48
|
uses: pnpm/action-setup@v6
|
|
49
49
|
with:
|
|
50
|
-
version:
|
|
50
|
+
version: 12
|
|
51
51
|
|
|
52
52
|
- name: Set up Node.js
|
|
53
53
|
uses: actions/setup-node@v7
|
|
@@ -57,7 +57,7 @@ jobs:
|
|
|
57
57
|
cache-dependency-path: './afterpython/_website/pnpm-lock.yaml'
|
|
58
58
|
|
|
59
59
|
- name: Install uv
|
|
60
|
-
uses: astral-sh/setup-uv@v10.
|
|
60
|
+
uses: astral-sh/setup-uv@v10.3.3
|
|
61
61
|
|
|
62
62
|
- name: Install the project
|
|
63
63
|
# your package + its dependencies (pdoc imports it for the API reference)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* Dark mode for what theme.css can't reach. Colors from Bootstrap 5.3's dark mode,
|
|
2
|
+
like pdoc's light ones are from its light mode. */
|
|
3
|
+
|
|
4
|
+
/* code blocks match inline code instead of github-dark's own background */
|
|
5
|
+
html.dark .pdoc .pdoc-code {
|
|
6
|
+
background: var(--code);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
html.dark .pdoc .decorator-deprecated {
|
|
10
|
+
color: #ea868f;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
{#- the icons have their light color baked in, swap it for the dark text color -#}
|
|
14
|
+
{% macro alert(kind, icon, light, color, background, border) %}
|
|
15
|
+
html.dark .pdoc .alert.{{ kind }} {
|
|
16
|
+
color: {{ color }};
|
|
17
|
+
background-color: {{ background }};
|
|
18
|
+
border-color: {{ border }};
|
|
19
|
+
background-image: url("data:image/svg+xml,{% filter urlencode %}{% filter replace(light, color) %}{% include 'resources/' ~ icon ~ '.svg' %}{% endfilter %}{% endfilter %}");
|
|
20
|
+
}
|
|
21
|
+
{% endmacro %}
|
|
22
|
+
{{ alert("note", "info-circle-fill", "#084298", "#6ea8fe", "#031633", "#084298") }}
|
|
23
|
+
{{ alert("tip", "lightbulb", "#0a3622", "#75b798", "#051b11", "#0f5132") }}
|
|
24
|
+
{{ alert("important", "exclamation-square-fill", "#055160", "#6edff6", "#032830", "#087990") }}
|
|
25
|
+
{{ alert("warning", "exclamation-triangle-fill", "#664d03", "#ffda6a", "#332701", "#997404") }}
|
|
26
|
+
{{ alert("caution", "exclamation-octagon-fill", "#842029", "#ea868f", "#2c0b0e", "#842029") }}
|
|
27
|
+
{{ alert("danger", "lightning-fill", "#842029", "#ea868f", "#2c0b0e", "#842029") }}
|
|
28
|
+
|
|
29
|
+
{#- pdoc indents every non-top-level nav link by one --indent, so a nested class's
|
|
30
|
+
members (e.g. Feed.Requests.download) line up with the outer class's own members
|
|
31
|
+
(Feed.download) and read as duplicates. Indent one more step per nesting level. -#}
|
|
32
|
+
nav.pdoc li li li a {
|
|
33
|
+
padding-left: calc(var(--pad) + 2 * var(--indent));
|
|
34
|
+
}
|
|
35
|
+
nav.pdoc li li li li a {
|
|
36
|
+
padding-left: calc(var(--pad) + 3 * var(--indent));
|
|
37
|
+
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{% extends "default/frame.html.jinja2" %}
|
|
2
|
-
{# Override pdoc's default 35vh logo height — too dominant in the sidebar. #}
|
|
3
2
|
{% block head %}
|
|
3
|
+
{# Same as the project website's app.html: follow the theme chosen on the website
|
|
4
|
+
(same origin, so its localStorage is shared), else the OS setting.
|
|
5
|
+
Dark colors are in theme.css, syntax-highlighting.css and custom.css. #}
|
|
6
|
+
<script>
|
|
7
|
+
(function () {
|
|
8
|
+
const query = window.matchMedia('(prefers-color-scheme: dark)');
|
|
9
|
+
const apply = (dark) => document.documentElement.classList.toggle('dark', dark);
|
|
10
|
+
const stored = localStorage.getItem('theme');
|
|
11
|
+
apply(stored ? stored === 'dark' : query.matches);
|
|
12
|
+
query.addEventListener('change', (e) => {
|
|
13
|
+
if (!localStorage.getItem('theme')) apply(e.matches);
|
|
14
|
+
});
|
|
15
|
+
})();
|
|
16
|
+
</script>
|
|
17
|
+
{# Override pdoc's default 35vh logo height — too dominant in the sidebar. #}
|
|
4
18
|
<style>
|
|
5
19
|
nav.pdoc img.logo { max-height: 5rem; margin-bottom: 1.5rem; }
|
|
6
20
|
</style>
|