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

Ignoring diffs does not work #774

Closed
physkets opened this issue Oct 7, 2024 · 4 comments
Closed

Ignoring diffs does not work #774

physkets opened this issue Oct 7, 2024 · 4 comments

Comments

@physkets
Copy link

physkets commented Oct 7, 2024

The following is the config I am trying to use in order for nbdime to ignore certain metadata as well as outputs for the purpose of displaying diffs under git diff and to prevent any data in there from being committed.

$ cat ~/.jupyter/nbdime_config.json
{
  "Diff": {
    "ignore": [
      "/metadata/papermill",
      "/cells/*/metadata/papermill",
      "/cells/*/metadata/execution",
      "/cells/*/execution_count",
      "/cells/*/outputs"
    ]
  },
  "Merge": {
    "ignore": [
      "/metadata/papermill",
      "/cells/*/metadata/papermill",
      "/cells/*/metadata/execution",
      "/cells/*/execution_count",
      "/cells/*/outputs"
    ]
  }
}

When I verify it, I see:

$ nbdime --config
All available config options, and their current values:

NbDiff:
  Ignore: {}
  attachments: <unset, resolves to true>
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

NbDiffWeb:
  Ignore: {}
  attachments: <unset, resolves to true>
  base_url: "/"
  browser: null
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ip: "127.0.0.1"
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  persist: false
  port: 0
  sources: <unset, resolves to true>
  workdirectory: "/home/user/Programs/Gels"

NbMerge:
  Ignore: {}
  attachments: <unset, resolves to true>
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ignore_transients: true
  input_strategy: null
  merge_strategy: "inline"
  metadata: <unset, resolves to true>
  output_strategy: null
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

NbMergeWeb:
  Ignore: {}
  attachments: <unset, resolves to true>
  base_url: "/"
  browser: null
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ignore_transients: true
  input_strategy: null
  ip: "127.0.0.1"
  merge_strategy: "inline"
  metadata: <unset, resolves to true>
  output_strategy: null
  outputs: <unset, resolves to true>
  persist: false
  port: 0
  show_base: true
  sources: <unset, resolves to true>
  workdirectory: "/home/user/Programs/Gels"

NbShow:
  Ignore: {}
  attachments: <unset, resolves to true>
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

Server:
  base_url: "/"
  browser: null
  ip: "127.0.0.1"
  persist: false
  port: 8888
  workdirectory: "/home/user/Programs/Gels"

Extension:
  Ignore: {}
  attachments: <unset, resolves to true>
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

NbDiffDriver:
  Ignore: {}
  attachments: <unset, resolves to true>
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

NbDiffTool:
  Ignore: {}
  attachments: <unset, resolves to true>
  base_url: "/"
  browser: null
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ip: "127.0.0.1"
  metadata: <unset, resolves to true>
  outputs: <unset, resolves to true>
  persist: false
  port: 0
  sources: <unset, resolves to true>
  workdirectory: "/home/user/Programs/Gels"

NbMergeDriver:
  Ignore: {}
  attachments: <unset, resolves to true>
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ignore_transients: true
  input_strategy: null
  merge_strategy: "inline"
  metadata: <unset, resolves to true>
  output_strategy: null
  outputs: <unset, resolves to true>
  sources: <unset, resolves to true>

NbMergeTool:
  Ignore: {}
  attachments: <unset, resolves to true>
  base_url: "/"
  browser: null
  color_words: false
  details: <unset, resolves to true>
  id: <unset, resolves to true>
  ignore: ["/metadata/papermill", "/cells/*/metadata/papermill", "/cells/*/metadata/execution", "/cells/*/execution_count", "/cells/*/outputs"]
  ignore_transients: true
  input_strategy: null
  ip: "127.0.0.1"
  merge_strategy: "inline"
  metadata: <unset, resolves to true>
  output_strategy: null
  outputs: <unset, resolves to true>
  persist: false
  port: 0
  sources: <unset, resolves to true>
  workdirectory: "/home/user/Programs/Gels"

which tells me that the configuration was successfully applied.

However, when I look at a git diff, I still see all the metadata begin diffed.

When I use nbdime directly for the diff, with the config file specified, I get the following error:

$ nbdime diff --config /home/user/.jupyter/nbdime_config.json path/to/notebook.ipynb
Traceback (most recent call last):
  File "/usr/bin/nbdime", line 8, in <module>
    sys.exit(main_dispatch())
             ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nbdime/__main__.py", line 135, in main_dispatch
    return main(args)
           ^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nbdime/nbdiffapp.py", line 129, in main
    arguments = _build_arg_parser().parse_args(args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 1896, in parse_args
    args, argv = self.parse_known_args(args, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nbdime/args.py", line 35, in parse_known_args
    return super(ConfigBackedParser, self).parse_known_args(args=args, namespace=namespace)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 1932, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 2153, in _parse_known_args
    start_index = consume_optional(start_index)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 2093, in consume_optional
    take_action(action, args, option_string)
  File "/usr/lib/python3.12/argparse.py", line 2008, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/lib/python3.12/site-packages/nbdime/args.py", line 117, in __call__
    header = entrypoint_configurables[parser.prog].__name__
             ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'nbdime'

Is this a bug with nbdime or am I doing something wrong?

@vidartf
Copy link
Collaborator

vidartf commented Oct 9, 2024

Does the behavior change if you change it from ignore to Ignore? I see both entries in the printed config, so I wonder if it is case sensitive?

@physkets
Copy link
Author

That fixes it! Oh boy, that was a very silly mistake on my part. Thanks a lot!

@physkets
Copy link
Author

Actually, that causes a new problem. The extension crashes with the following error message:

Traceback (most recent call last):
  File "/usr/bin/git-nbdiffdriver", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/lib/python3.12/site-packages/nbdime/vcs/git/diffdriver.py", line 115, in main
    opts = parser.parse_args(args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/argparse.py", line 1896, in parse_args
    args, argv = self.parse_known_args(args, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/nbdime/args.py", line 32, in parse_known_args
    set_notebook_diff_ignores(ignore)
  File "/usr/lib/python3.12/site-packages/nbdime/diffing/notebooks.py", line 578, in set_notebook_diff_ignores
    for path, subkeys in ignore_paths.items():
                         ^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'items'
fatal: external diff died, stopping at path/to/notebook.ipynb

My current config file is:

{
  "Diff": {
    "Ignore": [
      "/metadata/papermill",
      "/cells/*/metadata/papermill",
      "/cells/*/metadata/execution",
      "/cells/*/execution_count",
      "/cells/*/outputs"
    ]
  },
  "Merge": {
    "Ignore": [
      "/metadata/papermill",
      "/cells/*/metadata/papermill",
      "/cells/*/metadata/execution",
      "/cells/*/execution_count",
      "/cells/*/outputs"
    ]
  }
}

Any idea what might be wrong with it?

@physkets physkets reopened this Oct 11, 2024
@physkets
Copy link
Author

Again, my bad .. looks like the config expects the Ignore to be a dict:

https://nbdime.readthedocs.io/en/latest/config.html

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

2 participants