Skip to content

Commit

Permalink
Add pre-commit to run codespell and other tools
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Aug 30, 2024
1 parent 3ac5cf0 commit d2b4b3b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/nikola.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
shell: bash
run: |
pip install --user codespell[toml]
codespell --ignore-words-list=gameboy,ist,mata,nd,openend,theses --quiet=3 --skip="./archive/*,*.html,*.js"
codespell --toml=pyproject.toml
- name: Build docs
shell: bash
run: |
Expand All @@ -37,3 +37,12 @@ jobs:
# reuse the venv
venv_nikola/bin/python -m pip install ghp-import
venv_nikola/bin/ghp-import -m"Automatic push by ghp-import" -f -p -r origin -b gh-pages --cname=pypy.org public
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: pre-commit/action@v3.0.1
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Learn more about this config here: https://pre-commit.com/

# To enable these pre-commit hooks run:
# `pipx install pre-commit` or `brew install pre-commit`
# Then in the project root directory run `pre-commit install`

# default_language_version:
# python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: detect-private-key
- id: file-contents-sorter
- id: fix-byte-order-marker
- id: forbid-new-submodules
- id: forbid-submodules
- id: mixed-line-ending
- id: name-tests-test
- id: pretty-format-json
- id: requirements-txt-fixer
- id: sort-simple-yaml
# - id: check-builtin-literals
# - id: check-shebang-scripts-are-executable
# - id: check-vcs-permalinks
# - id: double-quote-string-fixer
# - id: end-of-file-fixer
# - id: fix-encoding-pragma
# - id: no-commit-to-branch
# - id: trailing-whitespace

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
args: ["--toml=pyproject.toml"]
additional_dependencies:
- tomli

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.2.1
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.19
hooks:
- id: validate-pyproject
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ all: build

venv_nikola/bin/nikola: ## create a virtualenv to build the website
> @virtualenv -ppython3 ./venv_nikola
> @venv_nikola/bin/python -mpip install nikola==8.2.2 markdown==3.3 jinja2 aiohttp watchdog ruamel.yaml feedparser codespell
> @venv_nikola/bin/python -mpip install nikola==8.2.2 markdown==3.3 jinja2 aiohttp watchdog ruamel.yaml feedparser codespell tomli
> @venv_nikola/bin/nikola plugin -i sidebar
> @venv_nikola/bin/nikola plugin -i localsearch

Expand All @@ -25,7 +25,7 @@ plugins/import_blogger: venv_nikola/bin/nikola

codespell: venv_nikola/bin/nikola ## check and fix typos
# If codespell is not found, rerun `make venv_nikola/bin/nikola`
> venv_nikola/bin/codespell --ignore-words-list=gameboy,ist,mata,nd,openend,theses --quiet=3 --skip="./venv_nikola/*,./archive/*,*.html,*.js,./public" --write-changes
> venv_nikola/bin/codespell --toml=pyproject.toml --write-changes

build: codespell ## build the website if needed, the result is in ./public
> venv_nikola/bin/nikola build
Expand Down Expand Up @@ -60,4 +60,3 @@ help: ## Show this help.
> @echo "\nHelp for building the website, based on nikola"
> @echo "Possible commands are:"
> @grep -h "##" $(MAKEFILE_LIST) | grep -v grep | sed -e 's/\(.*\):.*##\(.*\)/ \1: \2/'

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.codespell]
ignore-words-list = "gameboy,ist,mata,nd,openend,theses"
quiet-level = 3
skip = "*.html,*.js,./.*,./archive/*,./venv_nikola,archive/*"

0 comments on commit d2b4b3b

Please sign in to comment.