Skip to content

Commit

Permalink
🔧 MAINTAIN: Update to nbdime4
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Nov 28, 2023
1 parent b58c5b2 commit ad66b31
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
("py:class", "Session"),
("py:exc", "nbconvert.preprocessors.CellExecutionError"),
("py:class", "nbdime.diff_format.DiffEntry"),
("py:class", "nbdime.diffing.config.DiffConfig"),
("py:class", "_pytest._py.path.LocalPath"),
("py:meth", "Item.reportinfo"),
]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"importlib-metadata~=6.0;python_version<'3.10'",
"importlib-resources~=5.0;python_version<'3.9'",
"nbclient~=0.5.10",
"nbdime",
"nbdime<5,>=4",
"nbformat",
"jsonschema",
]
Expand Down
31 changes: 18 additions & 13 deletions pytest_notebook/diffing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import copy
import operator
import re
from typing import List, Sequence, Union
from typing import List, Sequence

from nbdime.diff_format import DiffEntry, SequenceDiffBuilder
from nbdime.diffing.config import DiffConfig
from nbdime.diffing.generic import default_differs, default_predicates, diff
from nbdime.diffing.notebooks import diff_attachments, diff_single_outputs
from nbdime.prettyprint import PrettyPrintConfig, pretty_print_diff
Expand All @@ -19,23 +20,24 @@ def diff_sequence_simple(
initial: Sequence,
final: Sequence,
path: str = "",
predicates: Union[None, dict] = None,
differs: Union[None, dict] = None,
config: DiffConfig = None,
) -> dict:
"""Compute diff of two lists with configurable behaviour.
If the lists are of different lengths,
we assume that items have been appended or removed from the end of the initial list.
"""
if config is None:
config = DiffConfig()

if predicates is None:
predicates = default_predicates()
if differs is None:
differs = default_differs()
if config.predicates is None:
config.predicates = default_predicates()
if config.differs is None:
config.differs = default_differs()

subpath = "/".join((path, "*"))
diffit = differs[subpath]
diffit = config.differs[subpath]

di = SequenceDiffBuilder()

Expand All @@ -48,7 +50,7 @@ def diff_sequence_simple(
di.addrange(i, [bval])
continue

cd = diffit(aval, bval, path=subpath, predicates=predicates, differs=differs)
cd = diffit(aval, bval, path=subpath, config=config)
if cd:
di.patch(i, cd)

Expand All @@ -75,10 +77,7 @@ def diff_notebooks(
we shouldn't need to worry about insertions.
"""
return diff(
initial,
final,
path=initial_path,
config = DiffConfig(
predicates=defaultdict2(lambda: [operator.__eq__], {}),
differs=defaultdict2(
lambda: diff,
Expand All @@ -91,6 +90,12 @@ def diff_notebooks(
},
),
)
return diff(
initial,
final,
path=initial_path,
config=config,
)


R_IS_INT = re.compile(r"^[-+]?\d+$")
Expand Down

0 comments on commit ad66b31

Please sign in to comment.