Skip to content

Commit ca71405

Browse files
authored
⬆️ Support nbdime v4 (drop <4 support) (chrisjsewell#62)
This patch addresses the incompatibility with nbdime version 4. Note this will no longer support v3
1 parent 4136098 commit ca71405

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,19 @@ ENV/
104104
env.bak/
105105
venv.bak/
106106

107+
# PyCharm project settings
108+
.idea
109+
107110
# Spyder project settings
108111
.spyderproject
109112
.spyproject
110113

111114
# Rope project settings
112115
.ropeproject
113116

117+
# VSCode project settings
118+
.vscode
119+
114120
# mkdocs documentation
115121
/site
116122

@@ -125,4 +131,3 @@ dmypy.json
125131
.DS_Store
126132
_archive/
127133
docs/source/apidoc/
128-
.vscode/

docs/source/conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"_pytest": ("https://doc.pytest.org/en/latest/", None),
4242
# "PIL": ("http://pillow.readthedocs.org/en/latest/", None),
4343
"nbclient": ("https://nbclient.readthedocs.io/en/latest/", None),
44+
"nbdime": ("https://nbdime.readthedocs.io/en/latest/", None),
4445
"nbformat": ("https://nbformat.readthedocs.io/en/latest/", None),
4546
"attr": ("https://www.attrs.org/en/stable/", None),
4647
"coverage": ("https://coverage.readthedocs.io/en/6.2/", None),
@@ -60,6 +61,7 @@
6061
("py:class", "Session"),
6162
("py:exc", "nbconvert.preprocessors.CellExecutionError"),
6263
("py:class", "nbdime.diff_format.DiffEntry"),
64+
("py:class", "nbdime.diffing.config.DiffConfig"),
6365
("py:class", "_pytest._py.path.LocalPath"),
6466
("py:meth", "Item.reportinfo"),
6567
]

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = [
3131
"importlib-metadata~=6.0;python_version<'3.10'",
3232
"importlib-resources~=5.0;python_version<'3.9'",
3333
"nbclient~=0.5.10",
34-
"nbdime",
34+
"nbdime>=4",
3535
"nbformat",
3636
"jsonschema",
3737
]

pytest_notebook/diffing.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import copy
33
import operator
44
import re
5-
from typing import List, Sequence, Union
5+
from typing import List, Sequence
66

77
from nbdime.diff_format import DiffEntry, SequenceDiffBuilder
8+
from nbdime.diffing.config import DiffConfig
89
from nbdime.diffing.generic import default_differs, default_predicates, diff
910
from nbdime.diffing.notebooks import diff_attachments, diff_single_outputs
1011
from nbdime.prettyprint import PrettyPrintConfig, pretty_print_diff
@@ -19,23 +20,24 @@ def diff_sequence_simple(
1920
initial: Sequence,
2021
final: Sequence,
2122
path: str = "",
22-
predicates: Union[None, dict] = None,
23-
differs: Union[None, dict] = None,
23+
config: DiffConfig = None,
2424
) -> dict:
2525
"""Compute diff of two lists with configurable behaviour.
2626
2727
If the lists are of different lengths,
2828
we assume that items have been appended or removed from the end of the initial list.
2929
3030
"""
31+
if config is None:
32+
config = DiffConfig()
3133

32-
if predicates is None:
33-
predicates = default_predicates()
34-
if differs is None:
35-
differs = default_differs()
34+
if config.predicates is None:
35+
config.predicates = default_predicates()
36+
if config.differs is None:
37+
config.differs = default_differs()
3638

3739
subpath = "/".join((path, "*"))
38-
diffit = differs[subpath]
40+
diffit = config.differs[subpath]
3941

4042
di = SequenceDiffBuilder()
4143

@@ -48,7 +50,7 @@ def diff_sequence_simple(
4850
di.addrange(i, [bval])
4951
continue
5052

51-
cd = diffit(aval, bval, path=subpath, predicates=predicates, differs=differs)
53+
cd = diffit(aval, bval, path=subpath, config=config)
5254
if cd:
5355
di.patch(i, cd)
5456

@@ -75,10 +77,7 @@ def diff_notebooks(
7577
we shouldn't need to worry about insertions.
7678
7779
"""
78-
return diff(
79-
initial,
80-
final,
81-
path=initial_path,
80+
config = DiffConfig(
8281
predicates=defaultdict2(lambda: [operator.__eq__], {}),
8382
differs=defaultdict2(
8483
lambda: diff,
@@ -91,6 +90,12 @@ def diff_notebooks(
9190
},
9291
),
9392
)
93+
return diff(
94+
initial,
95+
final,
96+
path=initial_path,
97+
config=config,
98+
)
9499

95100

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

0 commit comments

Comments
 (0)