-
Notifications
You must be signed in to change notification settings - Fork 160
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
add --compatible diff flag to output a diff more compatible with other tools #647
base: master
Are you sure you want to change the base?
Conversation
@vidartf did you get a chance to look at this? thanks! |
I don't really understand what this change is doing. If its trying to output the diff as a proper unified diff, we would need to map the json diffs back to line/character numbers in the original file. There is no trivial way to make this happen. So I assume this change is trying to make some compromise/middle-ground, but not sure exactly what. Please add more details to the PR / command's help key. |
@vidartf sorry for the lack of details, I will try to explain the problem and if you are OK with the solution, I'll also update the CLI help. The problem is described in dandavison/delta#1256 which is an issue I opened because https://github.com/dandavison/delta (syntax highlighting for diffs) didn't work with nbdiff. You can look at the issue for the full details, where the original creator of unified diff also commented there). The TLDR is:
|
Thanks for clarifying! Having an output that is more compatible with unified diff does indeed sound useful 👍 Retaining the current default, and putting the new behavior behind a flag sounds good. Since your main motivation here is to have it be parsed by other tools, I think it can be hard to change this output format after initial release. With that in mind, I would suggest the following:
|
Thanks @vidartf for the quick and helpful response. You suggestions sound good. As for tests, I assume they should go into https://github.com/jupyter/nbdime/tree/master/nbdime/tests is that right? |
Yes, I would probably make a new file, and then you could start with something like this: def test_notebook_diff(any_nb_pair):
"Test unified diff output on any pair of notebooks in the test suite."
a, b = any_nb_pair
diff = diff_notebooks(a, b)
output = []
class Printer:
def write(self, text):
output.append(text)
argv = [] # your arguments for diff CLI here
arguments = _build_arg_parser().parse_args(argv)
config = prettyprint_config_from_args(args, out=Printer())
pretty_print_notebook_diff(a.name, b.name, a, diff, config)
assert "".join(output) == expected_output |
For context: dandavison/delta#1256