Skip to content
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

Add initial cell identifiers awareness #566

Merged
merged 10 commits into from
Apr 12, 2021
6 changes: 5 additions & 1 deletion nbdime/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ def add_diff_args(parser):
'-m', '--metadata',
action=IgnorableAction,
help="process/ignore metadata.")
ignorables.add_argument(
'-i', '--id',
action=IgnorableAction,
help="process/ignore identifiers.")
ignorables.add_argument(
'-d', '--details',
action=IgnorableAction,
Expand Down Expand Up @@ -392,7 +396,7 @@ def process_diff_flags(args):
# Note: This will blow away any options set via config (for these fields)
set_notebook_diff_targets(
args.sources, args.outputs, args.attachments, args.metadata,
args.details)
args.id, args.details)


def resolve_diff_args(args):
Expand Down
6 changes: 6 additions & 0 deletions nbdime/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ class _Ignorables(NbdimeConfigurable):
help="process/ignore metadata.",
).tag(config=True)

id = Bool(
None,
allow_none=True,
help="process/ignore identifiers.",
).tag(config=True)

attachments = Bool(
None,
allow_none=True,
Expand Down
3 changes: 2 additions & 1 deletion nbdime/diffing/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,15 @@ def set_notebook_diff_ignores(ignore_paths):


def set_notebook_diff_targets(sources=True, outputs=True, attachments=True,
metadata=True, details=True):
metadata=True, identifier=True, details=True):
"""Configure the notebook differs to include/ignore various changes."""

config = {
'/cells/*/source': not sources,
'/cells/*/outputs': not outputs,
'/cells/*/attachments': not attachments,
'/metadata': not metadata,
'/cells/*/id': not identifier,
'/cells/*/metadata': not metadata,
'/cells/*/outputs/*/metadata': not metadata,
'/cells/*': False if details else ('execution_count',),
Expand Down
2 changes: 1 addition & 1 deletion nbdime/ignorables.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

from __future__ import unicode_literals

diff_ignorables = ('sources', 'outputs', 'attachments', 'metadata', 'details')
diff_ignorables = ('sources', 'outputs', 'attachments', 'metadata', 'id', 'details')
2 changes: 1 addition & 1 deletion nbdime/merging/decisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def apply_decisions(base, decisions):
else:
if md.action == "clear_all":
clear_all_flag = True
# Clear any exisiting decisions!
# Clear any existing decisions!
diffs = []
ad = resolve_action(resolved, md)
if line:
Expand Down
2 changes: 1 addition & 1 deletion nbdime/merging/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .chunks import make_merge_chunks, chunk_typename
from .strategies import (
resolve_strategy_generic,
resolve_conflicted_decisions_dict,
resolve_conflicted_decisions_dict,
resolve_conflicted_decisions_list,
resolve_conflicted_decisions_strings,
resolve_strategy_inline_source,
Expand Down
1 change: 1 addition & 0 deletions nbdime/merging/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

def notebook_merge_strategies(args):
strategies = Strategies({
"/cells/*/id": "remove",
vidartf marked this conversation as resolved.
Show resolved Hide resolved
# These fields should never conflict, that would be an internal error:
"/nbformat": "fail",
"/cells/*/cell_type": "fail",
Expand Down
6 changes: 6 additions & 0 deletions nbdime/merging/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ def resolve_strategy_inline_recurse(path, base, decisions):
"remote_metadata": rcell[k],
}

elif k == 'id':
cell[k] = {
"local_id": lcell[k],
"remote_id": rcell[k],
}

elif k == 'execution_count':
cell[k] = None # Clear

Expand Down
4 changes: 4 additions & 0 deletions nbdime/nbshowapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def _build_arg_parser():
'-m', '--metadata',
action=IgnorableAction,
help="show/ignore metadata.")
ignorables.add_argument(
'-i', '--id',
action=IgnorableAction,
help="show/ignore identifiers.")
ignorables.add_argument(
'-d', '--details',
action=IgnorableAction,
Expand Down
4 changes: 3 additions & 1 deletion nbdime/prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def should_ignore_path(self, path):
return not self.attachments
if starred.startswith('/cells/*/metadata') or starred.startswith('/metadata'):
return not self.metadata
if starred.startswith('/cells/*/id'):
return not self.id
vidartf marked this conversation as resolved.
Show resolved Hide resolved
if starred.startswith('/cells/*/outputs'):
return (
not self.outputs or
Expand Down Expand Up @@ -699,7 +701,7 @@ def c():

exclude_keys = {
'cell_type', 'source', 'execution_count', 'outputs', 'metadata',
'attachment',
'id', 'attachment',
}
if (set(cell) - exclude_keys) and config.details:
# present anything we haven't special-cased yet (future-proofing)
Expand Down
2 changes: 1 addition & 1 deletion nbdime/tests/test_cli_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_nbshow_app(filespath, capsys):
args = nbshowapp._build_arg_parser().parse_args([afn, '--log-level=CRITICAL'])
process_exclusive_ignorables(
args,
('sources', 'outputs', 'attachments', 'metadata', 'details'))
('sources', 'outputs', 'attachments', 'metadata', 'id', 'details'))
assert 0 == main_show(args)
assert args.log_level == 'CRITICAL'
assert nbdime.log.logger.level == logging.CRITICAL
Expand Down
Loading