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

Use nbdiff in JupyterLab extension #534

Open
ashleyswang opened this issue Aug 5, 2020 · 4 comments
Open

Use nbdiff in JupyterLab extension #534

ashleyswang opened this issue Aug 5, 2020 · 4 comments

Comments

@ashleyswang
Copy link

I am trying to use nbdiff as a part of another extension I am writing for JupyterLab, but I can't find enough documentation to figure out how to do so. Is this possible to do with nbdime?

To be clear I would like to be able to do something like this in a src file for the extension:

import * as nbdime from 'nbdime';

const base = '1';
const local='2';
const remote='3';

nbdime.merge(base, local, remote);

Any help would be greatly appreciated!

@vidartf
Copy link
Collaborator

vidartf commented Aug 5, 2020

Note that the actual diff processing of nbdime is running on the server. You can send it the files for processing using the (unfortunately undocumented) REST APIs: https://github.com/jupyter/nbdime/blob/master/nbdime/webapp/nb_server_extension.py

Ideally the nbdime labextension would be something you could require and call into, but for now that hasn't been built out yet. If you are willing to help with that I'm sure it is something we could do.

@vidartf
Copy link
Collaborator

vidartf commented Aug 5, 2020

Also: How would you want to consume the diff? Do you want a rendered diff view, or do you want the diff as expressed by the JSON diff format?

@ashleyswang
Copy link
Author

I noticed on the REST API in the documentation have included a call to api/merge. After reading the actual file that you linked, it seems as though the request API and handler exist but are not actually added to the server extension. Do you have plans to add this later on? Or am I just reading it incorrectly?

For some context: my extension essentially pulls changes from a remote git repository, merges the version in JupyterLab (that the user is working on) and the pulled version comparing it to a base version. If the files can merge without conflicts, the code editor should automatically be updated with the merged version of the file. If not, the diff viewer should pop up.

I'm not quite sure what the best way to do this is, as this is my first JupyterLab extension. It seems that maybe requiring the nbdime labextension would be easier, but I'm not quite sure how to do that (if you have any pointers that would be great).

Thank you!

@ianhi
Copy link

ianhi commented Aug 11, 2020

@ashleyswang the jupyterlab-git extension uses nbdime to display diffs so that may be helpful starting place, although it does not do exactly what you described. The Diff code lives here: https://github.com/jupyterlab/jupyterlab-git/tree/master/src/components/diff. jlab-git uses Git in a subprocess to generate the actual diff and then feeds that to the nbdime web frontend. Maybe you could do something similar to the jlab-git rest api that just results in a call to nbdime-merge.

Also, if you're interested, contributing something like what you described to jupyterlab-git would be awesome. There's an open issue on exactly this jupyterlab/jupyterlab-git#301 as well as one for the ability to merge branches: jupyterlab/jupyterlab-git#310

p.s. jupyterlab-git was the first extension I contributed to, and I found that doing so helped me learn a lot about how to make labextensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants