afterpython 0.2.0__py3-none-any.whl → 0.3.0__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 +8 -0
- afterpython/builders/faq_json.py +43 -0
- afterpython/builders/jupyter_notebook.py +1 -14
- afterpython/builders/llms_txt.py +248 -0
- afterpython/builders/marimo_notebook.py +144 -0
- afterpython/builders/metadata.py +36 -3
- afterpython/builders/url_md.py +107 -0
- afterpython/cli/commands/build.py +30 -0
- afterpython/cli/commands/init.py +30 -11
- afterpython/cli/commands/serve.py +29 -0
- afterpython/cli/commands/sync.py +6 -0
- afterpython/cli/commands/update.py +84 -4
- afterpython/cli/main.py +2 -0
- afterpython/templates/ci-workflow-template.yml +16 -9
- afterpython/templates/deploy-workflow-template.yml +1 -0
- afterpython/tools/_afterpython.py +2 -0
- afterpython/tools/github_actions.py +56 -22
- afterpython/tools/pyproject.py +8 -2
- {afterpython-0.2.0.dist-info → afterpython-0.3.0.dist-info}/METADATA +21 -18
- {afterpython-0.2.0.dist-info → afterpython-0.3.0.dist-info}/RECORD +22 -17
- {afterpython-0.2.0.dist-info → afterpython-0.3.0.dist-info}/WHEEL +1 -1
- {afterpython-0.2.0.dist-info → afterpython-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
|
|
5
5
|
|
|
6
6
|
if TYPE_CHECKING:
|
|
7
7
|
from pathlib import Path
|
|
8
|
+
from typing import Literal
|
|
8
9
|
|
|
9
10
|
from afterpython._typing import NodeEnv
|
|
10
11
|
|
|
@@ -17,9 +18,13 @@ from click.exceptions import Exit
|
|
|
17
18
|
import afterpython as ap
|
|
18
19
|
from afterpython.builders import (
|
|
19
20
|
build_content_json,
|
|
21
|
+
build_faq_json,
|
|
20
22
|
build_jupyter_notebooks,
|
|
23
|
+
build_llms_txt,
|
|
24
|
+
build_marimo_readme,
|
|
21
25
|
build_markdown,
|
|
22
26
|
build_metadata,
|
|
27
|
+
build_url_md,
|
|
23
28
|
create_placeholder_index_md_files,
|
|
24
29
|
delete_placeholder_index_md_files,
|
|
25
30
|
)
|
|
@@ -85,12 +90,29 @@ def prebuild():
|
|
|
85
90
|
shutil.rmtree(path)
|
|
86
91
|
build_path.mkdir(parents=True, exist_ok=True)
|
|
87
92
|
|
|
93
|
+
def _get_readme_py_mode() -> Literal["wasm", "static"]:
|
|
94
|
+
"""Read `[website].readme_py` from afterpython.toml. Defaults to "wasm".
|
|
95
|
+
|
|
96
|
+
Falls back to "wasm" silently for unknown values rather than failing the
|
|
97
|
+
build — the metadata.json resolver does the same, keeping the two views
|
|
98
|
+
consistent.
|
|
99
|
+
"""
|
|
100
|
+
from afterpython._io.toml import _from_tomlkit
|
|
101
|
+
from afterpython.tools._afterpython import read_afterpython
|
|
102
|
+
|
|
103
|
+
afterpython = read_afterpython()
|
|
104
|
+
website = _from_tomlkit(afterpython.get("website", {}))
|
|
105
|
+
mode = str(website.get("readme_py", "wasm"))
|
|
106
|
+
return mode if mode in ("wasm", "static") else "wasm"
|
|
107
|
+
|
|
88
108
|
_check_initialized()
|
|
89
109
|
_clean_up_builds()
|
|
90
110
|
|
|
91
111
|
delete_placeholder_index_md_files()
|
|
92
112
|
create_placeholder_index_md_files()
|
|
93
113
|
build_metadata()
|
|
114
|
+
build_faq_json()
|
|
115
|
+
build_marimo_readme(mode=_get_readme_py_mode())
|
|
94
116
|
build_markdown()
|
|
95
117
|
build_jupyter_notebooks()
|
|
96
118
|
|
|
@@ -164,6 +186,14 @@ def postbuild(dev_build: bool = False):
|
|
|
164
186
|
# Copy all static files from afterpython/static/ to afterpython/_website/static/
|
|
165
187
|
_move_files(ap.paths.static_path, website_static, is_copy=True)
|
|
166
188
|
|
|
189
|
+
# Publish raw markdown alongside rendered HTML so each page is fetchable
|
|
190
|
+
# at /{type}/{slug}.md for LLMs / AI agents (Mintlify-style).
|
|
191
|
+
build_url_md()
|
|
192
|
+
|
|
193
|
+
# Generate llms.txt — a single catalog of the site for AI agents (depends
|
|
194
|
+
# on url_md outputs since llms.txt links point at /{type}/{slug}.md).
|
|
195
|
+
build_llms_txt()
|
|
196
|
+
|
|
167
197
|
|
|
168
198
|
@click.command(
|
|
169
199
|
add_help_option=False, # disable click's --help option so that ap build --help can work
|
afterpython/cli/commands/init.py
CHANGED
|
@@ -16,9 +16,13 @@ def init_ruff_toml():
|
|
|
16
16
|
click.echo(f"Created {ruff_toml_path}")
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
def
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
def init_faq():
|
|
20
|
+
faq_path = ap.paths.afterpython_path / "faq.yml"
|
|
21
|
+
if faq_path.exists():
|
|
22
|
+
click.echo(f"FAQ file already exists at {faq_path}")
|
|
23
|
+
return
|
|
24
|
+
faq_path.touch()
|
|
25
|
+
click.echo(f"Created {faq_path}")
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
def init_py_typed():
|
|
@@ -39,7 +43,7 @@ def init_py_typed():
|
|
|
39
43
|
click.echo(f"Created {py_typed_path}")
|
|
40
44
|
|
|
41
45
|
|
|
42
|
-
@click.
|
|
46
|
+
@click.group(invoke_without_command=True)
|
|
43
47
|
@click.option(
|
|
44
48
|
"--yes",
|
|
45
49
|
"-y",
|
|
@@ -49,18 +53,20 @@ def init_py_typed():
|
|
|
49
53
|
@click.option(
|
|
50
54
|
"--skip-website",
|
|
51
55
|
is_flag=True,
|
|
52
|
-
help="Skip website template initialization",
|
|
56
|
+
help="Skip website template initialization (run `ap init website` later to add it)",
|
|
53
57
|
)
|
|
54
58
|
@click.pass_context
|
|
55
59
|
def init(ctx, yes, skip_website: bool):
|
|
56
60
|
"""Initialize AfterPython project structure and website template"""
|
|
61
|
+
if ctx.invoked_subcommand is not None:
|
|
62
|
+
return
|
|
63
|
+
|
|
57
64
|
from afterpython.tools._afterpython import init_afterpython
|
|
58
65
|
from afterpython.tools.commitizen import init_commitizen
|
|
59
66
|
from afterpython.tools.github_actions import (
|
|
60
67
|
create_dependabot,
|
|
61
68
|
create_workflow,
|
|
62
69
|
)
|
|
63
|
-
from afterpython.tools.myst import init_myst
|
|
64
70
|
from afterpython.tools.pre_commit import init_pre_commit
|
|
65
71
|
from afterpython.tools.pyproject import init_pyproject
|
|
66
72
|
|
|
@@ -76,16 +82,12 @@ def init(ctx, yes, skip_website: bool):
|
|
|
76
82
|
|
|
77
83
|
init_afterpython()
|
|
78
84
|
|
|
79
|
-
init_myst()
|
|
80
|
-
|
|
81
85
|
if not skip_website:
|
|
82
|
-
|
|
83
|
-
init_website()
|
|
86
|
+
subprocess.run(["ap", "init", "website"])
|
|
84
87
|
|
|
85
88
|
# TODO: add type checking related stuff here
|
|
86
89
|
init_py_typed()
|
|
87
90
|
|
|
88
|
-
create_workflow("deploy")
|
|
89
91
|
create_workflow("ci")
|
|
90
92
|
|
|
91
93
|
if yes or click.confirm(
|
|
@@ -110,3 +112,20 @@ def init(ctx, yes, skip_website: bool):
|
|
|
110
112
|
default=True,
|
|
111
113
|
):
|
|
112
114
|
create_dependabot()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@init.command("website")
|
|
118
|
+
def init_website_subcommand():
|
|
119
|
+
"""Initialize project website (MyST config, template, deploy workflow)
|
|
120
|
+
|
|
121
|
+
Use this if you ran `ap init --skip-website` and now want to add
|
|
122
|
+
the website to an existing AfterPython project.
|
|
123
|
+
"""
|
|
124
|
+
from afterpython.tools.github_actions import create_workflow
|
|
125
|
+
from afterpython.tools.myst import init_myst
|
|
126
|
+
|
|
127
|
+
init_faq()
|
|
128
|
+
init_myst()
|
|
129
|
+
click.echo(f"Initializing project website template in {ap.paths.website_path}...")
|
|
130
|
+
subprocess.run(["ap", "update", "website"])
|
|
131
|
+
create_workflow("deploy")
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
from click.exceptions import Exit
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@click.command()
|
|
8
|
+
@click.pass_context
|
|
9
|
+
def serve(ctx):
|
|
10
|
+
"""Serve the production build of the project website"""
|
|
11
|
+
from afterpython.utils import find_node_env, is_website_initialized
|
|
12
|
+
|
|
13
|
+
if not is_website_initialized():
|
|
14
|
+
click.echo(
|
|
15
|
+
"Website has not been initialized. Skipping serve.\n"
|
|
16
|
+
"Run 'ap update website' to initialize the website."
|
|
17
|
+
)
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
paths = ctx.obj["paths"]
|
|
21
|
+
node_env = find_node_env()
|
|
22
|
+
click.echo(
|
|
23
|
+
"Serving the production build of the project website (including myst's builds)..."
|
|
24
|
+
)
|
|
25
|
+
result = subprocess.run(
|
|
26
|
+
["pnpm", "serve"], cwd=paths.website_path, env=node_env, check=False
|
|
27
|
+
)
|
|
28
|
+
if result.returncode != 0:
|
|
29
|
+
raise Exit(result.returncode)
|
afterpython/cli/commands/sync.py
CHANGED
|
@@ -58,6 +58,10 @@ def sync():
|
|
|
58
58
|
website_favicon = normalize_static_path(
|
|
59
59
|
str(_from_tomlkit(afterpython.get("website", {})).get("favicon", ""))
|
|
60
60
|
)
|
|
61
|
+
if website_favicon and not website_favicon.lower().endswith(".ico"):
|
|
62
|
+
raise ValueError(
|
|
63
|
+
f"Invalid favicon '{website_favicon}': mystmd only supports .ico files."
|
|
64
|
+
)
|
|
61
65
|
website_logo = normalize_static_path(
|
|
62
66
|
str(_from_tomlkit(afterpython.get("website", {})).get("logo", ""))
|
|
63
67
|
)
|
|
@@ -100,6 +104,8 @@ def sync():
|
|
|
100
104
|
# based on the current values in pyproject.toml and afterpython.toml
|
|
101
105
|
for content_type in CONTENT_TYPES:
|
|
102
106
|
path = ap.paths.afterpython_path / content_type
|
|
107
|
+
if not (path / "myst.yml").exists():
|
|
108
|
+
continue
|
|
103
109
|
# nav_bar_per_content_type = [
|
|
104
110
|
# item for item in nav_bar if item["title"] != content_type.capitalize() + "s"
|
|
105
111
|
# ]
|
|
@@ -28,14 +28,23 @@ def update():
|
|
|
28
28
|
)
|
|
29
29
|
@click.option(
|
|
30
30
|
"--all",
|
|
31
|
+
"all_",
|
|
31
32
|
is_flag=True,
|
|
32
33
|
help="Also update pre-commit hooks and pixi dependencies",
|
|
33
34
|
)
|
|
34
|
-
|
|
35
|
+
@click.option(
|
|
36
|
+
"--exclude",
|
|
37
|
+
"exclude",
|
|
38
|
+
multiple=True,
|
|
39
|
+
metavar="PACKAGE",
|
|
40
|
+
help="Package to exclude from upgrade (can be passed multiple times)",
|
|
41
|
+
)
|
|
42
|
+
def dependencies(upgrade: bool, all_: bool, exclude: tuple[str, ...]):
|
|
35
43
|
"""Check and update project dependencies to latest versions"""
|
|
36
44
|
from afterpython.pcu import get_dependencies, update_dependencies
|
|
37
45
|
from afterpython.utils import has_pixi, has_uv
|
|
38
46
|
|
|
47
|
+
excluded = set(exclude)
|
|
39
48
|
dependencies: Dependencies = get_dependencies()
|
|
40
49
|
has_at_least_one_update = False
|
|
41
50
|
for dep_type in dependencies:
|
|
@@ -55,11 +64,15 @@ def dependencies(upgrade: bool, all: bool):
|
|
|
55
64
|
for dep in deps:
|
|
56
65
|
msg = f" {dep.requirement.name}: {dep.min_version}"
|
|
57
66
|
has_update = dep.min_version != dep.latest_version
|
|
67
|
+
is_excluded = dep.requirement.name in excluded
|
|
58
68
|
if has_update:
|
|
59
|
-
|
|
69
|
+
if not is_excluded:
|
|
70
|
+
has_at_least_one_update = True
|
|
60
71
|
msg += (
|
|
61
72
|
f" → {click.style(dep.latest_version, fg='green', bold=True)}"
|
|
62
73
|
)
|
|
74
|
+
if is_excluded:
|
|
75
|
+
msg += f" {click.style('(excluded)', fg='yellow')}"
|
|
63
76
|
if category_name:
|
|
64
77
|
msg += f" ({category_name})"
|
|
65
78
|
click.echo(msg)
|
|
@@ -67,6 +80,15 @@ def dependencies(upgrade: bool, all: bool):
|
|
|
67
80
|
click.echo(f"\n{click.style('No dependencies to update.', bold=True)}")
|
|
68
81
|
return
|
|
69
82
|
if has_at_least_one_update and upgrade:
|
|
83
|
+
if excluded:
|
|
84
|
+
for dep_type in dependencies:
|
|
85
|
+
for category, deps in dependencies[dep_type].items():
|
|
86
|
+
dependencies[dep_type][category] = [
|
|
87
|
+
dep._replace(latest_version=dep.min_version)
|
|
88
|
+
if dep.requirement.name in excluded
|
|
89
|
+
else dep
|
|
90
|
+
for dep in deps
|
|
91
|
+
]
|
|
70
92
|
update_dependencies(dependencies) # write the latest versions to pyproject.toml
|
|
71
93
|
if has_uv():
|
|
72
94
|
click.echo("Upgrading dependencies with uv...")
|
|
@@ -89,13 +111,16 @@ def dependencies(upgrade: bool, all: bool):
|
|
|
89
111
|
click.echo(
|
|
90
112
|
"uv not found. Updated pyproject.toml only (packages not installed)."
|
|
91
113
|
)
|
|
92
|
-
if
|
|
114
|
+
if upgrade and all_:
|
|
93
115
|
subprocess.run(["ap", "pre-commit", "autoupdate"])
|
|
94
116
|
click.echo("All pre-commit hooks updated successfully.")
|
|
95
117
|
if has_pixi():
|
|
96
118
|
click.echo("Upgrading dependencies with pixi...")
|
|
119
|
+
pixi_exclude_args = ["--exclude", "python"]
|
|
120
|
+
for pkg in excluded:
|
|
121
|
+
pixi_exclude_args += ["--exclude", pkg]
|
|
97
122
|
result = subprocess.run(
|
|
98
|
-
["pixi", "upgrade",
|
|
123
|
+
["pixi", "upgrade", *pixi_exclude_args], check=False
|
|
99
124
|
)
|
|
100
125
|
if result.returncode != 0:
|
|
101
126
|
raise Exit(result.returncode)
|
|
@@ -117,6 +142,61 @@ def dependencies(upgrade: bool, all: bool):
|
|
|
117
142
|
update.add_command(dependencies, name="deps") # alias for "dependencies"
|
|
118
143
|
|
|
119
144
|
|
|
145
|
+
@update.command()
|
|
146
|
+
@click.option("--deploy", is_flag=True, help="Update .github/workflows/deploy.yml")
|
|
147
|
+
@click.option("--ci", is_flag=True, help="Update .github/workflows/ci.yml")
|
|
148
|
+
@click.option("--release", is_flag=True, help="Update .github/workflows/release.yml")
|
|
149
|
+
@click.option("--dependabot", is_flag=True, help="Update .github/dependabot.yml")
|
|
150
|
+
@click.option(
|
|
151
|
+
"--all",
|
|
152
|
+
"all_",
|
|
153
|
+
is_flag=True,
|
|
154
|
+
help="Update every supported workflow file",
|
|
155
|
+
)
|
|
156
|
+
@click.option(
|
|
157
|
+
"--no-backup",
|
|
158
|
+
is_flag=True,
|
|
159
|
+
help="Skip creating .backup copies of existing workflow files",
|
|
160
|
+
)
|
|
161
|
+
def workflows(
|
|
162
|
+
deploy: bool,
|
|
163
|
+
ci: bool,
|
|
164
|
+
release: bool,
|
|
165
|
+
dependabot: bool,
|
|
166
|
+
all_: bool,
|
|
167
|
+
no_backup: bool,
|
|
168
|
+
):
|
|
169
|
+
"""Update GitHub Actions workflow files (deploy, ci, release, dependabot)
|
|
170
|
+
|
|
171
|
+
Existing files are backed up to <file>.backup before being overwritten
|
|
172
|
+
so user customizations (matrix tweaks, extra steps, etc.) aren't lost.
|
|
173
|
+
"""
|
|
174
|
+
from afterpython.tools.github_actions import (
|
|
175
|
+
VALID_WORKFLOWS,
|
|
176
|
+
update_workflow_file,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
selected_flags = {
|
|
180
|
+
"deploy": deploy,
|
|
181
|
+
"ci": ci,
|
|
182
|
+
"release": release,
|
|
183
|
+
"dependabot": dependabot,
|
|
184
|
+
}
|
|
185
|
+
individual = [name for name, picked in selected_flags.items() if picked]
|
|
186
|
+
|
|
187
|
+
if all_ and individual:
|
|
188
|
+
raise click.UsageError("Pass --all or individual workflow flags, not both.")
|
|
189
|
+
if not all_ and not individual:
|
|
190
|
+
raise click.UsageError(
|
|
191
|
+
"Specify which workflows to update with flags "
|
|
192
|
+
"(e.g. --deploy --ci) or pass --all."
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
selected = VALID_WORKFLOWS if all_ else individual
|
|
196
|
+
for name in selected:
|
|
197
|
+
update_workflow_file(name, backup=not no_backup)
|
|
198
|
+
|
|
199
|
+
|
|
120
200
|
@update.command()
|
|
121
201
|
@click.pass_context
|
|
122
202
|
@click.option(
|
afterpython/cli/main.py
CHANGED
|
@@ -25,6 +25,7 @@ from afterpython.cli.commands.pre_commit import pre_commit
|
|
|
25
25
|
from afterpython.cli.commands.preview import preview
|
|
26
26
|
from afterpython.cli.commands.release import release
|
|
27
27
|
from afterpython.cli.commands.remove import remove
|
|
28
|
+
from afterpython.cli.commands.serve import serve
|
|
28
29
|
from afterpython.cli.commands.start import blog, doc, example, guide, start, tutorial
|
|
29
30
|
from afterpython.cli.commands.sync import sync
|
|
30
31
|
from afterpython.cli.commands.update import update
|
|
@@ -118,6 +119,7 @@ afterpython_group.add_command(tutorial)
|
|
|
118
119
|
afterpython_group.add_command(example)
|
|
119
120
|
afterpython_group.add_command(guide)
|
|
120
121
|
afterpython_group.add_command(preview)
|
|
122
|
+
afterpython_group.add_command(serve)
|
|
121
123
|
afterpython_group.add_command(clean)
|
|
122
124
|
afterpython_group.add_command(pre_commit)
|
|
123
125
|
afterpython_group.add_command(pre_commit, name="pc")
|
|
@@ -30,10 +30,8 @@ jobs:
|
|
|
30
30
|
with:
|
|
31
31
|
version: "latest"
|
|
32
32
|
|
|
33
|
-
- name: Install
|
|
34
|
-
|
|
35
|
-
# This installs ruff and other tools defined in dependencies
|
|
36
|
-
run: uv pip install --system .
|
|
33
|
+
- name: Install ruff
|
|
34
|
+
run: uv pip install --system ruff
|
|
37
35
|
|
|
38
36
|
- name: Run ruff check
|
|
39
37
|
run: ruff check --config ./afterpython/ruff.toml .
|
|
@@ -116,9 +114,9 @@ jobs:
|
|
|
116
114
|
uses: actions/checkout@v6
|
|
117
115
|
|
|
118
116
|
- name: Set up pixi
|
|
119
|
-
uses: prefix-dev/setup-pixi@v0.9.
|
|
117
|
+
uses: prefix-dev/setup-pixi@v0.9.4
|
|
120
118
|
with:
|
|
121
|
-
pixi-version: v0.
|
|
119
|
+
pixi-version: v0.67.2
|
|
122
120
|
cache: true
|
|
123
121
|
# Optional: Uncomment if you need prefix.dev authentication
|
|
124
122
|
# auth-host: prefix.dev
|
|
@@ -189,9 +187,18 @@ jobs:
|
|
|
189
187
|
run: uv pip install --system dist/*.whl
|
|
190
188
|
|
|
191
189
|
- name: Verify installation
|
|
192
|
-
#
|
|
193
|
-
#
|
|
194
|
-
run:
|
|
190
|
+
# Generic verification: assume project.name maps to import name
|
|
191
|
+
# by replacing '-' with '_'. If a project breaks this rule, CI fails.
|
|
192
|
+
run: |
|
|
193
|
+
PROJECT_NAME="$(python - <<'PY'
|
|
194
|
+
import tomllib
|
|
195
|
+
with open("pyproject.toml", "rb") as f:
|
|
196
|
+
data = tomllib.load(f)
|
|
197
|
+
print(data["project"]["name"])
|
|
198
|
+
PY
|
|
199
|
+
)"
|
|
200
|
+
IMPORT_NAME="${PROJECT_NAME//-/_}"
|
|
201
|
+
python -c "import ${IMPORT_NAME}"
|
|
195
202
|
|
|
196
203
|
# Job 5: Type Check
|
|
197
204
|
# typecheck:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# VIBE-CODED
|
|
1
2
|
import shutil
|
|
2
3
|
from pathlib import Path
|
|
3
4
|
|
|
@@ -5,44 +6,77 @@ import click
|
|
|
5
6
|
|
|
6
7
|
import afterpython as ap
|
|
7
8
|
|
|
9
|
+
# Workflow names supported by `create_workflow` / `update_workflow_file`.
|
|
10
|
+
# "dependabot" is included even though it lives at .github/dependabot.yml
|
|
11
|
+
# (not under workflows/) so a single CLI surface can refresh all GH templates.
|
|
12
|
+
VALID_WORKFLOWS = ("deploy", "ci", "release", "dependabot")
|
|
8
13
|
|
|
9
|
-
def _copy_github_template(template_name: str, target_path: Path):
|
|
10
|
-
"""Helper to copy GitHub-related templates"""
|
|
11
|
-
if target_path.exists():
|
|
12
|
-
click.echo(f"{target_path} already exists")
|
|
13
|
-
return
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
target_path
|
|
15
|
+
def _resolve_workflow_target(name: str) -> tuple[Path, Path]:
|
|
16
|
+
"""Return (target_path, template_path) for a workflow name."""
|
|
17
|
+
if name not in VALID_WORKFLOWS:
|
|
18
|
+
raise ValueError(
|
|
19
|
+
f"Unknown workflow '{name}'. Valid: {', '.join(VALID_WORKFLOWS)}"
|
|
20
|
+
)
|
|
21
|
+
user_path = ap.paths.user_path
|
|
22
|
+
templates_path = ap.paths.templates_path
|
|
23
|
+
if name == "dependabot":
|
|
24
|
+
target = user_path / ".github" / "dependabot.yml"
|
|
25
|
+
template = templates_path / "dependabot-template.yml"
|
|
26
|
+
else:
|
|
27
|
+
target = user_path / ".github" / "workflows" / f"{name}.yml"
|
|
28
|
+
template = templates_path / f"{name}-workflow-template.yml"
|
|
29
|
+
return target, template
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
31
|
+
|
|
32
|
+
def _copy_github_template(template_path: Path, target_path: Path):
|
|
33
|
+
"""Copy a template file into the project, creating parent dirs as needed."""
|
|
20
34
|
if not template_path.exists():
|
|
21
35
|
raise FileNotFoundError(
|
|
22
36
|
f"Template file not found: {template_path}\n"
|
|
23
37
|
"This might indicate a corrupted installation. Please reinstall afterpython."
|
|
24
38
|
)
|
|
25
|
-
|
|
39
|
+
target_path.parent.mkdir(parents=True, exist_ok=True)
|
|
26
40
|
shutil.copy(template_path, target_path)
|
|
27
|
-
print(f"Created {target_path}")
|
|
28
41
|
|
|
29
42
|
|
|
30
43
|
def create_workflow(workflow_name: str):
|
|
31
|
-
"""Create a GitHub Actions workflow from template"""
|
|
44
|
+
"""Create a GitHub Actions workflow from template (no-op if it exists)."""
|
|
32
45
|
if ".yml" in workflow_name:
|
|
33
46
|
workflow_name = workflow_name.replace(".yml", "")
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
_copy_github_template(
|
|
48
|
+
target_path, template_path = _resolve_workflow_target(workflow_name)
|
|
49
|
+
if target_path.exists():
|
|
50
|
+
click.echo(f"{target_path} already exists")
|
|
51
|
+
return
|
|
52
|
+
_copy_github_template(template_path, target_path)
|
|
53
|
+
click.echo(f"Created {target_path}")
|
|
40
54
|
|
|
41
55
|
|
|
42
56
|
def create_dependabot():
|
|
43
|
-
"""Create Dependabot configuration for GitHub Actions updates"""
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
"""Create Dependabot configuration for GitHub Actions updates."""
|
|
58
|
+
target_path, template_path = _resolve_workflow_target("dependabot")
|
|
59
|
+
if target_path.exists():
|
|
60
|
+
click.echo(f"{target_path} already exists")
|
|
61
|
+
return
|
|
62
|
+
_copy_github_template(template_path, target_path)
|
|
63
|
+
click.echo(f"Created {target_path}")
|
|
64
|
+
|
|
47
65
|
|
|
48
|
-
|
|
66
|
+
def update_workflow_file(name: str, backup: bool = True):
|
|
67
|
+
"""Overwrite a workflow file with the latest template.
|
|
68
|
+
|
|
69
|
+
If the target already exists and ``backup`` is True, the existing file is
|
|
70
|
+
copied to ``<file>.backup`` first so user customizations aren't lost.
|
|
71
|
+
"""
|
|
72
|
+
target_path, template_path = _resolve_workflow_target(name)
|
|
73
|
+
if target_path.exists():
|
|
74
|
+
if backup:
|
|
75
|
+
backup_path = Path(str(target_path) + ".backup")
|
|
76
|
+
shutil.copy(target_path, backup_path)
|
|
77
|
+
click.echo(f"Backed up {target_path} → {backup_path}")
|
|
78
|
+
_copy_github_template(template_path, target_path)
|
|
79
|
+
click.echo(f"Updated {target_path}")
|
|
80
|
+
else:
|
|
81
|
+
_copy_github_template(template_path, target_path)
|
|
82
|
+
click.echo(f"Created {target_path}")
|
afterpython/tools/pyproject.py
CHANGED
|
@@ -24,8 +24,14 @@ def write_pyproject(data: TOMLDocument):
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def read_metadata() -> StandardMetadata:
|
|
27
|
-
"""Read metadata from pyproject.toml
|
|
28
|
-
|
|
27
|
+
"""Read metadata from pyproject.toml.
|
|
28
|
+
|
|
29
|
+
Pass `project_dir` so relative paths (e.g. `readme = "README.md"`) resolve
|
|
30
|
+
against the project root rather than the caller's CWD.
|
|
31
|
+
"""
|
|
32
|
+
return StandardMetadata.from_pyproject(
|
|
33
|
+
read_pyproject(), project_dir=ap.paths.user_path
|
|
34
|
+
)
|
|
29
35
|
|
|
30
36
|
|
|
31
37
|
def find_package_directory() -> Path:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: afterpython
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
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
|
|
@@ -17,16 +17,17 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
17
17
|
Requires-Dist: click>=8.2.1
|
|
18
18
|
Requires-Dist: trogon>=0.6.0
|
|
19
19
|
Requires-Dist: httpx>=0.28.1
|
|
20
|
-
Requires-Dist: tomlkit>=0.
|
|
21
|
-
Requires-Dist: ruamel-yaml>=0.
|
|
22
|
-
Requires-Dist: gitpython>=3.1.
|
|
23
|
-
Requires-Dist: python-dotenv>=1.2.
|
|
24
|
-
Requires-Dist: pyproject-metadata>=0.
|
|
25
|
-
Requires-Dist:
|
|
26
|
-
Requires-Dist:
|
|
27
|
-
Requires-Dist:
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Requires-Dist:
|
|
20
|
+
Requires-Dist: tomlkit>=0.14.0
|
|
21
|
+
Requires-Dist: ruamel-yaml>=0.19.1
|
|
22
|
+
Requires-Dist: gitpython>=3.1.49
|
|
23
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
24
|
+
Requires-Dist: pyproject-metadata>=0.11.0
|
|
25
|
+
Requires-Dist: jupytext>=1.19.1
|
|
26
|
+
Requires-Dist: mystmd>=1.9.0
|
|
27
|
+
Requires-Dist: great-docs>=0.9
|
|
28
|
+
Requires-Dist: ruff>=0.15.12
|
|
29
|
+
Requires-Dist: pre-commit>=4.6.0
|
|
30
|
+
Requires-Dist: commitizen>=4.13.10
|
|
30
31
|
Requires-Python: >=3.11
|
|
31
32
|
Project-URL: homepage, https://afterpython.afterpython.org
|
|
32
33
|
Project-URL: repository, https://github.com/AfterPythonOrg/afterpython
|
|
@@ -36,11 +37,13 @@ Description-Content-Type: text/markdown
|
|
|
36
37
|
# AfterPython: Python Package Maintenance Toolkit and Project Website Generator
|
|
37
38
|
|
|
38
39
|
[](https://afterpython.org)
|
|
39
|
-
](https://pypi.org/project/afterpython)
|
|
41
|
-

|
|
40
|
+
[](https://pepy.tech/project/afterpython)
|
|
41
|
+
[](https://pypi.org/project/afterpython)
|
|
42
|
+

|
|
42
43
|
[](https://github.com/AfterPythonOrg/afterpython/discussions)
|
|
43
44
|
[](https://deepwiki.com/AfterPythonOrg/afterpython)
|
|
45
|
+
[](https://codewiki.google/github.com/afterpythonorg/afterpython?utm_source=badge&utm_medium=github&utm_campaign=github.com/afterpythonorg/afterpython)
|
|
46
|
+
<!--  -->
|
|
44
47
|
<!-- [](https://pixi.sh) -->
|
|
45
48
|
|
|
46
49
|
|
|
@@ -50,7 +53,7 @@ Description-Content-Type: text/markdown
|
|
|
50
53
|
[pre-commit]: https://pre-commit.com
|
|
51
54
|
[pagefind]: https://pagefind.app
|
|
52
55
|
[SemVer]: https://semver.org
|
|
53
|
-
[
|
|
56
|
+
[great-docs]: https://posit-dev.github.io/great-docs/
|
|
54
57
|
[GitHub Actions]: https://github.com/features/actions
|
|
55
58
|
[PyTorch]: https://pytorch.org
|
|
56
59
|
[Scikit-Learn]: https://scikit-learn.org
|
|
@@ -63,7 +66,7 @@ Description-Content-Type: text/markdown
|
|
|
63
66
|
|
|
64
67
|
## Problem
|
|
65
68
|
Going from **writing Python code to publishing and maintaining a package** is **time-consuming**.
|
|
66
|
-
First-time maintainers must learn multiple tools and concepts, e.g. [MyST], [SemVer], CI/CD ([pre-commit] hooks, GitHub workflows), and they often
|
|
69
|
+
First-time maintainers must learn multiple tools and concepts, e.g. [MyST], [SemVer], CI/CD ([pre-commit] hooks, GitHub workflows), and they often spend hours just to deploy a documentation site whereas well-resourced projects like [PyTorch] and [Scikit-Learn] have **dedicated websites** that serve as their project hubs.
|
|
67
70
|
|
|
68
71
|
|
|
69
72
|
## Solution
|
|
@@ -78,8 +81,8 @@ First-time maintainers must learn multiple tools and concepts, e.g. [MyST], [Sem
|
|
|
78
81
|
- [x] Go from writing to **website deployment in minutes** — no need to learn any of the underlying tools
|
|
79
82
|
- [x] Centralize all your content in a modern, **unified project website** — from documentation to blog posts
|
|
80
83
|
- [x] Zero-config orchestration — Pre-configured modern tooling with sane defaults (see [Tech Stack](#tech-stack)), so you can start maintaining packages immediately **without learning each tool**
|
|
84
|
+
- [x] **⚡ Full-text search** across **ALL** your content in your website — docs, blogs, tutorials, everything
|
|
81
85
|
- [ ] Export content as PDF — for example, combine all blog posts into a single PDF file
|
|
82
|
-
- [ ] **⚡ Full-text search** across **ALL** your content in your website — docs, blogs, tutorials, everything
|
|
83
86
|
- [ ] **🤖 Embedded AI Chatbot** that answers questions directly using an in-browser LLM — at no cost
|
|
84
87
|
|
|
85
88
|
---
|
|
@@ -121,7 +124,7 @@ ap tui
|
|
|
121
124
|
- [project-website-template]
|
|
122
125
|
- [pre-commit]
|
|
123
126
|
- [GitHub Actions]
|
|
124
|
-
- [
|
|
127
|
+
- [great-docs]
|
|
125
128
|
- [commitizen]
|
|
126
129
|
- [uv]
|
|
127
130
|
- [ruff]
|