From b19de8e74a72ad3e49cab547967b6811d0905ae3 Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Mon, 19 Feb 2024 15:17:54 +0800 Subject: [PATCH] :construction_worker: Update pre-commit.ci --- .pre-commit-config.yaml | 52 ++++++++------------------ docs/conf.py | 3 +- pyproject.toml | 60 ++++++++++++++++++++---------- src/sphinxcontrib/eval/__init__.py | 3 +- src/sphinxcontrib/eval/myst.py | 1 + src/sphinxcontrib/eval/rst.py | 1 + src/sphinxcontrib/eval/utils.py | 5 ++- tests/__init__.py | 9 ++--- tests/__init___test.py | 2 +- tests/utils_test.py | 1 + 10 files changed, 70 insertions(+), 67 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 11fd2a9..8136c67 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ --- repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: fix-byte-order-marker @@ -26,7 +26,7 @@ repos: hooks: - id: remove-crlf - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.2.6 hooks: - id: codespell additional_dependencies: @@ -38,7 +38,7 @@ repos: args: - --msg-filename - repo: https://github.com/editorconfig-checker/editorconfig-checker.python - rev: 2.7.2 + rev: 2.7.3 hooks: - id: editorconfig-checker - repo: https://github.com/jumanjihouse/pre-commit-hooks @@ -46,15 +46,15 @@ repos: hooks: - id: check-mailmap - repo: https://github.com/rhysd/actionlint - rev: v1.6.25 + rev: v1.6.26 hooks: - id: actionlint - repo: https://github.com/adrienverge/yamllint - rev: v1.32.0 + rev: v1.35.1 hooks: - id: yamllint - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.17 hooks: - id: mdformat additional_dependencies: @@ -64,53 +64,33 @@ repos: - mdformat-toc - mdformat-deflist - mdformat-beautysh - - mdformat-black + - mdformat-ruff - mdformat-config + - mdformat-web - repo: https://github.com/DavidAnson/markdownlint-cli2 - rev: v0.8.1 + rev: v0.12.1 hooks: - id: markdownlint-cli2 additional_dependencies: - - markdown-it-texmath@0.9.1 + - markdown-it-texmath - repo: https://github.com/Freed-Wu/pre-commit-hooks rev: 0.0.11 hooks: - id: update-CITATION.cff - id: update-pyproject.toml - repo: https://github.com/perltidy/perltidy - rev: "20230701.02" + rev: "20230912.13" hooks: - id: perltidy - - repo: https://github.com/psf/black - rev: 23.7.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.2.1 hooks: - - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - - repo: https://github.com/pycqa/pydocstyle - rev: 6.3.0 - hooks: - - id: pydocstyle - additional_dependencies: - - tomli + - id: ruff + - id: ruff-format - repo: https://github.com/kumaraditya303/mirrors-pyright - rev: v1.1.322 + rev: v1.1.350 hooks: - id: pyright - - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 - hooks: - - id: bandit - args: - - -cpyproject.toml - additional_dependencies: - - tomli - - repo: https://github.com/nix-community/nixpkgs-fmt - rev: v1.3.0 - hooks: - - id: nixpkgs-fmt ci: skip: diff --git a/docs/conf.py b/docs/conf.py index 8f99b5b..57747ac 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,11 +2,10 @@ https://www.sphinx-doc.org/en/master/usage/configuration.html """ + import os from datetime import datetime -from sphinxcontrib.eval import __version__ as version - try: import tomllib # type: ignore except ImportError: diff --git a/pyproject.toml b/pyproject.toml index 2ddf571..be0ff95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,11 +6,9 @@ build-backend = "setuptools.build_meta" [project] name = "sphinxcontrib-eval" description = "Evaluate shell command or python code in sphinx and myst" -authors = [{ name = "Wu Zhenyu", email = "wuzhenyu@ustc.edu" }] readme = "README.md" requires-python = ">= 3.9" keywords = ["sphinx", "myst", "eval"] -license = { text = "GPL v3" } classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", @@ -25,9 +23,19 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", ] dynamic = ["version", "dependencies", "optional-dependencies"] +[[project.authors]] +name = "Wu Zhenyu" +email = "wuzhenyu@ustc.edu" + +[project.license] +text = "GPL v3" + [project.urls] Homepage = "https://sphinxcontrib-eval.readthedocs.io" Download = "https://github.com/sphinx-contrib/eval/releases" @@ -40,8 +48,8 @@ write_to = "src/sphinxcontrib/eval/_version.py" [tool.setuptools.package-data] "sphinxcontrib.eval" = ["py.typed"] -[tool.setuptools.dynamic] -dependencies = { file = "requirements.txt" } +[tool.setuptools.dynamic.dependencies] +file = "requirements.txt" # begin: scripts/update-pyproject.toml.pl [tool.setuptools.dynamic.optional-dependencies.dev] @@ -54,25 +62,37 @@ file = "requirements/myst.txt" [tool.mdformat] number = true -[tool.black] -line-length = 79 - -[tool.isort] -line_length = 79 -profile = "black" - -# https://github.com/PyCQA/pydocstyle/issues/418 -[tool.pydocstyle] -add_ignore = "D205, D400" - [tool.doq] template_path = "templates" -[tool.bandit] -skips = ["B404"] +[tool.ruff] +line-length = 79 -[tool.bandit.assert_used] -skips = ["tests/*.py", "*_test.py", "test_*.py"] +[tool.ruff.lint] +select = [ + # pycodestyle + "E", + # pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + "SIM", + # isort + "I", +] +ignore = ["D205", "D400"] +preview = true + +[tool.ruff.format] +docstring-code-format = true +preview = true [tool.coverage.report] -exclude_lines = ["if TYPE_CHECKING:", "if __name__ == .__main__.:"] +exclude_lines = [ + "if TYPE_CHECKING:", + "if __name__ == .__main__.:", + "\\s*import tomli as tomllib", +] diff --git a/src/sphinxcontrib/eval/__init__.py b/src/sphinxcontrib/eval/__init__.py index c58b422..d934abd 100644 --- a/src/sphinxcontrib/eval/__init__.py +++ b/src/sphinxcontrib/eval/__init__.py @@ -1,6 +1,7 @@ """Provide ``setup()`` to `sphinx `_. """ + from __future__ import annotations import io @@ -12,7 +13,7 @@ if TYPE_CHECKING: from sphinx.application import Sphinx -from ._version import __version__, __version_tuple__ # type: ignore +from ._version import __version__ # type: ignore from .rst import RSTEvalParser SH = os.getenv("SHELL", "sh") diff --git a/src/sphinxcontrib/eval/myst.py b/src/sphinxcontrib/eval/myst.py index 00f615e..7956a7b 100644 --- a/src/sphinxcontrib/eval/myst.py +++ b/src/sphinxcontrib/eval/myst.py @@ -3,6 +3,7 @@ Provide ``MystEvalParser``. """ + from myst_parser.parsers.sphinx_ import MystParser from .utils import patch_parser diff --git a/src/sphinxcontrib/eval/rst.py b/src/sphinxcontrib/eval/rst.py index be52ba5..c1f9d2e 100644 --- a/src/sphinxcontrib/eval/rst.py +++ b/src/sphinxcontrib/eval/rst.py @@ -3,6 +3,7 @@ Provide ``RSTEvalParser``. """ + from sphinx.parsers import RSTParser from .utils import patch_parser diff --git a/src/sphinxcontrib/eval/utils.py b/src/sphinxcontrib/eval/utils.py index 706cd87..4b9aae5 100644 --- a/src/sphinxcontrib/eval/utils.py +++ b/src/sphinxcontrib/eval/utils.py @@ -1,8 +1,9 @@ """Utilities ============ """ + import re -from typing import Callable, Type +from typing import Callable from docutils.nodes import document from sphinx.parsers import Parser @@ -50,7 +51,7 @@ def replace( return outputstring -def patch_parser(template: str, parser: Type[Parser]) -> Type[Parser]: +def patch_parser(template: str, parser: type[Parser]) -> type[Parser]: """Patch parser. :param template: diff --git a/tests/__init__.py b/tests/__init__.py index f1c7fb6..563c0b4 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,7 +1,9 @@ """Provide ``AppMixin``.""" + import os import shutil import tempfile +from contextlib import suppress from functools import update_wrapper from pathlib import Path @@ -62,11 +64,9 @@ def add_node(self, node): self.nodes.add(node.__name__) app = App() - try: + # Sphinx 1 doesn't have this + with suppress(AttributeError): addnodes.setup(app) # type: ignore - except AttributeError: - # Sphinx 1 doesn't have this - pass return app.nodes @@ -202,7 +202,6 @@ def ignore_warnings(self): @Lazy def doctree(self): """Doctree.""" - getattr(self, "build_app") self.build_app = True # type: ignore app = self.app return app.env.get_doctree("content/doc") # type: ignore diff --git a/tests/__init___test.py b/tests/__init___test.py index 635541e..23128d8 100644 --- a/tests/__init___test.py +++ b/tests/__init___test.py @@ -1,10 +1,10 @@ """Test ``__init__.py``.""" + import sys from shutil import which from unittest import TestCase import pytest - from sphinxcontrib.eval import eval_bash, eval_python, eval_sh from . import AppMixin diff --git a/tests/utils_test.py b/tests/utils_test.py index a7c3c30..18c6351 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -1,4 +1,5 @@ """Test utilities.""" + import re from sphinxcontrib.eval.utils import get_lang_map, replace