bookstore icon indicating copy to clipboard operation
bookstore copied to clipboard

Add ability to render diffs between published versions

Open MSeal opened this issue 6 years ago • 6 comments

Using the python dict diff from nbdimes we'd like to have a component based UI to render the diff between two notebook versions. There could be more use cases past this, but as a most basic step this would add a lot of utility.

https://github.com/jupyter/nbdime/blob/master/nbdime/diffing/notebooks.py#L605-L612

MSeal avatar Feb 06 '19 18:02 MSeal

format schema is found at https://github.com/jupyter/nbdime/blob/master/nbdime/diff_format.schema.json

In [9]: orig = nbformat.read("binder/process_highlight_dates.ipynb", as_version=4)                                                                                                                 

In [10]: new = nbformat.read("binder/process_highlight_dates_new.ipynb", as_version=4)                                                                                                             

In [11]: diff_notebooks(orig, new)                                                                                                                                                                 
Out[11]: 
[{'op': 'patch',
  'key': 'cells',
  'diff': [{'op': 'patch',
    'key': 3,
    'diff': [{'op': 'replace', 'key': 'execution_count', 'value': 1},
     {'op': 'patch',
      'key': 'outputs',
      'diff': [{'op': 'addrange',
        'key': 0,
        'valuelist': [{'name': 'stderr',
          'output_type': 'stream',
          'text': 'Input Notebook:  highlight_dates.ipynb\nOutput Notebook: ./highlight_dates_run_cli.ipynb\n'}]}]},
     {'op': 'patch',
      'key': 'source',
      'diff': [{'op': 'patch',
        'key': 1,
        'diff': [{'op': 'addrange',
          'key': 65,
          'valuelist': '-prepare-only -'}]}]}]}]},
 {'op': 'patch',
  'key': 'metadata',
  'diff': [{'op': 'patch',
    'key': 'language_info',
    'diff': [{'op': 'patch',
      'key': 'version',
      'diff': [{'op': 'patch',
        'key': 0,
        'diff': [{'op': 'addrange', 'key': 4, 'valuelist': '3'},
         {'op': 'removerange', 'key': 4, 'length': 1}]}]}]}]}]

MSeal avatar Feb 06 '19 19:02 MSeal

Idea: Sub component for each type of op. During rendering, iterate through the response and render each sub-component

jaipreet-s avatar Feb 06 '19 22:02 jaipreet-s

This makes me wonder if we could support this through an endpoint to compare between versions from two notebooks on S3, with exactly the code you provided.

rgbkrk avatar Feb 06 '19 23:02 rgbkrk

Is anyone looking in to this? I have been trying to produce automatic diffs for CI pipelines using nbdime, but it's built as a one-off cli tool, not a persistent web server that can take two notebooks and render the diff. Any progress in this area would be fantastic!

leosunmo avatar Aug 26 '20 10:08 leosunmo

There's not anyone taking on improving the diffing story in the open source atm that I'm aware of. https://github.com/jupyter/nbdime/issues/468 would enable an easy way to generate the diffs for CI tooling purposes. Current maintainers of nteract projects are focused on some other projects atm, so we'd love more contributors to take on these issues but we're not planning on tackling this feature in the near future afaik.

MSeal avatar Aug 27 '20 17:08 MSeal

Thanks for the quick reply @MSeal ! I am aware of the nbdime issue, but not much action there either, and no plans. Oh well! Thanks for your hard work!

leosunmo avatar Aug 27 '20 23:08 leosunmo