Skip to content

Commit af4707b

Browse files
authored
Add project documentation and templates for docs (#29)
* Add a --docs option to the CLI * Update sphinx config and make toctree less shouty * Add templates for project documentation * Make H1 size smaller Also, bring back the all caps * Add tests for documentation template output This changeset also switches to snapshot testing for checking the output of the jinja templates. * Remove deprecated is_flag option from Typer app * Remove templates from coverage report * Update documentation Add information about the new --docs parameter. Also add some sphinx extensions to the jinja documentation templates and fix up some formatting on the pyprefab documenation files. * Escape quotation marks in author and project description * Change python version down to 3.12 * Make "docs" section of project conditional * Bump version on changelog
1 parent bbfbb36 commit af4707b

26 files changed

+1445
-153
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
exclude: |
2+
(?x)(
3+
^test/__snapshots__/
4+
)
5+
16
repos:
27
- repo: https://github.com/astral-sh/uv-pre-commit
38
# uv version.
@@ -28,3 +33,4 @@ repos:
2833
rev: v2.3.0
2934
hooks:
3035
- id: codespell
36+
args: ['--skip', 'test/__snapshots__/*.*']

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.13
1+
3.12

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ All notable changes to `pyprefab` are documented here.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com), and the project uses [Semantic Versioning](https://semver.org/).
66

7-
## [Unreleased]
7+
## [0.5.0] - [2025-02-10]
88

99
### Added
1010

1111
- Sphinx-based project documentation (published on GitHub pages)
12+
- New CLI `--docs` option to include skeleton documentation in created package
13+
14+
### Fixed
15+
16+
- Add escape character to quotation marks in author name and project description
1217

1318
## [0.4.0] - [2025-01-26]
1419

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ you can submit them by [creating a pull request](https://docs.github.com/en/pull
136136
Please ensure the following are true before creating the PR:
137137

138138
- Your change is covered by tests, if applicable
139+
- Project documentation is updated, if applicable
139140
- All tests pass (`uv run pytest`)
140141
- All pre-commit checks are successful
141142
(these checks will run automatically as you make commits)

docs/source/_static/custom.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ div.body h1 {
1212
color: #003d45;
1313
font-family: 'Bungee Shade';
1414
font-weight: bold;
15-
font-size: 300%;
15+
font-size: 275%;
1616
}
1717

1818
ol.simple p,

docs/source/conf.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import os
1010
import sys
11+
from datetime import datetime
1112
from importlib import metadata
1213

1314
# If extensions (or modules to document with autodoc) are in another directory,
@@ -23,11 +24,31 @@
2324
extensions = [
2425
'sphinx.ext.autodoc',
2526
'sphinx.ext.githubpages',
27+
'sphinx.ext.intersphinx',
2628
'sphinx.ext.napoleon',
29+
'sphinx.ext.viewcode',
2730
'sphinx_copybutton',
31+
'sphinxext.opengraph',
2832
'myst_parser',
2933
]
3034

35+
myst_enable_extensions = [
36+
'colon_fence',
37+
'fieldlist',
38+
'replacements',
39+
'tasklist',
40+
]
41+
42+
# Settings from the copybutton's config
43+
# https://github.com/executablebooks/sphinx-copybutton/blob/master/docs/conf.py
44+
# There are useful for ensuring that the copy button only copies code
45+
# (as prefixed by ">>>" for example) and not the prompt or the output.
46+
copybutton_prompt_text = r'>>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: '
47+
copybutton_prompt_is_regexp = True
48+
copybutton_line_continuation_character = '\\'
49+
copybutton_here_doc_delimiter = 'EOT'
50+
copybutton_selector = 'div:not(.no-copybutton) > div.highlight > pre'
51+
3152
templates_path = ['_templates']
3253
exclude_patterns = []
3354

@@ -42,8 +63,9 @@
4263
master_doc = 'index'
4364

4465
# project information
66+
now = datetime.now()
4567
project = 'pyprefab'
46-
copyright = '2025, Becky Sweger'
68+
copyright = f'{now.year}, Becky Sweger | Last update {now.strftime("%B %d, %Y")}'
4769
author = 'Becky Sweger'
4870

4971
version = metadata.version('pyprefab')
@@ -76,7 +98,7 @@
7698
html_theme_options = {
7799
# 'logo': 'beepboop.png',
78100
# 'logo_name': True,
79-
'description': 'Simple CLI for Python project scaffolding',
101+
'description': f'Simple CLI for Python project scaffolding\n{release}',
80102
'github_user': 'bsweger',
81103
'github_repo': 'pyprefab',
82104
'github_banner': True,
@@ -157,7 +179,7 @@
157179
# html_show_sourcelink = True
158180

159181
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
160-
# html_show_sphinx = True
182+
html_show_sphinx = False
161183

162184
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
163185
# html_show_copyright = True

docs/source/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
66
.. toctree::
77
:hidden:
8-
:maxdepth: 2
8+
:maxdepth: 3
99
:caption: Contents:
1010

1111
usage
1212
CONTRIBUTING
1313
CHANGELOG
1414

15-
.. include:: readme.md
16-
:parser: myst_parser.sphinx_
15+
.. include:: README.md
16+
:parser: myst_parser.sphinx_

docs/source/usage.md

Lines changed: 154 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,133 @@
55
By design, pyprefab requires only a few pieces of information to create the
66
boilerplate for a Python package.
77

8-
```bash
9-
➜ pyprefab --help
10-
11-
Usage: pyprefab [OPTIONS] NAME
12-
13-
🐍 Create Python package boilerplate 🐍
14-
15-
╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
16-
* name TEXT Name of the project │
17-
│ [required] │
18-
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
19-
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
20-
* --author TEXT Project author │
21-
│ [required] │
22-
* --description TEXT Project description │
23-
│ [required] │
24-
* --dir PATH Directory that will contain the project │
25-
│ [required] │
26-
│ --help Show this message and exit. │
27-
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
8+
```sh
9+
>>> pyprefab --help
10+
11+
Usage: pyprefab [OPTIONS] NAME
12+
13+
🐍 Create Python package boilerplate 🐍
14+
15+
╭─ Arguments ───────────────────────────────────────────────────────────────╮
16+
* name TEXT Name of the project [required] │
17+
╰───────────────────────────────────────────────────────────────────────────╯
18+
╭─ Options ─────────────────────────────────────────────────────────────────╮
19+
* --author TEXT Project author [required] │
20+
* --description TEXT Project description [required] │
21+
* --dir PATH Directory that will contain the project [required] │
22+
│ --docs Include Sphinx documentation files │
23+
│ --help Show this message and exit. │
24+
╰───────────────────────────────────────────────────────────────────────────╯
25+
```
26+
27+
### Example CLI use
28+
29+
To create a Python package named `holodeck` in a directory named
30+
`trek/code/holodeck`:
31+
32+
```sh
33+
>>> pyprefab holodeck --author rbarclay \
34+
>>> --description "personal holodeck programs" \
35+
>>> --dir trek/code/holodeck
36+
37+
╭────────────── Project Created Successfully ────────────────╮
38+
│ Created new project holodeck in trek/code/holodeck │
39+
│ Author: rbarclay │
40+
│ Description: personal holodeck programs │
41+
╰────────────────────────────────────────────────────────────╯
42+
```
43+
44+
The pyprefab command above creates scaffolding for the new `holodeck` package,
45+
with the following files in `trek/code/holodeck`:
46+
47+
```sh
48+
.
49+
├── .github
50+
│   └── workflows
51+
│   ├── ci.yaml
52+
│   ├── publish-pypi-test.yaml
53+
│   └── publish-pypi.yaml
54+
├── .gitignore
55+
├── .pre-commit-config.yaml
56+
├── CHANGELOG.md
57+
├── CONTRIBUTING.md
58+
├── README.md
59+
├── pyproject.toml
60+
├── src
61+
│   └── holodeck
62+
│   ├── __init__.py
63+
│   └── app.py
64+
└── test
65+
└── test_app.py
2866
```
2967

30-
For example:
68+
:::{caution}
69+
If the `--dir` option points to a non-empty directory, pyprefab will overwrite
70+
the existing contents (after prompting you).
71+
:::
72+
73+
### Optional project documentation
74+
75+
Pass the `--docs` option to pyprefab to include Sphinx-based documentation files
76+
with the new package.
3177

3278
```sh
33-
pyprefab project_test --author lassie --description "this is a pet project for lassie" --dir ~/code/lassie
79+
>>> pyprefab holodeck --author rbarclay \
80+
>>> --description "personal holodeck programs" \
81+
>>> --dir /users/becky/code/trek/code/holodeck \
82+
>>> --docs
3483
```
3584

36-
If you don't explicitly pass the `--author`, `--description`, and `--dir` options,
37-
pyprefab will prompt you for them:
85+
This option adds a `docs` directory to the code base:
3886

3987
```sh
40-
➜ pyprefab project_test
41-
Project author: lassie
42-
Project description: this is a pet project for lassie
43-
Project directory: /Users/dogs/code/lassie
88+
.
89+
├── .github
90+
│   └── workflows
91+
│   ├── ci.yaml
92+
│   ├── publish-pypi-test.yaml
93+
│   └── publish-pypi.yaml
94+
├── .gitignore
95+
├── .pre-commit-config.yaml
96+
├── CHANGELOG.md
97+
├── CONTRIBUTING.md
98+
├── README.md
99+
├── docs
100+
│   └── source
101+
│   ├── CHANGELOG.md
102+
│   ├── CONTRIBUTING.md
103+
│   ├── README.md
104+
│   ├── _static
105+
│   │   └── custom.css
106+
│   ├── conf.py
107+
│   ├── index.rst
108+
│   └── usage.md
109+
├── pyproject.toml
110+
├── src
111+
│   └── holodeck
112+
│   ├── __init__.py
113+
│   └── app.py
114+
└── test
115+
└── test_app.py
116+
```
117+
118+
### Interactive mode
119+
120+
If you don't explicitly pass the `--author`, `--description`, `--dir` options,
121+
pyprefab will prompt for them:
122+
123+
```sh
124+
>>> pyprefab holodeck --docs
125+
Project author: rbarclay
126+
Project description: personal holodeck programs
127+
Project directory: trek/code/holodeck/docs
128+
129+
╭──────────── Project Created Successfully ─────────────╮
130+
│ Created new project holodeck in trek/code/holodeck │
131+
│ Author: rbarclay │
132+
│ Description: personal holodeck programs │
133+
│ Documentation: trek/code/holodeck/docs │
134+
╰───────────────────────────────────────────────────────╯
44135
```
45136

46137
## Creating a dev environment for the new package
@@ -64,32 +155,51 @@ These directions use `uv`, but you can use your preferred tooling.
64155
uv run <your_package_name>
65156
```
66157

67-
You should see a log output stating that the project has been set up correctly.
158+
You should see log output stating that the project has been set up correctly.
68159

69160
For example:
70-
`2025-01-13 02:29:08 [info ] project_test successfully created.`
161+
162+
```sh
163+
2025-01-13 02:29:08 [info] project_test successfully created.
164+
```
71165

72166
You can also run the tests:
73167

74168
```sh
75169
uv run pytest
76170
```
77171

78-
**Optional:**
172+
### Previewing documentation
79173

80-
- Add the new project to a git repository:
174+
If your project includes the optional Sphinx documentation, make sure you can
175+
build and preview the docs before updating them:
81176

82-
```sh
83-
git init
84-
git add .
85-
git commit -am "Initial commit"
86-
```
177+
```sh
178+
uv run --group docs sphinx-autobuild docs/source docs/_build/html
179+
```
87180

88-
- If you use [pre-commit](https://pre-commit.com/), pyprefab's boilerplate
89-
includes a baseline `pre-commit-config.yaml` configuration. To use it, make
90-
sure the project has been added to git (see above) and run the following
91-
command to install the pre-commit git hook scripts:
181+
The output of the above command provides a URL for viewing the documentation
182+
via a local server (usually http://127.0.0.1:8000).
92183

93-
```sh
94-
pre-commit install
95-
```
184+
```sh
185+
The HTML pages are in docs/_build/html.
186+
[sphinx-autobuild] Serving on http://127.0.0.1:8000
187+
[sphinx-autobuild] Waiting to detect changes...
188+
```
189+
190+
### Adding the project to git
191+
192+
To create a new git repository for the project (this is optional):
193+
194+
```sh
195+
git init
196+
git add .
197+
git commit -am "Initial commit"
198+
```
199+
200+
:::{tip}
201+
If you use [pre-commit](https://pre-commit.com/), pyprefab's boilerplate
202+
includes a baseline `pre-commit-config.yaml` configuration. To use it, make
203+
sure the project has been added to git (see above) and install the pre-commit
204+
hooks: `pre-commit install`
205+
:::

pyproject.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ dev = [
2727
'pytest',
2828
"pytest-random-order>=1.1.1",
2929
'ruff',
30+
"syrupy>=4.8.1",
3031
"tomli>=2.2.1",
3132
]
3233
docs = [
3334
"myst-parser>=3.0.1",
3435
"sphinx>=7.4.7",
3536
"sphinx-autobuild>=2024.10.3",
3637
"sphinx-copybutton>=0.5.2",
38+
"sphinxext-opengraph>=0.9.1",
3739
]
3840

3941
[project.scripts]
@@ -70,6 +72,12 @@ testpaths = [
7072
"test",
7173
]
7274

75+
[tool.coverage.run]
76+
omit = [
77+
# omit jinja templates from coverage reports
78+
'*/templates/*'
79+
]
80+
7381
[tool.ruff]
7482
line-length = 120
7583
lint.extend-select = ['I', 'Q']

0 commit comments

Comments
 (0)