Pondering generating notebooks from nbdime again (as per
https://github.com/jupyter/nbdime/issues/251 ) I was wondering if there's a simple way of getting numeric cell key values from a notebook?
eg if ai have a setup
fn1="test1.ipynb"
fn2="test2.ipynb"
a = nbformat.read(fn1, as_version=4)
b= nbformat.read(fn2, as_version=4)
I seem to be able to get a list of diffs as: nbdime.diffing.diff_notebooks(a, b)
nbdime.diffing.generic.diff_dicts(a, b)
though I don't really understand the datastructure (eg multiple levels of "diff" inside a "diff" per things like: {'diff': [{'diff': [{'diff': [{'diff': [{'diff': [{'diff': [{'key': 46, }
I assume that the 'key' uniquely identifies a line in the notebook a - if so, is there anything that takes notebook and returns it as a data structure with 'key' elements identified according to the same numbering scheme? Then I could print out the (unchanged) elements from a if the key is not in the diff file, or print the diff element if the key is in the diff file?
eg as a roundabout case in point - I can print notebook a as:
nbdime.prettyprint.pretty_print_notebook(a)
and diff between notebook a and b:
nbdime.prettyprint.pretty_print_notebook_diff(fn1,fn2,a,d)
that gives a display akin to nbdiff-web with "Hide unchanged cells" checked:
But how would I go about doing a pretty print to display the equivalent of nbdiff-web with "Hide unchanged cells" unchecked (i.e. displaying unchanged cells too)?
--tony
PS context is:
What I have in mind exploring is a set of functions equivalent to pretty_print_diff_entry() etc along the lines of nb_create_diff_entry() that add metadata annotated cells to an output notebook rather than as colour coded lines in an output text stream. Cell metadata state would identifying the state of the cell (added, removed, etc). I'd also like a switch to be able to add (optionally) unchanged cells to the output notebook, or just unchanged notebook cells with a particular metadata element set in the original notebook (so eg I could force a cell to always appear in the output diff whether it was changed or not).
My use case is trying to explore the space of instructor marking of student notebooks where students are provided with a template notebook which may contain lots of text. Idea would be to create an diff-notebook that contains just student modified cells and some heading cells from the original notebook. (Thinks: actually, I could do that anyway - add a 'stripme' metadata element to cells in notebook supplied to students then run student returned notebooks through a processor that creates a child notebook without the 'stripme' cells.)
The nbgrader doesn't quite work for my setting (and I'm not sure what workflow would). Something around diffing feels right, but I want to try to keep things as diff-revealing jupyter notebooks rather than a diff revealing text files.
I think I need to walk the dog again to try to clarify my thoughts a bit more!