From 2e6bce3b5bc64cccd890110d3b876633f3863899 Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Fri, 24 Nov 2023 07:54:58 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Replace=20black,=20isort,=20pyup?= =?UTF-8?q?grade=20with=20ruff=20formatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 24 +++++------------------- docs/conf.py | 2 +- docs/live_preview.py | 2 +- myst_parser/_docs.py | 1 + myst_parser/config/main.py | 1 + myst_parser/mdit_to_docutils/base.py | 12 ++++-------- myst_parser/mocking.py | 8 ++------ myst_parser/parsers/docutils_.py | 2 +- pyproject.toml | 12 ++---------- 9 files changed, 18 insertions(+), 46 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 64f407b2..d192d459 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,36 +12,22 @@ exclude: > repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-json - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/asottile/pyupgrade - rev: v3.11.1 - hooks: - - id: pyupgrade - args: [--py38-plus] - - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.290 + rev: v0.1.6 hooks: - id: ruff + args: [--fix] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.5.1 + rev: v1.7.0 hooks: - id: mypy args: [--config-file=pyproject.toml] diff --git a/docs/conf.py b/docs/conf.py index 93d8b042..43f9c970 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -167,7 +167,7 @@ # OpenGraph metadata ogp_site_url = "https://myst-parser.readthedocs.io/en/latest" # This is the image that GitHub stores for our social media previews -ogp_image = "https://repository-images.githubusercontent.com/240151150/316bc480-cc23-11eb-96fc-4ab2f981a65d" # noqa: E501 +ogp_image = "https://repository-images.githubusercontent.com/240151150/316bc480-cc23-11eb-96fc-4ab2f981a65d" ogp_custom_meta_tags = [ '', ] diff --git a/docs/live_preview.py b/docs/live_preview.py index 87e1224d..7a3a62b4 100644 --- a/docs/live_preview.py +++ b/docs/live_preview.py @@ -28,7 +28,7 @@ class SimpleWriter(Writer): def apply_template(self): subs = self.interpolation_dict() - return "%(body)s\n" % subs + return "{body}\n".format(**subs) def __init__(self): self.parts = {} diff --git a/myst_parser/_docs.py b/myst_parser/_docs.py index f51218ec..99900a06 100644 --- a/myst_parser/_docs.py +++ b/myst_parser/_docs.py @@ -13,6 +13,7 @@ from sphinx.util.docutils import SphinxDirective from myst_parser.parsers.docutils_ import to_html5_demo + from .config.main import MdParserConfig from .parsers.docutils_ import Parser as DocutilsParser from .warnings_ import MystWarnings diff --git a/myst_parser/config/main.py b/myst_parser/config/main.py index ac5fa834..ae29dfad 100644 --- a/myst_parser/config/main.py +++ b/myst_parser/config/main.py @@ -17,6 +17,7 @@ ) from myst_parser.warnings_ import MystWarnings + from .dc_validators import ( any_, deep_iterable, diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py index 6631a711..cbf041eb 100644 --- a/myst_parser/mdit_to_docutils/base.py +++ b/myst_parser/mdit_to_docutils/base.py @@ -27,9 +27,8 @@ from docutils import nodes from docutils.frontend import OptionParser from docutils.languages import get_language -from docutils.parsers.rst import Directive, DirectiveError +from docutils.parsers.rst import Directive, DirectiveError, directives, roles from docutils.parsers.rst import Parser as RSTParser -from docutils.parsers.rst import directives, roles from docutils.parsers.rst.directives.misc import Include from docutils.parsers.rst.languages import get_language as get_language_rst from docutils.statemachine import StringList @@ -55,6 +54,7 @@ ) from myst_parser.parsers.directives import MarkupError, parse_directive_text from myst_parser.warnings_ import MystWarnings, create_warning + from .html_to_nodes import html_to_nodes if TYPE_CHECKING: @@ -1799,9 +1799,7 @@ def run_directive( result = [msg_node] except MockingError as exc: error_msg = self.reporter.error( - "Directive '{}' cannot be mocked: {}: {}".format( - name, exc.__class__.__name__, exc - ), + f"Directive '{name}' cannot be mocked: {exc.__class__.__name__}: {exc}", nodes.literal_block(content, content), line=position, ) @@ -1813,9 +1811,7 @@ def run_directive( for i in range(len(result)): assert isinstance( result[i], nodes.Node - ), 'Directive "{}" returned non-Node object (index {}): {}'.format( - name, i, result[i] - ) + ), f'Directive "{name}" returned non-Node object (index {i}): {result[i]}' return result def render_substitution_inline(self, token: SyntaxTreeNode) -> None: diff --git a/myst_parser/mocking.py b/myst_parser/mocking.py index b26dc014..0bafa424 100644 --- a/myst_parser/mocking.py +++ b/myst_parser/mocking.py @@ -84,9 +84,7 @@ def __getattr__(self, name: str): """ # TODO use document.reporter mechanism? if hasattr(Inliner, name): - msg = "{cls} has not yet implemented attribute '{name}'".format( - cls=type(self).__name__, name=name - ) + msg = f"{type(self).__name__} has not yet implemented attribute '{name}'" raise MockingError(msg).with_traceback(sys.exc_info()[2]) msg = f"{type(self).__name__} has no attribute {name}" raise MockingError(msg).with_traceback(sys.exc_info()[2]) @@ -307,9 +305,7 @@ def __getattr__(self, name: str): been defined. Defined attributes will not be overridden. """ if hasattr(RSTStateMachine, name): - msg = "{cls} has not yet implemented attribute '{name}'".format( - cls=type(self).__name__, name=name - ) + msg = f"{type(self).__name__} has not yet implemented attribute '{name}'" raise MockingError(msg).with_traceback(sys.exc_info()[2]) msg = f"{type(self).__name__} has no attribute {name}" raise MockingError(msg).with_traceback(sys.exc_info()[2]) diff --git a/myst_parser/parsers/docutils_.py b/myst_parser/parsers/docutils_.py index 78875e4d..d9997b75 100644 --- a/myst_parser/parsers/docutils_.py +++ b/myst_parser/parsers/docutils_.py @@ -338,7 +338,7 @@ class SimpleWriter(Writer): def apply_template(self): subs = self.interpolation_dict() - return "%(body)s\n" % subs + return "{body}\n".format(**subs) def __init__(self): self.parts = {} diff --git a/pyproject.toml b/pyproject.toml index 8f8bf9e8..6e47613f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,17 +101,9 @@ exclude = [ "tests/", ] -[tool.isort] -profile = "black" -known_first_party = ["myst_parser", "tests"] -known_third_party = ["docutils", "markdown_it", "sphinx"] -# Group first party and local folder imports together -no_lines_before = "LOCALFOLDER" - [tool.ruff] -line-length = 100 -extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM"] -extend-ignore = ["RUF005", "RUF012"] +extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"] +extend-ignore = ["ISC001", "RUF005", "RUF012"] [tool.mypy] show_error_codes = true