def __init__(self): def get_wrapped(fun): @wraps(fun[1]) def wrapped(*args, **kwargs): # args = list(args) # args.pop(0) #remove self r = fun[1](*args, **kwargs) return weval(r) return wrapped methods = inspect.getmembers(mwl, predicate=inspect.isfunction) for i, mwl_method in enum(methods): self.__dict__[mwl_method[0]] = get_wrapped(mwl_method)
def _process_includes(self): inputs = self._raw lines = inputs.split('\n') includes = [] for idx, line in enum(lines): if 'INCLUDE' in line: new_js = JS( line.split(':')[1].replace('"', '').replace( "'", '').strip())._process_includes() includes.append((idx, new_js)) for i in includes: # lines will now be multiline strings lines[i[0]] = i[1] return '\n'.join(lines)
def __init__(self): self.__dict__['_'] = SimpleNamespace() self._.exprs = [] self._.pending_if_condition = None self._.pending_if_branch = None self._.pending_else_branch = None def get_wrapped(fun): @wraps(fun[1]) def wrapped(*args, **kwargs): # args = list(args) # args.pop(0) #remove self r = fun[1](*args, **kwargs) self._.exprs.append(r) return wrapped methods = inspect.getmembers(mwl, predicate=inspect.isfunction) for i, mwl_method in enum(methods): self.__dict__[mwl_method[0]] = get_wrapped(mwl_method)
def FormatWLInput(ss): f_s = '' OPEN_Ps = [] OPEN_Cs = [] OPEN_Bs = [] OPENS = ['(', '{', '['] CLOSES = [')', '}', ']'] in_str = False fragments = [] for ii, cc in enum(ss): if in_str: in_str = cc != '"' else: in_str = cc == '"' if cc == '(': OPEN_Ps.append(ii) elif cc == '{': OPEN_Cs.append(ii) elif cc == '[': OPEN_Bs.append(ii) elif cc == ',': pass elif cc == ')': fragments.append((OPEN_Ps.pop(), ii)) elif cc == '}': fragments.append((OPEN_Cs.pop(), ii)) elif cc == ']': fragments.append((OPEN_Bs.pop(), ii)) elif cc == ';': pass for ii, f in enum(fragments): fragments[ii] = list(f) + [f[1] - f[0]] frag_for_i = [] for ii in itr(ss): added = False for f in fragments: if f[0] == ii or f[1] == ii: frag_for_i.append(f) added = True break if not added: frag_for_i.append(None) in_str = False opening = False closed = False THRESHOLD = 10 for ii, cc in enum(ss): newline_after = False newline_before = False frag = None if in_str: in_str = cc != '"' else: in_str = cc == '"' if cc in OPENS: opening = True if cc in [',', ';']: newline_after = True frag = (0, 0, 100) if opening and cc not in OPENS: newline_before = True opening = False frag = frag_for_i[ii - 1] if closed and cc not in CLOSES: closed = False if not closed and cc in CLOSES: newline_before = True frag = frag_for_i[ii] closed = True if newline_before and frag[2] >= THRESHOLD: f_s += '\n' f_s += cc if newline_after and frag[2] >= THRESHOLD: f_s += '\n' return f_s
def _get_cfg(self): assert len(self.registered_flags()) == len(set(self.registered_flags())) freecfg = File('freecfg.json').load() prof = 'default' cfg = 'default' changes = {} flags = [] cell = False for idx, a in enum(sys.argv): if idx == 0: continue elif a.startswith('--'): k, v = tuple(a.replace('--', '').split('=')) if k == 'tic': continue changes[k] = v elif a.startswith('-'): k, v = tuple(a.replace('-', '').split('=')) if k == 'prof': prof = v elif k == 'cfg': cfg = v else: err('arguments with one dash (-) need to be prof= or cfg=') elif cell or a in self.registered_flags(): if a == 'cell': cell = True flags += [a] else: err(f'invalid argument:{a} please see README') prof = Project.CFG['profiles'][prof] cfg = Project.CFG['configs'][cfg] for k in listkeys(prof): if k in listkeys(cfg): prof_ntrain = prof[k] for i, n in enum(cfg[k]): if isstr(n) and n[0] == 'i': cfg[k][i] = prof_ntrain[int(n[1])] cfg = {**prof, **cfg, 'FLAGS': flags} for k, v in listitems(changes): if k not in listkeys(cfg): err(f'invalid -- arguments: {k}, please see {Project.CFG.name} for configuration options') if isinstance(cfg[k], bool): v = bool(int(v)) cfg[k] = v # hello from freecomp for k, v in listitems(freecfg): log(f'freecfg: {k}:{v}') cfg[k] = v # cfg['EPOCHS'] = freecfg['EPOCHS'] return obj(cfg)