Skip to content

Commit 4e9e337

Browse files
docs: add template wiki and standalone publishing workflow
1 parent 51a8af2 commit 4e9e337

11 files changed

Lines changed: 328 additions & 0 deletions

‎.github/workflows/publish-wiki.yml‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish wiki
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'wiki/**'
8+
- '.github/workflows/publish-wiki.yml'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
concurrency:
15+
group: publish-wiki
16+
cancel-in-progress: false
17+
18+
jobs:
19+
publish:
20+
if: github.ref == 'refs/heads/main'
21+
runs-on: ubuntu-24.04
22+
timeout-minutes: 5
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
persist-credentials: false
27+
28+
- name: Sync Markdown pages
29+
shell: bash
30+
env:
31+
WIKI_TOKEN: ${{ secrets.WIKI_TOKEN || github.token }}
32+
GIT_TERMINAL_PROMPT: '0'
33+
run: |
34+
set -euo pipefail
35+
test -s wiki/Home.md
36+
test -s wiki/_Sidebar.md
37+
38+
# Use an ephemeral Git config; never embed credentials in the remote URL.
39+
auth=$(printf 'x-access-token:%s' "$WIKI_TOKEN" | base64 -w0)
40+
echo "::add-mask::$auth"
41+
export GIT_CONFIG_COUNT=1
42+
export GIT_CONFIG_KEY_0=http.https://github.com/.extraheader
43+
export GIT_CONFIG_VALUE_0="AUTHORIZATION: basic $auth"
44+
unset auth WIKI_TOKEN
45+
46+
destination="$RUNNER_TEMP/published-wiki"
47+
if ! git clone "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.wiki.git" "$destination"; then
48+
echo "::error::Initialize the wiki with a Home page in GitHub and verify wiki access."
49+
exit 1
50+
fi
51+
52+
# Preserve pages that are not managed by the source directory.
53+
cp -- wiki/*.md "$destination/"
54+
git -C "$destination" add -- .
55+
if git -C "$destination" diff --cached --quiet; then
56+
echo "Wiki already up to date." >> "$GITHUB_STEP_SUMMARY"
57+
exit 0
58+
fi
59+
60+
git -C "$destination" -c user.name='github-actions[bot]' \
61+
-c user.email='41898282+github-actions[bot]@users.noreply.github.com' \
62+
commit -m "Publish wiki from ${GITHUB_SHA}"
63+
if ! git -C "$destination" push; then
64+
echo "::error::Wiki push failed. Check wiki write access; configure WIKI_TOKEN if the job token is insufficient. Retry after resolving concurrent edits."
65+
exit 1
66+
fi
67+
echo "Published wiki from ${GITHUB_SHA}." >> "$GITHUB_STEP_SUMMARY"

‎wiki/Architecture.md‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Architecture
2+
3+
The repository has two scopes: root files maintain and test the template, while Copier renders only `template/`. Generated applications have their own isolated dependencies and CI.
4+
5+
| Generated file | Responsibility |
6+
| --- | --- |
7+
| src/my_tool/cli.py | Cyclopts commands and centralized error handling |
8+
| src/my_tool/__main__.py | Module entrypoint |
9+
| src/my_tool/config.py | Safe YAML settings, platform paths, Loguru setup |
10+
| src/my_tool/output.py | Shared output options, JSON/JSONL, Rich progress |
11+
| src/my_tool/database.py | SQLite connection, schema and record API |
12+
| src/my_tool/doctor.py | Read-only environment checks |
13+
| src/my_tool/logging_utils.py | Optional synchronous call tracing |
14+
| src/my_tool/errors.py | Expected application failures |
15+
| pyproject.toml | Package metadata, entrypoint, dependency and tool configuration |
16+
| Taskfile.yml | Repeatable development commands |
17+
| AGENTS.md | Project-local development instructions |
18+
| tests/ | CLI and component regression tests |
19+
20+
The console entrypoint and module entrypoint invoke `cli.main()`. Keep business logic outside CLI handlers. Commands validate arguments via Cyclopts, call domain functions, then emit data through the existing Output class.
21+
22+
## Persistence boundaries
23+
24+
Use YAML for configuration and SQLite for application data. Use platformdirs for per-user paths rather than the current working directory. The starter SQLite schema is version 1 with a key/value records table. Extend it with explicit migrations and project-specific operations. Parameterize queries and reuse `database.connect()`; it enables WAL and foreign keys, commits or rolls back transactions, and closes connections.
25+
26+
SQLite initializes lazily. Help, config and doctor do not initialize it; db-list does. Keep WAL databases on a local filesystem and use a proper SQLite backup mechanism for live data.
27+
28+
## Packaging
29+
30+
uv_build produces a wheel and source distribution. The project starts at version 0.1.0; the runtime requires Python >=3.14, and the development interpreter is pinned to 3.14.7.

‎wiki/CLI-Contract.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# CLI contract
2+
3+
Use the same interface for people and automation. Every starter application subcommand and the root configuration actions accept shared output options.
4+
5+
| Flag | Effect |
6+
| --- | --- |
7+
| --json | One compact JSON document |
8+
| --jsonl | One record per line; an empty list emits nothing |
9+
| --quiet | Suppress progress and console diagnostics, retain results and errors |
10+
| --verbose | Debug console logs for business commands, verbose diagnostic notes |
11+
12+
JSON and JSONL are mutually exclusive; quiet and verbose are mutually exclusive. Machine output is UTF-8 with trailing newlines, no ANSI formatting or progress. Results go to stdout; logs, progress and errors go to stderr. Help and parse errors remain textual.
13+
14+
```sh
15+
uv run my-tool hello --name Ada --json
16+
uv run my-tool doctor --json
17+
uv run my-tool db-path --json
18+
uv run my-tool db-list --jsonl
19+
```
20+
21+
Doctor checks Python, platform, YAML settings, config/log/database paths and SQLite. It returns status 1 for failed checks, after emitting results. Its database check reads an on-disk immutable snapshot, not live WAL state. db-path does not initialize the database; db-list may initialize it and returns records sorted by key.
22+
23+
## Implement new commands
24+
25+
Reuse the existing immutable default output options rather than constructing an object in a function signature. Create Output(options), call domain logic and use output.emit(data). Use output.track() or output.progress() for progress. Do not implement separate serializers.
26+
27+
Raise ApplicationError for expected domain failures. The main boundary handles expected application, filesystem, SQLite, Unicode and YAML errors; unexpected programming failures propagate. Cyclopts owns parsing and argument validation. Do not duplicate error handling in each command.

‎wiki/Configuration.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Configuration
2+
3+
Settings are stored in the platform-specific user config directory, in config.yml. Use the application to discover the actual path.
4+
5+
```sh
6+
uv run my-tool --config-path
7+
uv run my-tool --init-config
8+
uv run my-tool --show-config
9+
uv run my-tool set-config logging.file_enabled false
10+
uv run my-tool set-config cli.hello.name Ada
11+
```
12+
13+
The root config flags are mutually exclusive. Use --path with --init-config, --show-config or set-config (not --config-path). The hello command accepts --config instead.
14+
15+
If the implicit config file is absent, reads use in-memory defaults. Initialization refuses to overwrite a file. set-config accepts dotted keys and YAML values, preserves unrelated settings and comments, and replaces the file via a sibling temporary file.
16+
17+
## Defaults and logging
18+
19+
```yaml
20+
logging:
21+
file_level: INFO
22+
console_level: WARNING
23+
file_enabled: true
24+
cli:
25+
hello:
26+
name: Ada
27+
```
28+
29+
Explicit arguments override YAML command defaults, which override Python defaults. Cyclopts loads and validates these defaults for the sample hello command; other commands can opt in. Do not duplicate its argument merging.
30+
31+
Loguru uses independent named levels for file and console logs. --verbose selects DEBUG for the console, --quiet suppresses console logging, and neither changes file logging. Logs go to stderr or the platform-specific app.log; files rotate at 5 MB and are retained for 7 days. Help and configuration commands do not initialize logging.
32+
33+
Do not store secrets in YAML or log them. Prefer direct Loguru calls; optionally use @log_call for synchronous entry/duration/failure-type tracing or @logger.catch(reraise=True) for exceptions. Do not stack the two decorators.

‎wiki/Development.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Development
2+
3+
Install uv and Go Task. Initialize Git before task setup so it installs pre-commit.
4+
5+
| Task | Purpose |
6+
| --- | --- |
7+
| task setup | Sync development dependencies and install hooks at Git root |
8+
| task dev -- hello --json | Run a command in the development environment |
9+
| task test | Focused tests using pytest-testmon |
10+
| task test:all | Full tests and refresh selection baseline |
11+
| task lint | Check Ruff lint and formatting |
12+
| task fix | Apply safe lint fixes, format and recheck |
13+
| task build | Build distribution artifacts |
14+
| task install | Install user-level executable (uv preferred; pipx fallback) |
15+
| task clean | Remove build artifacts and test/lint caches |
16+
| task doctor -- --json | Diagnose environment |
17+
| task update | Upgrade lockfile and sync dependencies |
18+
19+
## Git hooks
20+
21+
The local pre-commit hooks run the project's Ruff on staged Python files. The lint hook applies safe fixes (including import sorting through the I rule); the format hook formats code. If files change, review and stage them again before retrying the commit. Do not bypass hooks.
22+
23+
Run `uv run pre-commit run --all-files` for an explicit all-files pass. Ruff settings and version resolution are shared with normal development commands.
24+
25+
## Agent workflow
26+
27+
Read the generated AGENTS.md. Write a failing test for the behavior, implement the smallest passing change, then run task fix and task test. Before acceptance run task lint and task test:all. Keep logic in appropriate existing modules, avoid parallel infrastructure, prefer native Cyclopts parameter types and validators, and do not change shared CI or global Python environments from a generated project.

‎wiki/Getting-Started.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Getting started
2+
3+
Install uv, Git and (for task shortcuts) [Go Task](https://taskfile.dev/docs/installation).
4+
5+
```sh
6+
uvx copier copy gh:RuchirChawdhry/copier-python-cli my-tool
7+
cd my-tool
8+
git init
9+
task setup
10+
```
11+
12+
Choose My Tool / my-tool / my_tool / my-tool when prompted. Without Go Task, run `uv sync --group dev` and `uv run pre-commit install` after initializing Git.
13+
14+
## Copier answers
15+
16+
| Answer | Purpose | Example |
17+
| --- | --- | --- |
18+
| project_name | Display name | My Tool |
19+
| project_slug | Distribution and storage name | my-tool |
20+
| package_name | Python import name | my_tool |
21+
| cli_command | Installed executable | my-tool |
22+
| description | Package summary | A useful CLI |
23+
| author_name | Copyright holder | Your name |
24+
25+
Slugs and executable names use lowercase letters, digits and single hyphens, starting with a letter. Package names permit underscores. Copier 9.14.1 or later is required.
26+
27+
For noninteractive generation:
28+
29+
```sh
30+
uvx copier copy --defaults -d project_name='My Tool' gh:RuchirChawdhry/copier-python-cli my-tool
31+
```
32+
33+
## Verify the project
34+
35+
```sh
36+
uv run my-tool --help
37+
uv run my-tool hello --name Ada --json
38+
uv run my-tool doctor --json
39+
task lint
40+
task test:all
41+
```
42+
43+
Expected greeting: `{"message":"Hello, Ada!"}`. Doctor returns nonzero if a check fails.
44+
45+
Commit the generated lockfile and Copier answers. To apply later template changes, work from a clean Git tree, review the selected template revision, and run `uvx copier update`. Copier updates can require conflict resolution; inspect the diff and run tests afterward.

‎wiki/Home.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python CLI template
2+
3+
Build an installable, agent-friendly Python command-line application without recreating the same infrastructure in every project.
4+
5+
The template provides Python 3.14.7 and uv, Cyclopts, Rich, ruamel.yaml, platformdirs, Loguru, orjson, SQLite, pytest, Ruff, pre-commit and Go Task.
6+
7+
## Start here
8+
9+
- [Getting started](Getting-Started): generate and run a project.
10+
- [Architecture](Architecture): understand the reusable building blocks.
11+
- [Configuration](Configuration): settings, logging and command defaults.
12+
- [CLI contract](CLI-Contract): machine output, errors and persistence commands.
13+
- [Development](Development): tasks, hooks and the agent workflow.
14+
- [Testing and CI](Testing-and-CI): validate the template and generated applications.
15+
- [Troubleshooting](Troubleshooting): diagnose common issues.
16+
- [Wiki publishing](Wiki-Publishing): maintain these pages.
17+
18+
[Source repository](https://github.com/RuchirChawdhry/copier-python-cli) · [Central workflows](https://github.com/RuchirChawdhry/ci-workflows)
19+
20+
These pages describe the template, not a deployed application. Examples use an executable named `my-tool`.

‎wiki/Testing-and-CI.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Testing and CI
2+
3+
## Generated projects
4+
5+
```sh
6+
task test
7+
task test:all
8+
task lint
9+
task build
10+
```
11+
12+
pytest-testmon uses observed Python execution to select affected tests. The first run establishes a baseline. Use the full suite for final acceptance and subprocess, external-resource or dynamic changes; focused selection cannot cover all such dependencies.
13+
14+
The generated PR-only workflow calls python-cli.yml and python-build.yml in the [central workflow repository](https://github.com/RuchirChawdhry/ci-workflows). It currently passes Python 3.14.7 and the configured CLI command and references the central main branch. Pin workflow revisions if stricter reproducibility is required.
15+
16+
## Template repository
17+
18+
```sh
19+
uv run --no-project --with copier==9.14.1 --with pytest --with PyYAML pytest tests/test_template.py -q
20+
```
21+
22+
The root PR-only Template CI calls the central copier-ci.yml workflow. It checks the template contracts, renders a project, validates lint and tests, builds distributions and performs installed-wheel functional checks on Ubuntu 24.04.
23+
24+
The functional smoke suite in tests/smoke_installed.py expects CLI_EXECUTABLE to point to an installed console script. It checks actual JSON output, configuration precedence, malformed YAML diagnostics, SQLite WAL, and read-only doctor behavior outside the generated source tree. It is intended to run with an installed wheel, not as an ordinary standalone test without that environment.
25+
26+
The generated workflow lives under template/.github/workflows; GitHub does not activate it in the template repository. The wiki publisher is separate from both CI workflows.

‎wiki/Troubleshooting.md‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Troubleshooting
2+
3+
| Symptom | Action |
4+
| --- | --- |
5+
| CLI command not found | Run uv sync --group dev, then uv run my-tool --help. For a standalone command run task install and reopen the shell. |
6+
| Commit stopped after formatting | Inspect git diff, stage the intended changes again and retry the commit. |
7+
| Hooks not installed | Initialize Git at the project root and rerun task setup. |
8+
| Focused tests miss a change | Run task test:all, especially for subprocess or external changes. |
9+
| JSON parsing fails | Remove incompatible flags; parse stdout only, and check stderr and exit status. |
10+
| Invalid YAML or named logging level | Inspect --show-config or the error details, correct the file, and run doctor. |
11+
| Config initialization fails | Check --config-path; an existing file is deliberately not overwritten. |
12+
| SQLite schema or path problem | Run doctor --json, verify the local storage path and schema version; do not delete a user's data as a repair. |
13+
| Shared CI failure | Inspect the failing job and its central workflow; reproduce the relevant validation locally before changing code. |
14+
15+
Useful commands:
16+
17+
```sh
18+
uv run my-tool doctor --json
19+
uv run my-tool --config-path
20+
uv run my-tool db-path
21+
uv run ruff check .
22+
uv run pytest -q
23+
```
24+
25+
See [Wiki publishing](Wiki-Publishing) for documentation sync issues.

‎wiki/Wiki-Publishing.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Wiki publishing
2+
3+
The source of these pages is the root [wiki directory](https://github.com/RuchirChawdhry/copier-python-cli/tree/main/wiki), outside the Copier-rendered template.
4+
5+
Edit the Markdown files in the source repository. The Publish wiki workflow runs on main-branch pushes that touch wiki pages or the publishing workflow; it can also be run manually from the Actions tab. Only main can publish. The publisher copies top-level Markdown pages into the existing GitHub wiki repository, commits changes and pushes normally. It does not force-push or delete other pages. A page with the same filename is replaced by the source version; edit managed pages in the source repository, not the wiki UI. Removing a source page does not delete its previously published counterpart.
6+
7+
## First run
8+
9+
Enable Wikis in the repository settings and create an initial Home page through the GitHub wiki UI if one does not exist. GitHub requires an initial page before the wiki can be cloned.
10+
11+
The workflow first uses the built-in job token with contents: write. If the token cannot push to the wiki, configure a repository Actions secret named WIKI_TOKEN with a Git credential authorized to write that wiki, then rerun. Keep the token in Actions secrets, never in a file or commit. A classic personal access token with public_repo scope is an option for this public repository; set an expiration and revoke it when no longer needed.
12+
13+
Verify a successful run in [Actions](https://github.com/RuchirChawdhry/copier-python-cli/actions/workflows/publish-wiki.yml) and inspect the [published wiki](https://github.com/RuchirChawdhry/copier-python-cli/wiki). Repeated runs with identical sources should make no new commit.
14+
15+
The workflow is intentionally local to this repository for the pilot; it is not copied into generated projects.

0 commit comments

Comments
 (0)