sequence
stringlengths
1.19k
35k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'formatFlow'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's'}, {...
def formatFlow(s): result = "" shifts = [] pos = 0 nextIsList = False def IsNextList(index, maxIndex, buf): if index == maxIndex: return False if buf[index + 1] == '<': return True if index < maxIndex - 1: if buf[index + 1] == '\n' and buf[...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'train'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 's...
def train(self, training_set, iterations=500): if len(training_set) > 2: self.__X = np.matrix([example[0] for example in training_set]) if self.__num_labels == 1: self.__y = np.matrix([example[1] for example in training_set]).reshape((-1, 1)) else: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__cost'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'valu...
def __cost(self, params, phase, X): params = self.__roll(params) a = np.concatenate((np.ones((X.shape[0], 1)), X), axis=1) calculated_a = [a] calculated_z = [0] for i, theta in enumerate(params): z = calculated_a[-1] * theta.transpose() calculated_z.append...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_many'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
def insert_many(self, it): unique_indexes = self._uniqueIndexes NO_SUCH_ATTR = object() new_objs = list(it) if unique_indexes: for ind in unique_indexes: ind_attr = ind.attr new_keys = dict((getattr(obj, ind_attr, NO_SUCH_ATTR), obj) for obj in...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_query_attr_sort_fn'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
def _query_attr_sort_fn(self, attr_val): attr, v = attr_val if attr in self._indexes: idx = self._indexes[attr] if v in idx: return len(idx[v]) else: return 0 else: return 1e9
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'se...
def sort(self, key, reverse=False): if isinstance(key, (basestring, list, tuple)): if isinstance(key, basestring): attrdefs = [s.strip() for s in key.split(',')] attr_orders = [(a.split()+['asc', ])[:2] for a in attrdefs] else: if isinstanc...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'select'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': '...
def select(self, fields, **exprs): fields = self._parse_fields_string(fields) def _make_string_callable(expr): if isinstance(expr, basestring): return lambda r: expr % r else: return expr exprs = dict((k, _make_string_callable(v)) for k, v ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_import'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'chi...
def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs): reader_args = dict((k, v) for k, v in kwargs.items() if k not in ['encoding', 'csv_source', ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'csv_export'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], ...
def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"): close_on_exit = False if isinstance(csv_dest, basestring): if PY_3: csv_dest = open(csv_dest, 'w', newline='', encoding=encoding) else: csv_dest = open(csv_dest, 'wb') c...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_import'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children...
def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject): class _JsonFileReader(object): def __init__(self, src): self.source = src def __iter__(self): current = '' for line in self.source: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'json_export'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [],...
def json_export(self, dest, fieldnames=None, encoding="UTF-8"): close_on_exit = False if isinstance(dest, basestring): if PY_3: dest = open(dest, 'w', encoding=encoding) else: dest = open(dest, 'w') close_on_exit = True try: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'groupby'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': ...
def groupby(self, keyexpr, **outexprs): if isinstance(keyexpr, basestring): keyattrs = keyexpr.split() keyfn = lambda o: tuple(getattr(o, k) for k in keyattrs) elif isinstance(keyexpr, tuple): keyattrs = (keyexpr[0],) keyfn = keyexpr[1] else: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_counts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [...
def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10): if len(self._pivot_attrs) == 1: out.write("Pivot: %s\n" % ','.join(self._pivot_attrs)) maxkeylen = max(len(str(k)) for k in self.keys()) maxvallen = colwidth keytally = {} for k, sub in ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'as_table'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], '...
def as_table(self, fn=None, col=None, col_label=None): if col_label is None: col_label = col if fn is None: fn = len if col_label is None: col_label = 'count' ret = Table() do_all(ret.create_index(attr) for attr in self._pivot_attrs) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_edge'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'valu...
def remove_edge(self, u, v): print('Dynamically removing uv=(%r, %r)' % (u, v)) self.graph.remove_edge(u, v) e = (u, v) if not self.forests[0].has_edge(u, v): return for i in reversed(range(0, self.level[e] + 1)): self.forests[i].remove_edge(u, v) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '39']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_stats_str'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22', '25', '28', '31', '34', '37']...
def get_stats_str(list_=None, newlines=False, keys=None, exclude_keys=[], lbl=None, precision=None, axis=0, stat_dict=None, use_nan=False, align=False, use_median=False, **kwargs): from utool.util_str import repr4 import utool as ut if stat_dict is None: stat_dict...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_module'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'childr...
def search_module(mod, pat, ignore_case=True, recursive=False, _seen=None): r if _seen is not None and mod in _seen: return [] import utool as ut reflags = re.IGNORECASE * ignore_case found_list = [name for name in dir(mod) if re.search(pat, name, flags=reflags)] if recursive: if...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'instancelist'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
def instancelist(obj_list, check=False, shared_attrs=None): class InstanceList_(object): def __init__(self, obj_list, shared_attrs=None): self._obj_list = [] self._shared_public_attrs = [] self._example_type = None if len(obj_list) > 0: import ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_rows'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def merge_rows(self, key, merge_scalars=True): import utool as ut unique_labels, groupxs = self.group_indicies(key) single_xs = [xs for xs in groupxs if len(xs) == 1] multi_xs = [xs for xs in groupxs if len(xs) > 1] singles = self.take(ut.flatten(single_xs)) multis = [sel...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '98', '115', '131', '145']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '7', '59']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': '_inject_execstr'}; {'id': '4', 'type': 'parameters',...
def _inject_execstr(modname, import_tuples): if modname == 'utool': injecter = 'util_inject' injecter_import = '' else: injecter_import = 'import utool' injecter = 'utool' injectstr_fmt = textwrap.dedent( r''' {injecter_import} print, rrr, profile = {i...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '424']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '34']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'dynamic_import'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7...
def dynamic_import(modname, import_tuples, developing=True, ignore_froms=[], dump=False, ignore_startswith=[], ignore_endswith=[], ignore_list=[], check_not_imported=True, return_initstr=False, verbose=False): if verbose: print('[UTIL_IMPORT] Running ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'write_to'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', ...
def write_to(fpath, to_write, aslines=False, verbose=None, onlyifdiff=False, mode='w', n=None): if onlyifdiff: import utool as ut if ut.hashstr(read_from(fpath)) == ut.hashstr(to_write): print('[util_io] * no difference') return verbose = _rectify_verb_write(...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'read_from'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'chi...
def read_from(fpath, verbose=None, aslines=False, strict=True, n=None, errors='replace'): r if n is None: n = __READ_TAIL_N__ verbose = _rectify_verb_read(verbose) if verbose: print('[util_io] * Reading text file: %r ' % util_path.tail(fpath, n=n)) try: if not util_path.check...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_cPkl'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def load_cPkl(fpath, verbose=None, n=None): verbose = _rectify_verb_read(verbose) if verbose: print('[util_io] * load_cPkl(%r)' % (util_path.tail(fpath, n=n),)) try: with open(fpath, 'rb') as file_: data = pickle.load(file_) except UnicodeDecodeError: if six.PY3: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'save_hdf5'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], '...
def save_hdf5(fpath, data, verbose=None, compression='lzf'): r import h5py verbose = _rectify_verb_write(verbose) if verbose: print('[util_io] * save_hdf5(%r, data)' % (util_path.tail(fpath),)) if verbose > 1: if isinstance(data, dict): print('[util_io] ... shapes=%r' % (...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'formatex'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id': '4', 'ty...
def formatex(ex, msg='[!?] Caught exception', prefix=None, key_list=[], locals_=None, iswarning=False, tb=False, N=0, keys=None, colored=None): r if prefix is None: prefix = get_caller_prefix(aserror=True, N=N) if locals_ is None: locals_ = get_parent_frame(N=N).f_l...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__send_rdy'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def __send_rdy(self, connection, command): if self.__consumer.original_rdy is None: node_count = self.__consumer.get_node_count_for_topic( connection.context.topic) self.__logger_rdy.debug("Calculating RDY: max_in_flight=(%d) " ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_instruction'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def add_instruction (self, instr): assert(isinstance(instr, Instruction)) self.instruction_list.append(instr) if instr.lhs not in self.defined_variables: if isinstance(instr.lhs, Variable): self.defined_variables.append(instr.lhs) if isinstance(instr, EqInstru...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tokenize'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, ...
def tokenize(self): self.token_list = [] ps = self.parse_string.strip() i = 0 last_token = None while i < len(ps) and ps[i].isspace(): i += 1 while i < len(ps): token = '' if ps[i].isalpha(): while i < len(ps) and (ps[i]...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_repo'}, {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '7', '12', '17', '22',...
def setup_repo(): r print('\n [setup_repo]!') from functools import partial import utool as ut code_dpath = ut.truepath(ut.get_argval('--code-dir', default='~/code')) _code_dpath = ut.unexpanduser(code_dpath) repo_fname = (ut.get_argval(('--repo', '--repo-name'), type_=str)) repo_dpath ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '36']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'generate2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24', '27', '30', '33']}; {'i...
def generate2(func, args_gen, kw_gen=None, ntasks=None, ordered=True, force_serial=False, use_pool=False, chunksize=None, nprocs=None, progkw={}, nTasks=None, verbose=None): r if verbose is None: verbose = 2 if ntasks is None: ntasks = nTasks if ntasks is None...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'buffered_generator'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [...
def buffered_generator(source_gen, buffer_size=2, use_multiprocessing=False): r if buffer_size < 2: raise RuntimeError("Minimal buffer_ size is 2!") if use_multiprocessing: print('WARNING seems to freeze if passed in a generator') if False: pool = multiprocessing.Pool(pro...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_window_ids'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def sort_window_ids(winid_list, order='mru'): import utool as ut winid_order = XCtrl.sorted_window_ids(order) sorted_win_ids = ut.isect(winid_order, winid_list) return sorted_win_ids
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__infer_setup_kwargs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], '...
def __infer_setup_kwargs(module, kwargs): name = kwargs['name'] packages = kwargs.get('packages', []) if name not in packages: packages.append(name) kwargs['packages'] = packages if 'version' not in kwargs: version = parse_package_for_version(name) kwargs['version'] = ver...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'on_exception_report_input'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter'...
def on_exception_report_input(func_=None, force=False, keys=None): def _closure_onexceptreport(func): if not ONEX_REPORT_INPUT and not force: return func @ignores_exc_tb(outer_wrapper=False) def wrp_onexceptreport(*args, **kwargs): try: return func(*ar...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'accepts_scalar_input'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def accepts_scalar_input(func): @ignores_exc_tb(outer_wrapper=False) def wrp_asi(self, input_, *args, **kwargs): if util_iter.isiterable(input_): return func(self, input_, *args, **kwargs) else: ret = func(self, [input_], *args, **kwargs) if ret is not None: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'preserve_sig'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
def preserve_sig(wrapper, orig_func, force=False): from utool._internal import meta_util_six from utool import util_str from utool import util_inspect if wrapper is orig_func: return orig_func orig_docstr = meta_util_six.get_funcdoc(orig_func) orig_docstr = '' if orig_docstr is None else...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_timestamp'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], ...
def parse_timestamp(timestamp, zone='UTC', timestamp_format=None): r if timestamp is None: return None use_delorean = True or six.PY2 if use_delorean: import delorean if not isinstance(timestamp, six.string_types): raise NotImplementedError('Unknown format: timestamp=%r' % (t...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_cache'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'chi...
def load_cache(dpath, fname, cfgstr, ext='.cPkl', verbose=None, enabled=True): if verbose is None: verbose = VERBOSE_CACHE if not USE_CACHE or not enabled: if verbose > 1: print('[util_cache] ... cache disabled: dpath=%s cfgstr=%r' % (basename(dpath), cfgstr,)) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cached_func'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13', '16', '19', '22']}; {'id': '4', 'type': 'default_...
def cached_func(fname=None, cache_dir='default', appname='utool', key_argx=None, key_kwds=None, use_cache=None, verbose=None): r if verbose is None: verbose = VERBOSE_CACHE def cached_closure(func): from utool import util_decor import utool as ut fname_ = util...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'path_ndir_split'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'chil...
def path_ndir_split(path_, n, force_unix=True, winroot='C:', trailing=True): r if not isinstance(path_, six.string_types): return path_ if n is None: cplat_path = ensure_crossplat_path(path_) elif n == 0: cplat_path = '' else: sep = '/' if force_unix else os.sep ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_files_in_dir'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identif...
def remove_files_in_dir(dpath, fname_pattern_list='*', recursive=False, verbose=VERBOSE, dryrun=False, ignore_errors=False): if isinstance(fname_pattern_list, six.string_types): fname_pattern_list = [fname_pattern_list] if verbose > 2: print('[util_path] Removing files:')...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_fpaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', ...
def remove_fpaths(fpaths, verbose=VERBOSE, quiet=QUIET, strict=False, print_caller=PRINT_CALLER, lbl='files'): import utool as ut if print_caller: print(util_dbg.get_caller_name(range(1, 4)) + ' called remove_fpaths') n_total = len(fpaths) _verbose = (not quiet and n_total > 0)...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'checkpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], ...
def checkpath(path_, verbose=VERYVERBOSE, n=None, info=VERYVERBOSE): r assert isinstance(path_, six.string_types), ( 'path_=%r is not a string. type(path_) = %r' % (path_, type(path_))) path_ = normpath(path_) if sys.platform.startswith('win32'): if path_.startswith('\\'): di...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'glob'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'iden...
def glob(dpath, pattern=None, recursive=False, with_files=True, with_dirs=True, maxdepth=None, exclude_dirs=[], fullpath=True, **kwargs): r gen = iglob(dpath, pattern, recursive=recursive, with_files=with_files, with_dirs=with_dirs, maxdepth=maxdepth, fullpath=fullpath, ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_images'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'c...
def list_images(img_dpath_, ignore_list=[], recursive=False, fullpath=False, full=None, sort=True): r if full is not None: fullpath = fullpath or full img_dpath_ = util_str.ensure_unicode(img_dpath_) img_dpath = realpath(img_dpath_) ignore_set = set(ignore_list) gname_lis...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'matching_fpaths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier',...
def matching_fpaths(dpath_list, include_patterns, exclude_dirs=[], greater_exclude_dirs=[], exclude_patterns=[], recursive=True): r if isinstance(dpath_list, six.string_types): dpath_list = [dpath_list] for dpath in dpath_list: for root, dname_list, fn...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sed'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4', 'type': 'identi...
def sed(regexpr, repl, force=False, recursive=False, dpath_list=None, fpath_list=None, verbose=None, include_patterns=None, exclude_patterns=[]): if include_patterns is None: include_patterns = ['*.py', '*.pyx', '*.pxi', '*.cxx', '*.cpp', '*.hxx', '*.hpp', '*.c', '*.h', '*.html', '*.tex'] ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'grep'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29', '32', '35']}; {'id': ...
def grep(regex_list, recursive=True, dpath_list=None, include_patterns=None, exclude_dirs=[], greater_exclude_dirs=None, inverse=False, exclude_patterns=[], verbose=VERBOSE, fpath_list=None, reflags=0, cache=None): r from utool import util_regex from utool import util_list if ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_lib_fpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'child...
def find_lib_fpath(libname, root_dir, recurse_down=True, verbose=False, debug=False): def get_lib_fname_list(libname): if sys.platform.startswith('win32'): libnames = ['lib' + libname + '.dll', libname + '.dll'] elif sys.platform.startswith('darwin'): libnames = ['lib' + libn...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_candidate_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier...
def search_candidate_paths(candidate_path_list, candidate_name_list=None, priority_paths=None, required_subpaths=[], verbose=None): import utool as ut if verbose is None: verbose = 0 if QUIET else 1 if verbose >= 1: print('[search_candida...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'symlink'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [...
def symlink(real_path, link_path, overwrite=False, on_error='raise', verbose=2): path = normpath(real_path) link = normpath(link_path) if verbose: print('[util_path] Creating symlink: path={} link={}'.format(path, link)) if os.path.islink(link): if verbose: print(...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'view_directory'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'children...
def view_directory(dname=None, fname=None, verbose=True): from utool.util_arg import STRICT from utool.util_path import checkpath if HAVE_PATHLIB and isinstance(dname, pathlib.Path): dname = str(dname) if verbose: print('[cplat] view_directory(%r) ' % dname) dname = os.getcwd() if dn...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__parse_cmd_args'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], ...
def __parse_cmd_args(args, sudo, shell): if isinstance(args, tuple) and len(args) == 1 and isinstance(args[0], tuple): args = args[0] if shell: if isinstance(args, six.string_types): pass elif isinstance(args, (list, tuple)) and len(args) > 1: args = ' '.join(arg...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cmd2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [],...
def cmd2(command, shell=False, detatch=False, verbose=False, verbout=None): import shlex if isinstance(command, (list, tuple)): raise ValueError('command tuple not supported yet') args = shlex.split(command, posix=not WIN32) if verbose is True: verbose = 2 if verbout is None: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'search_env_paths'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [],...
def search_env_paths(fname, key_list=None, verbose=None): r import utool as ut if key_list is None: key_list = [key for key in os.environ if key.find('PATH') > -1] print('key_list = %r' % (key_list,)) found = ut.ddict(list) for key in key_list: dpath_list = os.environ[key].sp...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'partition_varied_cfg_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'child...
def partition_varied_cfg_list(cfg_list, default_cfg=None, recursive=False): r import utool as ut if default_cfg is None: nonvaried_cfg = reduce(ut.dict_intersection, cfg_list) else: nonvaried_cfg = reduce(ut.dict_intersection, [default_cfg] + cfg_list) nonvaried_keys = list(nonvaried...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '32']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_cfgstr_list2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26', '29']}; {'id'...
def parse_cfgstr_list2(cfgstr_list, named_defaults_dict=None, cfgtype=None, alias_keys=None, valid_keys=None, expand_nested=True, strict=True, special_join_dict=None, is_nestedcfgtype=False, metadata=None): r import utool as ut cfg_combos_...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'gridsearch_timer'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children'...
def gridsearch_timer(func_list, args_list, niters=None, **searchkw): import utool as ut timings = ut.ddict(list) if niters is None: niters = len(args_list) if ut.is_funclike(args_list): get_args = args_list else: get_args = args_list.__getitem__ func_labels = searchkw.get...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_string_monkey'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [],...
def to_string_monkey(df, highlight_cols=None, latex=False): try: import pandas as pd import utool as ut import numpy as np import six if isinstance(highlight_cols, six.string_types) and highlight_cols == 'all': highlight_cols = np.arange(len(df.columns)) t...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'translate'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'value'}...
def translate(value): if isinstance(value, BaseValidator): return value if value is None: return Anything() if isinstance(value, type): return IsA(value) if type(value) in compat.func_types: real_value = value() return IsA(type(real_value), default=real_value) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse_keys'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children...
def parse_keys(string, with_spaces = False, with_tabs = False, with_newlines = False, modifiers = None): "Return the parsed keys" keys = [] if not modifiers: modifiers = [] index = 0 while index < len(string): c = string...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_argflag'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type'...
def get_argflag(argstr_, default=False, help_='', return_specified=None, need_prefix=True, return_was_specified=False, argv=None, debug=None, **kwargs): if argv is None: argv = sys.argv assert isinstance(default, bool), 'default must be boolean' argstr...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_arg_dict'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '11']}; {'id': '4', 'type': 'default_parameter', 'children':...
def get_arg_dict(argv=None, prefix_list=['--'], type_hints={}): r if argv is None: argv = sys.argv arg_dict = {} def startswith_prefix(arg): return any([arg.startswith(prefix) for prefix in prefix_list]) def argx_has_value(argv, argx): if argv[argx].find('=') > -1: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__argv_flag_dec'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children'...
def __argv_flag_dec(func, default=False, quiet=QUIET, indent=False): from utool import util_decor flagname = meta_util_six.get_funcname(func) if flagname.find('no') == 0: flagname = flagname[2:] flags = ( '--' + flagname.replace('_', '-'), '--' + flagname, ) @util_decor.i...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'include_file'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
def include_file(self, path, include_dirs = []): if self.include_includes: if self.debug: print("------------------ Including a file: %s"%path) inc_dirs = include_dirs if include_dirs else self.include_dirs parser = LEMSFileParser(self, inc_dirs, self.includ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_simulation'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': []...
def resolve_simulation(self, fc, ct): for run in ct.simulation.runs: try: run2 = Run(fc.component_references[run.component].referenced_component, run.variable, fc.parameters[run.increment].numeric_value, ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_derived_parameters'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
def order_derived_parameters(component): if len(component.derived_parameters) == 0: return [] ordering = [] dps = [] for dp in component.derived_parameters: dps.append(dp.name) maxcount = 5 count = maxcount while count > 0 and dps != []: count = count - 1 for ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'order_derived_variables'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
def order_derived_variables(regime): ordering = [] dvs = [] dvsnoexp = [] maxcount = 5 for dv in regime.derived_variables: if dv.expression_tree == None: dvsnoexp.append(dv.name) else: dvs.append(dv.name) for dv in regime.conditional_derived_variables: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_event_connections'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'chi...
def build_event_connections(self, component, runnable, structure): if self.debug: print("\n++++++++ Calling build_event_connections of %s with runnable %s, parent %s"%(component.id, runnable.id, runnable.parent)) for ec in structure.event_connections: if self.debug: print(ec.toxml()) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_foreach'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'childre...
def build_foreach(self, component, runnable, foreach, name_mappings = {}): if self.debug: print("\n++++++++ Calling build_foreach of %s with runnable %s, parent %s, name_mappings: %s"%(component.id, runnable.id, runnable.parent, name_mappings)) target_array = runnable.resolve_path(foreach.instances) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_static_member_vars'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'childr...
def check_static_member_vars(class_, fpath=None, only_init=True): import utool as ut if isinstance(class_, six.string_types): classname = class_ if fpath is None: raise Exception('must specify fpath') else: if not isinstance(class_, type): class_instance = cla...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_funcnames_from_modpath'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children':...
def get_funcnames_from_modpath(modpath, include_methods=True): import utool as ut if True: import jedi source = ut.read_from(modpath) definition_list = jedi.names(source) funcname_list = [definition.name for definition in definition_list if definition.type == 'function'] ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_defined_by_module'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': ...
def is_defined_by_module(item, module, parent=None): flag = False if isinstance(item, types.ModuleType): if not hasattr(item, '__file__'): try: import utool as ut name = ut.get_modname_from_modpath(module.__file__) flag = name in str(item) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_funcs_called_with_kwargs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'childre...
def find_funcs_called_with_kwargs(sourcecode, target_kwargs_name='kwargs'): r import ast sourcecode = 'from __future__ import print_function\n' + sourcecode pt = ast.parse(sourcecode) child_funcnamess = [] debug = False or VERYVERB_INSPECT if debug: print('\nInput:') print('t...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_qt_set_leaf_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
def _qt_set_leaf_data(self, qvar): if VERBOSE_PREF: print('') print('+--- [pref.qt_set_leaf_data]') print('[pref.qt_set_leaf_data] qvar = %r' % qvar) print('[pref.qt_set_leaf_data] _intern.name=%r' % self._intern.name) print('[pref.qt_set_leaf_data] _intern.type_=%r' % self._...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inject_all_external_modules'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier'...
def inject_all_external_modules(self, classname=None, allow_override='override+warn', strict=True): if classname is None: classname = self.__class__.__name__ NEW = True if NEW: classkey_list = [key for key in __CLASSTYPE_ATTRIBU...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '27']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'inject_func_as_method'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18', '21', '24']}; {'id': '4...
def inject_func_as_method(self, func, method_name=None, class_=None, allow_override=False, allow_main=False, verbose=True, override=None, force=False): if override is not None: allow_override = override if method_name is None: method_name = get...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'reload_class'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
def reload_class(self, verbose=True, reload_module=True): import utool as ut verbose = verbose or VERBOSE_CLASS classname = self.__class__.__name__ try: modname = self.__class__.__module__ if verbose: print('[class] reloading ' + classname + ' from ' + modname) if has...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'avl_join'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
def avl_join(t1, t2, node): if DEBUG_JOIN: print('-- JOIN node=%r' % (node,)) if t1 is None and t2 is None: if DEBUG_JOIN: print('Join Case 1') top = node elif t1 is None: if DEBUG_JOIN: print('Join Case 2') top = avl_insert_dir(t2, node, 0) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'git_sequence_editor_squash'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], ...
def git_sequence_editor_squash(fpath): r import utool as ut text = ut.read_from(fpath) print(text) prev_msg = None prev_dt = None new_lines = [] def get_commit_date(hashid): out, err, ret = ut.cmd('git show -s --format=%ci ' + hashid, verbose=False, quiet=True, pad_stdout=False) ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '25']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'build_proteintable'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22']}; {'id': '4', ...
def build_proteintable(pqdb, headerfields, mergecutoff, isobaric=False, precursor=False, probability=False, fdr=False, pep=False, genecentric=False): pdmap = create_featuredata_map(pqdb, genecentric=genecentric, psm_fill_fun=pinfo.add_...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'start_logging'}, {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'chi...
def start_logging(log_fpath=None, mode='a', appname='default', log_dir=None): r global __UTOOL_ROOT_LOGGER__ global __UTOOL_PRINT__ global __UTOOL_WRITE__ global __UTOOL_FLUSH__ global __CURRENT_LOG_FPATH__ if LOGGING_VERBOSE: print('[utool] start_logging()') if __UTOOL_ROOT_LOGG...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_all_eq_to'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
def list_all_eq_to(list_, val, strict=True): if util_type.HAVE_NUMPY and isinstance(val, np.ndarray): return all([np.all(item == val) for item in list_]) try: with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=FutureWarning) flags = [item == val fo...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'isect'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'list1'...
def isect(list1, list2): r set2 = set(list2) return [item for item in list1 if item in set2]
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort'}, {'id': '3', 'type': 'parameters', 'children': ['4', '6']}; {'id': '4', 'type': 'list_splat_pattern', 'children': ['5']}, {'...
def argsort(*args, **kwargs): if len(args) == 1 and isinstance(args[0], dict): dict_ = args[0] index_list = list(dict_.keys()) value_list = list(dict_.values()) return sortedby2(index_list, value_list) else: index_list = list(range(len(args[0]))) return sortedby2(...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'argsort2'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value'...
def argsort2(indexable, key=None, reverse=False): if isinstance(indexable, dict): vk_iter = ((v, k) for k, v in indexable.items()) else: vk_iter = ((v, k) for k, v in enumerate(indexable)) if key is None: indices = [k for v, k in sorted(vk_iter, reverse=reverse)] else: in...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'issorted'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'li...
def issorted(list_, op=operator.le): return all(op(list_[ix], list_[ix + 1]) for ix in range(len(list_) - 1))
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'depth_profile'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'child...
def depth_profile(list_, max_depth=None, compress_homogenous=True, compress_consecutive=False, new_depth=False): r if isinstance(list_, dict): list_ = list(list_.values()) level_shape_list = [] if not any(map(util_type.is_listlike, list_)): return len(list_) if False and new_depth: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'list_alignment'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'v...
def list_alignment(list1, list2, missing=False): import utool as ut item1_to_idx = make_index_lookup(list1) if missing: sortx = ut.dict_take(item1_to_idx, list2, None) else: sortx = ut.take(item1_to_idx, list2) return sortx
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_update_hasher'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value'...
def _update_hasher(hasher, data): if isinstance(data, (tuple, list, zip)): needs_iteration = True elif (util_type.HAVE_NUMPY and isinstance(data, np.ndarray) and data.dtype.kind == 'O'): needs_iteration = True else: needs_iteration = False if needs_iteration: SE...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'hash_data'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
def hash_data(data, hashlen=None, alphabet=None): r if alphabet is None: alphabet = ALPHABET_27 if hashlen is None: hashlen = HASH_LEN2 if isinstance(data, stringlike) and len(data) == 0: text = (alphabet[0] * hashlen) else: hasher = hashlib.sha512() _update_h...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'quick_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'childre...
def quick_search(self, name, platform=None, sort_by=None, desc=True): if platform is None: query_filter = "name:{0}".format(name) else: query_filter = "name:{0},platforms:{1}".format(name, platform) search_params = {"filter": query_filter} if sort_by is not None: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'smart_cast'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'v...
def smart_cast(var, type_): if type_ is None or var is None: return var try: if issubclass(type_, type(None)): return var except TypeError: pass if is_str(var): if type_ in VALID_BOOL_TYPES: return bool_from_str(var) elif type_ is slice: ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dump_autogen_code'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier...
def dump_autogen_code(fpath, autogen_text, codetype='python', fullprint=None, show_diff=None, dowrite=None): import utool as ut if dowrite is None: dowrite = ut.get_argflag(('-w', '--write')) if show_diff is None: show_diff = ut.get_argflag('--diff') num_context_lin...
{'id': '0', 'type': 'module', 'children': ['1', '356', '361', '370', '381', '390', '400']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_default_docstr'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', ...
def make_default_docstr(func, with_args=True, with_ret=True, with_commandline=True, with_example=True, with_header=False, with_debug=False): r import utool as ut funcinfo = ut.util_inspect.infer_function_info(func) argname_list = funcinfo.argname_list ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_protein_group'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': []...
def sort_protein_group(pgroup, sortfunctions, sortfunc_index): pgroup_out = [] subgroups = sortfunctions[sortfunc_index](pgroup) sortfunc_index += 1 for subgroup in subgroups: if len(subgroup) > 1 and sortfunc_index < len(sortfunctions): pgroup_out.extend(sort_protein_group(subgroup,...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_amounts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': ...
def sort_amounts(proteins, sort_index): amounts = {} for protein in proteins: amount_x_for_protein = protein[sort_index] try: amounts[amount_x_for_protein].append(protein) except KeyError: amounts[amount_x_for_protein] = [protein] return [v for k, v in sorted(...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'compare_groups'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value'...
def compare_groups(true_groups, pred_groups): r import utool as ut true = {frozenset(_group) for _group in true_groups} pred = {frozenset(_group) for _group in pred_groups} common = true.intersection(pred) true_sets = true.difference(common) pred_sets = pred.difference(common) pred_conn ...
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'colwise_diag_idxs'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
def colwise_diag_idxs(size, num=2): r import utool as ut diag_idxs = ut.iprod(*[range(size) for _ in range(num)]) upper_diag_idxs = [ tup[::-1] for tup in diag_idxs if all([a > b for a, b in ut.itertwo(tup)]) ] return upper_diag_idxs