Skip to content

Commit a7df9af

Browse files
authored
Update ruff config (#2079)
1 parent fd5bec9 commit a7df9af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+159
-178
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: ["ubuntu-20.04", "macos-latest", "windows-latest"]
26-
python-version: ["3.8", "3.11"]
26+
python-version: ["3.8", "3.12"]
2727
include:
2828
- os: "windows-latest"
2929
python-version: "3.9"
30-
- os: "ubuntu-20.04"
30+
- os: "macos-latest"
3131
python-version: "3.10"
3232
- os: "ubuntu-20.04"
33+
python-version: "3.11"
3334
fail-fast: false
3435
steps:
3536
- uses: actions/checkout@v4
@@ -57,15 +58,6 @@ jobs:
5758
5859
- uses: jupyterlab/maintainer-tools/.github/actions/upload-coverage@v1
5960

60-
python312:
61-
runs-on: ubuntu-latest
62-
steps:
63-
- uses: actions/checkout@v4
64-
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
65-
with:
66-
python_version: "3.12"
67-
- run: hatch run test:test
68-
6961
coverage:
7062
runs-on: ubuntu-latest
7163
needs:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.2
24+
rev: 0.27.3
2525
hooks:
2626
- id: check-github-workflows
2727

@@ -81,7 +81,7 @@ repos:
8181
- id: rst-inline-touching-normal
8282

8383
- repo: https://github.com/astral-sh/ruff-pre-commit
84-
rev: v0.1.6
84+
rev: v0.1.7
8585
hooks:
8686
- id: ruff
8787
types_or: [python, jupyter]

docs/autogen_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
"""
32
autogen_config.py
43

docs/source/conf.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
#
31
# nbconvert documentation build configuration file, created by
42
# sphinx-quickstart on Tue Jun 9 17:11:30 2015.
53
#
@@ -25,7 +23,7 @@
2523

2624
# Automatically generate config_options.rst
2725
with open(os.path.join(HERE, "..", "autogen_config.py")) as f:
28-
exec(compile(f.read(), "autogen_config.py", "exec"), {}) # noqa
26+
exec(compile(f.read(), "autogen_config.py", "exec"), {}) # noqa: S102
2927
print("Created docs for config options")
3028

3129
# -- General configuration ------------------------------------------------
@@ -47,7 +45,7 @@
4745
]
4846

4947
try:
50-
import enchant # type:ignore # noqa
48+
import enchant # noqa: F401
5149

5250
extensions += ["sphinxcontrib.spelling"]
5351
except ImportError:
@@ -74,7 +72,7 @@
7472

7573

7674
year = datetime.now(tz=timezone.utc).date().year
77-
copyright = "2015-%s, Jupyter Development Team" % year # noqa
75+
copyright = "2015-%s, Jupyter Development Team" % year
7876
author = "Jupyter Development Team"
7977

8078
extlinks = {"ghpull": ("https://github.com/jupyter/nbconvert/pull/%s", "PR #%s")}
@@ -90,7 +88,7 @@
9088
# Get information from _version.py and use it to generate version and release
9189
_version_py = os.path.join(HERE, "../../nbconvert/_version.py")
9290
version_ns = {}
93-
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns) # noqa
91+
exec(compile(open(_version_py).read(), _version_py, "exec"), version_ns) # noqa: SIM115, S102
9492
# The short X.Y version.
9593
version = "%i.%i" % version_ns["version_info"][:2]
9694
# The full version, including alpha/beta/rc tags.

hatch_build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_css_file(template_name, url, filename):
4747
os.makedirs(directory)
4848
print("Downloading CSS: %s" % url)
4949
try:
50-
css = urlopen(url).read() # noqa
50+
css = urlopen(url).read() # noqa: S310
5151
except Exception as e:
5252
msg = f"Failed to download css from {url}: {e}"
5353
print(msg, file=sys.stderr)

nbconvert/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# Build up version_info tuple for backwards compatibility
99
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)"
1010
match = re.match(pattern, __version__)
11-
assert match is not None # noqa
11+
assert match is not None
1212
parts: List[object] = [int(match[part]) for part in ["major", "minor", "patch"]]
1313
if match["rest"]:
1414
parts.append(match["rest"])

nbconvert/exporters/base.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,10 @@
3333
class ExporterNameError(NameError):
3434
"""An exporter name error."""
3535

36-
pass
37-
3836

3937
class ExporterDisabledError(ValueError):
4038
"""An exporter disabled error."""
4139

42-
pass
43-
4440

4541
def export(exporter, nb, **kw):
4642
"""
@@ -74,7 +70,7 @@ def export(exporter, nb, **kw):
7470
if exporter is None:
7571
msg = "Exporter is None"
7672
raise TypeError(msg)
77-
elif not isinstance(exporter, Exporter) and not issubclass(exporter, Exporter):
73+
if not isinstance(exporter, Exporter) and not issubclass(exporter, Exporter):
7874
msg = "exporter does not inherit from Exporter (base)"
7975
raise TypeError(msg)
8076
if nb is None:
@@ -95,7 +91,7 @@ def export(exporter, nb, **kw):
9591
return output, resources
9692

9793

98-
def get_exporter(name, config=get_config()): # noqa
94+
def get_exporter(name, config=get_config()): # noqa: B008
9995
"""Given an exporter name or import path, return a class ready to be instantiated
10096
10197
Raises ExporterName if exporter is not found or ExporterDisabledError if not enabled
@@ -110,8 +106,7 @@ def get_exporter(name, config=get_config()): # noqa
110106
exporter = items[0].load()
111107
if getattr(exporter(config=config), "enabled", True):
112108
return exporter
113-
else:
114-
raise ExporterDisabledError('Exporter "%s" disabled in configuration' % (name))
109+
raise ExporterDisabledError('Exporter "%s" disabled in configuration' % (name))
115110
except IndexError:
116111
pass
117112

@@ -120,19 +115,18 @@ def get_exporter(name, config=get_config()): # noqa
120115
exporter = import_item(name)
121116
if getattr(exporter(config=config), "enabled", True):
122117
return exporter
123-
else:
124-
raise ExporterDisabledError('Exporter "%s" disabled in configuration' % (name))
118+
raise ExporterDisabledError('Exporter "%s" disabled in configuration' % (name))
125119
except ImportError:
126120
log = get_logger()
127-
log.error("Error importing %s" % name, exc_info=True)
121+
log.error("Error importing %s", name, exc_info=True) # noqa: G201
128122

129123
msg = 'Unknown exporter "{}", did you mean one of: {}?'.format(
130124
name, ", ".join(get_export_names())
131125
)
132126
raise ExporterNameError(msg)
133127

134128

135-
def get_export_names(config=get_config()): # noqa
129+
def get_export_names(config=get_config()): # noqa: B008
136130
"""Return a list of the currently supported export targets
137131
138132
Exporters can be found in external packages by registering

nbconvert/exporters/exporter.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,30 @@ def register_preprocessor(self, preprocessor, enabled=False):
253253
preprocessor_cls = import_item(preprocessor)
254254
return self.register_preprocessor(preprocessor_cls, enabled)
255255

256-
if constructed and hasattr(preprocessor, "__call__"): # noqa
256+
if constructed and callable(preprocessor):
257257
# Preprocessor is a function, no need to construct it.
258258
# Register and return the preprocessor.
259259
if enabled:
260260
preprocessor.enabled = True
261261
self._preprocessors.append(preprocessor)
262262
return preprocessor
263263

264-
elif isclass and issubclass(preprocessor, HasTraits):
264+
if isclass and issubclass(preprocessor, HasTraits):
265265
# Preprocessor is configurable. Make sure to pass in new default for
266266
# the enabled flag if one was specified.
267267
self.register_preprocessor(preprocessor(parent=self), enabled)
268+
return None
268269

269-
elif isclass:
270+
if isclass:
270271
# Preprocessor is not configurable, construct it
271272
self.register_preprocessor(preprocessor(), enabled)
273+
return None
272274

273-
else:
274-
# Preprocessor is an instance of something without a __call__
275-
# attribute.
276-
raise TypeError(
277-
"preprocessor must be callable or an importable constructor, got %r" % preprocessor
278-
)
275+
# Preprocessor is an instance of something without a __call__
276+
# attribute.
277+
raise TypeError(
278+
"preprocessor must be callable or an importable constructor, got %r" % preprocessor
279+
)
279280

280281
def _init_preprocessors(self):
281282
"""

nbconvert/exporters/html.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ def default_config(self):
213213
def _valid_language_code(self, proposal):
214214
if self.language_code not in iso639_1:
215215
self.log.warning(
216-
f'"{self.language_code}" is not an ISO 639-1 language code. '
217-
'It has been replaced by the default value "en".'
216+
'"%s" is not an ISO 639-1 language code. '
217+
'It has been replaced by the default value "en".',
218+
self.language_code,
218219
)
219220
return proposal["trait"].default_value
220221
return proposal["value"]
@@ -265,7 +266,7 @@ def from_notebook_node( # type:ignore[explicit-override, override]
265266
elem.attrs["alt"] = "No description has been provided for this image"
266267
missing_alt += 1
267268
if missing_alt:
268-
self.log.warning(f"Alternative text is missing on {missing_alt} image(s).")
269+
self.log.warning("Alternative text is missing on %s image(s).", missing_alt)
269270
# Set input and output focusable
270271
for elem in soup.select(".jp-Notebook div.jp-Cell-inputWrapper"):
271272
elem.attrs["tabindex"] = "0"
@@ -274,7 +275,7 @@ def from_notebook_node( # type:ignore[explicit-override, override]
274275

275276
return str(soup), resources
276277

277-
def _init_resources(self, resources): # noqa
278+
def _init_resources(self, resources):
278279
def resources_include_css(name):
279280
env = self.environment
280281
code = """<style type="text/css">\n%s</style>""" % (env.loader.get_source(env, name)[0])

nbconvert/exporters/pdf.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .latex import LatexExporter
1818

1919

20-
class LatexFailed(IOError): # noqa
20+
class LatexFailed(IOError):
2121
"""Exception for failed latex run
2222
2323
Captured latex output is in error.output.
@@ -33,8 +33,7 @@ def __unicode__(self):
3333

3434
def __str__(self):
3535
"""String representation."""
36-
u = self.__unicode__()
37-
return u
36+
return self.__unicode__()
3837

3938

4039
def prepend_to_env_search_path(varname, value, envdict):
@@ -85,9 +84,7 @@ def _file_extension_default(self):
8584
def _template_extension_default(self):
8685
return ".tex.j2"
8786

88-
def run_command( # noqa
89-
self, command_list, filename, count, log_function, raise_on_failure=None
90-
):
87+
def run_command(self, command_list, filename, count, log_function, raise_on_failure=None):
9188
"""Run command_list count times.
9289
9390
Parameters
@@ -141,12 +138,12 @@ def run_command( # noqa
141138
stdout=stdout,
142139
stderr=subprocess.STDOUT,
143140
stdin=null,
144-
shell=shell, # noqa
141+
shell=shell, # noqa: S603
145142
env=env,
146143
)
147144
out, _ = p.communicate()
148145
if p.returncode:
149-
if self.verbose: # noqa
146+
if self.verbose: # noqa: SIM108
150147
# verbose means I didn't capture stdout with PIPE,
151148
# so it's already been displayed and `out` is None.
152149
out_str = ""

0 commit comments

Comments
 (0)