def decorator(func): name = func.__name__ target = Maker.inst().get_target(name) target.def_conf = conf return func
def decorator(func): conf = kwargs.get('conf' , None ) bind = kwargs.get('bind' , None) default = kwargs.get('default', False) depends = kwargs.get('depends', None ) desc = kwargs.get('desc' , None ) or func.__doc__ name = kwargs.get('name' , None ) or func.__name__ target = Maker.inst().get_target(name) if target.func and bind != 'override': report.error("target already bound: '{}'", name) return target.func = func if conf: if isinstance(conf, dict): conf = makeconf.from_dict(conf) target.def_conf = conf if default: if Maker.inst().def_target: report.warn("default target set more than once.") Maker.inst().def_target = target if depends: # Add dependencies that are not already in the target's dependency # list. target.depends.extend(x for x in depends if x not in target.depends) if desc: desc = desc.replace('\n', '').replace('\r', '').strip() i = len(desc) while True: desc = desc.replace(' ', ' ') j = len(desc) if i == j: break i = j target.desc = desc return func
def print_targets(): targets = sorted(Maker.inst().targets, key=lambda t: t.name) if len(targets) == 0: return print("\nTargets:") n = 0 for target in targets: # Add one since we also add a space or an asterisk to the target name # when printing it. n = max(len(target.name) + 1, n) s1 = " {: <" + str(n) + "}" s2 = s1 + " -" maxlen = 72 - n for target in targets: default = target is Maker.inst().def_target desc = target.desc name = " " + target.name if not default else "*" + target.name s = s2 if desc else s1 print(s.format(name), end='') if desc: words = desc.split(' ') desc = '' while len(words) > 0: while len(words) > 0 and len(desc) + len(words[0]) < maxlen: desc += words[0] + " " words = words[1:] print(desc) desc = ' ' * (n + 4) else: print('') print('')
def decorator(func): depends = args name = func.__name__ target = Maker.inst().get_target(name) if depends: # Add dependencies that are not already in the target's dependency # list. target.depends.extend(x for x in depends if x not in target.depends) return func
def print_usage(): name = os.path.split(sys.argv[0])[1] s = "[target]" if Maker.inst().def_target else "<target>" print(( """ Usage: python {} [options] {} Options: --no-color - disable text color --no-exit - do not exit automatically after making --no-warn - do not display warnings --targets - show available targets --version - show pymake3 version """).format(name, s))
def pymake3(conf=None, args=None): targets = sorted(t.name for t in Maker.inst().targets) parser = argparse.ArgumentParser() parser.add_argument("todo", nargs="*", choices=targets, default=[]) parser.add_argument("--conf", help="set the configuration to use") parser.add_argument("--no-color", action="store_true") parser.add_argument("--targets", action="store_true") parser.add_argument("--version", action="store_true") if argcomplete is not None: argcomplete.autocomplete(parser) args = parser.parse_args() if args.conf: options.option_conf(args.conf) options.disable_color = args.no_color if args.version: options.option_version() return if args.targets: info.print_targets() return if conf and isinstance(conf, dict): conf = makeconf.from_dict(conf) conf = conf or options.conf or makeconf.from_dict({}) if options.conf: conf = makeconf.merge(conf, options.conf) Maker.inst().check_targets() report_problems() targets = args.todo if not targets: targets = [None] for name in targets: if not name and not Maker.inst().def_target: println("\nNo target specified and there is no default target.") info.print_targets() sys.exit(EXIT_NO_MAKE) try: Maker.inst().make(name, conf) except NoSuchTargetError as e: fatal("no such target: '{}'", e.target_name)
def decorator(func): target = Maker.inst().get_target(name) target.pre_funcs.append(func) return func