Skip to content

Commit 1be3fca

Browse files
committed
ENH: Add CI infrastructure for pre-commit checks
Introduce a noxfile with two sessions: 1. pre-commit: Runs pre-commit checks on all files except the ones generated by cookiecutter. 2. pre-commit-cookie: Runs pre-commit checks on a generated folder based on the cookiecutter template. The approach was adapted from the implementation at https://github.com/scientific-python/cookie/, originally contributed by @henryiii. Add corresponding GitHub Actions workflows in lint.yml to automate the pre-commit checks.
1 parent 88b2614 commit 1be3fca

File tree

7 files changed

+460
-0
lines changed

7 files changed

+460
-0
lines changed

.github/workflows/lint.yml

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI (Lint)
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
pre-commit:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-python@v5
21+
22+
- uses: pre-commit/[email protected]
23+
24+
pre-commit-cookie:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- run: pipx run nox -s 'pre-commit-cookie'

.gitignore

+170
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/
161+
162+
### Python Patch ###
163+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
164+
poetry.toml
165+
166+
# ruff
167+
.ruff_cache/
168+
169+
# LSP config files
170+
pyrightconfig.json

.pre-commit-config.yaml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
exclude: "^{{cookiecutter\\.project_name}}/"
2+
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: "v4.6.0"
6+
hooks:
7+
- id: check-added-large-files
8+
- id: check-case-conflict
9+
- id: check-merge-conflict
10+
- id: check-symlinks
11+
- id: check-toml
12+
- id: check-yaml
13+
- id: debug-statements
14+
- id: end-of-file-fixer
15+
- id: mixed-line-ending
16+
- id: trailing-whitespace
17+
- id: requirements-txt-fixer
18+
19+
- repo: https://github.com/adamchainz/blacken-docs
20+
rev: "1.18.0"
21+
hooks:
22+
- id: blacken-docs
23+
additional_dependencies: [black==24.*]
24+
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: "v0.5.7"
27+
hooks:
28+
# Run the linter.
29+
- id: ruff
30+
args: ["--fix", "--show-fixes"]
31+
# Run the formatter.
32+
- id: ruff-format
33+
34+
- repo: https://github.com/rbubley/mirrors-prettier
35+
rev: "v3.3.3"
36+
hooks:
37+
- id: prettier
38+
types_or: [yaml, json]
39+
40+
- repo: https://github.com/codespell-project/codespell
41+
rev: "v2.3.0"
42+
hooks:
43+
- id: codespell
44+
args: ["-Lnd", "-w"]
45+
46+
- repo: https://github.com/python-jsonschema/check-jsonschema
47+
rev: "0.29.1"
48+
hooks:
49+
- id: check-github-workflows

.ruff.toml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
[lint]
2+
select = [
3+
"ARG", # flake8-unused-arguments
4+
"ANN", # flake8-annotations
5+
"B", # flake8-bugbear
6+
"C4", # flake8-comprehensions
7+
"D", # pydocstyle
8+
"E", "F", "W", # flake8
9+
"EXE", # flake8-executable
10+
"G", # flake8-logging-format
11+
"I", # isort
12+
"ICN", # flake8-import-conventions
13+
"ISC", # flake8-implicit-str-concat
14+
"NPY", # NumPy specific rules
15+
"PGH", # pygrep-hooks
16+
"PIE", # flake8-pie
17+
"PL", # pylint
18+
"PT", # flake8-pytest-style
19+
"RET", # flake8-return
20+
"RUF", # Ruff-specific
21+
"S", # flake8-bandit
22+
"SIM", # flake8-simplify
23+
"UP", # pyupgrade
24+
"YTT", # flake8-2020
25+
"W", # Warning
26+
]
27+
extend-ignore = [
28+
"ANN101", # missing-type-self
29+
"G004", # logging-f-string
30+
"PIE790", # unnecessary-pass
31+
32+
"D10", # undocumented-public-*
33+
"D200", # One-line docstring should fit on one line
34+
35+
# Disable linting rules conflicting with "ruff formatter"
36+
# See https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
37+
"COM812",
38+
"COM819",
39+
"D206",
40+
"D300",
41+
"E111",
42+
"E114",
43+
"E117",
44+
"ISC001",
45+
"ISC002",
46+
"Q000",
47+
"Q002",
48+
"Q003",
49+
"W191",
50+
]
51+
flake8-annotations.suppress-dummy-args = true
52+
flake8-annotations.suppress-none-returning = true
53+
pydocstyle.convention = "pep257"

0 commit comments

Comments
 (0)