Skip to content

Commit

Permalink
Add flake8 and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed Jun 21, 2018
1 parent 3e0b852 commit 3e7fd4f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
7 changes: 7 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ url = "https://pypi.python.org/simple"
name = "pypi"
verify_ssl = true

[scripts]

lint = "flake8 nbcollate"

[dev-packages]

Expand All @@ -13,6 +16,10 @@ keyring = "*"
Sphinx = "*"
bumpversion = "*"
sphinx_rtd_theme = "*"
flake8 = "*"
mccabe = "*"
pycodestyle = "==2.3.1" # newer versions are incompatible with flake8 https://github.com/PyCQA/pycodestyle/issues/741
pyflakes = "*"


[packages]
Expand Down
30 changes: 29 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions nbcollate/nbcollate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from difflib import SequenceMatcher
from itertools import starmap

import nbformat

# QUESTION_RE = r'#+ (Exercise|Question)'
SOURCE_METADATA_KEY = 'nbcollate_source'

Expand Down Expand Up @@ -87,16 +89,17 @@ def nbcollate(assignment_nb, answer_nbs, *, ids=None, labels=None, clear_outputs


def make_label_cell(label):
"Create a cell that labels a collated notebook with ``label``."
"""Create a cell that labels a collated notebook with ``label``."""
return nbformat.v4.new_markdown_cell(source='**{}**'.format(label))


def cell_strings(nb):
"Return a cell's normalized source, for comparison."
"""Return a cell's normalized source, for comparison."""
return [cell.source.strip() for cell in nb.cells]


def NotebookMatcher(nb1, nb2):
"""A SequenceMatcher whose sequences are the notebook cell strings."""
return SequenceMatcher(None, cell_strings(nb1), cell_strings(nb2))


Expand Down Expand Up @@ -149,15 +152,14 @@ def sort_answers(nb):
Args:
nb (Notebook): A Jupyter notebook. This is modified in place.
"""
dups = []
out = []
for _, cells in i_sections(nb):
out += sorted(cells, key=lambda c: (len(c.source.strip().splitlines()), c.source.strip()))
nb.cells = out


def get_cell_source_id(cell):
"Return an answer notebook id that was placed in a cell by :func:`nbcollate`."
"""Return an answer notebook id that was placed in a cell by :func:`nbcollate`."""
return getattr(cell.metadata, SOURCE_METADATA_KEY, None)


Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
nbformat~=4.4.0
# ReadTheDocs.org uses this

nbformat~=4.4
9 changes: 0 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ test = pytest

[bumpversion:file:nbcollate/__init__.py]

[pep8]
max-line-length = 160

[flake8]
max-line-length = 160
ignore = D100,D101,D102,D103,D104,H101,H301,H306
exclude = nbcollate/__init__.py,tests

[yapf]
based_on_style = pep8 │XlsxWriter (1.0.0)
column_limit = 120

0 comments on commit 3e7fd4f

Please sign in to comment.