Exemple #1
0
def run_command(command_config_uri, tempdir):
    """Run a command from a serialized command configuration
    at COMMAND_CONFIG_URI.
    """
    if tempdir is not None:
        RVConfig.set_tmp_dir(tempdir)
    rv.runner.CommandRunner.run(command_config_uri)
 def test_set_tmp_dir(self):
     if platform.system() == 'Linux':
         directory = '/tmp/xxx/'
         while os.path.exists(directory):
             directory = directory + 'xxx/'
         self.assertFalse(os.path.exists(directory))
         RVConfig.set_tmp_dir(directory)
         self.assertTrue(os.path.exists(directory))
         self.assertTrue(os.path.isdir(directory))
         shutil.rmtree(directory)
Exemple #3
0
def run(runner, commands, experiment_module, dry_run, skip_file_check, arg,
        prefix, methods, path, filters, rerun, tempdir, splits):
    """Run Raster Vision commands from experiments, using the
    experiment runner named RUNNER."""

    if tempdir:
        RVConfig.set_tmp_dir(tempdir)

    # Validate runner
    valid_runners = list(
        map(lambda x: x.lower(), rv.ExperimentRunner.list_runners()))
    if runner not in valid_runners:
        print_error('Invalid experiment runner: "{}". '
                    'Must be one of: "{}"'.format(runner,
                                                  '", "'.join(valid_runners)))
        sys.exit(1)

    runner = ExperimentRunner.get_runner(runner)

    if experiment_module and path:
        print_error('Must specify only one of experiment_module or path')
        sys.exit(1)

    if not commands:
        commands = rv.all_commands()
    else:
        commands = list(map(lambda x: x.upper(), commands))

    experiment_args = {}
    for k, v in arg:
        experiment_args[k] = v

    loader = ExperimentLoader(experiment_args=experiment_args,
                              experiment_method_prefix=prefix,
                              experiment_method_patterns=methods,
                              experiment_name_patterns=filters)
    try:
        if experiment_module:
            experiments, command_configs = loader.load_from_module(
                experiment_module)
        elif path:
            experiments, command_configs = loader.load_from_file(path)
        else:
            experiments, command_configs = loader.load_from_module('__main__')
    except LoaderError as e:
        print_error(str(e))
        sys.exit(1)

    if not experiments and not commands:
        if experiment_module:
            print_error(
                'No experiments found in {}.'.format(experiment_module))
        elif path:
            print_error('No experiments found in {}.'.format(path))
        else:
            print_error('No experiments found.')

    runner.run(experiments,
               command_configs=command_configs,
               commands_to_run=commands,
               rerun_commands=rerun,
               skip_file_check=skip_file_check,
               dry_run=dry_run,
               splits=splits)