Skip to content

⬆️ Support nbdime v4 (drop <4 support) #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,19 @@ ENV/
env.bak/
venv.bak/

# PyCharm project settings
.idea

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# VSCode project settings
.vscode

# mkdocs documentation
/site

Expand All @@ -125,4 +131,3 @@ dmypy.json
.DS_Store
_archive/
docs/source/apidoc/
.vscode/
2 changes: 2 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"_pytest": ("https://doc.pytest.org/en/latest/", None),
# "PIL": ("http://pillow.readthedocs.org/en/latest/", None),
"nbclient": ("https://nbclient.readthedocs.io/en/latest/", None),
"nbdime": ("https://nbdime.readthedocs.io/en/latest/", None),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but now you should be able to remove the nbdime items in nitpick_ignore 😅

Copy link
Contributor Author

@amotl amotl Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I just tried, but it doesn't work: Same error from Sphinx as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tried adding ("py:class", "DiffConfig"): ("py:class", "nbdime.diffing.config.DiffConfig") to intersphinx_aliases, but it does not make any difference either.

"nbformat": ("https://nbformat.readthedocs.io/en/latest/", None),
"attr": ("https://www.attrs.org/en/stable/", None),
"coverage": ("https://coverage.readthedocs.io/en/6.2/", None),
Expand All @@ -60,6 +61,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>=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