Skip to content

Commit

Permalink
Add linting to CI via pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 19, 2022
1 parent 71f3b76 commit 74b4b79
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 27 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.
-->
-->
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
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: [--target-version=py37]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

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

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

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.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"

.PHONY: clean
clean: clean-venv
Expand Down Expand Up @@ -186,3 +187,8 @@ check: ensure-venv
serve:
@echo "The 'serve' target was removed, use 'htmlview' instead" \
"(see https://github.com/python/cpython/issues/80510)"

.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
7 changes: 4 additions & 3 deletions _extensions/custom_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ def role(name, rawtext, text, lineno, inliner, _options=None, _content=None):
url_text = text
url = pattern.format(url_text)
# don't create a reference if the text starts with !
if text.startswith('!'):
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
42 changes: 21 additions & 21 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
sys.path.insert(0, os.path.abspath(".") + "/_extensions")

extensions = [
'custom_roles',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx_copybutton',
'sphinxext.rediraffe',
"custom_roles",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx_copybutton",
"sphinxext.rediraffe",
]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = "Python Developer's Guide"
Expand All @@ -23,18 +23,18 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = [
'_build',
'venv*',
'env*',
'README.rst',
'.github',
"_build",
"venv*",
"env*",
"README.rst",
".github",
]

html_theme = 'furo'
html_theme = "furo"
html_theme_options = {}
html_static_path = ['_static']
html_static_path = ["_static"]
html_css_files = [
'devguide_overrides.css',
"devguide_overrides.css",
]
html_logo = "_static/python-logo.svg"

Expand All @@ -46,7 +46,7 @@
# http://www.sphinx-doc.org/en/stable/config.html?highlight=linkcheck#confval-linkcheck_anchors_ignore
linkcheck_anchors_ignore = [
# match any anchor that starts with a '/' since this is an invalid HTML anchor
r'\/.*',
r"\/.*",
]
rediraffe_redirects = {
"clang.rst": "advanced-tools/clang.rst",
Expand Down Expand Up @@ -89,17 +89,17 @@

linkcheck_ignore = [
# The voters repo is private and appears as a 404
'https://github.com/python/voters/',
"https://github.com/python/voters/",
# The python-core team link is private, redirects to login
'https://github.com/orgs/python/teams/python-core',
"https://github.com/orgs/python/teams/python-core",
# The Discourse groups are private unless you are logged in
'https://discuss.python.org/groups/staff',
'https://discuss.python.org/groups/moderators',
'https://discuss.python.org/groups/admins',
"https://discuss.python.org/groups/staff",
"https://discuss.python.org/groups/moderators",
"https://discuss.python.org/groups/admins",
]

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
"python": ("https://docs.python.org/3", None),
}

todo_include_todos = True
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 74b4b79

Please sign in to comment.