From 0bffd12449670d9c9a8b02fac52ad9f04e794eb4 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 2 Apr 2022 07:32:41 -0500 Subject: [PATCH 1/2] add flake8 --- .pre-commit-config.yaml | 20 ++++---- docs/source/conf.py | 11 +--- nbconvert/exporters/base.py | 4 +- nbconvert/exporters/exporter.py | 5 +- nbconvert/exporters/pdf.py | 3 +- nbconvert/exporters/templateexporter.py | 4 +- nbconvert/exporters/tests/test_exporter.py | 8 +-- nbconvert/exporters/tests/test_html.py | 16 ------ nbconvert/exporters/tests/test_pdf.py | 1 - nbconvert/exporters/tests/test_rst.py | 2 - nbconvert/exporters/tests/test_webpdf.py | 1 - nbconvert/filters/citation.py | 2 +- nbconvert/filters/highlight.py | 2 +- nbconvert/filters/tests/test_highlight.py | 2 - nbconvert/filters/tests/test_markdown.py | 8 +-- nbconvert/filters/tests/test_metadata.py | 4 +- nbconvert/nbconvertapp.py | 2 +- nbconvert/postprocessors/serve.py | 2 +- nbconvert/postprocessors/tests/test_serve.py | 2 +- nbconvert/preprocessors/clearmetadata.py | 8 +-- nbconvert/preprocessors/csshtmlheader.py | 3 -- nbconvert/preprocessors/execute.py | 2 +- nbconvert/preprocessors/svg2pdf.py | 1 - .../preprocessors/tests/test_regexremove.py | 1 - .../preprocessors/tests/test_sanitize.py | 3 +- nbconvert/preprocessors/tests/test_svg2pdf.py | 6 +-- nbconvert/tests/base.py | 1 - nbconvert/tests/test_nbconvertapp.py | 27 +++++----- nbconvert/tests/utils.py | 4 +- nbconvert/utils/io.py | 2 +- nbconvert/utils/lexers.py | 2 +- nbconvert/utils/pandoc.py | 4 +- nbconvert/utils/tests/test_io.py | 2 - nbconvert/utils/tests/test_pandoc.py | 2 - nbconvert/writers/files.py | 1 - setup.cfg | 51 ++++++++----------- 36 files changed, 75 insertions(+), 144 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 013b4e337..948224884 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -48,16 +48,16 @@ repos: - id: doc8 args: [--max-line-length=200] - # - repo: https://github.com/pycqa/flake8 - # rev: 4.0.1 - # hooks: - # - id: flake8 - # additional_dependencies: - # [ - # "flake8-bugbear==20.1.4", - # "flake8-logging-format==0.6.0", - # "flake8-implicit-str-concat==0.2.0", - # ] + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + additional_dependencies: + [ + "flake8-bugbear==20.1.4", + "flake8-logging-format==0.6.0", + "flake8-implicit-str-concat==0.2.0", + ] - repo: https://github.com/sirosen/check-jsonschema rev: 0.14.1 diff --git a/docs/source/conf.py b/docs/source/conf.py index 1b9b09ea4..8444a4f08 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -240,16 +240,7 @@ # -- Options for LaTeX output --------------------------------------------- -latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - #'preamble': '', - # Latex figure (float) alignment - #'figure_align': 'htbp', -} +latex_elements = {} # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, diff --git a/nbconvert/exporters/base.py b/nbconvert/exporters/base.py index f7cd50352..48300f336 100644 --- a/nbconvert/exporters/base.py +++ b/nbconvert/exporters/base.py @@ -87,7 +87,7 @@ def export(exporter, nb, **kw): return output, resources -def get_exporter(name, config=get_config()): +def get_exporter(name, config=get_config()): # noqa """Given an exporter name or import path, return a class ready to be instantiated Raises ExporterName if exporter is not found or ExporterDisabledError if not enabled @@ -130,7 +130,7 @@ def get_exporter(name, config=get_config()): ) -def get_export_names(config=get_config()): +def get_export_names(config=get_config()): # noqa """Return a list of the currently supported export targets Exporters can be found in external packages by registering diff --git a/nbconvert/exporters/exporter.py b/nbconvert/exporters/exporter.py index 8c675af39..e47bdabd4 100644 --- a/nbconvert/exporters/exporter.py +++ b/nbconvert/exporters/exporter.py @@ -9,7 +9,6 @@ import collections import copy import datetime -import io import os import sys from typing import Optional @@ -171,7 +170,7 @@ def from_filename(self, filename: str, resources: Optional[dict] = None, **kw): # Pull the metadata from the filesystem. if resources is None: resources = ResourcesDict() - if not "metadata" in resources or resources["metadata"] == "": + if "metadata" not in resources or resources["metadata"] == "": resources["metadata"] = ResourcesDict() path, basename = os.path.split(filename) notebook_name = os.path.splitext(basename)[0] @@ -239,7 +238,7 @@ def register_preprocessor(self, preprocessor, enabled=False): preprocessor_cls = import_item(preprocessor) return self.register_preprocessor(preprocessor_cls, enabled) - if constructed and hasattr(preprocessor, "__call__"): + if constructed and hasattr(preprocessor, "__call__"): # noqa # Preprocessor is a function, no need to construct it. # Register and return the preprocessor. if enabled: diff --git a/nbconvert/exporters/pdf.py b/nbconvert/exporters/pdf.py index c9421ff36..1c72f3e9a 100644 --- a/nbconvert/exporters/pdf.py +++ b/nbconvert/exporters/pdf.py @@ -8,7 +8,6 @@ import subprocess import sys from tempfile import TemporaryDirectory -from typing import Optional from traitlets import Bool, Instance, Integer, List, Unicode, default @@ -128,7 +127,7 @@ def run_command(self, command_list, filename, count, log_function, raise_on_fail with open(os.devnull, "rb") as null: stdout = subprocess.PIPE if not self.verbose else None - for index in range(count): + for _ in range(count): p = subprocess.Popen( command, stdout=stdout, diff --git a/nbconvert/exporters/templateexporter.py b/nbconvert/exporters/templateexporter.py index 5a47ae574..1db3670bb 100644 --- a/nbconvert/exporters/templateexporter.py +++ b/nbconvert/exporters/templateexporter.py @@ -425,7 +425,7 @@ def _register_filter(self, environ, name, jinja_filter): filter_cls = import_item(jinja_filter) return self._register_filter(environ, name, filter_cls) - if constructed and hasattr(jinja_filter, "__call__"): + if constructed and hasattr(jinja_filter, "__call__"): # noqa # filter is a function, no need to construct it. environ.filters[name] = jinja_filter return jinja_filter @@ -510,7 +510,7 @@ def _init_preprocessors(self): # * We rely on recursive_update, which can only merge dicts, lists will be overwritten # * We can use the key with numerical prefixing to guarantee ordering (/etc/*.d/XY-file style) # * We can disable preprocessors by overwriting the value with None - for key, preprocessor in sorted(preprocessors.items(), key=lambda x: x[0]): + for _, preprocessor in sorted(preprocessors.items(), key=lambda x: x[0]): if preprocessor is not None: kwargs = preprocessor.copy() preprocessor_cls = kwargs.pop("type") diff --git a/nbconvert/exporters/tests/test_exporter.py b/nbconvert/exporters/tests/test_exporter.py index 76addfec0..665ac8b63 100644 --- a/nbconvert/exporters/tests/test_exporter.py +++ b/nbconvert/exporters/tests/test_exporter.py @@ -19,7 +19,7 @@ from traitlets.config import Config from ...preprocessors.base import Preprocessor -from ..base import ExporterDisabledError, get_export_names +from ..base import get_export_names from ..exporter import Exporter from .base import ExportersTestsBase @@ -58,12 +58,6 @@ def test_preprocessor(self): (notebook, resources) = exporter.from_filename(self._get_notebook()) self.assertEqual(notebook["pizza"], "cheese") - def test_get_export_names_disable(self): - """Can we disable a specific importer?""" - config = Config({"Exporter": {"enabled": False}}) - export_names = get_export_names() - self.assertFalse("Exporter" in export_names) - def test_get_export_names_disable(self): """Can we disable all exporters then enable a single one""" config = Config({"Exporter": {"enabled": False}, "NotebookExporter": {"enabled": True}}) diff --git a/nbconvert/exporters/tests/test_html.py b/nbconvert/exporters/tests/test_html.py index a9cf9d287..6235ac365 100644 --- a/nbconvert/exporters/tests/test_html.py +++ b/nbconvert/exporters/tests/test_html.py @@ -47,22 +47,6 @@ def test_export_notebook(self): (output, resources) = HTMLExporter(template_name="lab").from_filename(self._get_notebook()) assert len(output) > 0 - def test_prompt_number(self): - """ - Does HTMLExporter properly format input and output prompts? - """ - (output, resources) = HTMLExporter(template_name="lab").from_filename( - self._get_notebook(nb_name="prompt_numbers.ipynb") - ) - in_regex = r"In \[(.*)\]:" - out_regex = r"Out\[(.*)\]:" - - ins = ["2", "10", " ", " ", "0"] - outs = ["10"] - - assert re.findall(in_regex, output) == ins - assert re.findall(out_regex, output) == outs - def test_prompt_number(self): """ Does HTMLExporter properly format input and output prompts? diff --git a/nbconvert/exporters/tests/test_pdf.py b/nbconvert/exporters/tests/test_pdf.py index 5b3b2eed5..d321f4655 100644 --- a/nbconvert/exporters/tests/test_pdf.py +++ b/nbconvert/exporters/tests/test_pdf.py @@ -3,7 +3,6 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import logging import os import shutil from tempfile import TemporaryDirectory diff --git a/nbconvert/exporters/tests/test_rst.py b/nbconvert/exporters/tests/test_rst.py index 8170094fd..2c1afcc39 100644 --- a/nbconvert/exporters/tests/test_rst.py +++ b/nbconvert/exporters/tests/test_rst.py @@ -3,11 +3,9 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import io import re import nbformat -import pytest from nbformat import v4 from ...tests.utils import onlyif_cmds_exist diff --git a/nbconvert/exporters/tests/test_webpdf.py b/nbconvert/exporters/tests/test_webpdf.py index 184f91d52..994324fd6 100644 --- a/nbconvert/exporters/tests/test_webpdf.py +++ b/nbconvert/exporters/tests/test_webpdf.py @@ -3,7 +3,6 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import io from unittest.mock import patch import pytest diff --git a/nbconvert/filters/citation.py b/nbconvert/filters/citation.py index b9f668606..77ef008eb 100644 --- a/nbconvert/filters/citation.py +++ b/nbconvert/filters/citation.py @@ -78,7 +78,7 @@ def get_offset(self): # Compute startposition in source lin, offset = self.getpos() pos = 0 - for i in range(lin - 1): + for _ in range(lin - 1): pos = self.data.find("\n", pos) + 1 return pos + offset diff --git a/nbconvert/filters/highlight.py b/nbconvert/filters/highlight.py index ddd3d0ae6..02abee60f 100644 --- a/nbconvert/filters/highlight.py +++ b/nbconvert/filters/highlight.py @@ -121,7 +121,7 @@ def __call__(self, source, language=None, metadata=None, strip_verbatim=False): source, LatexFormatter(**self.extra_formatter_options), language, metadata ) if strip_verbatim: - latex = latex.replace(r"\begin{Verbatim}[commandchars=\\\{\}]" + "\n", "") + latex = latex.replace(r"\begin{Verbatim}[commandchars=\\\{\}]" + "\n", "") # noqa return latex.replace("\n\\end{Verbatim}\n", "") else: return latex diff --git a/nbconvert/filters/tests/test_highlight.py b/nbconvert/filters/tests/test_highlight.py index 170af1ce6..1a9b08073 100644 --- a/nbconvert/filters/tests/test_highlight.py +++ b/nbconvert/filters/tests/test_highlight.py @@ -16,8 +16,6 @@ import xml -from traitlets.config import Config - from ...tests.base import TestsBase from ..highlight import Highlight2HTML, Highlight2Latex diff --git a/nbconvert/filters/tests/test_markdown.py b/nbconvert/filters/tests/test_markdown.py index 492f5a2fd..72107a12a 100644 --- a/nbconvert/filters/tests/test_markdown.py +++ b/nbconvert/filters/tests/test_markdown.py @@ -122,7 +122,7 @@ def test_markdown2html_math(self): # all the "<", ">", "&" must be escaped correctly cases = [ ( - "\\begin{equation*}\n" + "\\begin{equation*}\n" # noqa + ( "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 " "\\leq \\left( \\sum_{k=1}^n a_k^2 \\right) " @@ -130,7 +130,7 @@ def test_markdown2html_math(self): ) + "\\end{equation*}" ), - ("$$\n" "a = 1 *3* 5\n" "$$"), + ("$$\na = 1 *3* 5\n$$"), "$ a = 1 *3* 5 $", "$s_i = s_{i}\n$", "$aa;a-b<0$$", "$$$$", - ("$$x\n" "=\n" "2$$"), + ("$$x\n=\n2$$"), ( "$$\n" "b = \\left[\n" @@ -148,7 +148,7 @@ def test_markdown2html_math(self): "\\right]\n" "$$" ), - ("\\begin{equation*}\n" "x = 2 *55* 7\n" "\\end{equation*}"), + ("\\begin{equation*}\nx = 2 *55* 7\n\\end{equation*}"), """$ \\begin{tabular}{ l c r } 1 & 2 & 3 \\ diff --git a/nbconvert/filters/tests/test_metadata.py b/nbconvert/filters/tests/test_metadata.py index a08408594..ee1541390 100644 --- a/nbconvert/filters/tests/test_metadata.py +++ b/nbconvert/filters/tests/test_metadata.py @@ -14,7 +14,7 @@ def test_get_metadata(): } assert get_metadata(output, "nowhere") is None assert get_metadata(output, "height") == 2 - assert get_metadata(output, "unconfined") == None - assert get_metadata(output, "unconfined", "image/png") == True + assert get_metadata(output, "unconfined") is None + assert get_metadata(output, "unconfined", "image/png") is True assert get_metadata(output, "width", "image/png") == 1 assert get_metadata(output, "height", "image/png") == 3 diff --git a/nbconvert/nbconvertapp.py b/nbconvert/nbconvertapp.py index ad6713bc6..16ff275ec 100755 --- a/nbconvert/nbconvertapp.py +++ b/nbconvert/nbconvertapp.py @@ -391,7 +391,7 @@ def init_notebooks(self): self.log.warning("pattern %r matched no files", pattern) for filename in globbed_files: - if not filename in filenames: + if filename not in filenames: filenames.append(filename) self.notebooks = filenames diff --git a/nbconvert/postprocessors/serve.py b/nbconvert/postprocessors/serve.py index 061a617e1..18714122e 100644 --- a/nbconvert/postprocessors/serve.py +++ b/nbconvert/postprocessors/serve.py @@ -95,7 +95,7 @@ def postprocess(self, input): if self.open_in_browser: try: browser = webbrowser.get(self.browser or None) - b = lambda: browser.open(url, new=2) + b = lambda: browser.open(url, new=2) # noqa threading.Thread(target=b).start() except webbrowser.Error as e: self.log.warning("No web browser found: %s." % e) diff --git a/nbconvert/postprocessors/tests/test_serve.py b/nbconvert/postprocessors/tests/test_serve.py index 26b85127b..54ea43c0c 100644 --- a/nbconvert/postprocessors/tests/test_serve.py +++ b/nbconvert/postprocessors/tests/test_serve.py @@ -19,6 +19,6 @@ def test_constructor(self): try: from ..serve import ServePostProcessor except ImportError: - print("Something weird is happening.\n" "Tornado is sometimes present, sometimes not.") + print("Something weird is happening.\nTornado is sometimes present, sometimes not.") raise ServePostProcessor() diff --git a/nbconvert/preprocessors/clearmetadata.py b/nbconvert/preprocessors/clearmetadata.py index 482751707..df7080ff5 100644 --- a/nbconvert/preprocessors/clearmetadata.py +++ b/nbconvert/preprocessors/clearmetadata.py @@ -15,15 +15,11 @@ class ClearMetadataPreprocessor(Preprocessor): clear_cell_metadata = Bool( True, - help=( - "Flag to choose if cell metadata is to be cleared " "in addition to notebook metadata." - ), + help=("Flag to choose if cell metadata is to be cleared in addition to notebook metadata."), ).tag(config=True) clear_notebook_metadata = Bool( True, - help=( - "Flag to choose if notebook metadata is to be cleared " "in addition to cell metadata." - ), + help=("Flag to choose if notebook metadata is to be cleared in addition to cell metadata."), ).tag(config=True) preserve_nb_metadata_mask = Set( [("language_info", "name")], diff --git a/nbconvert/preprocessors/csshtmlheader.py b/nbconvert/preprocessors/csshtmlheader.py index 43e25f98c..42e44c374 100644 --- a/nbconvert/preprocessors/csshtmlheader.py +++ b/nbconvert/preprocessors/csshtmlheader.py @@ -5,15 +5,12 @@ # Distributed under the terms of the Modified BSD License. import hashlib -import io import os from jupyterlab_pygments import JupyterStyle from pygments.style import Style from traitlets import Type, Unicode, Union -import nbconvert.resources - from .base import Preprocessor try: diff --git a/nbconvert/preprocessors/execute.py b/nbconvert/preprocessors/execute.py index 594cb6408..1966d8265 100644 --- a/nbconvert/preprocessors/execute.py +++ b/nbconvert/preprocessors/execute.py @@ -5,7 +5,7 @@ from nbclient import execute as _execute # Backwards compatability for imported name -from nbclient.exceptions import CellExecutionError +from nbclient.exceptions import CellExecutionError # noqa # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. diff --git a/nbconvert/preprocessors/svg2pdf.py b/nbconvert/preprocessors/svg2pdf.py index c6a91ff87..7fddf33e1 100644 --- a/nbconvert/preprocessors/svg2pdf.py +++ b/nbconvert/preprocessors/svg2pdf.py @@ -6,7 +6,6 @@ # Distributed under the terms of the Modified BSD License. import base64 -import io import os import subprocess import sys diff --git a/nbconvert/preprocessors/tests/test_regexremove.py b/nbconvert/preprocessors/tests/test_regexremove.py index 097b3427b..1281ba623 100644 --- a/nbconvert/preprocessors/tests/test_regexremove.py +++ b/nbconvert/preprocessors/tests/test_regexremove.py @@ -7,7 +7,6 @@ import re -from nbformat import from_dict from nbformat import v4 as nbformat from ..regexremove import RegexRemovePreprocessor diff --git a/nbconvert/preprocessors/tests/test_sanitize.py b/nbconvert/preprocessors/tests/test_sanitize.py index fdd557c8d..7da6c4155 100644 --- a/nbconvert/preprocessors/tests/test_sanitize.py +++ b/nbconvert/preprocessors/tests/test_sanitize.py @@ -125,7 +125,8 @@ def test_style_whitelist(self): "few ", preprocessor, ), - '_A_ few ' "<script>tags</script>", + '_A_ few ' # noqa + + " #<script>tags</script>", ) def test_tag_passthrough(self): diff --git a/nbconvert/preprocessors/tests/test_svg2pdf.py b/nbconvert/preprocessors/tests/test_svg2pdf.py index 0b0775317..988fa35c2 100644 --- a/nbconvert/preprocessors/tests/test_svg2pdf.py +++ b/nbconvert/preprocessors/tests/test_svg2pdf.py @@ -3,7 +3,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -from unittest.mock import Mock, patch +from unittest.mock import patch from nbformat import v4 as nbformat @@ -80,10 +80,6 @@ def test_inkscape_version_default(self, mock_popen): preprocessor = self.build_preprocessor() assert preprocessor.inkscape_version == "0.92.3" - def test_inkscape_pre_v1_command(self): - preprocessor = self.build_preprocessor(inkscape_version="0.92.3") - assert preprocessor.command == "0.92.3" - def test_inkscape_pre_v1_command(self): preprocessor = self.build_preprocessor(inkscape="fake-inkscape", inkscape_version="0.92.3") assert preprocessor.command == [ diff --git a/nbconvert/tests/base.py b/nbconvert/tests/base.py index a1c915bb5..60db5df42 100644 --- a/nbconvert/tests/base.py +++ b/nbconvert/tests/base.py @@ -5,7 +5,6 @@ import contextlib import glob -import io import os import shlex import shutil diff --git a/nbconvert/tests/test_nbconvertapp.py b/nbconvert/tests/test_nbconvertapp.py index 958cfadeb..c6b6b5ef4 100644 --- a/nbconvert/tests/test_nbconvertapp.py +++ b/nbconvert/tests/test_nbconvertapp.py @@ -3,7 +3,6 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import io import os from tempfile import TemporaryDirectory @@ -11,8 +10,7 @@ import pytest from traitlets.tests.utils import check_help_all_output -from nbconvert import nbconvertapp -from nbconvert.exporters import Exporter, HTMLExporter +from nbconvert.exporters import HTMLExporter from ..postprocessors import PostProcessorBase from ..tests.utils import onlyif_cmds_exist @@ -155,7 +153,7 @@ def test_webpdf_with_chromium(self): Generate PDFs if chromium allowed to be downloaded? """ with self.create_temp_cwd(["notebook2.ipynb"]): - self.nbconvert("--to webpdf " "--allow-chromium-download " '"notebook2"') + self.nbconvert('--to webpdf --allow-chromium-download "notebook2"') assert os.path.isfile("notebook2.pdf") @onlyif_cmds_exist("pandoc", "xelatex") @@ -176,8 +174,7 @@ def test_post_processor(self): """Do post processors work?""" with self.create_temp_cwd(["notebook1.ipynb"]): out, err = self.nbconvert( - "--log-level 0 --to python notebook1 " - "--post nbconvert.tests.test_nbconvertapp.DummyPost" + "--log-level 0 --to python notebook1 --post nbconvert.tests.test_nbconvertapp.DummyPost" ) self.assertIn("Dummy:notebook1.py", out) @@ -200,7 +197,7 @@ def test_spurious_cr(self): def test_png_base64_html_ok(self): """Is embedded png data well formed in HTML?""" with self.create_temp_cwd(["notebook2.ipynb"]): - self.nbconvert("--log-level 0 --to HTML " "notebook2.ipynb --template lab") + self.nbconvert("--log-level 0 --to HTML notebook2.ipynb --template lab") assert os.path.isfile("notebook2.html") with open("notebook2.html", encoding="utf8") as f: assert "data:image/png;base64,b'" not in f.read() @@ -211,7 +208,7 @@ def test_template(self): Do export templates work? """ with self.create_temp_cwd(["notebook2.ipynb"]): - self.nbconvert("--log-level 0 --to slides " "notebook2.ipynb") + self.nbconvert("--log-level 0 --to slides notebook2.ipynb") assert os.path.isfile("notebook2.slides.html") with open("notebook2.slides.html", encoding="utf8") as f: assert "/reveal.css" in f.read() @@ -219,10 +216,10 @@ def test_template(self): def test_output_ext(self): """test --output=outputfile[.ext]""" with self.create_temp_cwd(["notebook1.ipynb"]): - self.nbconvert("--log-level 0 --to python " "notebook1.ipynb --output nb.py") + self.nbconvert("--log-level 0 --to python notebook1.ipynb --output nb.py") assert os.path.exists("nb.py") - self.nbconvert("--log-level 0 --to python " "notebook1.ipynb --output nb2") + self.nbconvert("--log-level 0 --to python notebook1.ipynb --output nb2") assert os.path.exists("nb2.py") def test_glob_explicit(self): @@ -230,7 +227,7 @@ def test_glob_explicit(self): Can a search pattern be used along with matching explicit notebook names? """ with self.create_temp_cwd(["notebook*.ipynb"]): - self.nbconvert("--log-level 0 --to python " "*.ipynb notebook1.ipynb notebook2.ipynb") + self.nbconvert("--log-level 0 --to python *.ipynb notebook1.ipynb notebook2.ipynb") assert os.path.isfile("notebook1.py") assert os.path.isfile("notebook2.py") @@ -239,7 +236,7 @@ def test_explicit_glob(self): Can explicit notebook names be used and then a matching search pattern? """ with self.create_temp_cwd(["notebook*.ipynb"]): - self.nbconvert("--log-level 0 --to=python " "notebook1.ipynb notebook2.ipynb *.ipynb") + self.nbconvert("--log-level 0 --to=python notebook1.ipynb notebook2.ipynb *.ipynb") assert os.path.isfile("notebook1.py") assert os.path.isfile("notebook2.py") @@ -313,7 +310,7 @@ def test_different_build_dir(self): with self.create_temp_cwd(): self.create_empty_notebook("empty.ipynb") os.mkdir("output") - self.nbconvert("empty.ipynb --to notebook " "--FilesWriter.build_directory=output") + self.nbconvert("empty.ipynb --to notebook --FilesWriter.build_directory=output") assert os.path.isfile("output/empty.ipynb") def test_inplace(self): @@ -515,12 +512,12 @@ def test_markdown_display_priority(self): even if an (unsupported) PDF is present. """ with self.create_temp_cwd(["markdown_display_priority.ipynb"]): - self.nbconvert("--log-level 0 --to markdown " '"markdown_display_priority.ipynb"') + self.nbconvert('--log-level 0 --to markdown "markdown_display_priority.ipynb"') assert os.path.isfile("markdown_display_priority.md") with open("markdown_display_priority.md", encoding="utf8") as f: markdown_output = f.read() assert ( - "markdown_display_priority_files/" "markdown_display_priority_0_1.png" + "markdown_display_priority_files/markdown_display_priority_0_1.png" ) in markdown_output @onlyif_cmds_exist("pandoc") diff --git a/nbconvert/tests/utils.py b/nbconvert/tests/utils.py index 06afa89fb..21a039f89 100644 --- a/nbconvert/tests/utils.py +++ b/nbconvert/tests/utils.py @@ -9,7 +9,5 @@ def onlyif_cmds_exist(*commands): """ for cmd in commands: if not which(cmd): - return pytest.mark.skip( - "This test runs only if command '{}' " "is installed".format(cmd) - ) + return pytest.mark.skip(f"This test runs only if command '{cmd}' is installed") return lambda f: f diff --git a/nbconvert/utils/io.py b/nbconvert/utils/io.py index 00c4a7973..de67a509e 100644 --- a/nbconvert/utils/io.py +++ b/nbconvert/utils/io.py @@ -103,7 +103,7 @@ def link_or_copy(src, dst): new_dst = dst + f"-temp-{random.randint(1, 16**4):04X}" try: link_or_copy(src, new_dst) - except: + except BaseException: try: os.remove(new_dst) except OSError: diff --git a/nbconvert/utils/lexers.py b/nbconvert/utils/lexers.py index 9c57368db..e494deded 100644 --- a/nbconvert/utils/lexers.py +++ b/nbconvert/utils/lexers.py @@ -3,4 +3,4 @@ warn("nbconvert.utils.lexers is deprecated as of 5.0. Use IPython.lib.lexers") -from IPython.lib.lexers import * +from IPython.lib.lexers import * # noqa diff --git a/nbconvert/utils/pandoc.py b/nbconvert/utils/pandoc.py index 30a26bbf2..c2b289f70 100644 --- a/nbconvert/utils/pandoc.py +++ b/nbconvert/utils/pandoc.py @@ -125,12 +125,14 @@ def check_pandoc_version(): # ----------------------------------------------------------------------------- # Exception handling # ----------------------------------------------------------------------------- + + class PandocMissing(ConversionException): """Exception raised when Pandoc is missing.""" def __init__(self, *args, **kwargs): super().__init__( - "Pandoc wasn't found.\n" + "Pandoc wasn't found.\n" # noqa + "Please check that pandoc is installed:\n" + "https://pandoc.org/installing.html" ) diff --git a/nbconvert/utils/tests/test_io.py b/nbconvert/utils/tests/test_io.py index f517ee8dd..ce16c1a51 100644 --- a/nbconvert/utils/tests/test_io.py +++ b/nbconvert/utils/tests/test_io.py @@ -7,8 +7,6 @@ import sys from io import StringIO -import pytest - from ..io import unicode_std_stream diff --git a/nbconvert/utils/tests/test_pandoc.py b/nbconvert/utils/tests/test_pandoc.py index e24f5db41..4b86a09c6 100644 --- a/nbconvert/utils/tests/test_pandoc.py +++ b/nbconvert/utils/tests/test_pandoc.py @@ -12,8 +12,6 @@ import os import warnings -import pytest - from nbconvert.tests.base import TestsBase from ...tests.utils import onlyif_cmds_exist diff --git a/nbconvert/writers/files.py b/nbconvert/writers/files.py index 3bc4c31a6..766bc0599 100644 --- a/nbconvert/writers/files.py +++ b/nbconvert/writers/files.py @@ -4,7 +4,6 @@ # Distributed under the terms of the Modified BSD License. import glob -import io import os from pathlib import Path diff --git a/setup.cfg b/setup.cfg index fa96ad50c..737cd58e6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,33 +10,24 @@ ignore = .circleci/* [flake8] -ignore = E121, # continuation line under-indented for hanging indent - E123, # closing bracket does not match indentation of opening bracket's line - E124, # closing bracket does not match visual indentation - E126, # continuation line over-indented for hanging indent - E127, # continuation line over-indented for visual indent - E128, # continuation line under-indented for visual indent - E201, # whitespace after '{' - E202, # whitespace before '}' - E203, # whitespace before ':' - E221, # multiple spaces before operator - E222, # multiple spaces after operator - E225, # missing whitespace around operator - E226, # missing whitespace around arithmetic operator - E231, # missing whitespace after ',' - E241, # multiple spaces after ' - E251, # unexpected spaces around keyword / parameter equals - E261, # at least two spaces before inline comment - E265, # block comment should start with '# ' - E301, # expected 1 blank line, found 0 - E302, # expected 2 blank lines, found 1 - E303, # too many blank lines (2) - E305, # expected 2 blank lines after class or function definition, found 1 - E306, # expected 1 blank line before a nested definition, found 0 - E501, # line too long (90 > 79 characters) - F403, # 'from ... import *' used; unable to detect undefined names - W291, # trailing whitespace - W293, # blank line contains whitespace - W391, # blank line at end of file - W503, # line break before binary operator - W504, # line break after binary operator +ignore = E501, W503, E402 +builtins = c, get_config +exclude = + .cache, + .github, + docs, + setup.py +enable-extensions = G +extend-ignore = + G001, G002, G004, G200, G201, G202, + # black adds spaces around ':' + E203, +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 + nbconvert/*/tests/*: B011, F841, + nbconvert/tests/*: B011, F841, + # F401 'foo' imported but unused + # F403 'x' used; unable to detect undefined names + nbconvert/*/__init__.py: F401, F403 + nbconvert/__init__.py: F401, F403 From 2be21925a214596a9c776e0b6bfa1422aacd0c7d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 2 Apr 2022 07:41:17 -0500 Subject: [PATCH 2/2] update sanitizer test --- nbconvert/preprocessors/sanitize.py | 2 +- nbconvert/preprocessors/tests/test_sanitize.py | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/nbconvert/preprocessors/sanitize.py b/nbconvert/preprocessors/sanitize.py index 34462746c..16c981a31 100644 --- a/nbconvert/preprocessors/sanitize.py +++ b/nbconvert/preprocessors/sanitize.py @@ -26,7 +26,7 @@ class SanitizeHTML(Preprocessor): Unicode(), config=True, default_value=ALLOWED_STYLES, - help="Allowed CSS styles if