Skip to content

Commit

Permalink
Add linting to CI via pre-commit (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Jul 31, 2023
1 parent 65ae4a8 commit 1cb3c18
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max_line_length = 88
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ It should describe the change to be made.
Most PRs will require an issue number. Trivial changes, like fixing a typo,
do not need an issue.
-->
-->
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ jobs:
cache: pip
- name: Build docs
run: make html
- name: Check markup
run: make check
- name: Link check
run: make linkcheck
continue-on-error: true
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint

on: [push, pull_request, workflow_dispatch]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.0
47 changes: 47 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
args: [--skip-string-normalization]

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black]

- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [flake8-2020]

- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.7
hooks:
- id: sphinx-lint
args: ["--enable=default-role"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

ci:
autoupdate_schedule: quarterly
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@ Affirmer's express Statement of Purpose.
CC0 or use of the Work.

For more information, please see
<https://creativecommons.org/publicdomain/zero/1.0/>
<https://creativecommons.org/publicdomain/zero/1.0/>
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ help:
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " check to run a check for frequent markup errors"
@echo " lint to lint all the files"
@echo " versions to update release cycle after changing release-cycle.json"

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

.PHONY: lint
lint: venv
$(VENVDIR)/bin/python3 -m pre_commit --version > /dev/null || $(VENVDIR)/bin/python3 -m pip install pre-commit
$(VENVDIR)/bin/python3 -m pre_commit run --all-files

.PHONY: serve
serve:
@echo "The 'serve' target was removed, use 'htmlview' instead" \
Expand Down
5 changes: 3 additions & 2 deletions _extensions/custom_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def role(name, rawtext, text, lineno, inliner, _options=None, _content=None):
if text.startswith('!'):
node = nodes.literal(rawtext, text[1:])
else:
node = nodes.reference(rawtext, '', nodes.literal(rawtext, text),
refuri=url, internal=False)
node = nodes.reference(
rawtext, '', nodes.literal(rawtext, text), refuri=url, internal=False
)
return [node], []

return role
11 changes: 6 additions & 5 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'.github',
]


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

linkcheck_allowed_redirects = {
# Edit page
r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit",
r"https://docs.google.com/document/d/.*/": r"https://docs.google.com/document/d/.*/edit", # noqa: E501
# Canonical
r"https://docs.python.org/": r"https://docs.python.org/3/",
# Translations with country codes
r"https://docs.python.org/[a-z-]+/": r"https://docs.python.org/[a-z-]+/3/",
# Personal /my/ links redirect to login page
r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences",
r"https://discuss.python.org/my/.*": r"https://discuss.python.org/login-preferences", # noqa: E501
# Login page
r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*",
r"https://github.com/python/core-workflow/issues/new.*": r"https://github.com/login.*", # noqa: E501
# Archive redirect
r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main",
r"https://github.com/python/cpython/archive/main.zip": r"https://codeload.github.com/python/cpython/zip/refs/heads/main", # noqa: E501
# Blob to tree
r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*",
r"https://github.com/python/cpython/blob/.*": r"https://github.com/python/cpython/tree/.*", # noqa: E501
# HackMD shortcuts
r"https://hackmd.io/s/.*": r"https://hackmd.io/@.*",
# Read the Docs
Expand Down
1 change: 0 additions & 1 deletion developer-workflow/lang-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ to inform others who may propose a similar language change in the future.
.. _Ideas Discourse category: https://discuss.python.org/c/ideas/6
.. _Status Quo Wins a Stalemate: https://www.curiousefficiency.org/posts/2011/02/status-quo-wins-stalemate.html
.. _Justifying Python Language Changes: https://www.curiousefficiency.org/posts/2011/02/justifying-python-language-changes.html

0 comments on commit 1cb3c18

Please sign in to comment.