Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#1945)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and blink1073 authored Mar 9, 2023
1 parent 857631d commit acf41ac
Show file tree
Hide file tree
Showing 31 changed files with 31 additions and 54 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
rev: 0.21.0
hooks:
- id: check-github-workflows

Expand All @@ -31,12 +31,12 @@ repos:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.1.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.237
rev: v0.0.254
hooks:
- id: ruff
args: ["--fix"]
2 changes: 1 addition & 1 deletion check_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
remaining_all = all_reqs.copy()
errors = []

for (key, reqs) in data["project"]["optional-dependencies"].items():
for key, reqs in data["project"]["optional-dependencies"].items():
if key == "all":
continue
for req in reqs:
Expand Down
2 changes: 1 addition & 1 deletion hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_css_file(template_name, url, filename):
print("Already have CSS: %s, moving on." % dest)
else:
msg = "Need CSS to proceed."
raise OSError(msg)
raise OSError(msg) from None
return

with open(dest, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Utilities for converting notebooks to and from different formats."""

from ._version import __version__, version_info # noqa
from ._version import __version__, version_info

try:
from . import filters, postprocessors, preprocessors, writers
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ def get_export_names(config=get_config()): # noqa
if e.enabled:
enabled_exporters.append(exporter_name)
except (ExporterDisabledError, ValueError):
pass # noqa
pass
return enabled_exporters
1 change: 0 additions & 1 deletion nbconvert/exporters/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ def _init_preprocessors(self):
self.register_preprocessor(preprocessor, enabled=True)

def _init_resources(self, resources):

# Make sure the resources dict is of ResourcesDict type.
if resources is None:
resources = ResourcesDict()
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def find_lab_theme(theme_name):
matching_themes = []
theme_path = None
for path in paths:
for (dirpath, dirnames, filenames) in os.walk(path):
for dirpath, dirnames, filenames in os.walk(path):
# If it's a federated labextension that contains themes
if "package.json" in filenames and "themes" in dirnames:
# TODO Find the theme name in the JS code instead?
Expand Down Expand Up @@ -284,7 +284,7 @@ def resources_include_url(name):
with open(filename, "rb") as f:
data = f.read()
break
else: # noqa
else:
msg = f"No file {name!r} found in {searchpath!r}"
raise ValueError(msg)
data = base64.b64encode(data)
Expand Down
6 changes: 4 additions & 2 deletions nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def _file_extension_default(self):
def _template_extension_default(self):
return ".tex.j2"

def run_command(self, command_list, filename, count, log_function, raise_on_failure=None):
def run_command( # noqa
self, command_list, filename, count, log_function, raise_on_failure=None
):
"""Run command_list count times.
Parameters
Expand Down Expand Up @@ -143,7 +145,7 @@ def run_command(self, command_list, filename, count, log_function, raise_on_fail
)
out, _ = p.communicate()
if p.returncode:
if self.verbose:
if self.verbose: # noqa
# verbose means I didn't capture stdout with PIPE,
# so it's already been displayed and `out` is None.
out_str = ""
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/exporters/slides.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class _RevealMetadataPreprocessor(Preprocessor):
# A custom preprocessor adding convenience metadata to cells

def preprocess(self, nb, resources=None): # noqa
def preprocess(self, nb, resources=None):
nb = deepcopy(nb)

for cell in nb.cells:
Expand All @@ -42,7 +42,6 @@ def preprocess(self, nb, resources=None): # noqa
in_fragment = False

for index, cell in enumerate(nb.cells[first_slide_ix + 1 :], start=(first_slide_ix + 1)):

previous_cell = nb.cells[index - 1]

# Slides are <section> elements in the HTML, subslides (the vertically
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def _init_preprocessors(self):
preprocessor_cls = import_item(preprocessor_cls)
if preprocessor_cls.__name__ in self.config:
kwargs.update(self.config[preprocessor_cls.__name__])
preprocessor = preprocessor_cls(**kwargs)
preprocessor = preprocessor_cls(**kwargs) # noqa
self.register_preprocessor(preprocessor)

def _get_conf(self):
Expand Down Expand Up @@ -597,7 +597,7 @@ def get_compatibility_base_template_conf(cls, name):
if name == "full":
return {"base_template": "classic", "mimetypes": {"text/html": True}}

def get_template_names(self): # noqa
def get_template_names(self):
"""Finds a list of template names where each successive template name is the base template"""
template_names = []
root_dirs = self.get_prefix_root_dirs()
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/exporters/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_export_wrong_name(self):
exporter = get_exporter("not_a_name")
export(exporter, self._get_notebook())
except ExporterNameError as e:
pass # noqa
pass

def test_export_disabled(self):
"""
Expand Down
2 changes: 0 additions & 2 deletions nbconvert/exporters/tests/test_templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def test_exclude_input_prompt(self):
assert "# In[" not in nb_no_input_prompt

def test_exclude_markdown(self):

no_md = {
"TemplateExporter": {
"exclude_output": False,
Expand Down Expand Up @@ -630,7 +629,6 @@ def test_include_output_stdin(self):
assert "test input: input value" in nb_output_stdin

def test_remove_elements_with_tags(self):

conf = Config(
{
"TagRemovePreprocessor": {
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/filters/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def ansi2latex(text):
return _ansi2anything(text, _latexconverter)


def _htmlconverter(fg, bg, bold, underline, inverse): # noqa
def _htmlconverter(fg, bg, bold, underline, inverse):
"""
Return start and end tags for given foreground/background/bold/underline.
Expand Down Expand Up @@ -114,7 +114,7 @@ def _htmlconverter(fg, bg, bold, underline, inverse): # noqa
return starttag, "</span>"


def _latexconverter(fg, bg, bold, underline, inverse): # noqa
def _latexconverter(fg, bg, bold, underline, inverse):
"""
Return start and end markup given foreground/background/bold/underline.
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/filters/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __call__(self, source, language=None, metadata=None, strip_verbatim=False):
return latex


def _pygments_highlight(source, output_formatter, language="ipython", metadata=None): # noqa
def _pygments_highlight(source, output_formatter, language="ipython", metadata=None):
"""
Return a syntax-highlighted version of the input source
Expand All @@ -157,7 +157,6 @@ def _pygments_highlight(source, output_formatter, language="ipython", metadata=N
# If the cell uses a magic extension language,
# use the magic language instead.
if language.startswith("ipython") and metadata and "magics_language" in metadata:

language = metadata["magics_language"]

lexer = None
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 @@ -151,7 +151,7 @@ def render(self, s):
class IPythonRenderer(HTMLRenderer):
"""An ipython html renderer."""

def __init__(
def __init__( # noqa
self,
escape=True,
allow_harmful_protocols=True,
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/filters/tests/test_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def test_highlight2latex(self):
self._try_highlight(highlight2latex, test, self.tokens[index])

def test_parse_html_many_lang(self):

ht = highlight2html(self.tests[0])
rb = highlight2html_ruby(self.tests[0])

Expand All @@ -81,7 +80,7 @@ def test_inject_html(self):

def _extract_tokens(self, root, cls):
return set( # noqa
map(lambda x: x.text, root.findall(".//*[@class='" + cls + "']")) # type:ignore # noqa
map(lambda x: x.text, root.findall(".//*[@class='" + cls + "']")) # type:ignore
)

def _try_highlight(self, method, test, tokens):
Expand Down
1 change: 0 additions & 1 deletion nbconvert/filters/tests/test_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class TestMarkdown(TestsBase):

tests = [
"*test",
"**test",
Expand Down
1 change: 0 additions & 1 deletion nbconvert/nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ def init_notebooks(self):
# Use glob to replace all the notebook patterns with filenames.
filenames = []
for pattern in patterns:

# Use glob to find matching filenames. Allow the user to convert
# notebooks without having to type the extension.
globbed_files = glob.glob(pattern, recursive=self.recursive_glob)
Expand Down
1 change: 0 additions & 1 deletion nbconvert/preprocessors/convertfigures.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def preprocess_cell(self, cell, resources, cell_index):
and self.from_format in output.data
and self.to_format not in output.data
):

output.data[self.to_format] = self.convert_figure(
self.from_format, output.data[self.from_format]
)
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def preprocess_cell(self, cell, resources, cell_index):
code:
Sanitize outputs that could result in code execution
"""
if cell.cell_type == "raw":
if cell.cell_type == "raw": # noqa
# Sanitize all raw cells anyway.
# Only ones with the text/html mimetype should be emitted
# but erring on the side of safety maybe.
Expand Down
1 change: 0 additions & 1 deletion nbconvert/preprocessors/svg2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def convert_figure(self, data_format, data):

# Work in a temporary directory
with TemporaryDirectory() as tmpdir:

# Write fig to temp file
input_filename = os.path.join(tmpdir, "figure.svg")
# SVG data is unicode text
Expand Down
1 change: 0 additions & 1 deletion nbconvert/preprocessors/tagremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def preprocess_cell(self, cell, resources, cell_index):
self.remove_all_outputs_tags.intersection(cell.get("metadata", {}).get("tags", []))
and cell.cell_type == "code"
):

cell.outputs = []
cell.execution_count = None
# Remove metadata associated with output
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/tests/test_regexremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def test_output(self):
patterns = list(map(re.compile, preprocessor.patterns))
for cell in nb.cells:
for pattern in patterns:
self.assertFalse(pattern.match(cell.source)) # type:ignore
self.assertFalse(pattern.match(cell.source))
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/tests/test_sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class TestSanitizer(PreprocessorTestsBase):
"""Contains test functions for sanitize.py"""

maxDiff = None # noqa
maxDiff = None

def build_preprocessor(self):
"""Make an instance of a preprocessor"""
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestsBase(unittest.TestCase):
"""Base tests class. Contains useful fuzzy comparison and nbconvert
functions."""

def fuzzy_compare(
def fuzzy_compare( # noqa
self,
a,
b,
Expand Down Expand Up @@ -129,7 +129,6 @@ def copy_files_to(self, copy_filenames, dest="."):
shutil.copyfile(match, os.path.join(dest, os.path.basename(match)))

def _get_files_path(self):

# Get the relative path to this module in the IPython directory.
names = self.__module__.split(".")[1:-1]
names.append("files")
Expand Down
1 change: 0 additions & 1 deletion nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ def test_fenced_code_blocks_markdown(self):
assert "```" in output1 # but should have fenced blocks

with self.create_temp_cwd(["notebook_jl*.ipynb"]):

output2, _ = self.nbconvert("--to markdown --stdout notebook_jl.ipynb")
assert "```julia" in output2 # shouldn't have language
assert "```" in output2 # but should also plain ``` to close cell
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/utils/pandoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_pandoc_version():
PandocMissing
If pandoc is unavailable.
"""
global __version
global __version # noqa

if __version is None:
if not shutil.which("pandoc"):
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, *args, **kwargs):
# -----------------------------------------------------------------------------
def clean_cache():
"""Clean the internal cache."""
global __version
global __version # noqa
__version = None


Expand Down
2 changes: 1 addition & 1 deletion nbconvert/writers/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def write(self, output, resources, notebook_name="notebook", **kw):
if isinstance(resources["outputs"], dict):
print("outputs extracted from %s" % notebook_name)
print("-" * 80)
pprint(resources["outputs"], indent=2, width=70) # noqa
pprint(resources["outputs"], indent=2, width=70)
else:
print("no outputs extracted from %s" % notebook_name)
print("=" * 80)
3 changes: 0 additions & 3 deletions nbconvert/writers/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def write(self, output, resources, notebook_name=None, **kw):
os.path.join(resources.get("output_files_dir", ""), ""),
)
for filename, data in items:

# Determine where to write the file to
dest = os.path.join(build_directory, filename)
path = os.path.dirname(dest)
Expand All @@ -98,10 +97,8 @@ def write(self, output, resources, notebook_name=None, **kw):
# Copy referenced files to output directory
if build_directory:
for filename in self.files:

# Copy files that match search pattern
for matching_filename in glob.glob(filename):

# compute the relative path for the filename
if relpath != "":
dest_filename = os.path.relpath(matching_filename, relpath)
Expand Down
Loading

0 comments on commit acf41ac

Please sign in to comment.