def _build_parser(root_task=None, help_all=False): parser = argparse.ArgumentParser(add_help=False) # Unfortunately, we have to set it as optional to argparse, so we can # parse out stuff like `--module` before we call for `--help`. parser.add_argument( 'root_task', nargs='?', help='Task family to run. Is not optional.', metavar='Required root task', ) for task_name, is_without_section, param_name, param_obj in Register.get_all_params( ): is_the_root_task = task_name == root_task help = param_obj.description if any( (is_the_root_task, help_all, param_obj.always_in_help)) else argparse.SUPPRESS flag_name_underscores = param_name if is_without_section else task_name + '_' + param_name global_flag_name = '--' + flag_name_underscores.replace('_', '-') parser.add_argument(global_flag_name, help=help, **param_obj._parser_kwargs( param_name, task_name)) if is_the_root_task: local_flag_name = '--' + param_name.replace('_', '-') parser.add_argument(local_flag_name, help=help, **param_obj._parser_kwargs(param_name)) return parser
def get_global_parameters(): seen_params = set() for task_name, is_without_section, param_name, param in Register.get_all_params(): if param in seen_params: continue seen_params.add(param) yield task_name, is_without_section, param_name, param
def complete_config(): """ Create a temporary Luigi Config that has defaults for all variables """ def get_default(param_obj): if isinstance(param_obj, luigi.IntParameter): return '1' elif isinstance(param_obj, luigi.DateParameter): return datetime.date.today().isoformat() elif isinstance(param_obj, luigi.Parameter): return '' config = luigi.configuration.get_config() # Make sure every parameter has a default value sections_to_remove = [] options_to_remove = [] for task_name, is_without_section, param_name, param_obj in Register.get_all_params(): if param_obj._default == _no_value: if is_without_section: sections_to_remove.append(task_name) options_to_remove.append((task_name, param_name)) config.set(task_name, param_name, get_default(param_obj)) # Yield the completed config yield # Remove any config we set up for section, option in options_to_remove: config.remove_option(section, option) for section in sections_to_remove: config.remove_section(section)
def _build_parser(root_task=None, help_all=False): parser = argparse.ArgumentParser(add_help=False) # Unfortunately, we have to set it as optional to argparse, so we can # parse out stuff like `--module` before we call for `--help`. parser.add_argument('root_task', nargs='?', help='Task family to run. Is not optional.', metavar='Required root task', ) for task_name, is_without_section, param_name, param_obj in Register.get_all_params(): is_the_root_task = task_name == root_task help = param_obj.description if any((is_the_root_task, help_all, param_obj.always_in_help)) else argparse.SUPPRESS flag_name_underscores = param_name if is_without_section else task_name + '_' + param_name global_flag_name = '--' + flag_name_underscores.replace('_', '-') parser.add_argument(global_flag_name, help=help, **param_obj._parser_kwargs(param_name, task_name) ) if is_the_root_task: local_flag_name = '--' + param_name.replace('_', '-') parser.add_argument(local_flag_name, help=help, **param_obj._parser_kwargs(param_name) ) return parser
def _build_parser(active_tasks=set()): parser = argparse.ArgumentParser(add_help=False) for task_name, is_without_section, param_name, param_obj in Register.get_all_params(): as_active = task_name in active_tasks param_obj._add_to_cmdline_parser(parser, param_name, task_name, is_without_section=is_without_section, as_active=as_active) return parser
def _build_parser(active_tasks=set(), help_all=False): parser = argparse.ArgumentParser(add_help=False) for task_name, is_without_section, param_name, param_obj in Register.get_all_params(): as_active = task_name in active_tasks param_obj._add_to_cmdline_parser(parser, param_name, task_name, is_without_section=is_without_section, as_active=as_active, help_all=help_all) return parser
def _build_parser(active_tasks=set(), help_all=False): parser = argparse.ArgumentParser(add_help=False) # Unfortunately, we have to set it as optional to argparse, so we can # parse out stuff like `--module` before we call for `--help`. parser.add_argument('task', nargs='?', help='Task family to run. Is not optional.') for task_name, is_without_section, param_name, param_obj in Register.get_all_params(): as_active = task_name in active_tasks param_obj._add_to_cmdline_parser(parser, param_name, task_name, is_without_section=is_without_section, as_active=as_active, help_all=help_all) return parser
def _build_parser(active_tasks=set()): parser = argparse.ArgumentParser(add_help=False) for task_name, is_without_section, param_name, param_obj in Register.get_all_params( ): add = functools.partial(param_obj._add_to_cmdline_parser, parser, param_name, task_name, is_without_section=is_without_section) add(glob=True) if task_name in active_tasks: add(glob=False) return parser