Skip to content

Commit

Permalink
Tweak id pretty print
Browse files Browse the repository at this point in the history
Only show it if `details` flag is set, and display it like any other field.
  • Loading branch information
vidartf committed May 10, 2023
1 parent 663cc6c commit d8f5300
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions nbdime/prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,15 +647,19 @@ def c():
# Write cell type and optionally number:
numstr = "" if i is None else " %d" % i
k = "%s cell%s" % (cell.get("cell_type"), numstr)
if "id" in cell:
k += f" [{cell['id']}]"
pretty_print_key(k, prefix, config)
c.called = True
c.called = False

if force_header:
c()

id = cell.get("id")
if id and config.details:
# Write execution count if there (only source cells)
c()
pretty_print_item("id", id, key_prefix, config)

execution_count = cell.get("execution_count")
if execution_count and config.details:
# Write execution count if there (only source cells)
Expand Down
3 changes: 2 additions & 1 deletion nbdime/tests/filters/add_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def _build_arg_parser():
def clean(notebook):
if get_marker_cell(notebook) is None:
notebook['cells'].append(nbformat.v4.new_raw_cell(
source=MARKER
source=MARKER,
id='filtered-cell',
))

def smudge(notebook):
Expand Down
1 change: 1 addition & 0 deletions nbdime/tests/test_git_diffdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
## inserted before /cells/6:
+ raw cell:
+ id: filtered-cell
+ source:
+ nbdime test filter marker
Expand Down
2 changes: 2 additions & 0 deletions nbdime/tests/test_prettyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def test_pretty_print_markdown_cell():
def test_pretty_print_code_cell():
cell = v4.new_code_cell(source='def foo():\n return 4',
execution_count=3,
id='code-cell-id',
outputs=[
v4.new_output('stream', name='stdout', text='some\ntext'),
v4.new_output('display_data', {'text/plain': 'hello display'}),
Expand All @@ -213,6 +214,7 @@ def test_pretty_print_code_cell():

assert lines == [
'+code cell:',
'+ id: code-cell-id',
'+ execution_count: 3',
'+ source:',
'+ def foo():',
Expand Down

0 comments on commit d8f5300

Please sign in to comment.