def main(): parser = arg_parser() args = parser.parse_args() if args.project: for p in args.project: try: report(jetstream.Project(path=p)) except Exception as e: log.exception(f'Failed to generate report for "{p}"') else: report(jetstream.Project())
def test_reinit(self): """running jetstream init again should not affect project id""" args = [ 'init', ] cli_main(args) p = jetstream.Project() args = ['init', '-c', 'foo', 'bar'] cli_main(args) p2 = jetstream.Project() self.assertEqual(p.info['id'], p2.info['id'])
def main(args): log.debug(f'{__name__} {args}') paths = jetstream.projects.ProjectPaths(args.path) if paths.exists(): if args.force: log.info('Project already exists - force reinitializing') p = jetstream.projects.init( args.path, id=args.project_id, config=args.config ) else: log.info('Project already exists - updating config') p = jetstream.Project(args.path) p.update_index(args.config) else: log.info('Initializing project') p = jetstream.projects.init( args.path, id=args.project_id, config=args.config ) log.info(p)
def test_init_w_json_as_yaml(self): """specifying the config file type should ignore file extensions""" with open('config.yaml', 'w') as fp: fp.write('{"foo": "bar", "baz": 42}') args = ['init', '-C', 'config.yaml', '--config-file-type', 'json'] cli_main(args) p = jetstream.Project() self.assertEqual(p.index['foo'], 'bar') self.assertEqual(p.index['baz'], 42)
def test_init_w_yaml(self): """jetstream init -C with a yaml config file""" with open('config.yaml', 'w') as fp: fp.write('foo: bar\nbaz: 42') args = ['init', '-C', 'config.yaml'] cli_main(args) p = jetstream.Project() self.assertEqual(p.index['foo'], 'bar') self.assertEqual(p.index['baz'], 42)
def test_init_w_json(self): """jetstream init -C with a json config file""" with open('config.json', 'w') as fp: fp.write('{"foo": "bar", "baz": 42}') args = ['init', '-C', 'config.json'] cli_main(args) p = jetstream.Project() self.assertEqual(p.index['foo'], 'bar') self.assertEqual(p.index['baz'], 42)
def test_init_w_csv_nh(self): """jetstream init -C with csv-nh type set""" with open('config.csv', 'w') as fp: fp.write('foo,bar\nbaz,42\napple,banana') args = ['init', '-C', 'config.csv'] cli_main(args) p = jetstream.Project() second_row = p.index['__config_file__'][1] self.assertEqual(second_row['foo'], 'apple') self.assertEqual(second_row['bar'], 'banana')
def test_init_w_csv(self): """jetstream init -C should auto-detect csv config file""" with open('config.csv', 'w') as fp: fp.write('foo,bar\nbaz,42\napple,banana') args = ['init', '-C', 'config.csv', '--config-file-type', 'csv-nh'] cli_main(args) p = jetstream.Project() third_row = p.index['__config_file__'][2] self.assertEqual(third_row[0], 'apple') self.assertEqual(third_row[1], 'banana')
def main(args=None): parser = arg_parser() args = parser.parse_args(args) jetstream.start_logging(args.logging) setting_src = '\n'.join((str(s) for s in jetstream.settings.sources)) log.info(f'Version: {jetstream.__version__}') log.debug(f'Command args: {sys.argv}') log.debug(f'Settings files:\n{setting_src}') # Config item shuffle to get the monolithic config file to serve as the # base and then update it with the individual config items. If a config # file is loaded that does not yield a dictionary, it will be converted # to a dictionary with the contents loaded under __config_file__. if hasattr(args, 'config'): final = {} if args.config_file: if args.config_file_type: config_file = jetstream.utils.load_file( args.config_file, filetype=args.config_file_type) else: config_file = jetstream.utils.load_file(args.config_file) if not isinstance(config_file, dict): final = {'__config_file__': config_file} else: final.update(config_file) final.update(args.config) args.config = final if args.project: args.project = jetstream.Project(args.project) else: cwd = os.getcwd() if jetstream.projects.is_project(cwd): args.project = jetstream.Project(cwd) if args.pipeline: args.pipeline = jetstream.Pipeline(args.pipeline) if args.func: args.func(args) else: parser.error('the following arguments are required: subcommand')