Skip to content

Commit

Permalink
Merge pull request #106 from rstcheck/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
Cielquan authored Jan 11, 2025
2 parents a3ae4a9 + 3f19f01 commit ae716a6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 46 deletions.
30 changes: 15 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
minimum_pre_commit_version: "2.17"
default_stages: [commit]
default_stages: [pre-commit]
default_language_version:
python: python3.12

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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"]
Expand Down Expand Up @@ -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]

# ####################################################################################
#
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,7 +182,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}


Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -204,7 +202,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
]
Expand Down
50 changes: 26 additions & 24 deletions src/rstcheck_core/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -341,6 +341,10 @@ def __init__(

def translate(self) -> None:
"""Run CheckTranslator."""
if self.document is None:
err_msg = "No document to check."
raise AssertionError(err_msg)

visitor = _CheckTranslator(
self.document,
source=self.source,
Expand Down Expand Up @@ -715,8 +719,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
Expand Down Expand Up @@ -879,27 +883,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(
Expand Down

0 comments on commit ae716a6

Please sign in to comment.