Skip to content

Commit 642fb6a

Browse files
committed
Implement automatic spelling check on HTML build using pyspelling
1 parent 735c01d commit 642fb6a

File tree

6 files changed

+180
-16
lines changed

6 files changed

+180
-16
lines changed

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
_build/
2+
wordlist.dic

docs/Makefile

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,108 @@ SPHINXOPTS ?=
77
SPHINXBUILD ?= sphinx-build
88
SOURCEDIR = .
99
BUILDDIR = _build
10+
SPELLING_CONFIG = spellingcheck.yaml
1011

1112
# Put it first so that "make" without argument is like "make help".
1213
help:
1314
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
15+
@echo ""
16+
@echo "Additional spelling targets:"
17+
@echo " install-spelling-deps Install pyspelling and aspell dependencies"
18+
@echo " run Build docs and run pyspelling"
19+
@echo " spelling Run pyspelling on existing build"
1420

15-
.PHONY: help Makefile
21+
.PHONY: help Makefile install-spelling-deps spelling run
22+
23+
# Check if required dependencies are installed, install if missing
24+
check-spelling-deps:
25+
@echo "Checking for required spelling dependencies..."
26+
@if ! command -v aspell >/dev/null 2>&1; then \
27+
echo "aspell is not installed. Installing dependencies..."; \
28+
$(MAKE) install-spelling-deps; \
29+
elif ! python3 -c "import pyspelling" 2>/dev/null; then \
30+
echo "pyspelling is not installed. Installing dependencies..."; \
31+
$(MAKE) install-spelling-deps; \
32+
else \
33+
echo "All spelling dependencies are installed."; \
34+
fi
35+
36+
# Install spelling dependencies
37+
install-spelling-deps:
38+
@echo "Installing spelling dependencies..."
39+
@echo "Detecting operating system..."
40+
@if command -v apt-get >/dev/null 2>&1; then \
41+
echo "Detected Debian/Ubuntu system"; \
42+
echo "Installing aspell and aspell-en..."; \
43+
sudo apt-get update && sudo apt-get install -y aspell aspell-en; \
44+
elif command -v yum >/dev/null 2>&1; then \
45+
echo "Detected RHEL/CentOS system"; \
46+
echo "Installing aspell and aspell-en..."; \
47+
sudo yum install -y aspell aspell-en; \
48+
elif command -v dnf >/dev/null 2>&1; then \
49+
echo "Detected Fedora system"; \
50+
echo "Installing aspell and aspell-en..."; \
51+
sudo dnf install -y aspell aspell-en; \
52+
elif command -v pacman >/dev/null 2>&1; then \
53+
echo "Detected Arch Linux system"; \
54+
echo "Installing aspell and aspell-en..."; \
55+
sudo pacman -S --noconfirm aspell aspell-en; \
56+
elif [ "$$(uname)" = "Darwin" ]; then \
57+
echo "Detected macOS system"; \
58+
if command -v brew >/dev/null 2>&1; then \
59+
echo "Found Homebrew, installing aspell..."; \
60+
brew install aspell; \
61+
elif command -v port >/dev/null 2>&1; then \
62+
echo "Found MacPorts, installing aspell..."; \
63+
sudo port install aspell aspell-dict-en; \
64+
else \
65+
echo "Neither Homebrew nor MacPorts found."; \
66+
echo "Please install aspell manually:"; \
67+
echo " - Install Homebrew: https://brew.sh"; \
68+
echo " - Then run: brew install aspell"; \
69+
echo " - Or install MacPorts: https://www.macports.org"; \
70+
echo " - Then run: sudo port install aspell aspell-dict-en"; \
71+
exit 1; \
72+
fi \
73+
else \
74+
echo "Could not detect package manager."; \
75+
echo "Please manually install aspell and aspell-en for your system."; \
76+
echo "Common package names: aspell, aspell-en"; \
77+
exit 1; \
78+
fi
79+
@echo "Installing pyspelling via pip..."
80+
@python3 -m pip install pyspelling
81+
@echo "Spelling dependencies installed successfully!"
82+
@echo "You can now run 'make run' to build docs and check spelling."
83+
84+
# Check dependencies, install if needed, build HTML documentation, run pyspelling, then serve
85+
run: check-spelling-deps
86+
@echo "Building HTML documentation..."
87+
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
88+
@echo "Running spelling check..."
89+
@if [ ! -f "$(SPELLING_CONFIG)" ]; then \
90+
echo "Error: Spelling config file '$(SPELLING_CONFIG)' not found."; \
91+
exit 1; \
92+
fi
93+
pyspelling -c $(SPELLING_CONFIG)
94+
@echo "Press Ctrl+C to stop the server"
95+
sphinx-autobuild -b html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
96+
97+
# Run pyspelling on existing build
98+
spelling: check-spelling-deps
99+
@echo "Running pyspelling with config: $(SPELLING_CONFIG)"
100+
@if [ ! -f "$(SPELLING_CONFIG)" ]; then \
101+
echo "Error: Spelling config file '$(SPELLING_CONFIG)' not found."; \
102+
exit 1; \
103+
fi
104+
@if [ ! -d "$(BUILDDIR)/html" ]; then \
105+
echo "Error: HTML build directory '$(BUILDDIR)/html' not found."; \
106+
echo "Please run 'make html' first to build the documentation."; \
107+
exit 1; \
108+
fi
109+
pyspelling -c $(SPELLING_CONFIG) -j 8
16110

17111
# Catch-all target: route all unknown targets to Sphinx using the new
18112
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19113
%: Makefile
20114
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
21-
22-
# Start a local development server to automatically rebuild and serve the HTML documentation
23-
# whenever changes are made to the source files.
24-
run:
25-
sphinx-autobuild "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/contributing/index.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Propose changes
1010

1111
The following steps provide an overview of the process involved in proposing changes to Django OTP WebAuthn:
1212

13-
1. Create an issue in the repository to outline the proposed changes.
13+
1. Create an issue in the `repository <https://github.com/Stormbase/django-otp-webauthn>`_ to outline the proposed changes.
1414

15-
2. Fork the `repository <https://github.com/Stormbase/django-otp-webauthn>`_ and create a new branch for the changes.
15+
2. Fork the repository and create a new branch for the changes.
1616

1717
3. :ref:`set-up-django-otp-webauthn`.
1818

@@ -236,13 +236,7 @@ To build the documentation on your local machine, follow these steps:
236236
237237
cd docs
238238
239-
3. Build the documentation:
240-
241-
.. code-block:: console
242-
243-
make html
244-
245-
4. Serve and watch for changes:
239+
3. Build and serve the documentation, then watch for changes :
246240

247241
.. code-block:: console
248242

docs/spellingcheck.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
matrix:
2+
- name: HTML files
3+
aspell:
4+
lang: en
5+
d: en_US
6+
encoding: utf-8
7+
dictionary:
8+
wordlists:
9+
- wordlist.txt
10+
output: wordlist.dic
11+
sources:
12+
- _build/html/**/*.html|!_build/html/index.html|!_build/html/contributing/style_guide.html|!_build/html/glossary.html|!_build/html/genindex.html|!_build/html/search.html
13+
pipeline:
14+
- pyspelling.filters.html:
15+
comments: false
16+
attributes:
17+
- title
18+
- alt
19+
ignores:
20+
- code
21+
- pre
22+
- spellexception
23+
- link
24+
- title
25+
- div.relatedlinks
26+
- strong.command
27+
- div.visually-hidden
28+
- img
29+
- a.p-navigation__link

docs/wordlist.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
AbstractWebAuthnAttestation
2+
AbstractWebAuthnCredential
3+
auth
4+
authenticator
5+
authenticator's
6+
authenticators
7+
authenticatorSelection
8+
backends
9+
backticks
10+
BeginCredentialAuthenticationView
11+
BeginCredentialRegistrationView
12+
biometric
13+
biometrics
14+
Caddy
15+
CompleteCredentialAuthenticationView
16+
CompleteCredentialRegistrationView
17+
cryptographic
18+
django
19+
Frontend
20+
frontend
21+
Furo
22+
gettext
23+
github
24+
http
25+
htmlcov
26+
HTTPS
27+
js
28+
JSON
29+
localhost
30+
OneToOneField
31+
OTP
32+
OTPMiddleware
33+
otp
34+
passwordless
35+
pradyunsg
36+
pre
37+
PyPI
38+
py
39+
Quickstart
40+
reStructuredText
41+
residentKey
42+
Stormbase
43+
subclasses
44+
subclassing
45+
untrusted
46+
WebAuthn
47+
webauthn
48+
WebAuthnCredential
49+
WebAuthnUserHandle
50+
YubiKey

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ docs = [
6666
"sphinx_design==0.6.1",
6767
"sphinx-copybutton==0.5.2",
6868
"sphinx-autobuild==2024.10.3",
69+
"pyspelling==2.10",
6970
]
7071

7172
[project.urls]
@@ -110,7 +111,7 @@ include = [
110111

111112
[tool.hatch.envs.default]
112113
dependencies = [
113-
"django-otp-webauthn[testing]",
114+
"django-otp-webauthn[testing,docs]",
114115
]
115116

116117
[tool.hatch.envs.hatch-static-analysis]

0 commit comments

Comments
 (0)