Skip to content

Commit f428d50

Browse files
authored
Setup pre-commit hook for auto-formating both Python and C code (#1179)
Closes #1123
1 parent 26987f9 commit f428d50

20 files changed

+1140
-1211
lines changed

.clang-format

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: Google
4+
ColumnLimit: 79
5+
IndentWidth: 4
6+
StatementAttributeLikeMacros:
7+
# Defined in Include/pyport.h
8+
- Py_DEPRECATED
9+
- _Py_HOT_FUNCTION
10+
- Py_ALWAYS_INLINE
11+
- Py_NO_INLINE
12+
- Py_ALIGNED
13+
- Py_GCC_ATTRIBUTE
14+
- _Py_NO_RETURN
15+
- _Py_FALLTHROUGH
16+
StatementMacros:
17+
- PyObject_HEAD
18+
- PyObject_VAR_HEAD
19+
- PyException_HEAD
20+
- _PyTZINFO_HEAD
21+
- _PyDateTime_TIMEHEAD
22+
- _PyDateTime_DATETIMEHEAD
23+
- _PyGenObject_HEAD
24+
- Window_NoArgNoReturnFunction
25+
- Window_NoArgTrueFalseFunction
26+
- Window_NoArgNoReturnVoidFunction
27+
- Window_NoArg2TupleReturnFunction
28+
- Window_OneArgNoReturnVoidFunction
29+
- Window_OneArgNoReturnFunction
30+
- Window_TwoArgNoReturnFunction
31+
TabWidth: 4
32+
UseTab: Never
33+
WhitespaceSensitiveMacros:
34+
- _Py_XSTRINGIFY
35+
- Py_STRINGIFY
36+
IndentExternBlock: NoIndent
37+
AlwaysBreakAfterReturnType: All
38+
BreakBeforeBraces: Linux
39+
BinPackArguments: false
40+
...

.pre-commit-config.yaml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
ci:
44
autoupdate_schedule: quarterly
5+
skip:
6+
- clang-format
57

68
repos:
79
- repo: https://github.com/python-jsonschema/check-jsonschema.git
@@ -29,15 +31,18 @@ repos:
2931
args:
3032
- --strict
3133

32-
- repo: https://github.com/PyCQA/flake8.git
33-
rev: 7.2.0
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
# Ruff version.
36+
rev: v0.12.0
3437
hooks:
35-
- id: flake8
36-
alias: flake8-no-wps
37-
name: flake8 WPS-excluded
38-
additional_dependencies:
39-
- flake8-pyi ~= 24.1.0
40-
- flake8-pytest-style ~= 1.7.2
38+
- id: ruff-check
39+
args: ["--fix"]
40+
exclude: >-
41+
(?x)
42+
^
43+
tools/upgrade_pythoncapi\.py
44+
$
45+
- id: ruff-format
4146
exclude: >-
4247
(?x)
4348
^
@@ -108,7 +113,10 @@ repos:
108113
types:
109114
- file
110115
- rst
111-
116+
- repo: https://github.com/cpp-linter/cpp-linter-hooks
117+
rev: v0.8.0
118+
hooks:
119+
- id: clang-format
112120
- repo: https://github.com/pre-commit/mirrors-mypy.git
113121
rev: v1.15.0
114122
hooks:
@@ -144,5 +152,4 @@ repos:
144152
- --cobertura-xml-report=.tox/.tmp/.mypy/python-3.11
145153
- --html-report=.tox/.tmp/.mypy/python-3.11
146154
pass_filenames: false
147-
148155
...

CHANGES/1123.contrib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Setup pre-commit hook for auto-formatting both Python and C code.

Makefile

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,9 @@ all: test
1111
pip install -r requirements/dev.txt
1212
@touch .install-deps
1313

14-
15-
isort-check:
16-
@if ! isort --check $(SRC); then \
17-
echo "Import sort errors, run 'make fmt' to fix them!!!"; \
18-
isort --diff --check $(SRC); \
19-
false; \
20-
fi
21-
22-
black-check:
23-
@if ! isort --check $(SRC); then \
24-
echo "black errors, run 'make fmt' to fix them!!!"; \
25-
black -t py35 --diff --check $(SRC); \
26-
false; \
27-
fi
28-
29-
lint: black-check isort-check
14+
lint:
3015
python -Im pre_commit run --all-files --show-diff-on-failure
3116

32-
fmt:
33-
black -t py35 $(SRC)
34-
isort $(SRC)
35-
3617
.develop: .install-deps $(shell find multidict -type f)
3718
pip install -e .
3819
@touch .develop

benchmarks/istr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def add_impl_option(cmd, args):
4848
runner = perf.Runner(add_cmdline_args=add_impl_option)
4949

5050
parser = runner.argparser
51-
parser.description = "Allows to measure performance of " "istr implementations"
51+
parser.description = "Allows to measure performance of istr implementations"
5252
parser.add_argument(
5353
"--impl",
5454
choices=sorted(IMPLEMENTATIONS),

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def _replace_missing_aiohttp_hdrs_reference(
383383
node: pending_xref,
384384
contnode: literal,
385385
) -> "reference | None":
386-
if (node.get('refdomain'), node.get('reftype')) != ("py", "mod"):
386+
if (node.get("refdomain"), node.get("reftype")) != ("py", "mod"):
387387
return None
388388

389389
ref_target = node.get("reftarget", "")
@@ -401,7 +401,7 @@ def _replace_missing_aiohttp_hdrs_reference(
401401

402402

403403
def setup(app: Sphinx) -> dict[str, bool | str]:
404-
app.connect('missing-reference', _replace_missing_aiohttp_hdrs_reference)
404+
app.connect("missing-reference", _replace_missing_aiohttp_hdrs_reference)
405405

406406
return {
407407
"version": "builtin",

0 commit comments

Comments
 (0)