sequence
stringlengths
492
15.9k
code
stringlengths
75
8.58k
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:formatFlow; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 10; 5, 14; 5, 18; 5, 22; 5, 75; 5, 84; 5, 245; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:result; 9, string:""; 10, expression_statement; 10, 11; ...
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[...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:train; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:training_set; 6, default_parameter; 6, 7; 6, 8; 7, identifier:iterations; 8, integer:500; 9, block; 9, 10; 9, 177; 9, 189; 9, 201; 9, 210; 9, 221; 9, 232; 9, 236; 9, 311;...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:__cost; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:params; 6, identifier:phase; 7, identifier:X; 8, block; 8, 9; 8, 18; 8, 43; 8, 48; 8, 53; 8, 133; 8, 168; 8, 220; 8, 268; 8, 275; 8, 279; 8, 283; 8, 437; 8, 449; 9...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:insert_many; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:it; 6, block; 6, 7; 6, 13; 6, 19; 6, 26; 6, 141; 6, 180; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:unique_indexes; 10, attribute; 10, 11; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_query_attr_sort_fn; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:attr_val; 6, block; 6, 7; 6, 13; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 12; 9, pattern_list; 9, 10; 9, 11; 10, identifier:attr; 11, identifier: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
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:sort; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:reverse; 8, False; 9, block; 9, 10; 9, 227; 10, if_statement; 10, 11; 10, 19; 10, 207; 11, call; 11, 12; 11, 13; 12, i...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:select; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:fields; 6, dictionary_splat_pattern; 6, 7; 7, identifier:exprs; 8, block; 8, 9; 8, 18; 8, 41; 8, 62; 8, 66; 8, 114; 8, 130; 8, 136; 8, 169; 9, expression_statement; 9, 1...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:csv_import; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:self; 5, identifier:csv_source; 6, default_parameter; 6, 7; 6, 8; 7, identifier:encoding; 8, string:'utf-8'; 9, default_parameter; 9, 10; 9, 11; 10, identifier:tran...
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', ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:csv_export; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:csv_dest; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fieldnames; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:encoding; 11, string:"UTF-8"...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:json_import; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:source; 6, default_parameter; 6, 7; 6, 8; 7, identifier:encoding; 8, string:"UTF-8"; 9, default_parameter; 9, 10; 9, 11; 10, identifier:transforms; 11...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:json_export; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:dest; 6, default_parameter; 6, 7; 6, 8; 7, identifier:fieldnames; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:encoding; 11, string:"UTF-8"; 1...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:groupby; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:keyexpr; 6, dictionary_splat_pattern; 6, 7; 7, identifier:outexprs; 8, block; 8, 9; 8, 68; 8, 75; 8, 95; 8, 101; 8, 123; 8, 180; 9, if_statement; 9, 10; 9, 15; 9, 41; 9...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:dump_counts; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:out; 7, attribute; 7, 8; 7, 9; 8, identifier:sys; 9, identifier:stdout; 10, default_parameter; 10, 11; 10, 12; 11, identi...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:as_table; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fn; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:col; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, ident...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:remove_edge; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:u; 6, identifier:v; 7, block; 7, 8; 7, 17; 7, 27; 7, 33; 7, 48; 7, 77; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:print; 11, argument_list...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 39; 2, function_name:get_stats_str; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 3, 25; 3, 28; 3, 31; 3, 34; 3, 37; 4, default_parameter; 4, 5; 4, 6; 5, identifier:list_; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:newlines; 9, False;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:search_module; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:mod; 5, identifier:pat; 6, default_parameter; 6, 7; 6, 8; 7, identifier:ignore_case; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:recursive; 11, False; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:instancelist; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:obj_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:check; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:shared_attrs; 10, None; 11, block; 11, 12; 11, 455; 12, cl...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:merge_rows; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:key; 6, default_parameter; 6, 7; 6, 8; 7, identifier:merge_scalars; 8, True; 9, block; 9, 10; 9, 15; 9, 26; 9, 41; 9, 56; 9, 70; 9, 83; 9, 87; 9, 301; 9, 312; 9, 318...
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...
0, module; 0, 1; 1, ERROR; 1, 2; 1, 98; 1, 115; 1, 131; 1, 145; 2, function_definition; 2, 3; 2, 4; 2, 7; 2, 59; 3, function_name:_inject_execstr; 4, parameters; 4, 5; 4, 6; 5, identifier:modname; 6, identifier:import_tuples; 7, ERROR; 7, 8; 7, 31; 7, 40; 7, 41; 7, 44; 7, 46; 8, if_statement; 8, 9; 8, 12; 8, 21; 9, com...
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...
0, module; 0, 1; 1, ERROR; 1, 2; 1, 424; 2, function_definition; 2, 3; 2, 4; 2, 34; 3, function_name:dynamic_import; 4, parameters; 4, 5; 4, 6; 4, 7; 4, 10; 4, 13; 4, 16; 4, 19; 4, 22; 4, 25; 4, 28; 4, 31; 5, identifier:modname; 6, identifier:import_tuples; 7, default_parameter; 7, 8; 7, 9; 8, identifier:developing; 9,...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 21; 2, function_name:write_to; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 4, identifier:fpath; 5, identifier:to_write; 6, default_parameter; 6, 7; 6, 8; 7, identifier:aslines; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:verbose; 1...
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(...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:read_from; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:fpath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:aslines; 10, False; 11, default_parameter;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:load_cPkl; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:fpath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:n; 10, None; 11, block; 11, 12; 11, 19; 11, 38; 11, 130; 12, ex...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:save_hdf5; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:fpath; 5, identifier:data; 6, default_parameter; 6, 7; 6, 8; 7, identifier:verbose; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:compression; 11, string:'lzf'; 12, ...
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' % (...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:formatex; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:ex; 5, default_parameter; 5, 6; 5, 7; 6, identifier:msg; 7, string:'[!?] Caught exception'; 8, default_parameter; 8, 9; 8, 10; 9, identif...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:__send_rdy; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:connection; 6, identifier:command; 7, block; 7, 8; 7, 265; 7, 284; 7, 294; 7, 300; 7, 308; 7, 326; 7, 351; 8, if_statement; 8, 9; 8, 16; 8, 209; 9, comparison_operat...
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) " ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_instruction; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:instr; 6, block; 6, 7; 6, 14; 6, 23; 6, 52; 7, assert_statement; 7, 8; 8, parenthesized_expression; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11, argume...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:tokenize; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 12; 5, 22; 5, 26; 5, 30; 5, 50; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 11; 8, attribute; 8, 9; 8, 10; 9, identifier:self; 10, identifier:token_list; 11, list:...
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]...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:setup_repo; 3, parameters; 4, block; 4, 5; 4, 7; 4, 12; 4, 17; 4, 22; 4, 39; 4, 48; 4, 63; 4, 71; 4, 83; 4, 93; 4, 97; 4, 103; 4, 115; 4, 275; 5, expression_statement; 5, 6; 6, identifier:r; 7, expression_statement; 7, 8; 8, call; 8, 9; 8, 10; ...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 36; 2, function_name:generate2; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 3, 33; 4, identifier:func; 5, identifier:args_gen; 6, default_parameter; 6, 7; 6, 8; 7, identifier:kw_gen; 8, None; 9, default_parameter; 9, 10;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:buffered_generator; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:source_gen; 5, default_parameter; 5, 6; 5, 7; 6, identifier:buffer_size; 7, integer:2; 8, default_parameter; 8, 9; 8, 10; 9, identifier:use_multiprocessing; 10, False; 11, bloc...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:sort_window_ids; 3, parameters; 3, 4; 3, 5; 4, identifier:winid_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:order; 7, string:'mru'; 8, block; 8, 9; 8, 14; 8, 23; 8, 33; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 13; 1...
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
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:__infer_setup_kwargs; 3, parameters; 3, 4; 3, 5; 4, identifier:module; 5, identifier:kwargs; 6, block; 6, 7; 6, 13; 6, 23; 6, 41; 6, 59; 6, 79; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:name; 10, subscript; 10, 11...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:on_exception_report_input; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:func_; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:force; 9, False; 10, default_parameter; 10, 11; 10, 12; 11, identifier...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:accepts_scalar_input; 3, parameters; 3, 4; 4, identifier:func; 5, block; 5, 6; 5, 66; 5, 74; 6, decorated_definition; 6, 7; 6, 14; 7, decorator; 7, 8; 8, call; 8, 9; 8, 10; 9, identifier:ignores_exc_tb; 10, argument_list; 10, 11; 11, keyword_ar...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:preserve_sig; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:wrapper; 5, identifier:orig_func; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force; 8, False; 9, block; 9, 10; 9, 16; 9, 21; 9, 26; 9, 33; 9, 42; 9, 51; 9, 60; 9, 71; 9, 80; 9, 8...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:parse_timestamp; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:timestamp; 5, default_parameter; 5, 6; 5, 7; 6, identifier:zone; 7, string:'UTC'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:timestamp_format; 10, None; 11, block; 11, 12; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:load_cache; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 4, identifier:dpath; 5, identifier:fname; 6, identifier:cfgstr; 7, default_parameter; 7, 8; 7, 9; 8, identifier:ext; 9, string:'.cPkl'; 10, default_parameter; 10, 11; 10, 12; 11,...
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,)) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:cached_func; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 4, default_parameter; 4, 5; 4, 6; 5, identifier:fname; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:cache_dir; 9, string:'default'; 10, default_parameter; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:path_ndir_split; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:path_; 5, identifier:n; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force_unix; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:winroot; 11, string:'C...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:remove_files_in_dir; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:dpath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fname_pattern_list; 7, string:'*'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:recursive; 10, ...
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:')...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:remove_fpaths; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:fpaths; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, identifier:VERBOSE; 8, default_parameter; 8, 9; 8, 10; 9, identifier:quiet; 10, identifier:Q...
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)...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:checkpath; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:path_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, identifier:VERYVERBOSE; 8, default_parameter; 8, 9; 8, 10; 9, identifier:n; 10, None; 11, default_parameter; 11...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:glob; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:dpath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:pattern; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:recursive; 10, False; 11, ...
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, ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:list_images; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:img_dpath_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:ignore_list; 7, list:[]; 8, default_parameter; 8, 9; 8, 10; 9, identifier:recursive; 10, False; 11, de...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:matching_fpaths; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:dpath_list; 5, identifier:include_patterns; 6, default_parameter; 6, 7; 6, 8; 7, identifier:exclude_dirs; 8, list:[]; 9, default_parameter; 9, 10; 9, 11; 10, i...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:sed; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:regexpr; 5, identifier:repl; 6, default_parameter; 6, 7; 6, 8; 7, identifier:force; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:recur...
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'] ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 38; 2, function_name:grep; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 3, 32; 3, 35; 4, identifier:regex_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:recursive; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifie...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:find_lib_fpath; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:libname; 5, identifier:root_dir; 6, default_parameter; 6, 7; 6, 8; 7, identifier:recurse_down; 8, True; 9, default_parameter; 9, 10; 9, 11; 10, identifier:verbose; 11,...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:search_candidate_paths; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:candidate_path_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:candidate_name_list; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:priority_p...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:symlink; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:real_path; 5, identifier:link_path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:overwrite; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:on_error; 11, stri...
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(...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 13; 2, function_name:view_directory; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:dname; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:fname; 9, None; 10, default_parameter; 10, 11; 10, 12; 11, identifier:verbose; 12...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:__parse_cmd_args; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:args; 5, identifier:sudo; 6, identifier:shell; 7, block; 7, 8; 7, 36; 7, 229; 7, 265; 7, 301; 8, if_statement; 8, 9; 8, 29; 9, boolean_operator:and; 9, 10; 9, 22; 10, boolean_oper...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:cmd2; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:command; 5, default_parameter; 5, 6; 5, 7; 6, identifier:shell; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:detatch; 10, False; 11, default_parameter; 11, 12; 11...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:search_env_paths; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:fname; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key_list; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:verbose; 10, None; 11, block; 11, 12; 11, 14; 11, 19; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:partition_varied_cfg_list; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:cfg_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:default_cfg; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:recursive; 10, False; 11, block; 11, 12;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 32; 2, function_name:parse_cfgstr_list2; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 3, 29; 4, identifier:cfgstr_list; 5, default_parameter; 5, 6; 5, 7; 6, identifier:named_defaults_dict; 7, None; 8, default_parameter; 8, 9; 8, 10; 9...
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_...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:gridsearch_timer; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:func_list; 5, identifier:args_list; 6, default_parameter; 6, 7; 6, 8; 7, identifier:niters; 8, None; 9, dictionary_splat_pattern; 9, 10; 10, identifier:searchkw; 11, block;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:to_string_monkey; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:df; 5, default_parameter; 5, 6; 5, 7; 6, identifier:highlight_cols; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:latex; 10, False; 11, block; 11, 12; 12, try_stateme...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:translate; 3, parameters; 3, 4; 4, identifier:value; 5, block; 5, 6; 5, 15; 5, 24; 5, 36; 5, 63; 5, 120; 5, 212; 6, if_statement; 6, 7; 6, 12; 7, call; 7, 8; 7, 9; 8, identifier:isinstance; 9, argument_list; 9, 10; 9, 11; 10, identifier: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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:parse_keys; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:string; 5, default_parameter; 5, 6; 5, 7; 6, identifier:with_spaces; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:with_tabs; 10, False; 11, default_paramete...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 28; 2, function_name:get_argflag; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 3, 26; 4, identifier:argstr_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:default; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:help_; 10, strin...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:get_arg_dict; 3, parameters; 3, 4; 3, 7; 3, 11; 4, default_parameter; 4, 5; 4, 6; 5, identifier:argv; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:prefix_list; 9, list:['--']; 9, 10; 10, string:'--'; 11, default_parameter; 11, 12; ...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:__argv_flag_dec; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:func; 5, default_parameter; 5, 6; 5, 7; 6, identifier:default; 7, False; 8, default_parameter; 8, 9; 8, 10; 9, identifier:quiet; 10, identifier:QUIET; 11, default_parameter...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:include_file; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:path; 6, default_parameter; 6, 7; 6, 8; 7, identifier:include_dirs; 8, list:[]; 9, block; 9, 10; 10, if_statement; 10, 11; 10, 14; 11, attribute; 11, 12; 11, 13; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:resolve_simulation; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:fc; 6, identifier:ct; 7, block; 7, 8; 7, 73; 7, 193; 7, 257; 7, 337; 8, for_statement; 8, 9; 8, 10; 8, 15; 9, identifier:run; 10, attribute; 10, 11; 10, 14; ...
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, ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:order_derived_parameters; 3, parameters; 3, 4; 4, identifier:component; 5, block; 5, 6; 5, 18; 5, 22; 5, 26; 5, 41; 5, 45; 5, 49; 5, 124; 5, 142; 6, if_statement; 6, 7; 6, 15; 7, comparison_operator:==; 7, 8; 7, 14; 8, call; 8, 9; 8, 10; 9, ide...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:order_derived_variables; 3, parameters; 3, 4; 4, identifier:regime; 5, block; 5, 6; 5, 10; 5, 14; 5, 18; 5, 22; 5, 55; 5, 91; 5, 95; 5, 238; 5, 258; 6, expression_statement; 6, 7; 7, assignment; 7, 8; 7, 9; 8, identifier:ordering; 9, list:[]; 1...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:build_event_connections; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:component; 6, identifier:runnable; 7, identifier:structure; 8, block; 8, 9; 8, 30; 9, if_statement; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 1...
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()) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:build_foreach; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:component; 6, identifier:runnable; 7, identifier:foreach; 8, default_parameter; 8, 9; 8, 10; 9, identifier:name_mappings; 10, dictionary; 11, block; ...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:check_static_member_vars; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:class_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:fpath; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:only_init; 10, True; 11, block; 11, 12; 11, 17; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_funcnames_from_modpath; 3, parameters; 3, 4; 3, 5; 4, identifier:modpath; 5, default_parameter; 5, 6; 5, 7; 6, identifier:include_methods; 7, True; 8, block; 8, 9; 8, 14; 8, 165; 9, import_statement; 9, 10; 10, aliased_import; 10, 11; 10, 1...
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'] ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:is_defined_by_module; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:item; 5, identifier:module; 6, default_parameter; 6, 7; 6, 8; 7, identifier:parent; 8, None; 9, block; 9, 10; 9, 14; 9, 274; 10, expression_statement; 10, 11; 11, assignment; ...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:find_funcs_called_with_kwargs; 3, parameters; 3, 4; 3, 5; 4, identifier:sourcecode; 5, default_parameter; 5, 6; 5, 7; 6, identifier:target_kwargs_name; 7, string:'kwargs'; 8, block; 8, 9; 8, 11; 8, 14; 8, 20; 8, 29; 8, 33; 8, 39; 8, 83; 8, 399;...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_qt_set_leaf_data; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:qvar; 6, block; 6, 7; 6, 76; 6, 90; 6, 471; 7, if_statement; 7, 8; 7, 9; 8, identifier:VERBOSE_PREF; 9, block; 9, 10; 9, 15; 9, 20; 9, 27; 9, 38; 9, 51; 9, 65; 10, ...
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._...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:inject_all_external_modules; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:classname; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:allow_override; 10, string:'override+...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 27; 2, function_name:inject_func_as_method; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 4, identifier:self; 5, identifier:func; 6, default_parameter; 6, 7; 6, 8; 7, identifier:method_name; 8, None; 9, default_parameter; 9, 10; 9, 11; ...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:reload_class; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:verbose; 7, True; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reload_module; 10, True; 11, block; 11, 12; 11, 17; 11, 23; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:avl_join; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:t1; 5, identifier:t2; 6, identifier:node; 7, block; 7, 8; 7, 19; 7, 197; 8, if_statement; 8, 9; 8, 10; 9, identifier:DEBUG_JOIN; 10, block; 10, 11; 11, expression_statement; 11, 12; 12, c...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:git_sequence_editor_squash; 3, parameters; 3, 4; 4, identifier:fpath; 5, block; 5, 6; 5, 8; 5, 13; 5, 22; 5, 27; 5, 31; 5, 35; 5, 39; 5, 92; 5, 286; 5, 295; 5, 322; 5, 327; 6, expression_statement; 6, 7; 7, identifier:r; 8, import_statement; 8,...
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) ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 25; 2, function_name:build_proteintable; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 10; 3, 13; 3, 16; 3, 19; 3, 22; 4, identifier:pqdb; 5, identifier:headerfields; 6, identifier:mergecutoff; 7, default_parameter; 7, 8; 7, 9; 8, identifier:isobaric; 9, False; 10, de...
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_...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:start_logging; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:log_fpath; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:mode; 9, string:'a'; 10, default_parameter; 10, 11; 10, 12; 11, identif...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:list_all_eq_to; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:list_; 5, identifier:val; 6, default_parameter; 6, 7; 6, 8; 7, identifier:strict; 8, True; 9, block; 9, 10; 9, 39; 10, if_statement; 10, 11; 10, 22; 11, boolean_operator:and; 11, 12...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:isect; 3, parameters; 3, 4; 3, 5; 4, identifier:list1; 5, identifier:list2; 6, block; 6, 7; 6, 9; 6, 16; 7, expression_statement; 7, 8; 8, identifier:r; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:set2; 12, ca...
def isect(list1, list2): r set2 = set(list2) return [item for item in list1 if item in set2]
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:argsort; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 9, if_statement; 9, 10; 9, 24; 9, 59; 10, boolean_operator:and; 10, 11; 10, 17; 11, co...
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(...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:argsort2; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:indexable; 5, default_parameter; 5, 6; 5, 7; 6, identifier:key; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:reverse; 10, False; 11, block; 11, 12; 11, 52; 11, 102; 12, if_s...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:issorted; 3, parameters; 3, 4; 3, 5; 4, identifier:list_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:op; 7, attribute; 7, 8; 7, 9; 8, identifier:operator; 9, identifier:le; 10, block; 10, 11; 11, return_statement; 11, 12; 12, call; 12, 13...
def issorted(list_, op=operator.le): return all(op(list_[ix], list_[ix + 1]) for ix in range(len(list_) - 1))
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:depth_profile; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:list_; 5, default_parameter; 5, 6; 5, 7; 6, identifier:max_depth; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:compress_homogenous; 10, True; 11, default_...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:list_alignment; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:list1; 5, identifier:list2; 6, default_parameter; 6, 7; 6, 8; 7, identifier:missing; 8, False; 9, block; 9, 10; 9, 15; 9, 22; 9, 48; 10, import_statement; 10, 11; 11, aliased_import...
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
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_update_hasher; 3, parameters; 3, 4; 3, 5; 4, identifier:hasher; 5, identifier:data; 6, block; 6, 7; 6, 53; 7, if_statement; 7, 8; 7, 16; 7, 21; 7, 47; 8, call; 8, 9; 8, 10; 9, identifier:isinstance; 10, argument_list; 10, 11; 10, 12; 11, ident...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:hash_data; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:hashlen; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:alphabet; 10, None; 11, block; 11, 12; 11, 14; 11, 23; 11, 32; 1...
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...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:quick_search; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:name; 6, default_parameter; 6, 7; 6, 8; 7, identifier:platform; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:sort_by; 11, None; 12, de...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:smart_cast; 3, parameters; 3, 4; 3, 5; 4, identifier:var; 5, identifier:type_; 6, block; 6, 7; 6, 18; 6, 36; 6, 151; 7, if_statement; 7, 8; 7, 15; 8, boolean_operator:or; 8, 9; 8, 12; 9, comparison_operator:is; 9, 10; 9, 11; 10, identifier:type...
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: ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 2, function_name:dump_autogen_code; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 4, identifier:fpath; 5, identifier:autogen_text; 6, default_parameter; 6, 7; 6, 8; 7, identifier:codetype; 8, string:'python'; 9, default_parameter; 9, 10; 9, 11; 10, iden...
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...
0, module; 0, 1; 0, 356; 0, 361; 0, 370; 0, 381; 0, 390; 0, 400; 1, function_definition; 1, 2; 1, 3; 1, 23; 2, function_name:make_default_docstr; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 4, identifier:func; 5, default_parameter; 5, 6; 5, 7; 6, identifier:with_args; 7, True; 8, default_parameter; 8, ...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:sort_protein_group; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:pgroup; 5, identifier:sortfunctions; 6, identifier:sortfunc_index; 7, block; 7, 8; 7, 12; 7, 21; 7, 25; 7, 65; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, id...
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,...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:sort_amounts; 3, parameters; 3, 4; 3, 5; 4, identifier:proteins; 5, identifier:sort_index; 6, block; 6, 7; 6, 11; 6, 42; 7, expression_statement; 7, 8; 8, assignment; 8, 9; 8, 10; 9, identifier:amounts; 10, dictionary; 11, for_statement; 11, 12...
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(...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:compare_groups; 3, parameters; 3, 4; 3, 5; 4, identifier:true_groups; 5, identifier:pred_groups; 6, block; 6, 7; 6, 9; 6, 14; 6, 25; 6, 36; 6, 45; 6, 54; 6, 63; 6, 79; 6, 95; 6, 99; 6, 103; 6, 151; 6, 155; 6, 159; 6, 207; 6, 216; 6, 225; 6, 246...
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 ...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:colwise_diag_idxs; 3, parameters; 3, 4; 3, 5; 4, identifier:size; 5, default_parameter; 5, 6; 5, 7; 6, identifier:num; 7, integer:2; 8, block; 8, 9; 8, 11; 8, 16; 8, 36; 8, 68; 9, expression_statement; 9, 10; 10, identifier:r; 11, import_statem...
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