Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Replace black, isort, pyupgrade with ruff formatter #833

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'<meta name="twitter:card" content="summary_large_image">',
]
Expand Down
2 changes: 1 addition & 1 deletion docs/live_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions myst_parser/_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions myst_parser/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)

from myst_parser.warnings_ import MystWarnings

from .dc_validators import (
any_,
deep_iterable,
Expand Down
12 changes: 4 additions & 8 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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,
)
Expand All @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions myst_parser/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@
"""
# 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}'"

Check warning on line 87 in myst_parser/mocking.py

View check run for this annotation

Codecov / codecov/patch

myst_parser/mocking.py#L87

Added line #L87 was not covered by tests
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])
Expand Down Expand Up @@ -307,9 +305,7 @@
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}'"

Check warning on line 308 in myst_parser/mocking.py

View check run for this annotation

Codecov / codecov/patch

myst_parser/mocking.py#L308

Added line #L308 was not covered by tests
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])
Expand Down
2 changes: 1 addition & 1 deletion myst_parser/parsers/docutils_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
12 changes: 2 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down