Skip to content

Commit

Permalink
Some flake8 cleanups and one import bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Sandve Alnæs committed Jan 4, 2016
1 parent 555c7b2 commit 8673caa
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions nbdime/dformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from six import string_types
from six.moves import xrange as range

from .log import error, NBDiffFormatError
from .log import NBDiffFormatError


# Valid values for the action field in diff entries
Expand Down Expand Up @@ -36,7 +36,7 @@ def is_valid_diff(diff, deep=False):
try:
validate_diff(diff, deep=deep)
result = True
except NBDiffFormatError as e:
except NBDiffFormatError:
result = False
return result

Expand Down Expand Up @@ -175,7 +175,7 @@ def get_equal_ranges(a, b, d):
bcons = 0
ranges = []
for e in d:
action = e[0]
#action = e[0]
index = e[1]

# Consume n more unmentioned items.
Expand Down
7 changes: 4 additions & 3 deletions nbdime/diffing/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import difflib
import operator

from ..dformat import PATCH, SEQINSERT, SEQDELETE
from ..dformat import decompress_diff
#from ..dformat import PATCH, SEQINSERT, SEQDELETE
#from ..dformat import decompress_diff

from .comparing import strings_are_similar
#from .comparing import strings_are_similar
from .sequences import diff_sequence
from .generic import diff, diff_lists, diff_dicts
from .snakes import diff_sequence_multilevel
Expand Down Expand Up @@ -154,6 +154,7 @@ def diff_cells(a, b, compare="ignored"):

def old_diff_cells(cells_a, cells_b):
"Compute the diff of two sequences of cells."
compare_cells = compare_cell_source_and_outputs
shallow_diff = diff_sequence(cells_a, cells_b, compare_cells)
return diff_lists(cells_a, cells_b, compare=operator.__eq__, shallow_diff=shallow_diff)

Expand Down
2 changes: 1 addition & 1 deletion nbdime/diffing/seq_difflib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def opcodes_to_diff(a, b, opcodes):
for opcode in opcodes:
action, abegin, aend, bbegin, bend = opcode
asize = aend - abegin
bsize = bend - bbegin
#bsize = bend - bbegin
if action == "equal":
# Unlike difflib we don't represent equal stretches explicitly
pass
Expand Down
1 change: 0 additions & 1 deletion nbdime/diffing/seq_myers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from __future__ import unicode_literals

import operator
import numpy as np

__all__ = ["diff_sequence_myers"]

Expand Down
4 changes: 1 addition & 3 deletions nbdime/diffing/snakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
Up- and down-conversion is handled by nbformat.
"""

import operator

from ..dformat import PATCH, SEQINSERT, SEQDELETE
from .seq_bruteforce import bruteforce_compute_snakes
from .generic import diff

__all__ = ["diff_notebooks"]
__all__ = ["diff_sequence_multilevel"]


def compute_snakes(A, B, rect, compare):
Expand Down
15 changes: 11 additions & 4 deletions nbdime/merging/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
from six import string_types
from six.moves import xrange as range

import nbformat

from ..diffing import diff
from ..dformat import PATCH, INSERT, DELETE, REPLACE, SEQINSERT, SEQDELETE
from ..dformat import to_dict_diff
from ..patching import patch


# Set to true to enable some expensive debugging assertions
DEBUGGING = 0


# Sentinel to allow None value
Expand Down Expand Up @@ -280,11 +283,15 @@ def _merge_lists(base, local, remote, base_local_diff, base_remote_diff):
local_conflict_diff.append([PATCH, j, lco])
remote_conflict_diff.append([PATCH, j, rco])
elif lp:
assert local[i+loffset] == patch(base[i], local_patched[i][2]) # TODO: Remove expensive assert!
if DEBUGGING:
# This assert is expensive and must not be enabled in release mode
assert local[i+loffset] == patch(base[i], local_patched[i][2])
# Patched on local side only
merged.append(local[i+loffset])
elif rp:
assert remote[i+roffset] == patch(base[i], remote_patched[i][2]) # TODO: Remove expensive assert!
if DEBUGGING:
# This assert is expensive and must not be enabled in release mode
assert remote[i+roffset] == patch(base[i], remote_patched[i][2])
# Patched on remote side only
merged.append(remote[i+loffset])
else:
Expand Down
8 changes: 4 additions & 4 deletions nbdime/merging/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from __future__ import unicode_literals

from six import string_types
from six.moves import xrange as range
#from six import string_types
#from six.moves import xrange as range

import nbformat

from ..diffing import diff
from ..dformat import PATCH, INSERT, DELETE, REPLACE, SEQINSERT, SEQDELETE
#from ..diffing import diff
#from ..dformat import PATCH, INSERT, DELETE, REPLACE, SEQINSERT, SEQDELETE
from .generic import merge

def merge_notebooks(base, local, remote):
Expand Down
2 changes: 2 additions & 0 deletions nbdime/nbdiffapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def present_string_diff(a, d, path):
index = e[1]
arg = e[2]

actname = action_names[action]

# Consume untouched characters
if index > consumed:
dlines = a[consumed:index].split("\n")
Expand Down
8 changes: 4 additions & 4 deletions nbdime/tests/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
from __future__ import unicode_literals
from __future__ import print_function

import pytest
import copy
#import pytest
#import copy
import operator

from nbdime import patch, diff
from nbdime import diff
from nbdime.dformat import PATCH, INSERT, DELETE, REPLACE, SEQINSERT, SEQDELETE
from nbdime.diffing.snakes import compute_snakes_multilevel

from .fixtures import check_diff_and_patch, check_symmetric_diff_and_patch
from .fixtures import check_symmetric_diff_and_patch

def test_diff_and_patch():
# Note: check_symmetric_diff_and_patch handles (a,b) and (b,a) for both
Expand Down
2 changes: 1 addition & 1 deletion nbdime/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import copy
import pytest

from nbdime import merge, diff
from nbdime import merge


def cut(li, *indices):
Expand Down
5 changes: 3 additions & 2 deletions nbdime/tests/test_myers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import numpy as np
from six.moves import xrange as range

import pdb

# Set to true to enable additional assertions, array access checking, and printouts
DEBUGGING = 0
#import pdb


class DebuggingArray(object):
"Debugging tool to capture array accesses."
Expand Down Expand Up @@ -214,7 +215,7 @@ def find_reverse_path(A, B, V, V0, D, k, delta, compare=operator.__eq__):
V[V0+k] = x

if DEBUGGING:
FIXME
# FIXME
assert x0 < 0 or y0 < 0 or (x0-x) == 0 or compare(A[x0], B[y0])
assert x < 0 or y < 0 or not compare(A[x], B[y])
for i in range(x0-x):
Expand Down

0 comments on commit 8673caa

Please sign in to comment.