def test_ignore_config_simple(entrypoint_ignore_config, tmpdir): tmpdir.join('nbdime_config.json').write_text( text_type(json.dumps({ 'IgnorableConfig1': { 'Ignore': { '/cells/*/metadata': ['collapsed', 'autoscroll'] } }, })), encoding='utf-8' ) def mock_ignore_keys(inner, keys): return (inner, keys) parser = ConfigBackedParser('test-prog') old_keys = nbdime.diffing.notebooks.diff_ignore_keys nbdime.diffing.notebooks.diff_ignore_keys = mock_ignore_keys try: with tmpdir.as_cwd(): parser.parse_args([]) except: nbdime.diffing.notebooks.reset_notebook_differ() raise finally: nbdime.diffing.notebooks.diff_ignore_keys = old_keys try: assert notebook_differs['/cells/*/metadata'] == (diff, ['collapsed', 'autoscroll']) finally: nbdime.diffing.notebooks.reset_notebook_differ()
def test_ignore_config_simple(entrypoint_ignore_config, tmpdir): tmpdir.join('nbdime_config.json').write_text(text_type( json.dumps({ 'IgnorableConfig1': { 'Ignore': { '/cells/*/metadata': ['collapsed', 'autoscroll'] } }, })), encoding='utf-8') def mock_ignore_keys(inner, keys): return (inner, keys) parser = ConfigBackedParser('test-prog') old_keys = nbdime.diffing.notebooks.diff_ignore_keys nbdime.diffing.notebooks.diff_ignore_keys = mock_ignore_keys try: with tmpdir.as_cwd(): parser.parse_args([]) except: nbdime.diffing.notebooks.reset_notebook_differ() raise finally: nbdime.diffing.notebooks.diff_ignore_keys = old_keys try: assert notebook_differs['/cells/*/metadata'] == (diff, [ 'collapsed', 'autoscroll' ]) finally: nbdime.diffing.notebooks.reset_notebook_differ()
def test_ignore_config_merge(entrypoint_ignore_config, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text(json.dumps({ 'IgnorableConfig1': { 'Ignore': { '/cells/*/metadata': ['collapsed', 'autoscroll'] } }, 'IgnorableConfig2': { 'Ignore': { '/metadata': ['foo'], '/cells/*/metadata': ['tags'] } }, }), encoding='utf-8') def mock_ignore_keys(inner, keys): return (inner, keys) parser = ConfigBackedParser('test-prog') old_keys = nbdime.diffing.notebooks.diff_ignore_keys nbdime.diffing.notebooks.diff_ignore_keys = mock_ignore_keys try: with tmpdir.as_cwd(): parser.parse_args([]) finally: nbdime.diffing.notebooks.diff_ignore_keys = old_keys assert notebook_differs['/metadata'] == (diff, ['foo']) # Lists are not merged: assert notebook_differs['/cells/*/metadata'] == (diff, ['tags'])
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser('hg-nbdiff', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_diff_args(parser) add_diff_cli_args(parser) add_filename_args(parser, ('base', 'remote')) opts = parser.parse_args(args) # TODO: Filter base/remote: If directories, find all modified notebooks # If files that are not notebooks, ensure a decent error is printed. if not os.path.isfile(opts.base) or not os.path.isfile(opts.remote): base, remote = opts.base, opts.remote for a, b in diff_directories(base, remote): opts.base, opts.remote = a, b ret = nbdiffapp.main_diff(opts) if ret != 0: return ret return ret else: return nbdiffapp.main_diff(opts)
def test_config_parser(entrypoint_config): parser = ConfigBackedParser('test-prog') parser.add_argument( '--log-level', default='INFO', choices=('DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'), help="Set the log level by name.", action=LogLevelAction, ) # Check that log level default is taken from FixtureConfig arguments = parser.parse_args([]) assert arguments.log_level == 'WARN' arguments = parser.parse_args(['--log-level', 'ERROR']) assert arguments.log_level == 'ERROR'
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser('git-nbmergetool', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) subparsers = parser.add_subparsers(dest='subcommand') merge_parser = subparsers.add_parser('merge', description="The actual entrypoint for the mergetool. Git will call this." ) nbmergetool.build_arg_parser(merge_parser) config = add_git_config_subcommand(subparsers, enable, disable, subparser_help="Configure git to use nbdime via `git mergetool`", enable_help="enable nbdime mergetool via git config", disable_help="disable nbdime mergetool via git config") config.add_argument('--set-default', action='store_true', dest='set_default', help="set nbdime as default mergetool" ) opts = parser.parse_args(args) if opts.subcommand == 'merge': return nbmergetool.main_parsed(opts) elif opts.subcommand == 'config': opts.config_func(opts.scope, opts.set_default) return 0 else: parser.print_help() return 1
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser( 'hg-nbdiff', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_diff_args(parser) add_diff_cli_args(parser) add_prettyprint_args(parser) add_filename_args(parser, ('base', 'remote')) opts = parser.parse_args(args) # TODO: Filter base/remote: If directories, find all modified notebooks # If files that are not notebooks, ensure a decent error is printed. if not os.path.isfile(opts.base) or not os.path.isfile(opts.remote): base, remote = opts.base, opts.remote for a, b in diff_directories(base, remote): opts.base, opts.remote = a, b ret = nbdiffapp.main_diff(opts) if ret != 0: return ret return ret else: return nbdiffapp.main_diff(opts)
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser('hg-nbmergeweb', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) nbmergetool.build_arg_parser(parser) opts = parser.parse_args(args) return nbmergetool.main_parsed(opts)
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser( "git-pjmergedriver", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) subparsers = parser.add_subparsers(dest="subcommand") merge_parser = subparsers.add_parser( "merge", description= "The actual entrypoint for the merge tool. Git will call this.", ) add_generic_args(parser) add_diff_args(merge_parser) add_merge_args(merge_parser) # Argument list, we are given base, local, remote add_filename_args(merge_parser, ["base", "local", "remote"]) # TODO: support git-config-specified conflict markers inside sources merge_parser.add_argument("marker") merge_parser.add_argument("out", nargs="?") # "The merge driver can learn the pathname in which the merged result will # be stored via placeholder %P" # - NOTE: This is not where the driver should store its output, see below! add_git_config_subcommand( subparsers, enable, disable, subparser_help= "Configure git to use packson for notebooks in `git merge`", enable_help="enable packson merge driver via git config", disable_help="disable packson merge driver via git config", ) opts = parser.parse_args(args) if opts.subcommand == "merge": # "The merge driver is expected to leave the result of the merge in the # file named with %A by overwriting it, and exit with zero status if it # managed to merge them cleanly, or non-zero if there were conflicts." opts.out = opts.local # mergeapp expects an additional decisions arg: opts.decisions = False return main_merge(opts) elif opts.subcommand == "config": opts.config_func(opts.scope) return 0 else: parser.print_help() return 1
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser( 'hg-nbmergeweb', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) nbmergetool.build_arg_parser(parser) opts = parser.parse_args(args) return nbmergetool.main_parsed(opts)
def test_config_inherit(entrypoint_ignore_config, tmpdir, reset_notebook_diff): tmpdir.join('nbdime_config.json').write_text(json.dumps({ 'IgnorableConfig1': { 'metadata': False }, }), encoding='utf-8') parser = ConfigBackedParser('test-prog') with tmpdir.as_cwd(): parsed = parser.parse_args([]) assert parsed.metadata is False
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser('git-nbmergedriver', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) subparsers = parser.add_subparsers(dest='subcommand') merge_parser = subparsers.add_parser('merge', description="The actual entrypoint for the merge tool. Git will call this." ) add_generic_args(parser) add_diff_args(merge_parser) add_merge_args(merge_parser) # Argument list, we are given base, local, remote add_filename_args(merge_parser, ["base", "local", "remote"]) # TODO: support git-config-specified conflict markers inside sources merge_parser.add_argument('marker') merge_parser.add_argument('out', nargs='?') # "The merge driver can learn the pathname in which the merged result will # be stored via placeholder %P" # - NOTE: This is not where the driver should store its output, see below! add_git_config_subcommand( subparsers, enable, disable, subparser_help="Configure git to use nbdime for notebooks in `git merge`", enable_help="enable nbdime merge driver via git config", disable_help="disable nbdime merge driver via git config") opts = parser.parse_args(args) if opts.subcommand == 'merge': # "The merge driver is expected to leave the result of the merge in the # file named with %A by overwriting it, and exit with zero status if it # managed to merge them cleanly, or non-zero if there were conflicts." opts.out = opts.local # mergeapp expects an additional decisions arg: opts.decisions = False return nbmergeapp.main_merge(opts) elif opts.subcommand == 'config': opts.config_func(opts.scope) return 0 else: parser.print_help() return 1
def test_config_inherit(entrypoint_ignore_config, tmpdir): tmpdir.join('nbdime_config.json').write_text(text_type( json.dumps({ 'IgnorableConfig1': { 'metadata': False }, })), encoding='utf-8') parser = ConfigBackedParser('test-prog') with tmpdir.as_cwd(): parsed = parser.parse_args([]) try: assert parsed.metadata == False finally: nbdime.diffing.notebooks.reset_notebook_differ()
def test_config_inherit(entrypoint_ignore_config, tmpdir): tmpdir.join('nbdime_config.json').write_text( text_type(json.dumps({ 'IgnorableConfig1': { 'metadata': False }, })), encoding='utf-8' ) parser = ConfigBackedParser('test-prog') with tmpdir.as_cwd(): parsed = parser.parse_args([]) try: assert parsed.metadata == False finally: nbdime.diffing.notebooks.reset_notebook_differ()
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser( 'git-nbdifftool', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) subparsers = parser.add_subparsers(dest='subcommand') diff_parser = subparsers.add_parser( 'diff', description= "The actual entrypoint for the diff tool. Git will call this.") add_filter_args(diff_parser) nbdifftool.build_arg_parser(diff_parser) diff_parser.add_argument('path', type=Path) config = add_git_config_subcommand( subparsers, enable, disable, subparser_help="Configure git to use nbdime via `git difftool`", enable_help="enable nbdime difftool via git config", disable_help="disable nbdime difftool via git config") config.add_argument('--set-default', action='store_true', dest='set_default', help="set nbdime as default gui difftool") opts = parser.parse_args(args) if opts.subcommand == 'diff': remote = opts.remote if opts.use_filter and remote: remote = apply_possible_filter(opts.path, remote) return show_diff(opts.local, remote, opts) elif opts.subcommand == 'config': opts.config_func(opts.scope, opts.set_default) return 0 else: parser.print_help() return 1
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser('hg-nbmerge', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) add_diff_args(parser) add_merge_args(parser) # Argument list, we are given base, local, remote add_filename_args(parser, ["base", "local", "remote", "merged"]) opts = parser.parse_args(args) # mergeapp expects an additional decisions arg: opts.decisions = False opts.out = opts.merged del opts.merged return nbmergeapp.main_merge(opts)
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser('hg-nbdiffweb', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) nbdifftool.build_arg_parser(parser) opts = parser.parse_args(args) # TODO: If a/b are files that are not notebooks, ensure a decent error is printed. if not os.path.isfile(opts.local) or not os.path.isfile(opts.remote): local, remote = opts.local, opts.remote for a, b in diff_directories(local, remote): opts.local, opts.remote = a, b ret = nbdifftool.main_parsed(opts) if ret != 0: return ret return ret else: return nbdifftool.main_parsed(opts)
def main(args=None): if args is None: args = sys.argv[1:] parser = ConfigBackedParser( 'hg-nbmerge', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) add_diff_args(parser) add_merge_args(parser) # Argument list, we are given base, local, remote add_filename_args(parser, ["base", "local", "remote", "merged"]) opts = parser.parse_args(args) # mergeapp expects an additional decisions arg: opts.decisions = False opts.out = opts.merged del opts.merged return nbmergeapp.main_merge(opts)
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser( 'git-nbmergetool', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) subparsers = parser.add_subparsers(dest='subcommand') merge_parser = subparsers.add_parser( 'merge', description= "The actual entrypoint for the mergetool. Git will call this.") nbmergetool.build_arg_parser(merge_parser) config = add_git_config_subcommand( subparsers, enable, disable, subparser_help="Configure git to use nbdime via `git mergetool`", enable_help="enable nbdime mergetool via git config", disable_help="disable nbdime mergetool via git config") config.add_argument('--set-default', action='store_true', dest='set_default', help="set nbdime as default mergetool") opts = parser.parse_args(args) if opts.subcommand == 'merge': return nbmergetool.main_parsed(opts) elif opts.subcommand == 'config': opts.config_func(opts.scope, opts.set_default) return 0 else: parser.print_help() return 1
def main(args=None): if args is None: args = sys.argv[1:] import argparse parser = ConfigBackedParser('git-nbdifftool', description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter, ) add_generic_args(parser) subparsers = parser.add_subparsers(dest='subcommand') diff_parser = subparsers.add_parser('diff', description="The actual entrypoint for the diff tool. Git will call this." ) add_filter_args(diff_parser) nbdifftool.build_arg_parser(diff_parser) diff_parser.add_argument('path') config = add_git_config_subcommand(subparsers, enable, disable, subparser_help="Configure git to use nbdime via `git difftool`", enable_help="enable nbdime difftool via git config", disable_help="disable nbdime difftool via git config") config.add_argument('--set-default', action='store_true', dest='set_default', help="set nbdime as default gui difftool" ) opts = parser.parse_args(args) if opts.subcommand == 'diff': remote = opts.remote if opts.use_filter and remote: remote = apply_possible_filter(opts.path, remote) return show_diff(opts.local, remote, opts) elif opts.subcommand == 'config': opts.config_func(opts.scope, opts.set_default) return 0 else: parser.print_help() return 1