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

Update flake8 config #1749

Merged
merged 2 commits into from Apr 2, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Expand Up @@ -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
Expand Down
11 changes: 1 addition & 10 deletions docs/source/conf.py
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/exporters/base.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions nbconvert/exporters/exporter.py
Expand Up @@ -9,7 +9,6 @@
import collections
import copy
import datetime
import io
import os
import sys
from typing import Optional
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions nbconvert/exporters/pdf.py
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/exporters/templateexporter.py
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 1 addition & 7 deletions nbconvert/exporters/tests/test_exporter.py
Expand Up @@ -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

Expand Down Expand Up @@ -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}})
Expand Down
16 changes: 0 additions & 16 deletions nbconvert/exporters/tests/test_html.py
Expand Up @@ -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?
Expand Down
1 change: 0 additions & 1 deletion nbconvert/exporters/tests/test_pdf.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions nbconvert/exporters/tests/test_rst.py
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion nbconvert/exporters/tests/test_webpdf.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/citation.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/highlight.py
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions nbconvert/filters/tests/test_highlight.py
Expand Up @@ -16,8 +16,6 @@

import xml

from traitlets.config import Config

from ...tests.base import TestsBase
from ..highlight import Highlight2HTML, Highlight2Latex

Expand Down
8 changes: 4 additions & 4 deletions nbconvert/filters/tests/test_markdown.py
Expand Up @@ -122,15 +122,15 @@ 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) "
"\\left( \\sum_{k=1}^n b_k^2 \\right)\n"
)
+ "\\end{equation*}"
),
("$$\n" "a = 1 *3* 5\n" "$$"),
("$$\na = 1 *3* 5\n$$"),
"$ a = 1 *3* 5 $",
"$s_i = s_{i}\n$",
"$a<b&b<lt$",
Expand All @@ -139,7 +139,7 @@ def test_markdown2html_math(self):
"$$a<b&b<lt$$",
"$$a<b&lt;b>a;a-b<0$$",
"$$<k'>$$",
("$$x\n" "=\n" "2$$"),
("$$x\n=\n2$$"),
(
"$$\n"
"b = \\left[\n"
Expand All @@ -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 \\
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/filters/tests/test_metadata.py
Expand Up @@ -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
2 changes: 1 addition & 1 deletion nbconvert/nbconvertapp.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion nbconvert/postprocessors/serve.py
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/postprocessors/tests/test_serve.py
Expand Up @@ -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()
8 changes: 2 additions & 6 deletions nbconvert/preprocessors/clearmetadata.py
Expand Up @@ -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")],
Expand Down
3 changes: 0 additions & 3 deletions nbconvert/preprocessors/csshtmlheader.py
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/execute.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/preprocessors/sanitize.py
Expand Up @@ -26,7 +26,7 @@ class SanitizeHTML(Preprocessor):
Unicode(),
config=True,
default_value=ALLOWED_STYLES,
help="Allowed CSS styles if <style> tag is whitelisted",
help="Allowed CSS styles if <style> tag is allowed",
)
strip = Bool(
config=True,
Expand Down
1 change: 0 additions & 1 deletion nbconvert/preprocessors/svg2pdf.py
Expand Up @@ -6,7 +6,6 @@
# Distributed under the terms of the Modified BSD License.

import base64
import io
import os
import subprocess
import sys
Expand Down
1 change: 0 additions & 1 deletion nbconvert/preprocessors/tests/test_regexremove.py
Expand Up @@ -7,7 +7,6 @@

import re

from nbformat import from_dict
from nbformat import v4 as nbformat

from ..regexremove import RegexRemovePreprocessor
Expand Down