From 09cf975604374c3b5c9f065231ec32edc19b45e3 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 15 Aug 2023 10:25:12 +0100 Subject: [PATCH 1/5] Add pre-commit Useful for linters. Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000000..a8f04bcd41a --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,41 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.284 + hooks: + - id: ruff + args: ['--diff', '--format', 'github'] + + - repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-simplify + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + name: isort (python) + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.0 + hooks: + - id: mypy + additional_dependencies: + - docutils-stubs + - types-requests + files: ^sphinx/ + + - repo: https://github.com/sphinx-contrib/sphinx-lint + rev: v0.6.8 + hooks: + - id: sphinx-lint + args: ['--enable', 'line-too-long', '--max-line-length', '85'] + files: | + (?x)^( + CHANGES + | CONTRIBUTING.rst + | README.rst + | doc/.* + ) From 8ceb28d7c86bc81230ff0a873f453583957ed476 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 15 Aug 2023 10:27:13 +0100 Subject: [PATCH 2/5] pre-commit: Add additional checks Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a8f04bcd41a..d03053566a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,12 @@ repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-json + - id: check-yaml + - id: debug-statements + exclude: '^sphinx/cmd/build.py$' + - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.0.284 hooks: From b9f0a921667ad9b2d490c35d01888c0980bcabbd Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 16 Aug 2023 11:23:27 +0100 Subject: [PATCH 3/5] Use pre-commit in CI context Signed-off-by: Stephen Finucane --- .github/workflows/lint.yml | 61 ++++++++++---------------------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a39d98891b7..d146d4512ab 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -25,19 +25,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3" - - name: Install pip - run: python -m pip install --upgrade pip - - - name: Install known good Ruff - run: python -m pip install ruff==0.0.284 - - name: Lint with known good Ruff - run: ruff . --format github - - - name: Install latest Ruff - run: python -m pip install --upgrade ruff - - name: Lint with latest Ruff - continue-on-error: true - run: ruff . --format github + - uses: pre-commit/action@v3.0.0 + with: + extra_args: ruff --all-files flake8: runs-on: ubuntu-latest @@ -48,12 +38,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade "flake8>=3.5.0" "flake8-simplify" - - name: Lint with flake8 - run: flake8 . + - uses: pre-commit/action@v3.0.0 + with: + extra_args: flake8 --all-files isort: runs-on: ubuntu-latest @@ -64,12 +51,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade isort - - name: Lint with isort - run: isort --check-only --diff . + - uses: pre-commit/action@v3.0.0 + with: + extra_args: isort --all-files mypy: runs-on: ubuntu-latest @@ -80,12 +64,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade "mypy>=0.990" docutils-stubs types-requests - - name: Type check with mypy - run: mypy sphinx/ + - uses: pre-commit/action@v3.0.0 + with: + extra_args: mypy --all-files docs-lint: runs-on: ubuntu-latest @@ -96,21 +77,9 @@ jobs: uses: actions/setup-python@v4 with: python-version: "3" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade sphinx-lint - - name: Lint documentation with sphinx-lint - run: > - sphinx-lint - --enable line-too-long - --max-line-length 85 - AUTHORS.rst - CHANGES.rst - CODE_OF_CONDUCT.rst - CONTRIBUTING.rst - README.rst - doc/ + - uses: pre-commit/action@v3.0.0 + with: + extra_args: sphinx-lint --all-files twine: runs-on: ubuntu-latest From e573f7ed5df19ee8afc0086989f4e84b80f6a251 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 16 Aug 2023 11:23:59 +0100 Subject: [PATCH 4/5] tox: Add 'lint' target Signed-off-by: Stephen Finucane --- tox.ini | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tox.ini b/tox.ini index fb7e344ff0b..b9c2b805403 100644 --- a/tox.ini +++ b/tox.ini @@ -26,6 +26,14 @@ setenv = commands= python -X dev -X warn_default_encoding -m pytest --durations 25 {posargs} +[testenv:lint] +description = + Run style checks. +deps = + pre-commit +commands = + pre-commit run --all-files --show-diff-on-failure + [testenv:docs] basepython = python3 description = From 886a5ecec6ddb09ca9a02df7e4a11fcf259e0d1f Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 16 Aug 2023 11:24:30 +0100 Subject: [PATCH 5/5] pyproject: Remove 'lint' extras This is unnecessary duplication that isn't used anywhere. Signed-off-by: Stephen Finucane --- pyproject.toml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a0ada3cd3ae..f09ca15ffc5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,16 +79,6 @@ dynamic = ["version"] docs = [ "sphinxcontrib-websupport", ] -lint = [ - "flake8>=3.5.0", - "flake8-simplify", - "isort", - "ruff", - "mypy>=0.990", - "sphinx-lint", - "docutils-stubs", - "types-requests", -] test = [ "pytest>=4.6", "html5lib",