Skip to content

Commit

Permalink
Adopt ruff format (#2059)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Oct 29, 2023
1 parent 858d634 commit 9df32d6
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 40 deletions.
12 changes: 4 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-case-conflict
- id: check-ast
Expand Down Expand Up @@ -44,11 +44,6 @@ repos:
- id: blacken-docs
additional_dependencies: [black==23.7.0]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black

- repo: https://github.com/codespell-project/codespell
rev: "v2.2.6"
hooks:
Expand All @@ -63,13 +58,14 @@ repos:
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/scientific-python/cookie
rev: "2023.09.21"
rev: "2023.10.27"
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 1 addition & 1 deletion nbconvert/exporters/webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .html import HTMLExporter

PLAYWRIGHT_INSTALLED = importlib_util.find_spec("playwright") is not None
IS_WINDOWS = os.name == 'nt'
IS_WINDOWS = os.name == "nt"


class WebPDFExporter(HTMLExporter):
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/markdown_mistune.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

MISTUNE_V3 = False

def import_plugin(name: str) -> 'MarkdownPlugin': # type: ignore[misc]
def import_plugin(name: str) -> "MarkdownPlugin": # type: ignore[misc]
"""Simple implementation of Mistune V3's import_plugin for V2."""
return PLUGINS[name] # type: ignore[no-any-return]

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def clean_html(element):
kwargs = {}
css_sanitizer = _get_default_css_sanitizer()
if css_sanitizer:
kwargs['css_sanitizer'] = css_sanitizer
kwargs["css_sanitizer"] = css_sanitizer
return bleach.clean(
element,
tags=[*bleach.ALLOWED_TAGS, "div", "pre", "code", "span"],
Expand Down
4 changes: 3 additions & 1 deletion nbconvert/preprocessors/svg2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def _to_format_default(self):
@default("inkscape_version")
def _inkscape_version_default(self):
p = subprocess.Popen(
[self.inkscape, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE # noqa
[self.inkscape, "--version"], # noqa:S603
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output, _ = p.communicate()
if p.returncode != 0:
Expand Down
4 changes: 1 addition & 3 deletions nbconvert/preprocessors/tagremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class TagRemovePreprocessor(Preprocessor):
"matches tags in ``cell.metadata.tags``."
),
).tag(config=True)
remove_metadata_fields: set[str] = Set({"collapsed", "scrolled"}).tag(
config=True
) # type:ignore[assignment]
remove_metadata_fields: set[str] = Set({"collapsed", "scrolled"}).tag(config=True) # type:ignore[assignment]

def check_cell_conditions(self, cell, resources, index):
"""
Expand Down
24 changes: 11 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,20 @@ test = "mypy --install-types --non-interactive {args}"

[tool.hatch.envs.lint]
dependencies = [
"black[jupyter]==23.3.0",
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff==0.0.287"
"ruff==0.1.3"
]
detached = true
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs *.md}"
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs *.md}"
]

Expand Down Expand Up @@ -196,17 +195,16 @@ enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
disable_error_code = ["no-untyped-def", "no-untyped-call"]
warn_unreachable = true

[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py37"]
extend-exclude = ".*notebook1.ipynb$"

[tool.ruff]
target-version = "py37"
target-version = "py38"
line-length = 100

[tool.ruff.format]
exclude = [".*notebook1.ipynb$"]

[tool.ruff.lint]
select = [
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "ISC", "N",
"A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "N",
"PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP",
"W", "YTT",
]
Expand All @@ -233,7 +231,7 @@ unfixable = [
"RUF100",
]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# B011: Do not call assert False since python -O removes these calls
# F841 local variable 'foo' is assigned to but never used
# S101 Use of `assert` detected
Expand Down
2 changes: 1 addition & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def copy_files_to(self, copy_filenames, dest="."):
assert files
for match in files:
# Avoid copying the Julia file unless it is explicitly asked for.
if 'jl' in match and "jl" not in pattern:
if "jl" in match and "jl" not in pattern:
continue
shutil.copyfile(match, os.path.join(dest, os.path.basename(match)))

Expand Down
2 changes: 1 addition & 1 deletion tests/exporters/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_attachments(self):
check_for_png = re.compile(r'<img alt="image.png" src="([^"]*?)"/>')
result = check_for_png.search(output)
assert result
self.assertTrue(result.group(1).strip().startswith('data:image/png;base64,iVBOR'))
self.assertTrue(result.group(1).strip().startswith("data:image/png;base64,iVBOR"))

check_for_data = re.compile(r'<img alt="image.png" src="(?P<url>[^"]*?)"')
results = check_for_data.findall(output)
Expand Down
4 changes: 2 additions & 2 deletions tests/exporters/test_webpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@


class FakeBrowser:
executable_path: str = ''
executable_path: str = ""


def monkey_import_notfound(name, globals_ctx=None, locals_ctx=None, fromlist=(), level=0):
if name == "playwright.async_api":
msg = 'Fake missing'
msg = "Fake missing"
raise ModuleNotFoundError(msg)
return real_import(name, globals=globals_ctx, locals=locals_ctx, fromlist=fromlist, level=level)

Expand Down
2 changes: 1 addition & 1 deletion tests/filters/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_markdown2html_math(self):
# all the "<", ">", "&" must be escaped correctly
cases = [
(
"\\begin{equation*}\n" # noqa
"\\begin{equation*}\n"
+ (
"\\left( \\sum_{k=1}^n a_k b_k \\right)^2 "
"\\leq \\left( \\sum_{k=1}^n a_k^2 \\right) "
Expand Down
8 changes: 2 additions & 6 deletions tests/preprocessors/test_highlightmagics.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def test_tagging(self):
nb = self.build_notebook()
res = self.build_resources()
preprocessor = self.build_preprocessor()
nb.cells[
0
].source = """%%R -i x,y -o XYcoef
nb.cells[0].source = """%%R -i x,y -o XYcoef
lm.fit <- lm(y~x)
par(mfrow=c(2,2))
print(summary(lm.fit))
Expand All @@ -43,9 +41,7 @@ def test_no_false_positive(self):
nb = self.build_notebook()
res = self.build_resources()
preprocessor = self.build_preprocessor()
nb.cells[
0
].source = """# this should not be detected
nb.cells[0].source = """# this should not be detected
print(\"""
%%R -i x, y
\""")"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def test_no_input(self):
'<span class="o">=</span> '
'<span class="n">symbols</span>'
'<span class="p">(</span>'
'<span class="s1">\'x y z\'</span>'
"<span class=\"s1\">'x y z'</span>"
'<span class="p">)</span>'
)
for no_input_flag in (False, True):
Expand Down

0 comments on commit 9df32d6

Please sign in to comment.