From e3c986f8210f8ba2472f6897e52fba26183ad243 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:43:41 +0000 Subject: [PATCH 01/11] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: 2c9f875913ee60ca25ce70243dc24d5b6415598c → cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b](https://github.com/pre-commit/pre-commit-hooks/compare/2c9f875913ee60ca25ce70243dc24d5b6415598c...cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b) - [github.com/astral-sh/ruff-pre-commit: ac97362543353002a47d6cae8918b25444d102df → 89c421dff2e1026ba12cdb9ebd731f4a83aa8021](https://github.com/astral-sh/ruff-pre-commit/compare/ac97362543353002a47d6cae8918b25444d102df...89c421dff2e1026ba12cdb9ebd731f4a83aa8021) - [github.com/asottile/blacken-docs: 4c97c4a0d921007af6fefae92d8447cfbf63720b → 78a9dcbecf4f755f65d1f3dec556bc249d723600](https://github.com/asottile/blacken-docs/compare/4c97c4a0d921007af6fefae92d8447cfbf63720b...78a9dcbecf4f755f65d1f3dec556bc249d723600) - [github.com/pre-commit/pre-commit-hooks: 2c9f875913ee60ca25ce70243dc24d5b6415598c → cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b](https://github.com/pre-commit/pre-commit-hooks/compare/2c9f875913ee60ca25ce70243dc24d5b6415598c...cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b) - [github.com/pre-commit/pre-commit-hooks: 2c9f875913ee60ca25ce70243dc24d5b6415598c → cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b](https://github.com/pre-commit/pre-commit-hooks/compare/2c9f875913ee60ca25ce70243dc24d5b6415598c...cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b) - [github.com/astral-sh/ruff-pre-commit: ac97362543353002a47d6cae8918b25444d102df → 89c421dff2e1026ba12cdb9ebd731f4a83aa8021](https://github.com/astral-sh/ruff-pre-commit/compare/ac97362543353002a47d6cae8918b25444d102df...89c421dff2e1026ba12cdb9ebd731f4a83aa8021) - [github.com/pre-commit/pre-commit-hooks: 2c9f875913ee60ca25ce70243dc24d5b6415598c → cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b](https://github.com/pre-commit/pre-commit-hooks/compare/2c9f875913ee60ca25ce70243dc24d5b6415598c...cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b) - https://github.com/PyCQA/pylint/: da1956664d6be3d008a90ad3f72bdd9d8a7ecfaa → c28580be76fe1ec55a6cac41833c0bd68070d2f7 - [github.com/DavidAnson/markdownlint-cli2: 24eb4dce508ab81398d14d75179123fca425f12d → af14a2e768b741b941255b4c6b875339b4acbb73](https://github.com/DavidAnson/markdownlint-cli2/compare/24eb4dce508ab81398d14d75179123fca425f12d...af14a2e768b741b941255b4c6b875339b4acbb73) - [github.com/pre-commit/pre-commit-hooks: 2c9f875913ee60ca25ce70243dc24d5b6415598c → cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b](https://github.com/pre-commit/pre-commit-hooks/compare/2c9f875913ee60ca25ce70243dc24d5b6415598c...cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b) --- .pre-commit-config.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 00c3859f..6becb2ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ --- minimum_pre_commit_version: "2.17" -default_stages: [commit] +default_stages: [pre-commit] default_language_version: python: python3.12 @@ -15,7 +15,7 @@ repos: - repo: meta hooks: - id: identity - stages: [commit, manual] + stages: [pre-commit, manual] - id: check-hooks-apply stages: [manual] - id: check-useless-excludes @@ -27,12 +27,12 @@ repos: # file checking out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-case-conflict - id: check-shebang-scripts-are-executable exclude: '^.*\.rs$' - stages: [commit] + stages: [pre-commit] - id: check-symlinks - id: destroyed-symlinks - id: forbid-new-submodules @@ -49,7 +49,7 @@ repos: # ruff - python linter with fixing ability - repo: https://github.com/astral-sh/ruff-pre-commit - rev: ac97362543353002a47d6cae8918b25444d102df # frozen: v0.5.7 + rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 hooks: - id: ruff name: ruff (fix) @@ -59,7 +59,7 @@ repos: # blacken-docs - black for python code in docs (rst/md/tex) - repo: https://github.com/asottile/blacken-docs - rev: 4c97c4a0d921007af6fefae92d8447cfbf63720b # frozen: 1.18.0 + rev: 78a9dcbecf4f755f65d1f3dec556bc249d723600 # frozen: 1.19.1 hooks: - id: blacken-docs args: ["--line-length=100", "--target-version=py312"] @@ -104,12 +104,12 @@ repos: # code unspecific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: end-of-file-fixer - stages: [commit] + stages: [pre-commit] - id: trailing-whitespace - stages: [commit] + stages: [pre-commit] # #################################################################################### # @@ -134,7 +134,7 @@ repos: # code unspecific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-merge-conflict - id: detect-private-key @@ -145,7 +145,7 @@ repos: # ruff - python linter with fixing ability - repo: https://github.com/astral-sh/ruff-pre-commit - rev: ac97362543353002a47d6cae8918b25444d102df # frozen: v0.5.7 + rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 hooks: - id: ruff name: ruff (lint) @@ -156,7 +156,7 @@ repos: # python specific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: debug-statements - id: fix-encoding-pragma @@ -180,7 +180,7 @@ repos: # pylint - python linter - repo: https://github.com/PyCQA/pylint/ - rev: da1956664d6be3d008a90ad3f72bdd9d8a7ecfaa # frozen: v3.2.6 + rev: c28580be76fe1ec55a6cac41833c0bd68070d2f7 # frozen: v3.3.3 hooks: - id: pylint name: spell-check (pylint+pyenchant) @@ -218,7 +218,7 @@ repos: # markdownlint - md file checker - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: 24eb4dce508ab81398d14d75179123fca425f12d # frozen: v0.13.0 + rev: af14a2e768b741b941255b4c6b875339b4acbb73 # frozen: v0.17.1 hooks: - id: markdownlint-cli2 @@ -228,7 +228,7 @@ repos: # JSON specific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: 2c9f875913ee60ca25ce70243dc24d5b6415598c # frozen: v4.6.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-toml - id: check-yaml From c9c344faf1f349655e166a20ad4c0fa4fa20c8be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:44:08 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .pre-commit-config.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6becb2ef..eb1e4131 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: # file checking out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-case-conflict - id: check-shebang-scripts-are-executable @@ -49,7 +49,7 @@ repos: # ruff - python linter with fixing ability - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 + rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 hooks: - id: ruff name: ruff (fix) @@ -59,7 +59,7 @@ repos: # blacken-docs - black for python code in docs (rst/md/tex) - repo: https://github.com/asottile/blacken-docs - rev: 78a9dcbecf4f755f65d1f3dec556bc249d723600 # frozen: 1.19.1 + rev: 78a9dcbecf4f755f65d1f3dec556bc249d723600 # frozen: 1.19.1 hooks: - id: blacken-docs args: ["--line-length=100", "--target-version=py312"] @@ -104,7 +104,7 @@ repos: # code unspecific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: end-of-file-fixer stages: [pre-commit] @@ -134,7 +134,7 @@ repos: # code unspecific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-merge-conflict - id: detect-private-key @@ -145,7 +145,7 @@ repos: # ruff - python linter with fixing ability - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 + rev: 89c421dff2e1026ba12cdb9ebd731f4a83aa8021 # frozen: v0.8.6 hooks: - id: ruff name: ruff (lint) @@ -156,7 +156,7 @@ repos: # python specific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: debug-statements - id: fix-encoding-pragma @@ -180,7 +180,7 @@ repos: # pylint - python linter - repo: https://github.com/PyCQA/pylint/ - rev: c28580be76fe1ec55a6cac41833c0bd68070d2f7 # frozen: v3.3.3 + rev: c28580be76fe1ec55a6cac41833c0bd68070d2f7 # frozen: v3.3.3 hooks: - id: pylint name: spell-check (pylint+pyenchant) @@ -218,7 +218,7 @@ repos: # markdownlint - md file checker - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: af14a2e768b741b941255b4c6b875339b4acbb73 # frozen: v0.17.1 + rev: af14a2e768b741b941255b4c6b875339b4acbb73 # frozen: v0.17.1 hooks: - id: markdownlint-cli2 @@ -228,7 +228,7 @@ repos: # JSON specific out-of-the-box hooks - repo: https://github.com/pre-commit/pre-commit-hooks - rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 + rev: cef0300fd0fc4d2a87a85fa2093c6b283ea36f4b # frozen: v5.0.0 hooks: - id: check-toml - id: check-yaml From 9905875b82be3eb1f7e702fb8b24e983090621c4 Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:36:48 +0100 Subject: [PATCH 03/11] fix ruff ICN001; import xml as ET --- src/rstcheck_core/checker.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rstcheck_core/checker.py b/src/rstcheck_core/checker.py index 056fe034..8e2dae2d 100644 --- a/src/rstcheck_core/checker.py +++ b/src/rstcheck_core/checker.py @@ -18,7 +18,7 @@ import tempfile import typing as t import warnings -import xml.etree.ElementTree +import xml.etree.ElementTree as ET import docutils.core import docutils.io @@ -715,8 +715,8 @@ def check_xml(self, source_code: str) -> types.YieldedLintError: """ logger.debug("Check XML source.") try: - xml.etree.ElementTree.fromstring(source_code) # noqa: S314 - except xml.etree.ElementTree.ParseError as exception: + ET.fromstring(source_code) # noqa: S314 + except ET.ParseError as exception: message = f"{exception}" found = EXCEPTION_LINE_NO_REGEX.search(message) line_number = int(found.group(1)) if found else 0 From ffc46eece546005fced8d8ccc854126d3497a1e3 Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:39:51 +0100 Subject: [PATCH 04/11] use tempfile as context manager --- src/rstcheck_core/checker.py | 38 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/rstcheck_core/checker.py b/src/rstcheck_core/checker.py index 8e2dae2d..0a76dd51 100644 --- a/src/rstcheck_core/checker.py +++ b/src/rstcheck_core/checker.py @@ -879,27 +879,25 @@ def _run_in_subprocess( # NOTE: On windows a file cannot be opened twice. # Therefore close it before using it in subprocess. - temporary_file = tempfile.NamedTemporaryFile( + with tempfile.NamedTemporaryFile( mode="wb", suffix=filename_suffix, delete=False - ) - temporary_file_path = pathlib.Path(temporary_file.name) - try: - temporary_file.write(code.encode("utf-8")) - temporary_file.flush() - temporary_file.close() - - subprocess.run( # noqa: S603 - [*arguments, temporary_file.name], - capture_output=True, - cwd=source_origin_path.parent, - check=True, - ) - except subprocess.CalledProcessError as exc: - return (exc.stderr.decode(encoding), temporary_file_path) - else: - return None - finally: - temporary_file_path.unlink() + ) as temporary_file: + temporary_file_path = pathlib.Path(temporary_file.name) + try: + temporary_file.write(code.encode("utf-8")) + temporary_file.flush() + temporary_file.close() + + subprocess.run( # noqa: S603 + [*arguments, temporary_file.name], + capture_output=True, + cwd=source_origin_path.parent, + check=True, + ) + except subprocess.CalledProcessError as exc: + return (exc.stderr.decode(encoding), temporary_file_path) + + return None def _parse_gcc_style_error_message( From 5e10027b708eb7b459b36835c4749db8d4e92821 Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:43:29 +0100 Subject: [PATCH 05/11] fix mypy ignore comment --- src/rstcheck_core/checker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rstcheck_core/checker.py b/src/rstcheck_core/checker.py index 0a76dd51..10f29970 100644 --- a/src/rstcheck_core/checker.py +++ b/src/rstcheck_core/checker.py @@ -308,7 +308,7 @@ def _parse_and_filter_rst_errors( ) -class _CheckWriter(docutils.writers.Writer): # type: ignore[misc] +class _CheckWriter(docutils.writers.Writer): # type: ignore[type-arg] """Runs CheckTranslator on code blocks.""" def __init__( From 9dff45be523bdb7d3e49e4f20b52d56a54a0274e Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:43:38 +0100 Subject: [PATCH 06/11] add None check --- src/rstcheck_core/checker.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rstcheck_core/checker.py b/src/rstcheck_core/checker.py index 10f29970..90daf385 100644 --- a/src/rstcheck_core/checker.py +++ b/src/rstcheck_core/checker.py @@ -341,6 +341,9 @@ def __init__( def translate(self) -> None: """Run CheckTranslator.""" + if self.document is None: + raise AssertionError("No document to check.") + visitor = _CheckTranslator( self.document, source=self.source, From 8bc5b4bb5985c66348a9ed700f7c9d778258e1a4 Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:44:59 +0100 Subject: [PATCH 07/11] move error message into variable --- src/rstcheck_core/checker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rstcheck_core/checker.py b/src/rstcheck_core/checker.py index 90daf385..7e520de0 100644 --- a/src/rstcheck_core/checker.py +++ b/src/rstcheck_core/checker.py @@ -342,7 +342,8 @@ def __init__( def translate(self) -> None: """Run CheckTranslator.""" if self.document is None: - raise AssertionError("No document to check.") + err_msg = "No document to check." + raise AssertionError(err_msg) visitor = _CheckTranslator( self.document, From 2f82a67824cffd4bf4e3b2824071fb9a14c6ec7f Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:49:55 +0100 Subject: [PATCH 08/11] remove duplicate in ruff ignores --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index df633298..abc9dab3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -204,7 +204,6 @@ ignore = [ "Q003", # avoidable-escaped-quote "COM812", # missing-trailing-comma "COM819", # prohibited-trailing-comma - "PT011", # Use match for specific exceptions in pytest.raises "ISC001", # single-line-implicit-string-concatenation "ISC002", # multi-line-implicit-string-concatenation ] From 7c3a2b16e41052dc7c0db186d03407c6c1c51e1d Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:50:18 +0100 Subject: [PATCH 09/11] update ruff config for new version --- pyproject.toml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index abc9dab3..a94e0691 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -173,7 +173,7 @@ select = [ "SLOT", # flake8-slots # "T10", # flake8-debugger # pre-commit hook does that "T20", # flake8-print - "TCH", # flake8-type-checking + "TC", # flake8-type-checking "TD", # flake8-todos "TID", # flake8-tidy-imports "TRY", # tryceratops @@ -183,8 +183,6 @@ select = [ ] ignore = [ # deactivate because unwanted - "ANN101", # type self - "ANN102", # type cls "E501", # line length "G00", # logging uses format strings "PT011", # Use match for specific exceptions in pytest.raises From 8a4bc3fcbe48003cf3dc6f2c9616016d6be78653 Mon Sep 17 00:00:00 2001 From: Christian Riedel Date: Sat, 11 Jan 2025 12:52:49 +0100 Subject: [PATCH 10/11] remove deprecated get_html_theme_path --- docs/source/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index ec09b9da..56ad1116 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -184,7 +184,6 @@ def _remove_module_docstring( #: needs install: "sphinx-rtd-theme" extensions.append("sphinx_rtd_theme") html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] html_theme_options = {"style_external_links": True, "navigation_depth": 5} From 3f19f017f4c5c5772f6afd56e56d219b5766e5b0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 11 Jan 2025 11:53:08 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/conf.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 56ad1116..e04c1e0d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -11,8 +11,6 @@ from importlib.util import find_spec from pathlib import Path -import sphinx_rtd_theme # type: ignore[import-untyped] - if t.TYPE_CHECKING: import sphinx.ext.autodoc from sphinx.application import Sphinx