Skip to content

Commit 1cb3c18

Browse files
authored
Add linting to CI via pre-commit (#987)
1 parent 65ae4a8 commit 1cb3c18

File tree

10 files changed

+80
-12
lines changed

10 files changed

+80
-12
lines changed

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max_line_length = 88

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ It should describe the change to be made.
88
99
Most PRs will require an issue number. Trivial changes, like fixing a typo,
1010
do not need an issue.
11-
-->
11+
-->

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
cache: pip
2020
- name: Build docs
2121
run: make html
22-
- name: Check markup
23-
run: make check
2422
- name: Link check
2523
run: make linkcheck
2624
continue-on-error: true

.github/workflows/lint.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lint
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-python@v4
12+
with:
13+
python-version: "3.x"
14+
- uses: pre-commit/action@v3.0.0

.pre-commit-config.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repos:
2+
- repo: https://github.com/asottile/pyupgrade
3+
rev: v3.10.1
4+
hooks:
5+
- id: pyupgrade
6+
args: [--py38-plus]
7+
8+
- repo: https://github.com/psf/black
9+
rev: 23.7.0
10+
hooks:
11+
- id: black
12+
args: [--skip-string-normalization]
13+
14+
- repo: https://github.com/PyCQA/isort
15+
rev: 5.12.0
16+
hooks:
17+
- id: isort
18+
args: [--profile=black]
19+
20+
- repo: https://github.com/PyCQA/flake8
21+
rev: 6.1.0
22+
hooks:
23+
- id: flake8
24+
additional_dependencies: [flake8-2020]
25+
26+
- repo: https://github.com/sphinx-contrib/sphinx-lint
27+
rev: v0.6.7
28+
hooks:
29+
- id: sphinx-lint
30+
args: ["--enable=default-role"]
31+
32+
- repo: https://github.com/pre-commit/pygrep-hooks
33+
rev: v1.10.0
34+
hooks:
35+
- id: python-check-blanket-noqa
36+
37+
- repo: https://github.com/pre-commit/pre-commit-hooks
38+
rev: v4.4.0
39+
hooks:
40+
- id: check-json
41+
- id: check-merge-conflict
42+
- id: check-yaml
43+
- id: end-of-file-fixer
44+
- id: trailing-whitespace
45+
46+
ci:
47+
autoupdate_schedule: quarterly

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ Affirmer's express Statement of Purpose.
113113
CC0 or use of the Work.
114114

115115
For more information, please see
116-
<https://creativecommons.org/publicdomain/zero/1.0/>
116+
<https://creativecommons.org/publicdomain/zero/1.0/>

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ help:
3838
@echo " linkcheck to check all external links for integrity"
3939
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
4040
@echo " check to run a check for frequent markup errors"
41+
@echo " lint to lint all the files"
4142
@echo " versions to update release cycle after changing release-cycle.json"
4243

4344
.PHONY: clean
@@ -183,6 +184,11 @@ check: ensure-venv
183184
# Ignore the tools and venv dirs and check that the default role is not used.
184185
$(SPHINXLINT) -i tools -i $(VENVDIR) --enable default-role
185186

187+
.PHONY: lint
188+
lint: venv
189+
$(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit
190+
$(VENVDIR)/bin/python3 -m pre_commit run --all-files
191+
186192
.PHONY: serve
187193
serve:
188194
@echo "The 'serve' target was removed, use 'htmlview' instead" \

_extensions/custom_roles.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ def role(name, rawtext, text, lineno, inliner, _options=None, _content=None):
3535
if text.startswith('!'):
3636
node = nodes.literal(rawtext, text[1:])
3737
else:
38-
node = nodes.reference(rawtext, '', nodes.literal(rawtext, text),
39-
refuri=url, internal=False)
38+
node = nodes.reference(
39+
rawtext, '', nodes.literal(rawtext, text), refuri=url, internal=False
40+
)
4041
return [node], []
4142

4243
return role

conf.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'.github',
3535
]
3636

37+
3738
def _asset_hash(path: os.PathLike[str]) -> str:
3839
"""Append a `?digest=` to an url based on the file content."""
3940
full_path = (Path(html_static_path[0]) / path).resolve()
@@ -59,19 +60,19 @@ def _asset_hash(path: os.PathLike[str]) -> str:
5960

6061
linkcheck_allowed_redirects = {
6162
# Edit page
62-
r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit",
63+
r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit", # noqa: E501
6364
# Canonical
6465
r"https://docs.python.org/": r"https://docs.python.org/3/",
6566
# Translations with country codes
6667
r"https://docs.python.org/[a-z-]+/": r"https://docs.python.org/[a-z-]+/3/",
6768
# Personal /my/ links redirect to login page
68-
r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences",
69+
r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences", # noqa: E501
6970
# Login page
70-
r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*",
71+
r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*", # noqa: E501
7172
# Archive redirect
72-
r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main",
73+
r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main", # noqa: E501
7374
# Blob to tree
74-
r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*",
75+
r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*", # noqa: E501
7576
# HackMD shortcuts
7677
r"https://hackmd.io/s/.*": r"https://hackmd.io/@.*",
7778
# Read the Docs

developer-workflow/lang-changes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@ to inform others who may propose a similar language change in the future.
8686
.. _Ideas Discourse category: https://discuss.python.org/c/ideas/6
8787
.. _Status Quo Wins a Stalemate: https://www.curiousefficiency.org/posts/2011/02/status-quo-wins-stalemate.html
8888
.. _Justifying Python Language Changes: https://www.curiousefficiency.org/posts/2011/02/justifying-python-language-changes.html
89-

0 commit comments

Comments
 (0)