Skip to content

Commit

Permalink
Merge pull request #259 from blink1073/flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Apr 2, 2022
2 parents e4067d8 + e76d430 commit d8d7734
Show file tree
Hide file tree
Showing 42 changed files with 77 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Initial pre-commit reformat
e4067d87e1728bfd2219adbbe6ba18b4b8061cab
1 change: 0 additions & 1 deletion .github/scripts/parse_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# Standard library imports
import os
import subprocess

# Constants
HERE = os.path.abspath(os.path.dirname(__file__))
Expand Down
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ recursive-include nbformat *.json
recursive-include tests *.*
exclude scripts/jupyter-trust
exclude .pre-commit-config.yaml
exclude .git-blame-ignore-revs

# Javascript
include package.json
Expand Down
15 changes: 1 addition & 14 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import shlex
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -212,16 +208,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
1 change: 0 additions & 1 deletion nbformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import io

from traitlets.log import get_logger

Expand Down
10 changes: 0 additions & 10 deletions nbformat/_compat.py

This file was deleted.

10 changes: 5 additions & 5 deletions nbformat/_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,11 @@ def merge(self, __loc_data__=None, __conflict_solve=None, **kw):

# policies for conflict resolution: two argument functions which return
# the value that will go in the new struct
preserve = lambda old, new: old
update = lambda old, new: new
add = lambda old, new: old + new
add_flip = lambda old, new: new + old # note change of order!
add_s = lambda old, new: old + " " + new
preserve = lambda old, new: old # noqa
update = lambda old, new: new # noqa
add = lambda old, new: old + new # noqa
add_flip = lambda old, new: new + old # noqa # note change of order!
add_s = lambda old, new: old + " " + new # noqa

# default policy is to keep current keys when there's a conflict
conflict_solve = dict.fromkeys(self, preserve)
Expand Down
2 changes: 1 addition & 1 deletion nbformat/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ def convert(nb, to_version):
return convert(converted, to_version)
else:
raise ValueError(
"Cannot convert notebook to v%d because that " "version doesn't exist" % (to_version)
"Cannot convert notebook to v%d because that version doesn't exist" % (to_version)
)
4 changes: 0 additions & 4 deletions nbformat/corpus/tests/test_words.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

import random

import pytest

from .. import words


Expand Down
1 change: 0 additions & 1 deletion nbformat/corpus/words.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import uuid


Expand Down
4 changes: 2 additions & 2 deletions nbformat/json_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def validate(self, data):
try:
self._validator(data)
except _JsonSchemaException as error:
raise ValidationError(error.message, schema_path=error.path)
raise ValidationError(str(error), schema_path=error.path)

def iter_errors(self, data, schema=None):
if schema is not None:
Expand All @@ -63,7 +63,7 @@ def iter_errors(self, data, schema=None):
try:
validate_func(data)
except _JsonSchemaException as error:
errors = [ValidationError(error.message, schema_path=error.path)]
errors = [ValidationError(str(error), schema_path=error.path)]

return errors

Expand Down
5 changes: 3 additions & 2 deletions nbformat/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Distributed under the terms of the Modified BSD License.

import hashlib
import io
import os
import sys
from collections import OrderedDict
Expand All @@ -20,6 +19,8 @@
except ImportError:
sqlite3 = None

from base64 import encodebytes

from jupyter_core.application import JupyterApp, base_flags
from traitlets import (
Any,
Expand All @@ -36,7 +37,6 @@
from traitlets.config import LoggingConfigurable, MultipleInstanceError

from . import NO_CONVERT, __version__, read, reads
from ._compat import encodebytes

try:
# Python 3
Expand Down Expand Up @@ -576,6 +576,7 @@ class TrustNotebookApp(JupyterApp):
Otherwise, you will have to re-execute the notebook to see output.
"""
# This command line tool should use the same config file as the notebook

@default("config_file_name")
def _config_file_name_default(self):
return "jupyter_notebook_config"
Expand Down
3 changes: 0 additions & 3 deletions nbformat/v1/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
# Imports
# -----------------------------------------------------------------------------

import pprint
import uuid

from .._struct import Struct

# -----------------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions nbformat/v2/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
# Imports
# -----------------------------------------------------------------------------

from .nbbase import (
new_code_cell,
new_notebook,
new_output,
new_text_cell,
new_worksheet,
)
from .nbbase import new_code_cell, new_notebook, new_text_cell, new_worksheet

# -----------------------------------------------------------------------------
# Code
Expand Down
3 changes: 0 additions & 3 deletions nbformat/v2/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
# Imports
# -----------------------------------------------------------------------------

import pprint
import uuid

from .._struct import Struct

# -----------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions nbformat/v2/rwbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
# Imports
# -----------------------------------------------------------------------------

import pprint

from .._compat import decodebytes, encodebytes
from base64 import decodebytes, encodebytes

# -----------------------------------------------------------------------------
# Code
Expand Down
12 changes: 1 addition & 11 deletions nbformat/v3/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,7 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from nbformat import v2

from .nbbase import (
nbformat,
nbformat_minor,
new_code_cell,
new_notebook,
new_output,
new_text_cell,
new_worksheet,
)
from .nbbase import nbformat, nbformat_minor


def _unbytes(obj):
Expand Down
4 changes: 1 addition & 3 deletions nbformat/v3/nbbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import pprint
import uuid
import warnings

from .._struct import Struct
Expand Down Expand Up @@ -59,7 +57,7 @@ def cast_str(obj):
UserWarning,
stacklevel=3,
)
dec = obj.decode("ascii", "replace")
return obj.decode("ascii", "replace")
else:
assert isinstance(obj, str)
return obj
Expand Down
1 change: 0 additions & 1 deletion nbformat/v3/nbjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
NotebookReader,
NotebookWriter,
rejoin_lines,
restore_bytes,
split_lines,
strip_transient,
)
Expand Down
2 changes: 1 addition & 1 deletion nbformat/v3/rwbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Distributed under the terms of the Modified BSD License.


from .._compat import decodebytes, encodebytes
from base64 import decodebytes, encodebytes


def restore_bytes(nb):
Expand Down
2 changes: 1 addition & 1 deletion nbformat/v4/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def upgrade(nb, from_version=None, from_minor=None):
if not from_version:
from_version = nb["nbformat"]
if not from_minor:
if not "nbformat_minor" in nb:
if "nbformat_minor" not in nb:
raise validator.ValidationError(
"The notebook does not include the nbformat minor which is needed"
)
Expand Down
4 changes: 2 additions & 2 deletions nbformat/v4/rwbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def rejoin_lines(nb):
cell.source = "".join(cell.source)

attachments = cell.get("attachments", {})
for key, attachment in attachments.items():
for _, attachment in attachments.items():
_rejoin_mimebundle(attachment)

if cell.get("cell_type", None) == "code":
Expand Down Expand Up @@ -80,7 +80,7 @@ def split_lines(nb):
cell["source"] = source.splitlines(True)

attachments = cell.get("attachments", {})
for key, attachment in attachments.items():
for _, attachment in attachments.items():
_split_mimebundle(attachment)

if cell.cell_type == "code":
Expand Down
1 change: 0 additions & 1 deletion nbformat/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import json
import os
import pprint
import sys

from traitlets.log import get_logger

Expand Down
21 changes: 21 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,24 @@ universal=0

[metadata]
license_file = COPYING.md

[flake8]
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
# B007 Loop control variable 'foo' not used within the loop body
tests/*: B011, F841, B007,
# F401 '.foo' imported but unused
nbformat/*/__init__.py: F401
1 change: 0 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import io
import os
import unittest

Expand Down
6 changes: 3 additions & 3 deletions tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_nb2(validator_name):
with TestsBase.fopen("test2.ipynb", "r") as f:
nb = read(f, as_version=4)
validate(nb)
assert isvalid(nb) == True
assert isvalid(nb)


@pytest.mark.parametrize("validator_name", VALIDATORS)
Expand All @@ -49,7 +49,7 @@ def test_nb3(validator_name):
with TestsBase.fopen("test3.ipynb", "r") as f:
nb = read(f, as_version=4)
validate(nb)
assert isvalid(nb) == True
assert isvalid(nb)


@pytest.mark.parametrize("validator_name", VALIDATORS)
Expand All @@ -59,7 +59,7 @@ def test_nb4(validator_name):
with TestsBase.fopen("test4.ipynb", "r") as f:
nb = read(f, as_version=4)
validate(nb)
assert isvalid(nb) == True
assert isvalid(nb)


@pytest.mark.parametrize("validator_name", VALIDATORS)
Expand Down
2 changes: 1 addition & 1 deletion tests/v1/nbexamples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nbformat.v1.nbbase import NotebookNode, new_code_cell, new_notebook, new_text_cell
from nbformat.v1.nbbase import new_code_cell, new_notebook, new_text_cell

nb0 = new_notebook()

Expand Down
2 changes: 1 addition & 1 deletion tests/v1/test_nbbase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import TestCase

from nbformat.v1.nbbase import NotebookNode, new_code_cell, new_notebook, new_text_cell
from nbformat.v1.nbbase import new_code_cell, new_notebook, new_text_cell


class TestCell(TestCase):
Expand Down

0 comments on commit d8d7734

Please sign in to comment.