From 74b4b794fa79b3187bedab069e247652ed24b68a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 19 Nov 2022 15:09:02 +0200 Subject: [PATCH] Add linting to CI via pre-commit --- .flake8 | 2 ++ .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/workflows/lint.yml | 14 ++++++++++ .pre-commit-config.yaml | 40 +++++++++++++++++++++++++++ LICENSE | 2 +- Makefile | 6 +++++ _extensions/custom_roles.py | 7 ++--- conf.py | 42 ++++++++++++++--------------- developer-workflow/lang-changes.rst | 1 - 9 files changed, 89 insertions(+), 27 deletions(-) create mode 100644 .flake8 create mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..f4546adb41 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max_line_length = 88 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 839471ed0c..b1d63fbf36 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -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. ---> \ No newline at end of file +--> diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..c78a4053ac --- /dev/null +++ b/.github/workflows/lint.yml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..68df2b9558 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/LICENSE b/LICENSE index 28289e8791..4594fb7384 100644 --- a/LICENSE +++ b/LICENSE @@ -113,4 +113,4 @@ Affirmer's express Statement of Purpose. CC0 or use of the Work. For more information, please see - \ No newline at end of file + diff --git a/Makefile b/Makefile index b64aecc453..80b7225cdf 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/_extensions/custom_roles.py b/_extensions/custom_roles.py index 2c4e9d9d06..fb05c0e7ee 100644 --- a/_extensions/custom_roles.py +++ b/_extensions/custom_roles.py @@ -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 diff --git a/conf.py b/conf.py index c914ccc1eb..afb340defa 100644 --- a/conf.py +++ b/conf.py @@ -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" @@ -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" @@ -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", @@ -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 diff --git a/developer-workflow/lang-changes.rst b/developer-workflow/lang-changes.rst index 7d663530c0..19cc42dd1a 100644 --- a/developer-workflow/lang-changes.rst +++ b/developer-workflow/lang-changes.rst @@ -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 -