Commit 1010a8ca authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments] Use raise_on_error decorator for commands

Also cleans up all the sys.exit calls.
parent 548b1339
......@@ -27,7 +27,6 @@
import os
import sys
import logging
import glob
import click
......@@ -48,6 +47,7 @@ from beat.core.hash import hashDataset
from .plotters import plot_impl as plotters_plot
from .plotters import pull_impl as plotters_pull
from .decorators import raise_on_error
logger = logging.getLogger(__name__)
......@@ -144,7 +144,6 @@ def run_experiment(configuration, name, force, use_docker, use_local):
logger.error("Failed to load the experiment `%s':", name)
for e in experiment.errors:
logger.error(' * %s', e)
sys.exit(1)
return 1
if not os.path.exists(configuration.cache):
......@@ -172,7 +171,6 @@ def run_experiment(configuration, name, force, use_docker, use_local):
logger.error("Cannot execute block `%s' on environment `%s': "
"environment was not found' - please install it",
key, search_key)
sys.exit(1)
return 1
if use_docker:
......@@ -194,7 +192,6 @@ def run_experiment(configuration, name, force, use_docker, use_local):
"Failed to load the execution information for `%s':", key)
for e in executor.errors:
logger.error(' * %s', e)
sys.exit(1)
return 1
if executor.outputs_exist and not force:
......@@ -226,7 +223,6 @@ def run_experiment(configuration, name, force, use_docker, use_local):
logger.error(" Captured system error:\n%s",
reindent(result['system_error'], 4))
logger.extra(" Environment: %s" % 'default environment')
sys.exit(1)
return 1
elif use_docker:
stats = result['statistics']
......@@ -265,7 +261,6 @@ def run_experiment(configuration, name, force, use_docker, use_local):
for name, details in executor.data['outputs'].items():
logger.extra(" * %s", details['path'])
sys.exit(0)
return 0
......@@ -557,6 +552,7 @@ def experiments(ctx):
'experiment on the local machine (default)',
default=True, is_flag=True)
@click.pass_context
@raise_on_error
def run(ctx, name, force, docker, local):
''' Runs an experiment locally'''
config = ctx.meta.get('config')
......@@ -573,6 +569,7 @@ def run(ctx, name, force, docker, local):
@click.option('--checksum', help='Checksums indexes for cache files',
is_flag=True)
@click.pass_context
@raise_on_error
def caches(ctx, name, list, delete, checksum):
'''Lists all cache files used by this experiment'''
config = ctx.meta.get('config')
......@@ -583,6 +580,7 @@ def caches(ctx, name, list, delete, checksum):
@click.option('--remote', help='Only acts on the remote copy of the list.',
is_flag=True)
@click.pass_context
@raise_on_error
def list(ctx, remote):
'''Lists all the experiments available on the platform.
......@@ -601,6 +599,7 @@ def list(ctx, remote):
@experiments.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def path(ctx, names):
'''Displays local path of experiment files
......@@ -613,6 +612,7 @@ def path(ctx, names):
@experiments.command()
@click.argument('name', nargs=1)
@click.pass_context
@raise_on_error
def edit(ctx, name):
'''Edit local experiment file
......@@ -627,6 +627,7 @@ def edit(ctx, name):
@experiments.command()
@click.argument('names', nargs=-1)
@click.pass_context
@raise_on_error
def check(ctx, names):
'''Checks a local experiment for validity.
......@@ -641,6 +642,7 @@ def check(ctx, names):
@click.option('--force', help='Performs operation regardless of conflicts',
is_flag=True)
@click.pass_context
@raise_on_error
def pull(ctx, names, force):
'''Downloads the specified experiments from the server.
......@@ -658,6 +660,7 @@ def pull(ctx, names, force):
@click.option('--dry-run', help="Doesn't really perform the task, just "
"comments what would do", is_flag=True)
@click.pass_context
@raise_on_error
def push(ctx, names, force, dry_run):
'''Uploads experiments to the server.
......@@ -676,6 +679,7 @@ def push(ctx, names, force, dry_run):
@experiments.command()
@click.argument('name', nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
'''Shows changes between the local dataformat and the remote version.
......@@ -692,6 +696,7 @@ def diff(ctx, name):
@experiments.command()
@click.pass_context
@raise_on_error
def status(ctx):
'''Shows (editing) status for all available experiments.
......@@ -707,6 +712,7 @@ def status(ctx):
@click.argument('src', nargs=1)
@click.argument('dst', nargs=1)
@click.pass_context
@raise_on_error
def fork(ctx, src, dst):
'''Forks a local experiment.
......@@ -721,6 +727,7 @@ def fork(ctx, src, dst):
@click.option('--remote', help='Only acts on the remote copy of the experiment',
is_flag=True)
@click.pass_context
@raise_on_error
def rm(ctx, names, remote):
'''Deletes a local experiment (unless --remote is specified).
......@@ -739,6 +746,7 @@ def rm(ctx, names, remote):
@click.option('--path', help='Use path to write files to disk (instead of the '
'current directory)', type=click.Path())
@click.pass_context
@raise_on_error
def draw(ctx, names, path):
'''Creates a visual representation of the experiment.'''
config = ctx.meta.get('config')
......@@ -755,6 +763,7 @@ def draw(ctx, names, path):
is_flag=True)
@click.option('--output-folder', help='<folder>', type=click.Path(exists=True))
@click.pass_context
@raise_on_error
def plot(ctx, names, force, remote, show, output_folder):
'''Plots output images of the experiment.'''
config = ctx.meta.get('config')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment