nbdime icon indicating copy to clipboard operation
nbdime copied to clipboard

Export nbdiff-web HTML from command line

Open david-macleod opened this issue 6 years ago • 10 comments

Is it possible to export the HTML difference generated by the in-notebook "Export" button directly from the command line (without having to manually interact with the application GUI). If not, would this be difficult to implement as a feature?

The use case is:

  1. A large number of notebooks containing plots need to be re-run after a change to the underlying source code is made, and diffs calculated
  2. The notebooks which have changed are then inspected visually

If we have a static HTML view of the difference we can automate the process of filtering the notebooks which have not changes. Additionally, having a fixed copy of the HTML difference for future reference is useful it itself.

Thank you

david-macleod avatar Apr 11 '19 10:04 david-macleod

This would also make the diff more usable in various CI scenarios

james-nesbitt avatar Apr 29 '19 19:04 james-nesbitt

Sorry, I could swear I wrote an answer to this. It must have gotten lost somewhere..

The current export button was added as a minimal implementation to get this functionality. What you are asking is not currently possible, but should be possible to build. However, it would require one of these two dependencies:

  • Either a headless browser to run the JS for generating the HTML DOM from the diff.
  • Or node.js with jsdom package for the same purpose.

Another alternative is to save the diff as a self-contained, dynamic HTML page, i.e.

  • The HTML template rendered out, with the diff in JSON format in the page.
  • The nbdime JS to convert the diff to DOM (either embedded in the doc, or as a side-by-side .js file).

The final alternative is to rewrite the diff to DOM logic in Python. This is not something that I will do at least, but I'd welcome any PRs, given they come with a commitment to help maintain the code.

I'm good with either of the first two alternatives. Given enough time, I guess both could be implemented, with a flag to choose between them.

Thoughts on the alternatives? (CC @minrk)

vidartf avatar Apr 30 '19 22:04 vidartf

The second option is probably the simplest to implement and maintain, if not the nicest in principle. Given our current circumstances, I'd probably go with that.

minrk avatar May 13 '19 14:05 minrk

@vidartf or @minrk , any update on this issue? My team would greatly benefit from this added functionality.

Synergist avatar May 12 '20 17:05 Synergist

@Synergist I'm not in a position where I can spend the time on this myself in the near future, but I would be happy to help anyone who would be willing to take this on!

vidartf avatar May 13 '20 12:05 vidartf

This would be hugely useful for me as well, unfortunately I am not familiar enough with Python or Jupyter projects to help.

My use case is to run this tool in a CI pipeline as well. It's very difficult to use currently as it requires us to spin up a lot of nbdime docker containers to display diffs.

leosunmo avatar Jun 01 '20 21:06 leosunmo

Is there any progress on this? If not I will be interested in contributing to this. If someone is willing to pair/review I would appreciate

trams avatar Nov 18 '20 05:11 trams

I'm willing to help with review, and helping out along the way 👍

vidartf avatar Nov 18 '20 14:11 vidartf

#552 should solve this

@vidartf I would appreciate your code review and your feedback

trams avatar Nov 22 '20 02:11 trams

Hi, I just posted a minimal PR that would let people address this issue without having to fork or patch nbdime's source code (or even change the default template): https://github.com/jupyter/nbdime/pull/744 In my PR description, I included a link to a gist showing an example of how this can be done with the PR.

cjerdonek avatar Jan 25 '24 19:01 cjerdonek