Skip to content

Commit 8a6a442

Browse files
committed
ci: add nitpick to standardize config
1 parent 1ca567d commit 8a6a442

6 files changed

Lines changed: 177 additions & 93 deletions

File tree

.editorconfig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ root = true
33

44
# All files.
55
[*]
6-
end_of_line = LF
6+
end_of_line = lf
77
indent_style = space
88
indent_size = 4
99
charset = utf-8
@@ -12,3 +12,12 @@ insert_final_newline = true
1212

1313
[*.{yml,yaml}]
1414
indent_size = 2
15+
16+
[*.{bat,cmd,ps1}]
17+
end_of_line = crlf
18+
19+
[*.{js,json,json5,yml,yaml,md,rb}]
20+
indent_size = 2
21+
22+
[Makefile]
23+
indent_style = tab

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
[Ll]ib
99
[Ll]ib64
1010
[Ll]ocal
11-
[Ss]cripts
1211
pyvenv.cfg
1312
.venv
1413
pip-selfcheck.json

.pre-commit-config.yaml

Lines changed: 94 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,95 @@
11
repos:
2-
- hooks:
3-
- args:
4-
- --markdown-linebreak-ext=md,markdown
5-
id: trailing-whitespace
6-
- id: end-of-file-fixer
7-
- id: check-yaml
8-
- id: check-added-large-files
9-
- id: check-ast
10-
- id: fix-byte-order-marker
11-
- id: check-merge-conflict
12-
- id: debug-statements
13-
- id: detect-private-key
14-
- id: check-builtin-literals
15-
- id: check-case-conflict
16-
- id: check-docstring-first
17-
- id: check-executables-have-shebangs
18-
- id: check-shebang-scripts-are-executable
19-
- id: check-symlinks
20-
- args:
21-
- --fix=lf
22-
id: mixed-line-ending
23-
- exclude: ^\.(vscode|devcontainer)/
24-
id: check-json
25-
- args:
26-
- --indent
27-
- '4'
28-
- --autofix
29-
- --no-sort-keys
30-
exclude: ^\.(vscode|devcontainer)/
31-
id: pretty-format-json
32-
- id: check-toml
33-
repo: https://github.com/pre-commit/pre-commit-hooks
34-
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c
35-
- repo: https://github.com/bwhmather/ssort
36-
rev: dcb59fdb9b46ed1bb8e6ca2107e35f76cdc9c97e # frozen: 0.12.4
37-
hooks:
38-
- id: ssort
39-
- hooks:
40-
- id: black
41-
repo: https://github.com/psf/black
42-
rev: 8fe627072f15ff2e3d380887b92f7868efaf6d05
43-
- hooks:
44-
- id: isort
45-
repo: https://github.com/pycqa/isort
46-
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3
47-
- hooks:
48-
- id: python-no-eval
49-
- id: python-no-log-warn
50-
repo: https://github.com/pre-commit/pygrep-hooks
51-
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316
52-
- hooks:
53-
- id: flynt
54-
repo: https://github.com/ikamensh/flynt
55-
rev: 651c822fdcf45fffcf9743dc755085f32acb65e3
56-
- hooks:
57-
- args:
58-
- --py38-plus
59-
id: pyupgrade
60-
repo: https://github.com/asottile/pyupgrade
61-
rev: 12af25eb252deaaecb6b259df40d01f42e716dc3
62-
- hooks:
63-
- additional_dependencies:
64-
- tomli ; python_version < '3.11'
65-
id: auto-walrus
66-
repo: https://github.com/MarcoGorelli/auto-walrus
67-
rev: 7855759486496a3248e9ff37dce7c6d57d39bfce
68-
- hooks:
69-
- additional_dependencies:
70-
- tomli ; python_version < '3.11'
71-
id: codespell
72-
repo: https://github.com/codespell-project/codespell
73-
rev: 6e41aba91fb32e9feb741a6258eefeb9c6e4a482
74-
- hooks:
75-
- id: commitizen
76-
repo: https://github.com/commitizen-tools/commitizen
77-
rev: 7c0bc1591103b1f089aab9810fc2a201ccb0552b
78-
- hooks:
79-
- entry: hatch run python3 -m mypy
80-
exclude: tests/.*
81-
id: mypy
82-
language: system
83-
name: mypy
84-
types:
85-
- python
86-
repo: local
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c
4+
hooks:
5+
- id: trailing-whitespace
6+
args:
7+
- --markdown-linebreak-ext=md,markdown
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
- id: check-ast
12+
- id: fix-byte-order-marker
13+
- id: check-merge-conflict
14+
- id: debug-statements
15+
- id: detect-private-key
16+
- id: check-builtin-literals
17+
- id: check-case-conflict
18+
- id: check-docstring-first
19+
- id: check-executables-have-shebangs
20+
- id: check-shebang-scripts-are-executable
21+
- id: check-symlinks
22+
- id: mixed-line-ending
23+
args:
24+
- --fix=lf
25+
- id: check-json
26+
exclude: ^\.(vscode|devcontainer)/
27+
- id: pretty-format-json
28+
exclude: ^\.(vscode|devcontainer)/
29+
args:
30+
- --indent
31+
- '4'
32+
- --autofix
33+
- --no-sort-keys
34+
- id: check-toml
35+
- repo: https://github.com/bwhmather/ssort
36+
rev: dcb59fdb9b46ed1bb8e6ca2107e35f76cdc9c97e # frozen: 0.12.4
37+
hooks:
38+
- id: ssort
39+
- repo: https://github.com/psf/black
40+
rev: 8fe627072f15ff2e3d380887b92f7868efaf6d05
41+
hooks:
42+
- id: black
43+
- repo: https://github.com/pycqa/isort
44+
rev: c235f5e450b4b84e58d114ed4c589cbf454175a3
45+
hooks:
46+
- id: isort
47+
- repo: https://github.com/pre-commit/pygrep-hooks
48+
rev: 3a6eb0fadf60b3cccfd80bad9dbb6fae7e47b316
49+
hooks:
50+
- id: python-no-eval
51+
- id: python-no-log-warn
52+
- repo: https://github.com/ikamensh/flynt
53+
rev: 651c822fdcf45fffcf9743dc755085f32acb65e3
54+
hooks:
55+
- id: flynt
56+
- repo: https://github.com/asottile/pyupgrade
57+
rev: 12af25eb252deaaecb6b259df40d01f42e716dc3
58+
hooks:
59+
- id: pyupgrade
60+
args:
61+
- --py38-plus
62+
- repo: https://github.com/MarcoGorelli/auto-walrus
63+
rev: 7855759486496a3248e9ff37dce7c6d57d39bfce
64+
hooks:
65+
- id: auto-walrus
66+
additional_dependencies:
67+
- tomli ; python_version < '3.11'
68+
- repo: https://github.com/codespell-project/codespell
69+
rev: 6e41aba91fb32e9feb741a6258eefeb9c6e4a482
70+
hooks:
71+
- id: codespell
72+
additional_dependencies:
73+
- tomli ; python_version < '3.11'
74+
- repo: https://github.com/commitizen-tools/commitizen
75+
rev: 7c0bc1591103b1f089aab9810fc2a201ccb0552b
76+
hooks:
77+
- id: commitizen
78+
- repo: local
79+
hooks:
80+
- id: mypy
81+
exclude: tests/.*
82+
entry: hatch run python3 -m mypy
83+
language: system
84+
name: mypy
85+
types:
86+
- python
87+
- repo: https://github.com/andreoliwa/nitpick
88+
rev: '36d4912df1f0bd2ed8cc535b57c5ba3b09ce3d46' # frozen: v0.35.0
89+
hooks:
90+
- id: nitpick
91+
minimum_pre_commit_version: 2.18.0
92+
default_install_hook_types:
93+
- pre-commit
94+
- pre-push
95+
- commit-msg

pyproject.toml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ dependencies = [
4545
"irc-parser-tests",
4646
"pre-commit",
4747
"mypy>=1.8",
48+
"ruamel.yaml",
4849
]
4950

5051
[tool.hatch.envs.default.scripts]
51-
setup-pre-commit = "python3 -m pre_commit install --install-hooks -t commit-msg -t pre-push -t pre-commit"
52-
setup-dev = ["setup-pre-commit"]
53-
54-
pre-commit = "python3 -m pre_commit run {args:--all}"
52+
setup-dev = ["hatch run pre-commit install"]
53+
fix-pre-commit = ["hatch run python3 -m scripts.fix_pre_commit"]
5554

5655
[tool.hatch.envs.hatch-test]
57-
default-args = ["tests", "polymatch"]
56+
default-args = ["tests", "irclib"]
5857
extra-args = ["-vv"]
5958
[tool.hatch.envs.hatch-test.scripts]
6059
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
@@ -67,7 +66,7 @@ python = ["3.13", "3.12", "3.11", "3.10", "3.9"]
6766
[tool.hatch.envs.types]
6867
extra-dependencies = ["mypy>=1.0.0"]
6968
[tool.hatch.envs.types.scripts]
70-
check = "mypy --install-types --non-interactive {args:polymatch tests}"
69+
check = "mypy --install-types --non-interactive {args:irclib tests}"
7170

7271
[tool.isort]
7372
profile = "black"
@@ -141,6 +140,7 @@ convention = "google"
141140
aggressive = true
142141
transform-joins = true
143142
transform-concats = true
143+
line-length = 120
144144

145145
[tool.mypy]
146146
namespace_packages = true
@@ -171,6 +171,7 @@ enable_error_code = [
171171
"truthy-iterable",
172172
"ignore-without-code",
173173
]
174+
ignore_missing_imports = true
174175

175176
[tool.pytest.ini_options]
176177
minversion = "6.0"
@@ -198,3 +199,9 @@ version_scheme = "semver"
198199
version_provider = "scm"
199200
update_changelog_on_bump = true
200201
major_version_zero = true
202+
203+
[tool.nitpick]
204+
style = ["gh://TotallyNotRobots/nitpick/lib-style-3.8.toml"]
205+
206+
[tool.check-spdx-header]
207+
headers = ["2017-present linuxdaemon <linuxdaemon.irc@gmail.com>"]

scripts/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: 2018-present linuxdaemon <linuxdaemon.irc@gmail.com>
2+
#
3+
# SPDX-License-Identifier: MIT

scripts/fix_pre_commit.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# SPDX-FileCopyrightText: 2018-present linuxdaemon <linuxdaemon.irc@gmail.com>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
from pathlib import Path
6+
7+
from ruamel.yaml import YAML
8+
from ruamel.yaml.comments import CommentedMap, CommentedSeq
9+
10+
yaml = YAML(typ="rt")
11+
12+
yaml.preserve_quotes = True
13+
yaml.sequence_dash_offset = 2
14+
yaml.map_indent = 2
15+
yaml.sequence_indent = 4
16+
17+
PRE_COMMIT_FILE = Path(".pre-commit-config.yaml")
18+
19+
20+
def main() -> None:
21+
with PRE_COMMIT_FILE.open() as f:
22+
data = yaml.load(f)
23+
24+
repos: CommentedSeq = data["repos"]
25+
for j in range(len(repos)):
26+
repo: CommentedMap = repos[j]
27+
new_repo = repo.copy_attributes(CommentedMap())
28+
29+
for v in ("repo", "rev"):
30+
if v in repo:
31+
old = repo.pop(v)
32+
new_repo[v] = old
33+
34+
for k, v in repo.items():
35+
new_repo[k] = v
36+
37+
hooks = new_repo["hooks"]
38+
for i in range(len(hooks)):
39+
hook = hooks[i]
40+
new_hook = hook.copy_attributes(CommentedMap())
41+
for k in ("id", "exclude"):
42+
if k in hook:
43+
new_hook[k] = hook.pop(k)
44+
45+
for k, v in hook.items():
46+
new_hook[k] = v
47+
48+
hooks[i] = new_hook
49+
50+
repos[j] = new_repo
51+
52+
with PRE_COMMIT_FILE.open("w") as f:
53+
yaml.dump(data, f)
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)