def execute(args): task_family = None # try to infer the task module from the passed task family and import it parts = args.task_family.rsplit(".", 1) if len(parts) == 2: modid, cls_name = parts try: mod = __import__(modid, globals(), locals(), [cls_name]) if hasattr(mod, cls_name): task_cls = getattr(mod, cls_name) if not issubclass(task_cls, Task): abort("object '{}' is not a Task".format(args.task_family)) task_family = task_cls.task_family except ImportError as e: logger.debug("import error in module {}: {}".format(modid, e)) # read task info from the db file and import it if task_family is None: info = read_task_from_db(args.task_family) if not info: abort("task family '{}' not found in db".format(args.task_family)) modid, task_family, _ = info try: __import__(modid, globals(), locals()) except ImportError: abort("could not import module '{}'".format(modid)) # import the module and run luigi luigi_run([task_family] + sys.argv[3:])
def run_and_expect(self, joined_params, retcode, extra_args=['--local-scheduler', '--no-lock']): with self.assertRaises(SystemExit) as cm: luigi_run((joined_params.split(' ') + extra_args)) self.assertEqual(cm.exception.code, retcode)
def execute(args, argv): """ Executes the *run* subprogram with parsed commandline *args*. """ task_family = None error = None # try to infer the task module from the passed task family and import it parts = args.task_family.rsplit(".", 1) if len(parts) == 2: modid, cls_name = parts try: mod = __import__(modid, globals(), locals(), [cls_name]) task_cls = getattr(mod, cls_name, None) if task_cls is not None: if not issubclass(task_cls, Task): abort("object '{}' is not a Task".format(args.task_family)) task_family = task_cls.get_task_family() except ImportError as e: # distinguish import errors resulting from an unknown modid from all other cases modid_unknown = str(e) == "No module named {}".format(modid) if modid_unknown: # keep the error in case the task family cannot be inferred from the index file error = e else: raise # read task info from the index file and import it if task_family is None: cfg = Config.instance() index_file = cfg.get_expanded("core", "index_file") if os.path.exists(index_file): info = read_task_from_index(args.task_family, index_file) if not info: abort("task family '{}' not found in index".format( args.task_family)) modid, task_family, _ = info __import__(modid, globals(), locals()) # complain when no task could be found if task_family is None: if error: raise error else: abort("task '{}' not found".format(args.task_family)) # run luigi sys.argv[0] += " run" luigi_run([task_family] + argv[3:])
def execute(args): # read the module id for that task family from the db file dbfile = Config.instance().get("core", "db_file") with open(dbfile, "r") as f: for line in f.readlines(): line = line.strip() try: mid, fam, params = line.split(":", 2) except ValueError: pass if fam == args.task_family: break else: abort("task family '%s' not found" % args.task_family) # import the module and run luigi __import__(mid, globals(), locals()) luigi_run([args.task_family] + sys.argv[3:])
def execute(args): """ Executes the *run* subprogram with parsed commandline *args*. """ task_family = None error = None # try to infer the task module from the passed task family and import it parts = args.task_family.rsplit(".", 1) if len(parts) == 2: modid, cls_name = parts try: mod = __import__(modid, globals(), locals(), [cls_name]) if hasattr(mod, cls_name): task_cls = getattr(mod, cls_name) if not issubclass(task_cls, Task): abort("object '{}' is not a Task".format(args.task_family)) task_family = task_cls.task_family except ImportError as e: logger.debug("import error in module {}: {}".format(modid, e)) error = e # read task info from the db file and import it if task_family is None: db_file = Config.instance().get_expanded("core", "db_file") if os.path.exists(db_file): info = read_task_from_db(args.task_family, db_file) if not info: abort("task family '{}' not found in db".format( args.task_family)) modid, task_family, _ = info __import__(modid, globals(), locals()) # complain when no task could be found if task_family is None: if error: raise error else: abort("task '{}' not found".format(args.task_family)) # import the module and run luigi luigi_run([task_family] + sys.argv[3:])
def run_and_expect(self, joined_params, retcode, extra_args=['--local-scheduler', '--no-lock']): with self.assertRaises(SystemExit) as cm: luigi_run((joined_params.split(' ') + extra_args)) self.assertEqual(cm.exception.code, retcode)
def sciluigi_run(argv=sys.argv[1:]): setup_logging() luigi_run(argv)
# -*- coding: utf-8 -*- from luigi.cmdline import luigi_run if __name__ == '__main__': luigi_run()
# -*- coding: utf-8 -*- # # Copyright 2012-2016 Spotify AB # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # from luigi.cmdline import luigi_run if __name__ == '__main__': luigi_run()
sys.path.append(os.path.abspath(sys.argv[0])) sys.path.append(os.path.dirname(__file__) + '/luigi_pipelines/') if bip: scheduler_str = '--scheduler-host {bip}'.format(bip=bip) else: scheduler_str = '--local-scheduler' if analyze_way == 'somatic': RUN_COMMAND = raw_input( """%s\n\n If you sure, please input Y/y.""" % formatter_output(parse_args.split(',')[0])) if RUN_COMMAND.upper() == 'Y': cmd_str = "--module SomaticPipelines workflow --x {args} {sch} --workers {worker}".format( args=parse_args, worker=str(worker), sch=scheduler_str) luigi_run(cmd_str.split(' ')) else: print 'Exit now.' exit() elif analyze_way == 'germline': RUN_COMMAND = raw_input( """%s\n\n If you sure, please input Y/y.""" % formatter_output(parse_args.split(',')[0])) if RUN_COMMAND.upper() == 'Y': cmd_str = '--module GermlinePipelines workflow --x {args} {sch} --workers {worker}'.format( args=parse_args, worker=str(worker), sch=scheduler_str) luigi_run(cmd_str.split(' ')) else: print 'Exit now.' exit()
def run(args): """A wrapper around luigi CLI.""" luigi_run(args)