sanitism 0.1.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.
- sanitism/__init__.py +3 -0
- sanitism/__main__.py +5 -0
- sanitism/cli.py +197 -0
- sanitism/overlay/AGENTS.md.tmpl +41 -0
- sanitism/overlay/Makefile.tmpl +53 -0
- sanitism/overlay/README.md.tmpl +97 -0
- sanitism/overlay/gitignore.tmpl +12 -0
- sanitism/overlay/pages.yml.tmpl +73 -0
- sanitism/overlay/pyproject.toml.tmpl +31 -0
- sanitism/overlay/shared/README.md.tmpl +26 -0
- sanitism/overlay/shared/manifest.yaml.tmpl +35 -0
- sanitism/overlay/shared/tables/example.csv +3 -0
- sanitism/project.py +468 -0
- sanitism-0.1.0.dist-info/METADATA +56 -0
- sanitism-0.1.0.dist-info/RECORD +17 -0
- sanitism-0.1.0.dist-info/WHEEL +4 -0
- sanitism-0.1.0.dist-info/entry_points.txt +2 -0
sanitism/__init__.py
ADDED
sanitism/__main__.py
ADDED
sanitism/cli.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""`sanitism`: set up one repository for a paper, its talks and what they share."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from . import project as pj
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _ask(prompt: str, default: str | None) -> str | None:
|
|
14
|
+
shown = f" [{default}]" if default else ""
|
|
15
|
+
try:
|
|
16
|
+
answer = input(f" {prompt}{shown}: ").strip()
|
|
17
|
+
except EOFError:
|
|
18
|
+
answer = ""
|
|
19
|
+
return answer or default
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def cmd_init(args: argparse.Namespace) -> int:
|
|
23
|
+
dest = Path(args.dir).resolve()
|
|
24
|
+
interactive = not args.yes and sys.stdin.isatty()
|
|
25
|
+
slug = args.name or pj.slugify(dest.name)
|
|
26
|
+
title = args.title or (
|
|
27
|
+
_ask("Title", slug.replace("-", " ").title()) if interactive
|
|
28
|
+
else slug.replace("-", " ").title()
|
|
29
|
+
)
|
|
30
|
+
author = args.author or pj.git_config("user.name")
|
|
31
|
+
email = args.email or pj.git_config("user.email")
|
|
32
|
+
if interactive:
|
|
33
|
+
author = args.author or _ask("Author", author)
|
|
34
|
+
email = args.email or _ask("Email", email)
|
|
35
|
+
answers = pj.Answers(slug, title or slug, author, email, args.description)
|
|
36
|
+
|
|
37
|
+
starters = [s for group in (args.starter or []) for s in group.split(",") if s]
|
|
38
|
+
try:
|
|
39
|
+
result = pj.create_project(
|
|
40
|
+
dest, answers,
|
|
41
|
+
starters=starters or None, first=args.first,
|
|
42
|
+
skills=not args.no_skills, force=args.force, git=args.git,
|
|
43
|
+
)
|
|
44
|
+
except pj.InitError as e:
|
|
45
|
+
print(f" error: {e}", file=sys.stderr)
|
|
46
|
+
return 1
|
|
47
|
+
|
|
48
|
+
here = Path.cwd().resolve()
|
|
49
|
+
shown = dest.relative_to(here) if dest.is_relative_to(here) else dest
|
|
50
|
+
tools = ", ".join(f"{name} {version}" for name, version in result.tools.items())
|
|
51
|
+
print(f" → {shown} ({answers.slug}, {tools})")
|
|
52
|
+
print(f" docs/ {', '.join('src/' + d + '/' for d in result.documents)}")
|
|
53
|
+
print(f" present/ {', '.join('presentations/' + p + '/' for p in result.presentations)}")
|
|
54
|
+
print(" shared/ manifest.yaml, imported by every manifest above")
|
|
55
|
+
if result.git:
|
|
56
|
+
print(f" git: {result.git}")
|
|
57
|
+
first_doc = "manuscript" if "manuscript" in result.documents else result.documents[0]
|
|
58
|
+
first_talk = result.presentations[0] if result.presentations else "kickoff"
|
|
59
|
+
print("\n next:")
|
|
60
|
+
if dest != here:
|
|
61
|
+
print(f" cd {shown}")
|
|
62
|
+
print(" make install # uv sync (one .venv), npm install in present/")
|
|
63
|
+
print(" # manim needs ffmpeg, cairo, pango, LaTeX;")
|
|
64
|
+
print(" # `uv sync --no-default-groups` skips it")
|
|
65
|
+
print(f" make docs-html VERSION={first_doc} # → docs/out/{first_doc}/html/index.html")
|
|
66
|
+
print(f" make dev TARGET={first_talk}:slides # the deck, with live reload")
|
|
67
|
+
print(" make check # both sides, before you share")
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def cmd_pages_init(args: argparse.Namespace) -> int:
|
|
72
|
+
root = pj.find_root(Path(args.root))
|
|
73
|
+
if root is None:
|
|
74
|
+
print(
|
|
75
|
+
f" error: no sanitism project at or above {Path(args.root).resolve()} "
|
|
76
|
+
f"(a folder with {pj.DOCS}/, {pj.PRESENT}/ and a Makefile)",
|
|
77
|
+
file=sys.stderr,
|
|
78
|
+
)
|
|
79
|
+
return 1
|
|
80
|
+
try:
|
|
81
|
+
path, notes = pj.pages_init(
|
|
82
|
+
root, branch=args.branch, pdf=not args.no_pdf, force=args.force
|
|
83
|
+
)
|
|
84
|
+
except pj.InitError as e:
|
|
85
|
+
print(f" error: {e}", file=sys.stderr)
|
|
86
|
+
return 1
|
|
87
|
+
print(f" → {path.relative_to(root)}")
|
|
88
|
+
print(" A Pages site is PUBLIC, even when the repository is private: every")
|
|
89
|
+
print(" document under docs/ and every presentation under present/ is published.")
|
|
90
|
+
print(" One-time setup: Settings → Pages → Build and deployment → Source: GitHub Actions.")
|
|
91
|
+
for note in notes:
|
|
92
|
+
print(f" note: {note}")
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def cmd_update(args: argparse.Namespace) -> int:
|
|
97
|
+
root = pj.find_root(Path(args.root))
|
|
98
|
+
if root is None:
|
|
99
|
+
print(
|
|
100
|
+
f" error: no sanitism project at or above {Path(args.root).resolve()} "
|
|
101
|
+
f"(a folder with {pj.DOCS}/, {pj.PRESENT}/ and a Makefile)",
|
|
102
|
+
file=sys.stderr,
|
|
103
|
+
)
|
|
104
|
+
return 1
|
|
105
|
+
if args.dry_run:
|
|
106
|
+
print(" (dry run: nothing is written)")
|
|
107
|
+
return pj.update_project(
|
|
108
|
+
root, shared=args.shared, lock=not args.no_lock, dry_run=args.dry_run
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
113
|
+
parser = argparse.ArgumentParser(
|
|
114
|
+
prog="sanitism",
|
|
115
|
+
description="One repository for a paper, its talks and what they share.",
|
|
116
|
+
)
|
|
117
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
118
|
+
sub = parser.add_subparsers(dest="command")
|
|
119
|
+
|
|
120
|
+
p_init = sub.add_parser(
|
|
121
|
+
"init",
|
|
122
|
+
help="Set up DIR with docs/ (document-sanity), present/ (presentation-sanity) and shared/",
|
|
123
|
+
description=(
|
|
124
|
+
"Run each tool's own `init` into DIR/docs and DIR/present, then add what "
|
|
125
|
+
"makes them one repository: shared/manifest.yaml (imported by every starter "
|
|
126
|
+
"manifest), a uv workspace so there is one environment, a Makefile, README, "
|
|
127
|
+
"AGENTS.md and both agent skills. Existing files are never overwritten "
|
|
128
|
+
"without --force."
|
|
129
|
+
),
|
|
130
|
+
)
|
|
131
|
+
p_init.add_argument("dir", nargs="?", default=".", metavar="DIR", help="Default: the current folder")
|
|
132
|
+
p_init.add_argument("--name", help="Project name (kebab-case; default: DIR's name)")
|
|
133
|
+
p_init.add_argument("--title", help="Title of the work (documents and the presentation project)")
|
|
134
|
+
p_init.add_argument("--author", help="Author name (default: git config user.name)")
|
|
135
|
+
p_init.add_argument("--email", help="Author email (default: git config user.email)")
|
|
136
|
+
p_init.add_argument("--description", help="One-line description")
|
|
137
|
+
p_init.add_argument("--starter", action="append", metavar="NAME",
|
|
138
|
+
help="Starter documents to keep in docs/: manuscript, proposal, or both "
|
|
139
|
+
"(default: both; repeat or comma-separate)")
|
|
140
|
+
p_init.add_argument("--first", metavar="FOLDER",
|
|
141
|
+
help="First presentation's folder under present/presentations/ (default: kickoff)")
|
|
142
|
+
p_init.add_argument("-y", "--yes", action="store_true", help="Don't prompt; use defaults")
|
|
143
|
+
p_init.add_argument("--git", action="store_true", help="git init and make a first commit")
|
|
144
|
+
p_init.add_argument("--force", action="store_true", help="Overwrite files that already exist")
|
|
145
|
+
p_init.add_argument("--no-skills", action="store_true", help="Don't install the agent skills")
|
|
146
|
+
p_init.set_defaults(func=cmd_init)
|
|
147
|
+
|
|
148
|
+
p_update = sub.add_parser(
|
|
149
|
+
"update",
|
|
150
|
+
help="Bring docs/ and present/ up to the current releases of both tools",
|
|
151
|
+
description=(
|
|
152
|
+
"Run `document-sanity update` in docs/ and `presentation-sanity update` in "
|
|
153
|
+
"present/, with the tools installed next to this package: each moves its "
|
|
154
|
+
"version pin, refreshes its agent skill at the repository root, and "
|
|
155
|
+
"present/ gets the files its shared/ Vue layer lacks. Then re-resolve "
|
|
156
|
+
"the one uv.lock. Run the newest release to update to it: "
|
|
157
|
+
"`uvx sanitism@latest update`."
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
p_update.add_argument("--root", "-r", default=".", help="Where to start (the root is found by walking up)")
|
|
161
|
+
p_update.add_argument("--shared", action="store_true",
|
|
162
|
+
help="Also take the template's version of present/shared/ files that differ")
|
|
163
|
+
p_update.add_argument("--no-lock", action="store_true", help="Don't run `uv lock`")
|
|
164
|
+
p_update.add_argument("--dry-run", action="store_true", help="Say what would change; write nothing")
|
|
165
|
+
p_update.set_defaults(func=cmd_update)
|
|
166
|
+
|
|
167
|
+
p_pages = sub.add_parser("pages", help="Publish on GitHub Pages")
|
|
168
|
+
pages_sub = p_pages.add_subparsers(dest="pages_command")
|
|
169
|
+
p_pages_init = pages_sub.add_parser(
|
|
170
|
+
"init",
|
|
171
|
+
help="Write the one workflow that builds docs/ and present/ into a single site",
|
|
172
|
+
description=(
|
|
173
|
+
"Write .github/workflows/pages.yml at the repository root. It runs "
|
|
174
|
+
"`make site` and deploys site/: docs/ under /docs/, present/ under "
|
|
175
|
+
"/present/. A Pages site is public, even from a private repository."
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
p_pages_init.add_argument("--root", "-r", default=".", help="Where to start (the root is found by walking up)")
|
|
179
|
+
p_pages_init.add_argument("--branch", default="main", help="Branch that deploys (default: main)")
|
|
180
|
+
p_pages_init.add_argument("--no-pdf", action="store_true", help="Publish HTML and Word only (no TeX on the runner)")
|
|
181
|
+
p_pages_init.add_argument("--force", action="store_true", help="Replace an existing workflow")
|
|
182
|
+
p_pages_init.set_defaults(func=cmd_pages_init)
|
|
183
|
+
p_pages.set_defaults(func=lambda args: (p_pages.print_help(), 0)[1])
|
|
184
|
+
return parser
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def main(argv: list[str] | None = None) -> int:
|
|
188
|
+
parser = build_parser()
|
|
189
|
+
args = parser.parse_args(argv)
|
|
190
|
+
if not getattr(args, "func", None):
|
|
191
|
+
parser.print_help()
|
|
192
|
+
return 0
|
|
193
|
+
return args.func(args)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
if __name__ == "__main__":
|
|
197
|
+
sys.exit(main())
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This repository holds one piece of work and everything written about it.
|
|
4
|
+
|
|
5
|
+
| Folder | What it is | Tool, and its project root |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| `docs/` | papers and proposals: `src/<doc>/manifest.yaml` + Markdown → PDF, HTML, Word | document-sanity; its ROOT is `docs/` |
|
|
8
|
+
| `present/` | talks and posts: `manifest.yaml` + `presentations/<id>/` → Slidev decks, VitePress blogs | presentation-sanity; its ROOT is `present/` |
|
|
9
|
+
| `shared/` | `manifest.yaml`, `figures/`, `tables/`: what both sides quote | imported by the manifests on both sides |
|
|
10
|
+
|
|
11
|
+
How to work on each side is in that tool's agent skill, installed at this
|
|
12
|
+
root: `.claude/skills/document-sanity/` and
|
|
13
|
+
`.claude/skills/presentation-sanity/` (also under `.agents/skills/`). Start
|
|
14
|
+
with the skill's `SKILL.md`. Both skills look for their project root by
|
|
15
|
+
walking up from the current folder; **here it is the subfolder above, not this
|
|
16
|
+
root**, and `init` is never the answer in this repository.
|
|
17
|
+
|
|
18
|
+
## Rules for this repository
|
|
19
|
+
|
|
20
|
+
- **The repository root is not a project of either tool.** Run
|
|
21
|
+
`uv run document-sanity … --root docs` and
|
|
22
|
+
`uv run presentation-sanity … --root present` (or `cd` into the folder).
|
|
23
|
+
Never create `manifest.yaml`, `presentations/` or `src/` at the root.
|
|
24
|
+
- **Anything quoted on both sides lives in `shared/manifest.yaml`** and is
|
|
25
|
+
imported. Before adding a variable, figure or table to a document or to
|
|
26
|
+
`present/manifest.yaml`, look there, and in the other side's manifest. If it
|
|
27
|
+
exists, use it; if the other side now needs something that is defined
|
|
28
|
+
locally, move the definition to `shared/` and delete the local one. A name
|
|
29
|
+
defined in both places is a build error by design. Never retype a number.
|
|
30
|
+
- **Never invent provenance.** `source`, `data`, `command` and `updated` say
|
|
31
|
+
where a value came from. Leave them out rather than guess.
|
|
32
|
+
- **One environment.** Python packages go in the root `pyproject.toml`
|
|
33
|
+
(`uv add` at the root); `uv sync` at the root installs both tools.
|
|
34
|
+
- **`make check` before you say done.** It runs both tools' checks.
|
|
35
|
+
- Each folder's own `AGENTS.md` or `README.md` has that side's ground rules;
|
|
36
|
+
they apply inside it.
|
|
37
|
+
|
|
38
|
+
## This project
|
|
39
|
+
|
|
40
|
+
<!-- What this work is, who the audience is, target venues, deadlines,
|
|
41
|
+
conventions the documents and talks should follow. -->
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
.PHONY: help install check dev site clean
|
|
2
|
+
|
|
3
|
+
# Where the site will be served from: empty at a domain root, "/<repo>" for a
|
|
4
|
+
# GitHub project site. The Pages workflow passes it.
|
|
5
|
+
BASE ?=
|
|
6
|
+
# Extra flags for each side of `make site`, e.g. DOCS_FLAGS=--no-pdf on a
|
|
7
|
+
# machine without TeX.
|
|
8
|
+
DOCS_FLAGS ?=
|
|
9
|
+
PRESENT_FLAGS ?=
|
|
10
|
+
UV_RUN ?= uv run
|
|
11
|
+
|
|
12
|
+
help:
|
|
13
|
+
@echo "Targets:"
|
|
14
|
+
@echo " install One environment for the repo (uv sync) and present/'s Node packages"
|
|
15
|
+
@echo " check Every document and every presentation: do all references resolve?"
|
|
16
|
+
@echo " docs-<x> A target of docs/Makefile, from here: make docs-pdf VERSION=manuscript"
|
|
17
|
+
@echo " dev A deck or post with live reload: make dev TARGET=kickoff:slides"
|
|
18
|
+
@echo " site docs/ and present/ built into site/ (what Pages publishes)"
|
|
19
|
+
@echo " clean Remove the built site/ folders"
|
|
20
|
+
@echo ""
|
|
21
|
+
@echo "Each side also works on its own: cd docs (document-sanity), cd present"
|
|
22
|
+
@echo "(presentation-sanity). What they share is declared in shared/manifest.yaml."
|
|
23
|
+
|
|
24
|
+
install:
|
|
25
|
+
uv sync
|
|
26
|
+
cd present && npm install
|
|
27
|
+
|
|
28
|
+
check:
|
|
29
|
+
$(UV_RUN) document-sanity check --root docs
|
|
30
|
+
$(UV_RUN) presentation-sanity check --root present
|
|
31
|
+
|
|
32
|
+
# Everything in docs/Makefile, without leaving the root:
|
|
33
|
+
# make docs-html VERSION=manuscript make docs-word make docs-preview
|
|
34
|
+
docs-%:
|
|
35
|
+
$(MAKE) -C docs $*
|
|
36
|
+
|
|
37
|
+
dev:
|
|
38
|
+
$(UV_RUN) presentation-sanity dev --root present $(TARGET)
|
|
39
|
+
|
|
40
|
+
# docs/ → site/docs/, present/ → site/present/, and an index linking both.
|
|
41
|
+
# A blog needs to know its final URL, hence BASE.
|
|
42
|
+
site:
|
|
43
|
+
$(UV_RUN) document-sanity site --root docs $(DOCS_FLAGS)
|
|
44
|
+
$(UV_RUN) presentation-sanity build --root present $(PRESENT_FLAGS) --base "$(BASE)/present/"
|
|
45
|
+
rm -rf site
|
|
46
|
+
mkdir -p site
|
|
47
|
+
cp -R docs/site site/docs
|
|
48
|
+
cp -R present/site site/present
|
|
49
|
+
@printf '%s\n' '@@INDEX_HTML@@' > site/index.html
|
|
50
|
+
@echo " → site/index.html"
|
|
51
|
+
|
|
52
|
+
clean:
|
|
53
|
+
rm -rf site docs/site present/site
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @@TITLE@@
|
|
2
|
+
|
|
3
|
+
@@DESCRIPTION@@
|
|
4
|
+
|
|
5
|
+
One repository for the work and everything written about it, set up by
|
|
6
|
+
[sanitism](https://sanitism.dev).
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
@@SLUG@@/
|
|
10
|
+
├── docs/ papers and proposals: Markdown + one manifest per document
|
|
11
|
+
│ → PDF, HTML and Word (document-sanity)
|
|
12
|
+
├── present/ talks and posts: one manifest, many presentations
|
|
13
|
+
│ → Slidev decks and VitePress blogs (presentation-sanity)
|
|
14
|
+
├── shared/ manifest.yaml, figures/, tables/: what both sides quote
|
|
15
|
+
├── pyproject.toml one environment and one uv.lock for the whole repo
|
|
16
|
+
└── Makefile install, check, site, and shortcuts into each side
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
make install # uv sync, and npm install in present/
|
|
23
|
+
make docs-html VERSION=@@FIRST_DOC@@ # → docs/out/@@FIRST_DOC@@/html/index.html
|
|
24
|
+
make dev TARGET=@@FIRST_PRESENTATION@@:slides # the deck, with live reload
|
|
25
|
+
make check # before you share anything
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`uv sync` needs manim's system libraries (ffmpeg, cairo, pango, LaTeX) for
|
|
29
|
+
`present/scenes/`; `uv sync --no-default-groups` skips manim. Commit the
|
|
30
|
+
`uv.lock` the first sync writes.
|
|
31
|
+
|
|
32
|
+
Each side is a complete project of its tool, so its own README and commands
|
|
33
|
+
apply inside it: `cd docs` and `uv run document-sanity …`, or `cd present` and
|
|
34
|
+
`uv run presentation-sanity …`. From the root, pass `--root docs` or
|
|
35
|
+
`--root present`.
|
|
36
|
+
|
|
37
|
+
## One number, everywhere
|
|
38
|
+
|
|
39
|
+
Anything the paper and a talk both quote is declared once in
|
|
40
|
+
[`shared/manifest.yaml`](shared/manifest.yaml):
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
variables:
|
|
44
|
+
cohort_size:
|
|
45
|
+
value: 12453
|
|
46
|
+
format: ","
|
|
47
|
+
description: "Participants after QC filtering"
|
|
48
|
+
source: "data/results.csv"
|
|
49
|
+
command: "python scripts/qc.py data/raw/ --out data/results.csv"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| | In `docs/` | In `present/` |
|
|
53
|
+
|---|---|---|
|
|
54
|
+
| a variable | `{{cohort_size}}` | `<DataValue var="cohort_size" />` |
|
|
55
|
+
| a figure in `shared/figures/<id>/` | `{{fig:id}}` | `<FigureImage figure="id" />` |
|
|
56
|
+
| a table in `shared/tables/` | `{{tab:id}}` | `<DataTable table="id" />` |
|
|
57
|
+
|
|
58
|
+
Change the value there and the PDF, the Word file, the HTML viewer, the deck
|
|
59
|
+
and the post all follow on the next build, each showing the same provenance.
|
|
60
|
+
The manifests under `docs/src/` and `present/manifest.yaml` already import
|
|
61
|
+
everything `shared/` declares; a manifest can import from another document or
|
|
62
|
+
from the presentation project the same way. See [shared/README.md](shared/README.md).
|
|
63
|
+
|
|
64
|
+
## Python packages
|
|
65
|
+
|
|
66
|
+
The root `pyproject.toml` is a uv workspace over `docs/` and `present/`, so
|
|
67
|
+
there is one `.venv` and one `uv.lock`. Add what your analysis needs with
|
|
68
|
+
`uv add <package>` at the root; scripts for the paper and for the talks then
|
|
69
|
+
import the same versions.
|
|
70
|
+
|
|
71
|
+
## Publish
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
make site # docs/ and present/ → site/
|
|
75
|
+
uvx sanitism pages init # one GitHub Pages workflow for both
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
A Pages site is **public**, even from a private repository.
|
|
79
|
+
|
|
80
|
+
## Upgrading the tools
|
|
81
|
+
|
|
82
|
+
`docs/pyproject.toml` pins document-sanity and `present/pyproject.toml` pins
|
|
83
|
+
presentation-sanity, each to a release tag. One command moves both to the
|
|
84
|
+
newest releases, re-resolves the one `uv.lock`, refreshes both agent skills
|
|
85
|
+
and adds what `present/shared/` lacks:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
uvx sanitism@latest update
|
|
89
|
+
uv sync
|
|
90
|
+
make check
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`--dry-run` says what would change. One side at a time works too:
|
|
94
|
+
`uvx document-sanity@latest update` inside `docs/`,
|
|
95
|
+
`uvx presentation-sanity@latest update` inside `present/`. Each tool's
|
|
96
|
+
[release notes](https://github.com/yakaboskic/sanitism#the-tools) say what a
|
|
97
|
+
release changed.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Build docs/ and present/ into one site and deploy it to GitHub Pages.
|
|
2
|
+
# Written by `sanitism pages init` (v@@VERSION@@); rerun it with --force to
|
|
3
|
+
# regenerate.
|
|
4
|
+
#
|
|
5
|
+
# A Pages site is PUBLIC, even when this repository is private. Everything
|
|
6
|
+
# `make site` builds is published: every document under docs/ (its HTML
|
|
7
|
+
# viewer with numbers and provenance, its PDF and its Word file) and every
|
|
8
|
+
# presentation under present/. `document-sanity site` refuses a document whose
|
|
9
|
+
# manifest sets metadata.notice (CUI, distribution statements).
|
|
10
|
+
#
|
|
11
|
+
# One-time setup: Settings → Pages → Build and deployment → Source: GitHub Actions.
|
|
12
|
+
#
|
|
13
|
+
# The runner does not render manim or export Excalidraw figures: it deploys
|
|
14
|
+
# the videos and figures committed in present/public/. Render locally, commit,
|
|
15
|
+
# push.@@TEX_NOTE@@
|
|
16
|
+
name: Deploy to GitHub Pages
|
|
17
|
+
|
|
18
|
+
on:
|
|
19
|
+
push:
|
|
20
|
+
branches: [@@BRANCH@@]
|
|
21
|
+
workflow_dispatch:
|
|
22
|
+
|
|
23
|
+
permissions:
|
|
24
|
+
contents: read
|
|
25
|
+
pages: write
|
|
26
|
+
id-token: write
|
|
27
|
+
|
|
28
|
+
concurrency:
|
|
29
|
+
group: pages
|
|
30
|
+
cancel-in-progress: false
|
|
31
|
+
|
|
32
|
+
jobs:
|
|
33
|
+
build:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v7
|
|
37
|
+
- id: pages
|
|
38
|
+
uses: actions/configure-pages@v6
|
|
39
|
+
- uses: astral-sh/setup-uv@v10.3.0
|
|
40
|
+
with:
|
|
41
|
+
enable-cache: true
|
|
42
|
+
- uses: actions/setup-node@v7
|
|
43
|
+
with:
|
|
44
|
+
node-version: 24
|
|
45
|
+
cache: npm
|
|
46
|
+
cache-dependency-path: present/package-lock.json
|
|
47
|
+
@@TEX_STEP@@ - name: Install document-sanity and presentation-sanity (no manim)
|
|
48
|
+
run: uv sync --locked --no-default-groups
|
|
49
|
+
- name: Install Slidev and VitePress
|
|
50
|
+
working-directory: present
|
|
51
|
+
run: npm ci
|
|
52
|
+
- name: Build site/
|
|
53
|
+
# base_path is "/<repo>" for a project site, "" for a custom domain or
|
|
54
|
+
# a <user>.github.io repository. Blogs need it absolute.
|
|
55
|
+
run: >-
|
|
56
|
+
make site
|
|
57
|
+
UV_RUN="uv run --no-sync"
|
|
58
|
+
BASE="${{ steps.pages.outputs.base_path }}"
|
|
59
|
+
DOCS_FLAGS="@@DOCS_FLAGS@@"
|
|
60
|
+
PRESENT_FLAGS="--skip-manim --skip-figures"
|
|
61
|
+
- uses: actions/upload-pages-artifact@v5
|
|
62
|
+
with:
|
|
63
|
+
path: site
|
|
64
|
+
|
|
65
|
+
deploy:
|
|
66
|
+
needs: build
|
|
67
|
+
runs-on: ubuntu-latest
|
|
68
|
+
environment:
|
|
69
|
+
name: github-pages
|
|
70
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
71
|
+
steps:
|
|
72
|
+
- id: deployment
|
|
73
|
+
uses: actions/deploy-pages@v5
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "@@SLUG@@"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "@@DESCRIPTION@@"
|
|
5
|
+
requires-python = ">=3.10"
|
|
6
|
+
# One environment and one uv.lock for the whole repository. `docs` and
|
|
7
|
+
# `present` are workspace members, each pinning its own tool to a release.
|
|
8
|
+
# Packages the paper and the talks both use (analysis, plotting) go here.
|
|
9
|
+
dependencies = [
|
|
10
|
+
"@@SLUG@@-docs",
|
|
11
|
+
"@@SLUG@@-present",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
# manim renders present/scenes/*.py (the machine needs ffmpeg, cairo, pango and
|
|
15
|
+
# LaTeX). `uv sync` installs it; `uv sync --no-default-groups` leaves it out,
|
|
16
|
+
# which is what the Pages workflow and a co-author without those tools use.
|
|
17
|
+
# In a workspace this group has to be declared here: the one in
|
|
18
|
+
# present/pyproject.toml only applies when that folder is synced on its own.
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
manim = ["presentation-sanity[manim]"]
|
|
21
|
+
|
|
22
|
+
[tool.uv]
|
|
23
|
+
package = false
|
|
24
|
+
default-groups = ["manim"]
|
|
25
|
+
|
|
26
|
+
[tool.uv.workspace]
|
|
27
|
+
members = ["docs", "present"]
|
|
28
|
+
|
|
29
|
+
[tool.uv.sources]
|
|
30
|
+
@@SLUG@@-docs = { workspace = true }
|
|
31
|
+
@@SLUG@@-present = { workspace = true }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# shared/
|
|
2
|
+
|
|
3
|
+
What the paper and the talks both quote, declared once.
|
|
4
|
+
|
|
5
|
+
| Here | In `docs/` (document-sanity) | In `present/` (presentation-sanity) |
|
|
6
|
+
|---|---|---|
|
|
7
|
+
| a variable in `manifest.yaml` | `{{name}}` | `<DataValue var="name" />` |
|
|
8
|
+
| `figures/<id>/<id>.{pdf,png,svg}` + an entry under `figures:` | `{{fig:id}}` | `<FigureImage figure="id" />` |
|
|
9
|
+
| `tables/<file>.csv` + an entry under `tables:` | `{{tab:id}}` | `<DataTable table="id" />` |
|
|
10
|
+
|
|
11
|
+
Every manifest that should see these has an `imports:` block pointing here;
|
|
12
|
+
`sanitism init` wrote one into each starter. A new document or project needs
|
|
13
|
+
its own:
|
|
14
|
+
|
|
15
|
+
```yaml
|
|
16
|
+
imports:
|
|
17
|
+
- from: ../../../shared # relative to that manifest; everything declared here
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
An import resolves or the build stops, and a name can't be declared both here
|
|
21
|
+
and in a manifest that imports it. The rules, in full:
|
|
22
|
+
[imports](https://github.com/yakaboskic/document-sanity/blob/main/docs/imports.md).
|
|
23
|
+
|
|
24
|
+
Data and the scripts that produce these values can live here too
|
|
25
|
+
(`shared/data/`, `shared/scripts/`); the `source` and `command` fields of a
|
|
26
|
+
variable are relative to this folder.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# What the paper and the talks both quote. Every document under docs/ and the
|
|
2
|
+
# presentation project in present/ import from this file (see `imports:` in
|
|
3
|
+
# their manifests), so a number, figure or table declared here is written
|
|
4
|
+
# down once.
|
|
5
|
+
#
|
|
6
|
+
# docs: {{example_shared_count}} {{fig:<id>}} {{tab:example_shared_table}}
|
|
7
|
+
# present: <DataValue var="example_shared_count" />
|
|
8
|
+
# <FigureImage figure="<id>" /> <DataTable table="example_shared_table" />
|
|
9
|
+
#
|
|
10
|
+
# A name declared here can't also be declared in a manifest that imports it:
|
|
11
|
+
# move the definition, don't copy it. Rules: document-sanity's docs/imports.md.
|
|
12
|
+
|
|
13
|
+
variables:
|
|
14
|
+
# An example. Replace it with a number your paper and your talks both quote.
|
|
15
|
+
example_shared_count:
|
|
16
|
+
value: 12453
|
|
17
|
+
format: "," # the format a bare token or <DataValue> uses
|
|
18
|
+
description: "Participants after QC filtering (an example value)"
|
|
19
|
+
# Where it comes from. Informational: nothing here is run by a build.
|
|
20
|
+
# source: "data/results.csv"
|
|
21
|
+
# command: "python scripts/qc.py data/raw/ --out data/results.csv"
|
|
22
|
+
# updated: "2026-01-01"
|
|
23
|
+
|
|
24
|
+
# One folder per figure, in as many formats as you have:
|
|
25
|
+
# figures/<id>/<id>.pdf print (the PDF)
|
|
26
|
+
# figures/<id>/<id>.png Word, and decks when there is no .svg
|
|
27
|
+
# figures/<id>/<id>.svg the HTML viewer, decks and posts
|
|
28
|
+
# Declare it here, then use it by id on either side.
|
|
29
|
+
# figures:
|
|
30
|
+
# study_design:
|
|
31
|
+
# width: "0.8\\textwidth"
|
|
32
|
+
|
|
33
|
+
tables:
|
|
34
|
+
example_shared_table:
|
|
35
|
+
source: tables/example.csv # csv, tsv or a markdown pipe table
|
sanitism/project.py
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
"""`sanitism init`: a paper, its talks and what they share, in one repository.
|
|
2
|
+
|
|
3
|
+
Nothing here is a third template. `init` runs `document-sanity init` into
|
|
4
|
+
`docs/` and `presentation-sanity init` into `present/`, each from the snapshot
|
|
5
|
+
and with the version pin of the tool installed next to this package, then adds
|
|
6
|
+
the thin layer that makes them one repository:
|
|
7
|
+
|
|
8
|
+
- `shared/`: a manifest (with `figures/` and `tables/`) that every starter
|
|
9
|
+
manifest on both sides imports from;
|
|
10
|
+
- a root `pyproject.toml`, a uv workspace over the two folders, so there is
|
|
11
|
+
one environment and one lock;
|
|
12
|
+
- a `Makefile`, `README.md`, `AGENTS.md` and `.gitignore`;
|
|
13
|
+
- both agent skills, installed once at the root.
|
|
14
|
+
|
|
15
|
+
The repository root is deliberately not a project of either tool. Each tool
|
|
16
|
+
finds its own root by walking up, so commands run from inside `docs/` or
|
|
17
|
+
`present/`, or from the root with `--root`.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import html
|
|
23
|
+
import os
|
|
24
|
+
import re
|
|
25
|
+
import shutil
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
28
|
+
from dataclasses import dataclass, field
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
import yaml
|
|
32
|
+
|
|
33
|
+
from . import __version__
|
|
34
|
+
|
|
35
|
+
DOCS = "docs"
|
|
36
|
+
PRESENT = "present"
|
|
37
|
+
SHARED = "shared"
|
|
38
|
+
OVERLAY = Path(__file__).parent / "overlay"
|
|
39
|
+
# Claude Code reads .claude/skills/; Codex, Pi, Cursor and others .agents/skills/.
|
|
40
|
+
SKILL_DIRS = (".claude/skills", ".agents/skills")
|
|
41
|
+
WORKFLOW = ".github/workflows/pages.yml"
|
|
42
|
+
_NAME_RE = re.compile(r"^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$")
|
|
43
|
+
|
|
44
|
+
IMPORT_BLOCK = """
|
|
45
|
+
# What this manifest takes from the rest of the repository: every variable,
|
|
46
|
+
# figure and table declared in shared/manifest.yaml (written by `sanitism
|
|
47
|
+
# init`). Narrow it with `variables: [a, b]`, or add another `- from:` for a
|
|
48
|
+
# document or the presentation project.
|
|
49
|
+
imports:
|
|
50
|
+
- from: {path}
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class InitError(Exception):
|
|
55
|
+
"""The project could not be set up as asked."""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass
|
|
59
|
+
class Answers:
|
|
60
|
+
slug: str
|
|
61
|
+
title: str
|
|
62
|
+
author: str | None = None
|
|
63
|
+
email: str | None = None
|
|
64
|
+
description: str | None = None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@dataclass
|
|
68
|
+
class Result:
|
|
69
|
+
dest: Path
|
|
70
|
+
answers: Answers
|
|
71
|
+
documents: list[str] = field(default_factory=list)
|
|
72
|
+
presentations: list[str] = field(default_factory=list)
|
|
73
|
+
written: list[str] = field(default_factory=list)
|
|
74
|
+
tools: dict[str, str] = field(default_factory=dict)
|
|
75
|
+
git: str | None = None
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def slugify(name: str) -> str:
|
|
79
|
+
slug = re.sub(r"[^A-Za-z0-9._-]+", "-", name.strip()).strip("-._").lower()
|
|
80
|
+
return slug or "project"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def git_config(key: str) -> str | None:
|
|
84
|
+
try:
|
|
85
|
+
out = subprocess.run(
|
|
86
|
+
["git", "config", "--get", key], capture_output=True, text=True, check=False
|
|
87
|
+
).stdout.strip()
|
|
88
|
+
except OSError:
|
|
89
|
+
return None
|
|
90
|
+
return out or None
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def tool_version(module: str) -> str:
|
|
94
|
+
return __import__(module).__version__
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# ── the root layer ───────────────────────────────────────────────────────────
|
|
98
|
+
|
|
99
|
+
def _render(name: str, values: dict[str, str]) -> str:
|
|
100
|
+
text = (OVERLAY / name).read_text(encoding="utf-8")
|
|
101
|
+
for key, value in values.items():
|
|
102
|
+
text = text.replace(f"@@{key}@@", value)
|
|
103
|
+
left = re.findall(r"@@[A-Z_]+@@", text)
|
|
104
|
+
if left:
|
|
105
|
+
raise InitError(f"{name}: unfilled {', '.join(sorted(set(left)))}")
|
|
106
|
+
return text
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _toml(value: str) -> str:
|
|
110
|
+
return value.replace("\\", "\\\\").replace('"', '\\"')
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def index_html(title: str) -> str:
|
|
114
|
+
"""The landing page `make site` writes: one line, safe inside '…' in a recipe."""
|
|
115
|
+
t = html.escape(title, quote=True)
|
|
116
|
+
page = (
|
|
117
|
+
'<!doctype html><meta charset="utf-8">'
|
|
118
|
+
'<meta name="viewport" content="width=device-width, initial-scale=1">'
|
|
119
|
+
f"<title>{t}</title>"
|
|
120
|
+
"<style>:root{color-scheme:light dark}"
|
|
121
|
+
"body{font:16px/1.6 ui-sans-serif,system-ui,sans-serif;max-width:34rem;"
|
|
122
|
+
"margin:18vh auto;padding:0 1.5rem}"
|
|
123
|
+
"h1{font-size:1.6rem;font-weight:600;margin:0 0 1.5rem}"
|
|
124
|
+
"ul{list-style:none;padding:0}li{margin:.7rem 0}"
|
|
125
|
+
"a{text-decoration:none;border-bottom:1px solid currentColor;font-weight:500}"
|
|
126
|
+
"span{opacity:.55;font-size:.85em;margin-left:.6em}</style>"
|
|
127
|
+
f"<h1>{t}</h1><ul>"
|
|
128
|
+
'<li><a href="./docs/">Documents</a><span>papers and proposals: HTML, PDF, Word</span></li>'
|
|
129
|
+
'<li><a href="./present/">Presentations</a><span>slide decks and posts</span></li>'
|
|
130
|
+
"</ul>"
|
|
131
|
+
)
|
|
132
|
+
# html.escape turned every ' into ', so '…' in the recipe stays closed;
|
|
133
|
+
# make reads $ as a variable.
|
|
134
|
+
return page.replace("$", "$$")
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def root_files(a: Answers, first_doc: str, first_presentation: str) -> dict[str, str]:
|
|
138
|
+
description = a.description or f"{a.title}: the paper, the talks and what they share"
|
|
139
|
+
values = {
|
|
140
|
+
"SLUG": a.slug,
|
|
141
|
+
"TITLE": a.title,
|
|
142
|
+
"DESCRIPTION": description,
|
|
143
|
+
"FIRST_DOC": first_doc,
|
|
144
|
+
"FIRST_PRESENTATION": first_presentation,
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
"pyproject.toml": _render(
|
|
148
|
+
"pyproject.toml.tmpl", {**values, "DESCRIPTION": _toml(description)}),
|
|
149
|
+
"Makefile": _render("Makefile.tmpl", {"INDEX_HTML": index_html(a.title)}),
|
|
150
|
+
"README.md": _render("README.md.tmpl", values),
|
|
151
|
+
"AGENTS.md": _render("AGENTS.md.tmpl", {}),
|
|
152
|
+
".gitignore": _render("gitignore.tmpl", {}),
|
|
153
|
+
f"{SHARED}/manifest.yaml": _render("shared/manifest.yaml.tmpl", {}),
|
|
154
|
+
f"{SHARED}/README.md": _render("shared/README.md.tmpl", {}),
|
|
155
|
+
f"{SHARED}/tables/example.csv": (OVERLAY / "shared/tables/example.csv").read_text(),
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def skill_files() -> dict[str, bytes]:
|
|
160
|
+
"""Both tools' agent skills, for the root's .claude/skills and .agents/skills."""
|
|
161
|
+
from document_sanity.init_project import skill_dir as document_skill
|
|
162
|
+
from presentation_sanity.init_project import skill_dir as presentation_skill
|
|
163
|
+
|
|
164
|
+
files: dict[str, bytes] = {}
|
|
165
|
+
for name, source in (
|
|
166
|
+
("document-sanity", document_skill()),
|
|
167
|
+
("presentation-sanity", presentation_skill()),
|
|
168
|
+
):
|
|
169
|
+
for path in sorted(source.rglob("*")):
|
|
170
|
+
if path.is_file() and "__pycache__" not in path.parts and path.name != ".DS_Store":
|
|
171
|
+
rel = path.relative_to(source).as_posix()
|
|
172
|
+
for base in SKILL_DIRS:
|
|
173
|
+
files[f"{base}/{name}/{rel}"] = path.read_bytes()
|
|
174
|
+
return files
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# ── the two sides ────────────────────────────────────────────────────────────
|
|
178
|
+
|
|
179
|
+
def _run_tool(module: str, args: list[str]) -> None:
|
|
180
|
+
proc = subprocess.run(
|
|
181
|
+
[sys.executable, "-m", module, *args], capture_output=True, text=True, check=False
|
|
182
|
+
)
|
|
183
|
+
if proc.returncode != 0:
|
|
184
|
+
detail = (proc.stderr.strip() or proc.stdout.strip() or "no output").strip()
|
|
185
|
+
raise InitError(f"`{module.replace('_', '-')} {' '.join(args[:2])}` failed:\n{detail}")
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _common(a: Answers, suffix: str) -> list[str]:
|
|
189
|
+
args = ["--yes", "--no-skills", "--name", f"{a.slug}-{suffix}", "--title", a.title]
|
|
190
|
+
for flag, value in (("--author", a.author), ("--email", a.email)):
|
|
191
|
+
if value:
|
|
192
|
+
args += [flag, value]
|
|
193
|
+
return args
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def add_import(manifest: Path, shared: Path) -> bool:
|
|
197
|
+
"""Point `manifest` at `shared`; False when it already has an `imports:`."""
|
|
198
|
+
text = manifest.read_text(encoding="utf-8")
|
|
199
|
+
raw = yaml.safe_load(text) or {}
|
|
200
|
+
if not isinstance(raw, dict) or raw.get("imports"):
|
|
201
|
+
return False
|
|
202
|
+
rel = Path(os.path.relpath(shared, manifest.parent)).as_posix()
|
|
203
|
+
manifest.write_text(
|
|
204
|
+
text.rstrip("\n") + "\n" + IMPORT_BLOCK.format(path=rel), encoding="utf-8"
|
|
205
|
+
)
|
|
206
|
+
yaml.safe_load(manifest.read_text(encoding="utf-8")) # still one valid document
|
|
207
|
+
return True
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def documents(docs: Path) -> list[str]:
|
|
211
|
+
src = docs / "src"
|
|
212
|
+
if not src.is_dir():
|
|
213
|
+
return []
|
|
214
|
+
return sorted(d.name for d in src.iterdir() if (d / "manifest.yaml").is_file())
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def presentations(present: Path) -> list[str]:
|
|
218
|
+
base = present / "presentations"
|
|
219
|
+
if not base.is_dir():
|
|
220
|
+
return []
|
|
221
|
+
return sorted(
|
|
222
|
+
d.relative_to(base).as_posix()
|
|
223
|
+
for d in base.rglob("*")
|
|
224
|
+
if d.is_dir() and ((d / "slides.md").is_file() or (d / "blog.md").is_file())
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _is_tool_project(dest: Path) -> str | None:
|
|
229
|
+
if (dest / "manifest.yaml").is_file() and (dest / "presentations").is_dir():
|
|
230
|
+
return "a presentation-sanity project"
|
|
231
|
+
if documents(dest):
|
|
232
|
+
return "a document-sanity project"
|
|
233
|
+
return None
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def create_project(
|
|
237
|
+
dest: Path,
|
|
238
|
+
answers: Answers,
|
|
239
|
+
*,
|
|
240
|
+
starters: list[str] | None = None,
|
|
241
|
+
first: str | None = None,
|
|
242
|
+
skills: bool = True,
|
|
243
|
+
force: bool = False,
|
|
244
|
+
git: bool = False,
|
|
245
|
+
) -> Result:
|
|
246
|
+
"""Set up `dest`: docs/, present/, shared/ and the root layer."""
|
|
247
|
+
if not _NAME_RE.match(answers.slug):
|
|
248
|
+
raise InitError(f"{answers.slug!r} is not a usable project name (letters, digits, - . _)")
|
|
249
|
+
if dest.exists() and not dest.is_dir():
|
|
250
|
+
raise InitError(f"{dest} exists and is not a directory")
|
|
251
|
+
kind = _is_tool_project(dest) if dest.is_dir() else None
|
|
252
|
+
if kind:
|
|
253
|
+
raise InitError(
|
|
254
|
+
f"{dest} is already {kind}. sanitism puts each tool's project in its own "
|
|
255
|
+
f"subfolder ({DOCS}/, {PRESENT}/) and keeps the root for what they share, "
|
|
256
|
+
"so it can't be set up on top of one. Start in a new folder and move "
|
|
257
|
+
"the existing project into it."
|
|
258
|
+
)
|
|
259
|
+
taken = [d for d in (DOCS, PRESENT) if (dest / d).is_dir() and any((dest / d).iterdir())]
|
|
260
|
+
if taken and not force:
|
|
261
|
+
raise InitError(
|
|
262
|
+
f"{dest} already has {' and '.join(t + '/' for t in taken)}; nothing was "
|
|
263
|
+
"written. --force lets each tool write into what is there (existing files "
|
|
264
|
+
"that differ are still refused by the tool itself)."
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
# Decide the root layer before touching disk, so a conflict stops everything.
|
|
268
|
+
first_presentation = first or "kickoff"
|
|
269
|
+
placeholder = root_files(answers, "manuscript", first_presentation)
|
|
270
|
+
extra = skill_files() if skills else {}
|
|
271
|
+
conflicts = sorted(rel for rel in (*placeholder, *extra) if (dest / rel).exists())
|
|
272
|
+
if conflicts and not force:
|
|
273
|
+
shown = "\n".join(f" {c}" for c in conflicts[:20])
|
|
274
|
+
more = f"\n … and {len(conflicts) - 20} more" if len(conflicts) > 20 else ""
|
|
275
|
+
raise InitError(
|
|
276
|
+
f"{dest} already has files this would replace; nothing was written:\n"
|
|
277
|
+
f"{shown}{more}\n --force overwrites them."
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
281
|
+
doc_args = ["init", str(dest / DOCS), *_common(answers, DOCS)]
|
|
282
|
+
for starter in starters or []:
|
|
283
|
+
doc_args += ["--starter", starter]
|
|
284
|
+
pres_args = ["init", str(dest / PRESENT), *_common(answers, PRESENT)]
|
|
285
|
+
if first:
|
|
286
|
+
pres_args += ["--first", first]
|
|
287
|
+
if force:
|
|
288
|
+
doc_args.append("--force")
|
|
289
|
+
pres_args.append("--force")
|
|
290
|
+
_run_tool("document_sanity", doc_args)
|
|
291
|
+
_run_tool("presentation_sanity", pres_args)
|
|
292
|
+
|
|
293
|
+
docs = documents(dest / DOCS)
|
|
294
|
+
talks = presentations(dest / PRESENT)
|
|
295
|
+
if not docs:
|
|
296
|
+
raise InitError(f"document-sanity made no document under {dest / DOCS / 'src'}")
|
|
297
|
+
shared = dest / SHARED
|
|
298
|
+
for doc in docs:
|
|
299
|
+
add_import(dest / DOCS / "src" / doc / "manifest.yaml", shared)
|
|
300
|
+
add_import(dest / PRESENT / "manifest.yaml", shared)
|
|
301
|
+
|
|
302
|
+
first_doc = "manuscript" if "manuscript" in docs else docs[0]
|
|
303
|
+
files = root_files(answers, first_doc, talks[0] if talks else first_presentation)
|
|
304
|
+
written: list[str] = []
|
|
305
|
+
for rel, text in files.items():
|
|
306
|
+
path = dest / rel
|
|
307
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
308
|
+
path.write_text(text, encoding="utf-8")
|
|
309
|
+
written.append(rel)
|
|
310
|
+
for rel, data in extra.items():
|
|
311
|
+
path = dest / rel
|
|
312
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
313
|
+
path.write_bytes(data)
|
|
314
|
+
written.append(rel)
|
|
315
|
+
|
|
316
|
+
result = Result(
|
|
317
|
+
dest, answers, docs, talks, written,
|
|
318
|
+
tools={
|
|
319
|
+
"document-sanity": tool_version("document_sanity"),
|
|
320
|
+
"presentation-sanity": tool_version("presentation_sanity"),
|
|
321
|
+
},
|
|
322
|
+
)
|
|
323
|
+
if git:
|
|
324
|
+
result.git = git_init(
|
|
325
|
+
dest,
|
|
326
|
+
f"Start {answers.slug} with sanitism {__version__}\n\n"
|
|
327
|
+
+ "\n".join(f"{name} {version}" for name, version in result.tools.items()),
|
|
328
|
+
)
|
|
329
|
+
return result
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def git_init(dest: Path, message: str) -> str:
|
|
333
|
+
"""`git init` and a first commit; says what happened.
|
|
334
|
+
|
|
335
|
+
A folder that is already inside a repository is left alone, as both tools'
|
|
336
|
+
own `init --git` do: `git add -A` there would stage the enclosing tree.
|
|
337
|
+
"""
|
|
338
|
+
if shutil.which("git") is None:
|
|
339
|
+
return "git not found: skipped"
|
|
340
|
+
|
|
341
|
+
def run(*args: str) -> subprocess.CompletedProcess[str]:
|
|
342
|
+
return subprocess.run(["git", *args], cwd=dest, capture_output=True, text=True)
|
|
343
|
+
|
|
344
|
+
if run("rev-parse", "--is-inside-work-tree").stdout.strip() == "true":
|
|
345
|
+
return "already inside a git repository: left it alone (commit when ready)"
|
|
346
|
+
if run("init", "-q", "-b", "main").returncode != 0 and run("init", "-q").returncode != 0:
|
|
347
|
+
return "git init failed"
|
|
348
|
+
run("add", "-A")
|
|
349
|
+
commit = run("commit", "-q", "-m", message)
|
|
350
|
+
if commit.returncode != 0:
|
|
351
|
+
return "git repository created; the first commit failed (set git user.name and user.email)"
|
|
352
|
+
return "git repository created with a first commit"
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
# ── pages ────────────────────────────────────────────────────────────────────
|
|
356
|
+
|
|
357
|
+
TEX_STEP = """\
|
|
358
|
+
- name: Install TeX (pdflatex, bibtex)
|
|
359
|
+
run: |
|
|
360
|
+
sudo apt-get update
|
|
361
|
+
sudo apt-get install -y --no-install-recommends \\
|
|
362
|
+
texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended lmodern
|
|
363
|
+
"""
|
|
364
|
+
TEX_NOTE = """
|
|
365
|
+
#
|
|
366
|
+
# PDFs need TeX: the build job installs a TeX Live subset from Ubuntu's
|
|
367
|
+
# packages (about a minute or two per run). If a template \\usepackage's
|
|
368
|
+
# something outside it, the PDF step fails with a missing .sty. Rerun with
|
|
369
|
+
# `pages init --no-pdf --force` to publish HTML and Word only."""
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def find_root(start: Path) -> Path | None:
|
|
373
|
+
"""The nearest folder at or above `start` that `sanitism init` set up."""
|
|
374
|
+
start = start.resolve()
|
|
375
|
+
for d in (start, *start.parents):
|
|
376
|
+
if (d / DOCS).is_dir() and (d / PRESENT).is_dir() and (d / "Makefile").is_file():
|
|
377
|
+
return d
|
|
378
|
+
return None
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def render_workflow(*, branch: str = "main", pdf: bool = True) -> str:
|
|
382
|
+
return _render("pages.yml.tmpl", {
|
|
383
|
+
"VERSION": __version__,
|
|
384
|
+
"BRANCH": branch,
|
|
385
|
+
"TEX_STEP": TEX_STEP if pdf else "",
|
|
386
|
+
"TEX_NOTE": TEX_NOTE if pdf else "",
|
|
387
|
+
"DOCS_FLAGS": "" if pdf else "--no-pdf",
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def pages_init(
|
|
392
|
+
root: Path, *, branch: str = "main", pdf: bool = True, force: bool = False
|
|
393
|
+
) -> tuple[Path, list[str]]:
|
|
394
|
+
"""Write the one workflow that publishes both sides. Returns (path, notes)."""
|
|
395
|
+
makefile = root / "Makefile"
|
|
396
|
+
if not re.search(r"^site:", makefile.read_text(encoding="utf-8"), re.M):
|
|
397
|
+
raise InitError(
|
|
398
|
+
f"{makefile} has no `site` target; the workflow runs `make site`. "
|
|
399
|
+
"Restore it from a fresh `sanitism init`."
|
|
400
|
+
)
|
|
401
|
+
path = root / WORKFLOW
|
|
402
|
+
text = render_workflow(branch=branch, pdf=pdf)
|
|
403
|
+
if path.is_file() and path.read_text(encoding="utf-8") != text and not force:
|
|
404
|
+
raise InitError(f"{path} exists and differs; --force replaces it")
|
|
405
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
406
|
+
path.write_text(text, encoding="utf-8")
|
|
407
|
+
|
|
408
|
+
notes = []
|
|
409
|
+
for lock, how in (
|
|
410
|
+
("uv.lock", "uv sync"),
|
|
411
|
+
(f"{PRESENT}/package-lock.json", f"npm install in {PRESENT}/"),
|
|
412
|
+
):
|
|
413
|
+
if not (root / lock).is_file():
|
|
414
|
+
notes.append(f"no {lock}: run `{how}` and commit it (the workflow installs from it)")
|
|
415
|
+
for nested in (f"{DOCS}/{WORKFLOW}", f"{PRESENT}/{WORKFLOW}"):
|
|
416
|
+
if (root / nested).is_file():
|
|
417
|
+
notes.append(
|
|
418
|
+
f"{nested} is never run by GitHub (workflows live at the repository "
|
|
419
|
+
"root): delete it"
|
|
420
|
+
)
|
|
421
|
+
return path, notes
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
# ── update ───────────────────────────────────────────────────────────────────
|
|
425
|
+
|
|
426
|
+
def update_project(
|
|
427
|
+
root: Path, *, shared: bool = False, lock: bool = True, dry_run: bool = False
|
|
428
|
+
) -> int:
|
|
429
|
+
"""Bring both sides up to the tools installed next to this package.
|
|
430
|
+
|
|
431
|
+
Runs each tool's own `update` in its folder (the pin, the agent skill at
|
|
432
|
+
this root, and for `present/` the shared Vue layer), then re-resolves the
|
|
433
|
+
workspace's one lock. Returns a process exit code; the tools print what
|
|
434
|
+
they did.
|
|
435
|
+
"""
|
|
436
|
+
flags = ["--no-lock"] + (["--dry-run"] if dry_run else [])
|
|
437
|
+
status = 0
|
|
438
|
+
for module, folder, extra in (
|
|
439
|
+
("document_sanity", DOCS, []),
|
|
440
|
+
("presentation_sanity", PRESENT, ["--shared"] if shared else []),
|
|
441
|
+
):
|
|
442
|
+
proc = subprocess.run(
|
|
443
|
+
[sys.executable, "-m", module, "update", "--root", str(root / folder), *flags, *extra]
|
|
444
|
+
)
|
|
445
|
+
status = status or proc.returncode
|
|
446
|
+
workflow = root / WORKFLOW
|
|
447
|
+
if workflow.is_file():
|
|
448
|
+
m = re.search(r"Written by `sanitism pages init` \(v([^)]+)\)", workflow.read_text(encoding="utf-8"))
|
|
449
|
+
if m and m.group(1) != __version__:
|
|
450
|
+
print(f" note: {WORKFLOW} was written by sanitism v{m.group(1)}: "
|
|
451
|
+
"`sanitism pages init --force` regenerates it")
|
|
452
|
+
if status or dry_run:
|
|
453
|
+
return status
|
|
454
|
+
if not lock:
|
|
455
|
+
print(" uv.lock: not run (--no-lock): run `uv lock`")
|
|
456
|
+
elif shutil.which("uv") is None:
|
|
457
|
+
print(" uv.lock: uv not found: install it, then run `uv lock`")
|
|
458
|
+
else:
|
|
459
|
+
proc = subprocess.run(["uv", "lock"], cwd=root, capture_output=True, text=True)
|
|
460
|
+
if proc.returncode != 0:
|
|
461
|
+
tail = "\n".join(
|
|
462
|
+
" " + line for line in (proc.stderr.strip() or proc.stdout.strip()).splitlines()[-6:])
|
|
463
|
+
print(f" uv.lock: `uv lock` failed; the pins are moved, fix this and run it again:\n{tail}",
|
|
464
|
+
file=sys.stderr)
|
|
465
|
+
return 1
|
|
466
|
+
print(" uv.lock: re-resolved (one lock for docs/ and present/)")
|
|
467
|
+
print("\n next:\n uv sync # install the new releases")
|
|
468
|
+
return 0
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sanitism
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One repository for a paper, its talks and what they share: `uvx sanitism init` sets up document-sanity and presentation-sanity side by side, with a shared manifest both import from.
|
|
5
|
+
Project-URL: Homepage, https://sanitism.dev
|
|
6
|
+
Project-URL: Repository, https://github.com/yakaboskic/sanitism
|
|
7
|
+
Project-URL: Issues, https://github.com/yakaboskic/sanitism/issues
|
|
8
|
+
Author: Chase Yakaboski
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Keywords: document-sanity,manuscripts,presentation-sanity,provenance,sanitism,slides
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: document-sanity<0.4,>=0.3.0
|
|
20
|
+
Requires-Dist: presentation-sanity<0.6,>=0.5.0
|
|
21
|
+
Requires-Dist: pyyaml>=6.0
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# sanitism
|
|
25
|
+
|
|
26
|
+
One repository for a piece of work and everything written about it: the
|
|
27
|
+
paper, the talks, the blog posts, and the numbers, figures and tables they
|
|
28
|
+
share.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
uvx sanitism init my-project
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
my-project/
|
|
36
|
+
├── docs/ papers and proposals (document-sanity)
|
|
37
|
+
├── present/ slide decks and blog posts (presentation-sanity)
|
|
38
|
+
├── shared/ manifest.yaml, figures/, tables/: what both sides quote
|
|
39
|
+
├── pyproject.toml one environment and one lock for the whole repo
|
|
40
|
+
└── Makefile check, site, and shortcuts into each side
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
A number declared once in `shared/manifest.yaml` is `{{cohort_size}}` in the
|
|
44
|
+
paper and `<DataValue var="cohort_size" />` in the deck, with the same
|
|
45
|
+
provenance behind both. Change it there and every output follows.
|
|
46
|
+
|
|
47
|
+
- [sanitism.dev](https://sanitism.dev)
|
|
48
|
+
- [document-sanity](https://github.com/yakaboskic/document-sanity): Markdown and one manifest to PDF, HTML and Word
|
|
49
|
+
- [presentation-sanity](https://github.com/yakaboskic/presentation-sanity): one manifest to Slidev decks and VitePress posts
|
|
50
|
+
- [How imports work](https://github.com/yakaboskic/document-sanity/blob/main/docs/imports.md)
|
|
51
|
+
|
|
52
|
+
`uvx sanitism@latest update` brings an existing project up to the newest
|
|
53
|
+
releases of both tools: the version pins, the one lock, the agent skills.
|
|
54
|
+
|
|
55
|
+
`sanitism pages init` writes one GitHub Pages workflow that publishes both
|
|
56
|
+
sides (a Pages site is public, even from a private repository).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
sanitism/__init__.py,sha256=Ggt3xa3zEviWr8TBLqn8xMyskk4_Fjlaku1k4hmQo_c,98
|
|
2
|
+
sanitism/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
sanitism/cli.py,sha256=OCFRFoSqsZrFrWDdBU-VHQdE19lh6nNITMMAsDAbfaY,9220
|
|
4
|
+
sanitism/project.py,sha256=fGUHtYEWTurFAKpKjzo1mgI2J9_Z4wtFEesw-_w6vzc,18649
|
|
5
|
+
sanitism/overlay/AGENTS.md.tmpl,sha256=M97zDV95QH-h59vWpjimVFxUo7zgKsjmFIVM4VVZYFY,2304
|
|
6
|
+
sanitism/overlay/Makefile.tmpl,sha256=_bK6lwhssg_HOrq_3HyBfC3Ae23w5-S8sTbF75mkIzQ,1915
|
|
7
|
+
sanitism/overlay/README.md.tmpl,sha256=BK5jeVgpyJRD0uPbd9hLGpT__mX-DXyq6cLdzfCsdJE,3651
|
|
8
|
+
sanitism/overlay/gitignore.tmpl,sha256=v4-SjxG6_HXyIMpaPBpsPUJEw5KE5Azt77WMtFg_Xz4,171
|
|
9
|
+
sanitism/overlay/pages.yml.tmpl,sha256=-fxWxOLY6BBLJB9oce82ncM-ML0IrNqGjoRAsq7iAdU,2321
|
|
10
|
+
sanitism/overlay/pyproject.toml.tmpl,sha256=TILSSX9zwfSpccV-cb3nFNGJRDps8XsK1QFM3VUrkIk,1025
|
|
11
|
+
sanitism/overlay/shared/README.md.tmpl,sha256=njB0x19QfgUGpS1tqom9AEkaS2nriRS7gbBeLVx40hE,1111
|
|
12
|
+
sanitism/overlay/shared/manifest.yaml.tmpl,sha256=DGeqb6V9VtExkwhJQruMJSyovyfsItvJ0_-eJIkjJ70,1560
|
|
13
|
+
sanitism/overlay/shared/tables/example.csv,sha256=CrzfOrZ_EGz9JYzpI4kZw4BW30utAHeOcClcn-RpoXc,52
|
|
14
|
+
sanitism-0.1.0.dist-info/METADATA,sha256=R_tou6IfHQMoRhwNXhtPOBrlgRbTDDEl2Y4px5qnHcU,2523
|
|
15
|
+
sanitism-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
16
|
+
sanitism-0.1.0.dist-info/entry_points.txt,sha256=NDQAri4MwNV4X2d9KvCDpOhNIkaBiH8b_u05f8u6Q78,47
|
|
17
|
+
sanitism-0.1.0.dist-info/RECORD,,
|