Exemplo n.º 1
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(
        description=_description,
        )
    add_generic_args(parser)
    add_diff_args(parser)
    add_diff_cli_args(parser)

    parser.add_argument(
        "base", help="the base notebook filename OR base git-revision.",
        nargs='?', default='HEAD',
    )
    parser.add_argument(
        "remote", help="the remote modified notebook filename OR remote git-revision.",
        nargs='?', default=None,
    )
    parser.add_argument(
        "paths", help="filter diffs for git-revisions based on path",
        nargs='*', default=None,
    )

    parser.add_argument(
        '--out',
        default=None,
        help="if supplied, the diff is written to this file. "
             "Otherwise it is printed to the terminal.")

    return parser
Exemplo n.º 2
0
def _build_arg_parser():
    import argparse
    parser = ConfigBackedParser('git-nbdiffdriver',
        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_git_diff_driver_args(diff_parser)
    add_diff_args(diff_parser)
    add_diff_cli_args(diff_parser)

    webdiff_parser = subparsers.add_parser('webdiff',
        description="The actual entrypoint for the webdiff tool. Git will call this."
    )
    add_git_diff_driver_args(webdiff_parser)
    add_diff_args(webdiff_parser)
    add_web_args(webdiff_parser, 0)

    # TODO: From git docs: "For a path that is unmerged, GIT_EXTERNAL_DIFF is called with 1 parameter, <path>."
    config = add_git_config_subcommand(subparsers,
        enable, disable,
        subparser_help="Configure git to use nbdime for notebooks in `git diff`",
        enable_help="enable nbdime diff driver via git config",
        disable_help="disable nbdime diff driver via git config")

    return parser
Exemplo n.º 3
0
def _build_arg_parser():
    """Creates an argument parser for the nbshow command."""
    parser = ConfigBackedParser(
        description=_description,
        add_help=True,
        )
    add_generic_args(parser)
    parser.add_argument("notebook", nargs="*", help="notebook filename(s) or - to read from stdin")

    # Things we can choose to show or not
    ignorables = parser.add_argument_group(
        title='ignorables',
        description='Set which parts of the notebook (not) to show.')
    ignorables.add_argument(
        '-s', '--sources',
        action=IgnorableAction,
        help="show/ignore sources.")
    ignorables.add_argument(
        '-o', '--outputs',
        action=IgnorableAction,
        help="show/ignore outputs.")
    ignorables.add_argument(
        '-a', '--attachments',
        action=IgnorableAction,
        help="show/ignore attachments.")
    ignorables.add_argument(
        '-m', '--metadata',
        action=IgnorableAction,
        help="show/ignore metadata.")
    ignorables.add_argument(
        '-d', '--details',
        action=IgnorableAction,
        help="show/ignore details not covered by other options.")

    return parser
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(
        description=_description,
        add_help=True,
        )
    from .args import add_generic_args, add_diff_args, add_merge_args, add_filename_args
    add_generic_args(parser)
    add_diff_args(parser)
    add_merge_args(parser)
    add_filename_args(parser, ["base", "local", "remote"])

    parser.add_argument(
        '--out',
        default=None,
        help="if supplied, the merged notebook is written "
             "to this file. Otherwise it is printed to the "
             "terminal.")
    parser.add_argument(
        '--decisions',
        action="store_true",
        help="print a human-readable summary of conflicted "
             "merge decisions instead of merging the notebook.")

    return parser
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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'])
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(
        description=_description,
        )
    add_generic_args(parser)
    add_diff_args(parser)
    add_diff_cli_args(parser)

    parser.add_argument(
        "base", help="the base notebook filename OR base git-revision.",
        nargs='?', default='HEAD',
    )
    parser.add_argument(
        "remote", help="the remote modified notebook filename OR remote git-revision.",
        nargs='?', default=None,
    )
    parser.add_argument(
        "paths", help="filter diffs for git-revisions based on path",
        nargs='*', default=None,
    )

    parser.add_argument(
        '--out',
        default=None,
        help="if supplied, the diff is written to this file. "
             "Otherwise it is printed to the terminal.")

    return parser
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
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
Exemplo n.º 14
0
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)
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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'
Exemplo n.º 17
0
def _build_arg_parser():
    """Creates an argument parser for the nbpatch command."""
    parser = ConfigBackedParser(
        description=_description,
        add_help=True,
        )
    from .args import add_generic_args, add_filename_args
    add_generic_args(parser)
    add_filename_args(parser, ["base", "patch"])
    parser.add_argument(
        '-o', '--output',
        default=None,
        help="if supplied, the patched notebook is written "
             "to this file. Otherwise it is printed to the "
             "terminal.")
    return parser
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
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()
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
def _build_arg_parser():
    import argparse
    parser = ConfigBackedParser(
        'git-nbdiffdriver',
        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_git_diff_driver_args(diff_parser)
    add_diff_args(diff_parser)
    add_diff_cli_args(diff_parser)
    add_prettyprint_args(diff_parser)

    webdiff_parser = subparsers.add_parser(
        'webdiff',
        description=
        "The actual entrypoint for the webdiff tool. Git will call this.")
    add_git_diff_driver_args(webdiff_parser)
    add_diff_args(webdiff_parser)
    add_web_args(webdiff_parser, 0)

    # TODO: From git docs: "For a path that is unmerged, GIT_EXTERNAL_DIFF is called with 1 parameter, <path>."
    add_git_config_subcommand(
        subparsers,
        enable,
        disable,
        subparser_help=
        "Configure git to use nbdime for notebooks in `git diff`",
        enable_help="enable nbdime diff driver via git config",
        disable_help="disable nbdime diff driver via git config")

    return parser
Exemplo n.º 22
0
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)
Exemplo n.º 23
0
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)
Exemplo n.º 24
0
def _build_arg_parser():
    """Creates an argument parser for the nbshow command."""
    parser = ConfigBackedParser(
        description=_description,
        add_help=True,
    )
    add_generic_args(parser)
    parser.add_argument("notebook",
                        nargs="*",
                        help="notebook filename(s) or - to read from stdin")

    # Things we can choose to show or not
    ignorables = parser.add_argument_group(
        title='ignorables',
        description='Set which parts of the notebook (not) to show.')
    ignorables.add_argument('-s',
                            '--sources',
                            action=IgnorableAction,
                            help="show/ignore sources.")
    ignorables.add_argument('-o',
                            '--outputs',
                            action=IgnorableAction,
                            help="show/ignore outputs.")
    ignorables.add_argument('-a',
                            '--attachments',
                            action=IgnorableAction,
                            help="show/ignore attachments.")
    ignorables.add_argument('-m',
                            '--metadata',
                            action=IgnorableAction,
                            help="show/ignore metadata.")
    ignorables.add_argument(
        '-d',
        '--details',
        action=IgnorableAction,
        help="show/ignore details not covered by other options.")

    return parser
Exemplo n.º 25
0
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
Exemplo n.º 26
0
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
Exemplo n.º 27
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(description=_description, add_help=True)
    from nbdime.args import (
        add_generic_args,
        add_diff_args,
        add_merge_args,
        filename_help,
        add_filename_args,
        add_prettyprint_args,
    )

    add_generic_args(parser)
    add_diff_args(parser)
    add_merge_args(parser)
    add_prettyprint_args(parser)

    parser.add_argument(
        "base",
        type=Path,
        help=filename_help["base"],
        nargs="?",
        default=EXPLICIT_MISSING_FILE,
    )
    add_filename_args(parser, ["local", "remote"])

    parser.add_argument(
        "--out",
        default=None,
        type=Path,
        help="if supplied, the merged notebook is written "
        "to this file. Otherwise it is printed to the "
        "terminal.",
    )
    parser.add_argument(
        "--decisions",
        action="store_true",
        help="print a human-readable summary of conflicted "
        "merge decisions instead of merging the notebook.",
    )

    return parser
Exemplo n.º 28
0
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'
Exemplo n.º 29
0
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
Exemplo n.º 30
0
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
Exemplo n.º 31
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(
        description=_description,
        add_help=True,
    )
    from .args import add_generic_args, add_diff_args, add_merge_args, add_filename_args
    add_generic_args(parser)
    add_diff_args(parser)
    add_merge_args(parser)
    add_filename_args(parser, ["base", "local", "remote"])

    parser.add_argument('--out',
                        default=None,
                        help="if supplied, the merged notebook is written "
                        "to this file. Otherwise it is printed to the "
                        "terminal.")
    parser.add_argument('--decisions',
                        action="store_true",
                        help="print a human-readable summary of conflicted "
                        "merge decisions instead of merging the notebook.")

    return parser