Skip to content

Commit 635d74f

Browse files
authored
🔧 Replace black, isort, pyupgrade with ruff formatter (#833)
1 parent f313a09 commit 635d74f

File tree

9 files changed

+18
-46
lines changed

9 files changed

+18
-46
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,22 @@ exclude: >
1212
repos:
1313

1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
15+
rev: v4.5.0
1616
hooks:
1717
- id: check-json
1818
- id: check-yaml
1919
- id: end-of-file-fixer
2020
- id: trailing-whitespace
2121

22-
- repo: https://github.com/asottile/pyupgrade
23-
rev: v3.11.1
24-
hooks:
25-
- id: pyupgrade
26-
args: [--py38-plus]
27-
28-
- repo: https://github.com/PyCQA/isort
29-
rev: 5.12.0
30-
hooks:
31-
- id: isort
32-
33-
- repo: https://github.com/psf/black
34-
rev: 23.9.1
35-
hooks:
36-
- id: black
37-
3822
- repo: https://github.com/astral-sh/ruff-pre-commit
39-
rev: v0.0.290
23+
rev: v0.1.6
4024
hooks:
4125
- id: ruff
26+
args: [--fix]
27+
- id: ruff-format
4228

4329
- repo: https://github.com/pre-commit/mirrors-mypy
44-
rev: v1.5.1
30+
rev: v1.7.0
4531
hooks:
4632
- id: mypy
4733
args: [--config-file=pyproject.toml]

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
# OpenGraph metadata
168168
ogp_site_url = "https://myst-parser.readthedocs.io/en/latest"
169169
# This is the image that GitHub stores for our social media previews
170-
ogp_image = "https://repository-images.githubusercontent.com/240151150/316bc480-cc23-11eb-96fc-4ab2f981a65d" # noqa: E501
170+
ogp_image = "https://repository-images.githubusercontent.com/240151150/316bc480-cc23-11eb-96fc-4ab2f981a65d"
171171
ogp_custom_meta_tags = [
172172
'<meta name="twitter:card" content="summary_large_image">',
173173
]

docs/live_preview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SimpleWriter(Writer):
2828

2929
def apply_template(self):
3030
subs = self.interpolation_dict()
31-
return "%(body)s\n" % subs
31+
return "{body}\n".format(**subs)
3232

3333
def __init__(self):
3434
self.parts = {}

myst_parser/_docs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from sphinx.util.docutils import SphinxDirective
1414

1515
from myst_parser.parsers.docutils_ import to_html5_demo
16+
1617
from .config.main import MdParserConfig
1718
from .parsers.docutils_ import Parser as DocutilsParser
1819
from .warnings_ import MystWarnings

myst_parser/config/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
from myst_parser.warnings_ import MystWarnings
20+
2021
from .dc_validators import (
2122
any_,
2223
deep_iterable,

myst_parser/mdit_to_docutils/base.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
from docutils import nodes
2828
from docutils.frontend import OptionParser
2929
from docutils.languages import get_language
30-
from docutils.parsers.rst import Directive, DirectiveError
30+
from docutils.parsers.rst import Directive, DirectiveError, directives, roles
3131
from docutils.parsers.rst import Parser as RSTParser
32-
from docutils.parsers.rst import directives, roles
3332
from docutils.parsers.rst.directives.misc import Include
3433
from docutils.parsers.rst.languages import get_language as get_language_rst
3534
from docutils.statemachine import StringList
@@ -55,6 +54,7 @@
5554
)
5655
from myst_parser.parsers.directives import MarkupError, parse_directive_text
5756
from myst_parser.warnings_ import MystWarnings, create_warning
57+
5858
from .html_to_nodes import html_to_nodes
5959

6060
if TYPE_CHECKING:
@@ -1799,9 +1799,7 @@ def run_directive(
17991799
result = [msg_node]
18001800
except MockingError as exc:
18011801
error_msg = self.reporter.error(
1802-
"Directive '{}' cannot be mocked: {}: {}".format(
1803-
name, exc.__class__.__name__, exc
1804-
),
1802+
f"Directive '{name}' cannot be mocked: {exc.__class__.__name__}: {exc}",
18051803
nodes.literal_block(content, content),
18061804
line=position,
18071805
)
@@ -1813,9 +1811,7 @@ def run_directive(
18131811
for i in range(len(result)):
18141812
assert isinstance(
18151813
result[i], nodes.Node
1816-
), 'Directive "{}" returned non-Node object (index {}): {}'.format(
1817-
name, i, result[i]
1818-
)
1814+
), f'Directive "{name}" returned non-Node object (index {i}): {result[i]}'
18191815
return result
18201816

18211817
def render_substitution_inline(self, token: SyntaxTreeNode) -> None:

myst_parser/mocking.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,7 @@ def __getattr__(self, name: str):
8484
"""
8585
# TODO use document.reporter mechanism?
8686
if hasattr(Inliner, name):
87-
msg = "{cls} has not yet implemented attribute '{name}'".format(
88-
cls=type(self).__name__, name=name
89-
)
87+
msg = f"{type(self).__name__} has not yet implemented attribute '{name}'"
9088
raise MockingError(msg).with_traceback(sys.exc_info()[2])
9189
msg = f"{type(self).__name__} has no attribute {name}"
9290
raise MockingError(msg).with_traceback(sys.exc_info()[2])
@@ -307,9 +305,7 @@ def __getattr__(self, name: str):
307305
been defined. Defined attributes will not be overridden.
308306
"""
309307
if hasattr(RSTStateMachine, name):
310-
msg = "{cls} has not yet implemented attribute '{name}'".format(
311-
cls=type(self).__name__, name=name
312-
)
308+
msg = f"{type(self).__name__} has not yet implemented attribute '{name}'"
313309
raise MockingError(msg).with_traceback(sys.exc_info()[2])
314310
msg = f"{type(self).__name__} has no attribute {name}"
315311
raise MockingError(msg).with_traceback(sys.exc_info()[2])

myst_parser/parsers/docutils_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ class SimpleWriter(Writer):
338338

339339
def apply_template(self):
340340
subs = self.interpolation_dict()
341-
return "%(body)s\n" % subs
341+
return "{body}\n".format(**subs)
342342

343343
def __init__(self):
344344
self.parts = {}

pyproject.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,9 @@ exclude = [
101101
"tests/",
102102
]
103103

104-
[tool.isort]
105-
profile = "black"
106-
known_first_party = ["myst_parser", "tests"]
107-
known_third_party = ["docutils", "markdown_it", "sphinx"]
108-
# Group first party and local folder imports together
109-
no_lines_before = "LOCALFOLDER"
110-
111104
[tool.ruff]
112-
line-length = 100
113-
extend-select = ["B0", "C4", "ICN", "ISC", "N", "RUF", "SIM"]
114-
extend-ignore = ["RUF005", "RUF012"]
105+
extend-select = ["B0", "C4", "I", "ICN", "ISC", "N", "RUF", "SIM", "UP"]
106+
extend-ignore = ["ISC001", "RUF005", "RUF012"]
115107

116108
[tool.mypy]
117109
show_error_codes = true

0 commit comments

Comments
 (0)