Skip to content

Commit

Permalink
Merge pull request #563 from JrGoodle/refactor-exceptions
Browse files Browse the repository at this point in the history
Refactor keyboard interrupt and system exit exception handling
  • Loading branch information
JrGoodle committed Jun 3, 2020
2 parents 56bd1e2 + 81b3cd2 commit bc2ff44
Show file tree
Hide file tree
Showing 38 changed files with 560 additions and 253 deletions.
3 changes: 0 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ exclude_lines =
raise AssertionError
raise NotImplementedError

# Don't complain if tests don't hit certain exceptions
except \(KeyboardInterrupt, SystemExit\):

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
2 changes: 1 addition & 1 deletion docs/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ API Reference
:maxdepth: 2

CLI API Reference <clowder.cli>
Config API Reference <clowder.config>
Models API Reference <clowder.model>
Git Utilities API Reference <clowder.git>
General Utils API Reference <clowder.util>
Exceptions API Reference <clowder.error>
6 changes: 3 additions & 3 deletions src/clowder/cli/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def add_branch_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to show branches for')))
help=fmt.project_options_help_message('projects and groups to show branches for')))
]

parser = subparsers.add_parser('branch', help='Display current branches')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)

mutually_exclusive_arguments = [
Expand Down
8 changes: 4 additions & 4 deletions src/clowder/cli/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def add_checkout_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['branch'], dict(nargs=1, action='store', help='branch to checkout', metavar='BRANCH')),
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['branch'], dict(nargs=1, action='store', help='branch to checkout', metavar='<branch>')),
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to checkout branches for')))
help=fmt.project_options_help_message('projects and groups to checkout branches for')))
]

parser = subparsers.add_parser('checkout', help='Checkout local branch in projects')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=checkout)

Expand Down
6 changes: 3 additions & 3 deletions src/clowder/cli/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def add_clean_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to clean'))),
help=fmt.project_options_help_message('projects and groups to clean'))),
(['--recursive', '-r'], dict(action='store_true', help='clean submodules recursively'))
]

parser = subparsers.add_parser('clean', help='Discard current changes in projects')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)

options_arguments = [
Expand Down
32 changes: 26 additions & 6 deletions src/clowder/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import argparse
from typing import Optional

import clowder.util.formatting as fmt
from clowder.clowder_controller import CLOWDER_CONTROLLER
Expand All @@ -18,14 +19,20 @@
from .util import add_parser_arguments


config_parser: Optional[argparse.ArgumentParser] = None
config_set_parser: Optional[argparse.ArgumentParser] = None


def add_config_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""Add clowder config parser
:param argparse._SubParsersAction subparsers: Subparsers action to add parser to
"""

parser = subparsers.add_parser('config', help='Manage clowder config (EXPERIMENTAL)')
config_subparsers = parser.add_subparsers()
global config_parser
config_parser = subparsers.add_parser('config', help='Manage clowder config (EXPERIMENTAL)')
config_parser.set_defaults(func=config_help)
config_subparsers = config_parser.add_subparsers()

add_config_clear_parser(config_subparsers)
add_config_get_parser(config_subparsers)
Expand Down Expand Up @@ -79,8 +86,10 @@ def add_config_set_parser(subparsers: argparse._SubParsersAction) -> None: # noq
"""

# clowder config set
parser = subparsers.add_parser('set', help='Set clowder config options')
config_set_subparsers = parser.add_subparsers()
global config_set_parser
config_set_parser = subparsers.add_parser('set', help='Set clowder config options')
config_set_parser.set_defaults(func=config_help_set)
config_set_subparsers = config_set_parser.add_subparsers()

# clowder config set rebase
rebase_parser = config_set_subparsers.add_parser('rebase', help='Set use rebase with herd command')
Expand All @@ -93,8 +102,7 @@ def add_config_set_parser(subparsers: argparse._SubParsersAction) -> None: # noq
# clowder config set projects
projects_arguments = [
(['projects'], dict(metavar='PROJECT', nargs='+', choices=CLOWDER_CONTROLLER.project_choices,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'Default projects and groups to run commands for')))
help=fmt.project_options_help_message('Default projects and groups to run commands for')))
]
projects_parser = config_set_subparsers.add_parser('projects', help='Set default projects and groups')
add_parser_arguments(projects_parser, projects_arguments)
Expand Down Expand Up @@ -185,6 +193,18 @@ def config_get_all(args) -> None: # noqa
config.current_clowder_config.print_configuration()


def config_help(args): # noqa
"""Clowder config help handler"""

config_parser.print_help()


def config_help_set(args): # noqa
"""Clowder config set help handler"""

config_set_parser.print_help()


@valid_clowder_yaml_required
@print_clowder_name
def config_set_jobs(args) -> None: # noqa
Expand Down
6 changes: 3 additions & 3 deletions src/clowder/cli/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def add_diff_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to show diff for'))),
help=fmt.project_options_help_message('projects and groups to show diff for'))),
]

parser = subparsers.add_parser('diff', help='Show git diff for projects')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=diff)

Expand Down
10 changes: 5 additions & 5 deletions src/clowder/cli/forall.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ def add_forall_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to run command for'))),
(['--command', '-c'], dict(nargs='+', metavar='COMMAND', default=None,
help=fmt.project_options_help_message('projects and groups to run command for'))),
(['--command', '-c'], dict(nargs='+', metavar='<command>', default=None,
help='command or script to run in project directories')),
(['--ignore-errors', '-i'], dict(action='store_true', help='ignore errors in command or script')),
(['--jobs', '-j'], dict(metavar='JOBS', nargs=1, default=None, type=int,
(['--jobs', '-j'], dict(metavar='<n>', nargs=1, default=None, type=int,
help='number of jobs to use runnning commands in parallel')),
]

parser = subparsers.add_parser('forall', help='Run command or script in project directories')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=forall)

Expand Down
14 changes: 7 additions & 7 deletions src/clowder/cli/herd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def add_herd_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to show branches for'))),
(['--jobs', '-j'], dict(metavar='JOBS', nargs=1, default=None, type=int,
help=fmt.project_options_help_message('projects and groups to show branches for'))),
(['--jobs', '-j'], dict(metavar='<n>', nargs=1, default=None, type=int,
help='number of jobs to use runnning commands in parallel')),
(['--rebase', '-r'], dict(action='store_true', help='use rebase instead of pull')),
(['--depth', '-d'], dict(default=None, type=int, nargs=1, metavar='DEPTH', help='depth to herd'))
(['--depth', '-d'], dict(default=None, type=int, nargs=1, metavar='<n>', help='depth to herd'))
]

parser = subparsers.add_parser('herd', help='Clone and update projects with latest changes')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)

mutually_exclusive_arguments = [
(['--branch', '-b'], dict(nargs=1, default=None, metavar='BRANCH', help='branch to herd if present')),
(['--tag', '-t'], dict(nargs=1, default=None, metavar='TAG', help='tag to herd if present'))
(['--branch', '-b'], dict(nargs=1, default=None, metavar='<branch>', help='branch to herd if present')),
(['--tag', '-t'], dict(nargs=1, default=None, metavar='<tag>', help='tag to herd if present'))
]
mutually_exclusive_group = parser.add_mutually_exclusive_group()
add_parser_arguments(mutually_exclusive_group, mutually_exclusive_arguments)
Expand Down
4 changes: 2 additions & 2 deletions src/clowder/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
def add_init_parser(subparsers: argparse._SubParsersAction) -> None: # noqa

arguments = [
(['url'], dict(metavar='URL', help='url of repo containing clowder yaml file')),
(['--branch', '-b'], dict(nargs=1, metavar='BRANCH', help='branch of repo containing clowder yaml file'))
(['url'], dict(metavar='<url>', help='url of repo containing clowder yaml file')),
(['--branch', '-b'], dict(nargs=1, metavar='<branch>', help='branch of repo containing clowder yaml file'))
]

parser = subparsers.add_parser('init', help='Clone repository to clowder directory and create clowder yaml symlink')
Expand Down
5 changes: 3 additions & 2 deletions src/clowder/cli/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def add_link_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
versions = get_saved_version_names()

arguments = [
(['version'], dict(metavar='VERSION', choices=versions, nargs='?', default=None,
help=fmt.options_help_message(versions, 'version to symlink')))
(['version'], dict(metavar='<version>', choices=versions, nargs='?', default=None,
help=fmt.version_options_help_message('version to symlink', versions)))
]

parser = subparsers.add_parser('link', help='Symlink clowder yaml version')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=link)

Expand Down
8 changes: 4 additions & 4 deletions src/clowder/cli/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def add_prune_parser(subparsers: argparse._SubParsersAction): # noqa
"""

arguments = [
(['branch'], dict(help='name of branch to remove', metavar='BRANCH')),
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['branch'], dict(help='name of branch to remove', metavar='<branch>')),
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to prune'))),
help=fmt.project_options_help_message('projects and groups to prune'))),
(['--force', '-f'], dict(action='store_true', help='force prune branches'))
]

parser = subparsers.add_parser('prune', help='Prune branches')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)

mutually_exclusive_arguments = [
Expand Down
8 changes: 4 additions & 4 deletions src/clowder/cli/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_repo_add_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['files'], dict(nargs='+', metavar='FILE', help='files to add'))
(['files'], dict(nargs='+', metavar='<file>', help='files to add'))
]

parser = subparsers.add_parser('add', help='Add files in clowder repo')
Expand All @@ -62,7 +62,7 @@ def add_repo_checkout_parser(subparsers: argparse._SubParsersAction) -> None: #
"""

arguments = [
(['ref'], dict(nargs=1, metavar='REF', help='git ref to checkout'))
(['ref'], dict(nargs=1, metavar='<ref>', help='git ref to checkout'))
]

parser = subparsers.add_parser('checkout', help='Checkout ref in clowder repo')
Expand All @@ -87,7 +87,7 @@ def add_repo_commit_parser(subparsers: argparse._SubParsersAction) -> None: # no
"""

arguments = [
(['message'], dict(nargs=1, metavar='MESSAGE', help='commit message'))
(['message'], dict(nargs=1, metavar='<message>', help='commit message'))
]

parser = subparsers.add_parser('commit', help='Commit current changes in clowder repo yaml files')
Expand Down Expand Up @@ -122,7 +122,7 @@ def add_repo_run_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['command'], dict(nargs=1, metavar='COMMAND', help='command to run in clowder repo directory'))
(['command'], dict(nargs=1, metavar='<command>', help='command to run in clowder repo directory'))
]

parser = subparsers.add_parser('run', help='Run command in clowder repo')
Expand Down
18 changes: 9 additions & 9 deletions src/clowder/cli/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ def add_reset_parser(subparsers: argparse._SubParsersAction): # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to reset'))),
(['--jobs', '-j'], dict(metavar='JOBS', nargs=1, default=None, type=int,
help=fmt.project_options_help_message('projects and groups to reset'))),
(['--jobs', '-j'], dict(metavar='<n>', nargs=1, default=None, type=int,
help='number of jobs to use runnning commands in parallel')),
(['--timestamp', '-t'], dict(choices=CLOWDER_CONTROLLER.project_names,
default=None, nargs=1, metavar='TIMESTAMP',
help='project to reset timestamps relative to'))
# (['--timestamp', '-t'], dict(choices=CLOWDER_CONTROLLER.project_names,
# default=None, nargs=1, metavar='<timestamp>',
# help='project to reset timestamps relative to'))
]

parser = subparsers.add_parser('reset', help='Reset branches to upstream commits or '
'check out detached HEADs for tags and shas')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=reset)

Expand All @@ -59,8 +59,8 @@ def reset(args) -> None:
"""Clowder reset command private implementation"""

timestamp_project = None
if args.timestamp:
timestamp_project = args.timestamp[0]
# if args.timestamp:
# timestamp_project = args.timestamp[0]

jobs = None
if args.jobs:
Expand Down
3 changes: 2 additions & 1 deletion src/clowder/cli/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
def add_save_parser(subparsers: argparse._SubParsersAction) -> None: # noqa

arguments = [
(['version'], dict(help='version to save', metavar='VERSION'))
(['version'], dict(help='version to save', metavar='<version>'))
]

parser = subparsers.add_parser('save', help='Create clowder yaml version for current repos')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=save)

Expand Down
8 changes: 4 additions & 4 deletions src/clowder/cli/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def add_start_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['branch'], dict(help='name of branch to create', nargs=1, default=None, metavar='BRANCH')),
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['branch'], dict(help='name of branch to create', nargs=1, default=None, metavar='<branch>')),
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to start branches for'))),
help=fmt.project_options_help_message('projects and groups to start branches for'))),
(['--tracking', '-t'], dict(action='store_true', help='create remote tracking branch'))
]

parser = subparsers.add_parser('start', help='Start a new branch')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=start)

Expand Down
6 changes: 3 additions & 3 deletions src/clowder/cli/stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def add_stash_parser(subparsers: argparse._SubParsersAction) -> None: # noqa
"""

arguments = [
(['projects'], dict(metavar='PROJECT', default='default', nargs='*',
(['projects'], dict(metavar='<project|group>', default='default', nargs='*',
choices=CLOWDER_CONTROLLER.project_choices_with_default,
help=fmt.options_help_message(CLOWDER_CONTROLLER.project_choices,
'projects and groups to stash changes for'))),
help=fmt.project_options_help_message('projects and groups to stash changes for'))),
]

parser = subparsers.add_parser('stash', help='Stash current changes')
parser.formatter_class = argparse.RawTextHelpFormatter
add_parser_arguments(parser, arguments)
parser.set_defaults(func=stash)

Expand Down

0 comments on commit bc2ff44

Please sign in to comment.