From e43f567e93c194e95efcd57f31121b7be2f4941f Mon Sep 17 00:00:00 2001 From: CAM Gerlach Date: Mon, 31 Jan 2022 20:49:58 -0600 Subject: [PATCH] Upgrade lint infra & add a few more conservative built-in checks (#2286) --- .github/CODEOWNERS | 8 ++-- .github/workflows/build.yml | 6 ++- .github/workflows/deploy-gh-pages.yml | 9 ++-- .github/workflows/lint.yml | 15 ++++-- .pre-commit-config.yaml | 66 ++++++++++++++++++++++----- pep-0418/clockutils.py | 0 scan-ops.py => pep-0465/scan-ops.py | 2 +- pep-0590.rst | 2 +- pep-0635.rst | 4 +- pep-0642.rst | 2 +- pep-0675.rst | 2 +- 11 files changed, 87 insertions(+), 29 deletions(-) mode change 100644 => 100755 pep-0418/clockutils.py rename scan-ops.py => pep-0465/scan-ops.py (98%) mode change 100644 => 100755 diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ae557e92a1f..41189c85330 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -6,7 +6,7 @@ * @python/pep-editors # PEP infrastructure -.github/workflows/ @AA-Turner +.github/workflows/ @AA-Turner @CAM-Gerlach Makefile @AA-Turner requirements.txt @AA-Turner .pre-commit-config.yml @CAM-Gerlach @@ -38,6 +38,7 @@ pep-0009.txt @warsaw pep-0010.txt @warsaw pep-0011.txt @brettcannon pep-0012.rst @brettcannon @warsaw +pep-0012/ @brettcannon # pep-0013.rst is owned by the entire core team. # ... pep-0020.txt @tim-one @@ -319,6 +320,7 @@ pep-0462.txt @ncoghlan # pep-0463.txt pep-0464.txt @dstufft pep-0465.txt @njsmith +pep-0465/ @njsmith pep-0466.txt @ncoghlan pep-0467.txt @ncoghlan @ethanfurman pep-0468.txt @ericsnowcurrently @@ -478,7 +480,7 @@ pep-0603-hamt_vs_dict.png @1st1 pep-0605.rst @zooba @ncoghlan pep-0605-example-release-calendar.png @zooba @ncoghlan pep-0605-overlapping-support-matrix.png @zooba @ncoghlan -/pep-0605/ @zooba @ncoghlan +pep-0605/ @zooba @ncoghlan pep-0606.rst @vstinner pep-0607.rst @ambv @zooba @ncoghlan pep-0608.rst @vstinner @@ -536,7 +538,7 @@ pep-0659.rst @markshannon pep-0660.rst @pfmoore pep-0661.rst @taleinat pep-0662.rst @brettcannon -pep-0662/pep-0662-editables.json @brettcannon +pep-0662/ @brettcannon pep-0663.txt @ethanfurman pep-0664.rst @pablogsal pep-0665.rst @brettcannon diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 535dbd1302f..622f5b2bfd1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,13 +1,15 @@ -name: Build +name: Docutils Build on: [push, pull_request, workflow_dispatch] jobs: build: + name: Build with Docutils runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - name: Check out repo + uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml index 8f61e4b14a7..de95eb3445c 100644 --- a/.github/workflows/deploy-gh-pages.yml +++ b/.github/workflows/deploy-gh-pages.yml @@ -1,9 +1,10 @@ -name: Deploy to GitHub Pages +name: Sphinx Build on: [push, pull_request, workflow_dispatch] jobs: deploy-to-pages: + name: Build & deploy to GitHub Pages runs-on: ubuntu-latest steps: @@ -15,13 +16,13 @@ jobs: - name: 🐍 Set up Python 3 uses: actions/setup-python@v2 with: - python-version: 3 + python-version: '3.x' cache: "pip" - name: 👷‍ Install dependencies run: | python -m pip install --upgrade pip - python -m pip install -r requirements.txt + python -m pip install --upgrade -r requirements.txt - name: 🔧 Build PEPs run: make pages -j$(nproc) @@ -33,7 +34,7 @@ jobs: - name: 🚀 Deploy to GitHub pages # This allows CI to build branches for testing if: github.ref == 'refs/heads/main' - uses: JamesIves/github-pages-deploy-action@4.1.1 + uses: JamesIves/github-pages-deploy-action@v4.2.2 with: branch: gh-pages # The branch to deploy to. folder: build # Synchronise with build.py -> build_directory diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4f3c2c941cf..ee5cd980ec4 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,8 +4,17 @@ on: [push, pull_request, workflow_dispatch] jobs: pre-commit: + name: Run pre-commit runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: pre-commit/action@v2.0.0 + - name: Check out repo + uses: actions/checkout@v2 + + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Run pre-commit hooks + uses: pre-commit/action@v2.0.3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb9238a528a..a98015fbdec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,33 +1,77 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + +minimum_pre_commit_version: '2.8.2' + +default_language_version: + python: python3 + +default_stages: [commit] + + repos: + # General file checks and fixers - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.1.0 hooks: - id: mixed-line-ending - name: Normalize mixed line endings + name: "Normalize mixed line endings" args: [--fix=lf] + - id: fix-byte-order-marker + name: "Remove Unicode BOM" + - id: file-contents-sorter + name: "Sort codespell ignore list" + files: '.codespell/ignore-words.txt' + + - id: check-case-conflict + name: "Check for case conflicts" + - id: check-merge-conflict + name: "Check for merge conflict markers" + - id: check-executables-have-shebangs + name: "Check that executables have shebangs" + - id: check-shebang-scripts-are-executable + name: "Check that shebangs are executable" + + - id: check-vcs-permalinks + name: "Check that VCS links are permalinks" + + - id: check-ast + name: "Check Python AST" + - id: check-json + name: "Check JSON" + - id: check-toml + name: "Check TOML" + - id: check-yaml + name: "Check YAML" + # RST checks - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.8.0 + rev: v1.9.0 hooks: - id: rst-backticks + name: "Check RST: No single backticks" - id: rst-inline-touching-normal + name: "Check RST: No backticks touching text" files: '^pep-\d+\.txt|\.rst$' types: [text] - id: rst-directive-colons + name: "Check RST: 2 colons after directives" files: '^pep-\d+\.txt|\.rst$' types: [text] + # Manual codespell check - repo: https://github.com/codespell-project/codespell rev: v2.1.0 hooks: - id: codespell - name: Check for common misspellings in text files + name: "Check for common misspellings in text files" stages: [manual] + # Local checks for PEP headers and more - repo: local hooks: - id: check-required-fields - name: "Check all PEPs have required fields" + name: "Check PEPs have all required fields" language: pygrep entry: '(?-m:^PEP:(?=[\s\S]*\nTitle:)(?=[\s\S]*\nAuthor:)(?=[\s\S]*\nStatus:)(?=[\s\S]*\nType:)(?=[\s\S]*\nContent-Type:)(?=[\s\S]*\nCreated:))' args: ['--negate', '--multiline'] @@ -41,19 +85,19 @@ repos: files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-status - name: "Validate PEP Status field" + name: "Validate PEP 'Status' field" language: pygrep entry: '^Status:(?:(?! +(Draft|Withdrawn|Rejected|Accepted|Final|Active|Provisional|Deferred|Superseded|April Fool!)$))' files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-type - name: "Validate PEP Type field" + name: "Validate PEP 'Type' field" language: pygrep entry: '^Type:(?:(?! +(Standards Track|Informational|Process)$))' files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-content-type - name: "Validate PEP Content-Type field" + name: "Validate PEP 'Content-Type' field" language: pygrep entry: '^Content-Type:(?:(?! +text\/x-rst$))' files: '^pep-\d+\.(rst|txt)$' @@ -65,19 +109,19 @@ repos: files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-created - name: "Validate created dates" + name: "Validate PEP 'Created' field" language: pygrep entry: '^Created:(?:(?! +([0-2][0-9]|(3[01]))-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(199[0-9]|20[0-9][0-9])( \([^()]+\))?$))' files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-python-version - name: "Validate PEP Python-Version field" + name: "Validate PEP 'Python-Version' field" language: pygrep entry: '^Python-Version:(?:(?! +( ?[1-9]\.([0-9][0-9]?|x)(\.[1-9][0-9]?)?\??,?)+( \([^()]+\))?$))' files: '^pep-\d+\.(rst|txt)$' types: [text] - id: validate-resolution - name: "Validate PEP Resolution field" + name: "Validate PEP 'Resolution' field" language: pygrep entry: '(?#]*?`)\n))' args: ['--multiline'] diff --git a/pep-0418/clockutils.py b/pep-0418/clockutils.py old mode 100644 new mode 100755 diff --git a/scan-ops.py b/pep-0465/scan-ops.py old mode 100644 new mode 100755 similarity index 98% rename from scan-ops.py rename to pep-0465/scan-ops.py index 79603b598b3..ac99037cb61 --- a/scan-ops.py +++ b/pep-0465/scan-ops.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# http://legacy.python.org/dev/peps/pep-0465/ +# https://www.python.org/dev/peps/pep-0465/ # https://gist.github.com/njsmith/9157645 # usage: diff --git a/pep-0590.rst b/pep-0590.rst index 41298d5534e..a3fa010fa06 100644 --- a/pep-0590.rst +++ b/pep-0590.rst @@ -308,7 +308,7 @@ References .. [2] tp_call/PyObject_Call calling convention https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_call .. [3] Using PY_VECTORCALL_ARGUMENTS_OFFSET in callee - https://github.com/markshannon/cpython/blob/vectorcall-minimal/Objects/classobject.c#L53 + https://github.com/markshannon/cpython/blob/815cc1a30d85cdf2e3d77d21224db7055a1f07cb/Objects/classobject.c#L53 .. [4] Argument Clinic https://docs.python.org/3/howto/clinic.html diff --git a/pep-0635.rst b/pep-0635.rst index 97a547aa3cf..d3ff5a55fda 100644 --- a/pep-0635.rst +++ b/pep-0635.rst @@ -97,8 +97,8 @@ but also on the value of some class attributes, like the ``BinOp`` example above. The Visitor pattern is insufficiently flexible for this: it can only select based on the class. -For a complete example, see -https://github.com/gvanrossum/patma/blob/master/examples/expr.py#L231 +See a `complete example +`_. Like the Visitor pattern, pattern matching allows for a strict separation of concerns: specific actions or data processing is independent of the diff --git a/pep-0642.rst b/pep-0642.rst index b06af6dc99f..6932bedb29b 100644 --- a/pep-0642.rst +++ b/pep-0642.rst @@ -1356,7 +1356,7 @@ they don't define ``__match_args__`` (the optimised fast path for the builtin and standard library types named in :pep:`634` is retained). Adapting the class matching example -`linked from PEP 635 `_ +`linked from PEP 635 `_ shows that for purely positional class matching, the main impact comes from the changes to value constraints and name binding, not from the class matching changes:: diff --git a/pep-0675.rst b/pep-0675.rst index 640452a3cde..a1b0464eb90 100644 --- a/pep-0675.rst +++ b/pep-0675.rst @@ -819,7 +819,7 @@ and render HTML as-is is to use functions like ``mark_safe`` in `Django `_ or ``do_mark_safe`` in `Jinja2 -`_, +`_, which cause XSS vulnerabilities: ::