sequence
stringlengths
546
16.2k
code
stringlengths
108
19.3k
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, 8; 5, 12; 5, 16; 5, 17; 5, 21; 5, 22; 5, 26; 5, 79; 5, 88; 5, 249; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, i...
def formatFlow(s): """Reformats the control flow output""" result = "" shifts = [] # positions of opening '<' pos = 0 # symbol position in a line nextIsList = False def IsNextList(index, maxIndex, buf): if index == maxIndex: return False if buf[index + 1]...
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, 12; 9, 179; 9, 191; 9, 203; 9, 212; 9, 223; 9, 234; 9, 238; ...
def train(self, training_set, iterations=500): """Trains itself using the sequence data.""" 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...
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, 11; 8, 20; 8, 45; 8, 46; 8, 51; 8, 52; 8, 57; 8, 58; 8, 145; 8, 180; 8, 232; 8, 233; 8, 283; 8, 29...
def __cost(self, params, phase, X): """Computes activation, cost function, and derivative.""" params = self.__roll(params) a = np.concatenate((np.ones((X.shape[0], 1)), X), axis=1) # This is a1 calculated_a = [a] # a1 is at index 0, a_n is at index n-1 calculated_z = [0] # There ...
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, 9; 6, 15; 6, 16; 6, 22; 6, 29; 6, 144; 6, 183; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 1...
def insert_many(self, it): """Inserts a collection of objects into the table.""" unique_indexes = self._uniqueIndexes # [ind for ind in self._indexes.values() if ind.is_unique] NO_SUCH_ATTR = object() new_objs = list(it) if unique_indexes: for ind in unique_indexes: ...
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, 9; 6, 15; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 14; 11, pattern_list...
def _query_attr_sort_fn(self, attr_val): """Used to order where keys by most selective key first""" attr, v = attr_val if attr in self._indexes: idx = self._indexes[attr] if v in idx: return len(idx[v]) else: return 0 el...
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, 12; 9, 235; 10, expression_statement; 10, 11; 11, comment; 12, if_statement; 12...
def sort(self, key, reverse=False): """Sort Table in place, using given fields as sort key. @param key: if this is a string, it is a comma-separated list of field names, optionally followed by 'desc' to indicate descending sort instead of the default ascending sort; if a ...
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, 11; 8, 20; 8, 43; 8, 64; 8, 68; 8, 116; 8, 132; 8, 138; 8, 171; 9, expression_statemen...
def select(self, fields, **exprs): """ Create a new table containing a subset of attributes, with optionally newly-added fields computed from each rec in the original table. @param fields: list of strings, or single space-delimited string, listing attribute name to be included in the ...
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): """Imports the contents of a CSV-formatted file into this table. @param csv_source: CSV file - if a string is given, the file with that name will be opened, read, and closed; if a file ...
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"): """Exports the contents of the table to a CSV-formatted file. @param csv_dest: CSV file - if a string is given, the file with that name will be opened, written, and closed; if a file object is given, then that object ...
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): """Imports the contents of a JSON data file into this table. @param source: JSON data file - if a string is given, the file with that name will be opened, read, and closed; if a file object is given...
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"): """Exports the contents of the table to a JSON-formatted file. @param dest: output file - if a string is given, the file with that name will be opened, written, and closed; if a file object is given, then that object ...
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, 11; 8, 70; 8, 77; 8, 97; 8, 103; 8, 125; 8, 182; 9, expression_statement; 9, 10; ...
def groupby(self, keyexpr, **outexprs): """simple prototype of group by, with support for expressions in the group-by clause and outputs @param keyexpr: grouping field and optional expression for computing the key value; if a string is passed @type keyexpr: stri...
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): """Dump out the summary counts of entries in this pivot table as a tabular listing. @param out: output stream to write to @param count_fn: (default=len) function for computing value for each pivot cell @param colw...
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): """Dump out the summary counts of this pivot table as a Table. """ if col_label is None: col_label = col if fn is None: fn = len if col_label is None: col_label = 'count' re...
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, 10; 7, 11; 7, 20; 7, 30; 7, 36; 7, 37; 7, 54; 7, 55; 7, 56; 7, 85; 7, 86; 7, 87; 7, 88; 8, expression_statement; 8, 9; 9, com...
def remove_edge(self, u, v): """ Using notation where 0 is top level Intuitively speaking, when the level of a nontree edge is increased, it is because we have discovered that its end points are close enough in F to fit in a smaller tree on a higher level. """ # ...
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): """ Returns the string version of get_stats DEPRICATE in favor of ut.repr3(ut.get_stats(.....
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""" Searches module functions, classes, and constants for members matching a pattern. Args: mod (module): live python module pat (str): regular expression Returns: list: found_list CommandLine...
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, 14; 11, 460...
def instancelist(obj_list, check=False, shared_attrs=None): """ Executes methods and attribute calls on a list of objects of the same type Bundles a list of object of the same type into a single object. The new object contains the same functions as each original object but applies them to each elem...
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, 12; 9, 17; 9, 28; 9, 43; 9, 58; 9, 72; 9, 85; 9, 89; 9, 316; 9, 327;...
def merge_rows(self, key, merge_scalars=True): """ Uses key as a unique index an merges all duplicates rows. Use cast_column to modify types of columns before merging to affect behavior of duplicate rectification. Args: key: row to merge on merge_scalars...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_inject_execstr; 3, parameters; 3, 4; 3, 5; 4, identifier:modname; 5, identifier:import_tuples; 6, block; 6, 7; 6, 9; 6, 34; 6, 43; 6, 53; 6, 63; 6, 67; 6, 71; 6, 114; 6, 131; 6, 147; 6, 161; 7, expression_statement; 7, 8; 8, comment; 9, if_sta...
def _inject_execstr(modname, import_tuples): """ Injection and Reload String Defs """ if modname == 'utool': # Special case import of the util_inject module injecter = 'util_inject' injecter_import = '' else: # Normal case implicit import of util_inject injecter_impor...
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:dynamic_import; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:modname; 5, identifier:import_tuples; 6, default_parameter; 6, 7; 6, 8; 7, identifier:developing; 8, True; 9, default_paramet...
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): """ MAIN ENTRY POINT Dynamically import ...
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): """ Writes text to a file. Automatically encodes text as utf8. Args: fpath (str): file path to_write (str): text to write (must be unicode text) aslines (bool): if True to_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""" Reads text from a file. Automatically returns utf8. Args: fpath (str): file path aslines (bool): if True returns list of lines verbose (bool): verbosity flag Returns: str: text fr...
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, 14; 11, 21; 11, 40; 11, 133...
def load_cPkl(fpath, verbose=None, n=None): """ Loads a pickled file with optional verbosity. Aims for compatibility between python2 and python3. TestPickleExtentsSimple: >>> def makedata_simple(): >>> data = np.empty((500, 2 ** 20), dtype=np.uint8) + 1 >>> return data ...
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""" Restricted save of data using hdf5. Can only save ndarrays and dicts of ndarrays. Args: fpath (str): data (ndarray): compression (str): DEFLATE/GZIP - standard LZF - fast SHUFF...
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""" Formats an exception with relevant info Args: ex (Exception): exception to print msg (unicode): a message to displa...
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, 10; 7, 281; 7, 282; 7, 283; 7, 302; 7, 303; 7, 304; 7, 305; 7, 306; 7, 307; 7, 308; 7, 318; 7, 324; 7, 332; 7, ...
def __send_rdy(self, connection, command): """Determine the RDY value, and set it. It can either be a static value a callback, or None. If it's None, we'll calculate the value based on our limits and connection counts. The documentation recommends starting with (1), but since we are alw...
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, 9; 6, 16; 6, 25; 6, 54; 7, expression_statement; 7, 8; 8, comment; 9, assert_statement; 9, 10; 10, parenthesized_expression; 10, 11; 11, cal...
def add_instruction (self, instr): """ Adds the argument instruction in the list of instructions of this basic block. Also updates the variable lists (used_variables, defined_variables) """ assert(isinstance(instr, Instruction)) self.instruction_list.append(instr) ...
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, 8; 5, 14; 5, 24; 5, 28; 5, 32; 5, 52; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11...
def tokenize(self): """ Tokenizes the string stored in the parser object into a list of tokens. """ self.token_list = [] ps = self.parse_string.strip() i = 0 last_token = None while i < len(ps) and ps[i].isspace(): i += 1 wh...
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, 13; 4, 18; 4, 23; 4, 24; 4, 41; 4, 50; 4, 65; 4, 73; 4, 85; 4, 95; 4, 99; 4, 105; 4, 117; 4, 278; 5, expression_statement; 5, 6; 6, comment; 7, expression_statement; 7, 8; 8, call; 8, 9...
def setup_repo(): r""" Creates default structure for a new repo CommandLine: python -m utool setup_repo --repo=dtool --codedir=~/code python -m utool setup_repo --repo=dtool --codedir=~/code python -m utool setup_repo --repo=ibeis-flukematch-module --codedir=~/code --modname=ibeis_...
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""" Interfaces to either multiprocessing or futures. Esentially maps ``args_gen`` onto ``func`` using poo...
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""" Generator that runs a slow source generator in a separate process. My generate function still seems faster on test cases. However, this function is more flexible in its compatability. Args: source_gen (itera...
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, 11; 8, 16; 8, 25; 8, 35; 9, expression_statement; 9, 10; 10, comment; 11, import_st...
def sort_window_ids(winid_list, order='mru'): """ Orders window ids by most recently used """ 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, 9; 6, 10; 6, 11; 6, 12; 6, 13; 6, 14; 6, 20; 6, 21; 6, 22; 6, 23; 6, 24; 6, 25; 6, 26; 6, 36; 6, 54; 6, 72; 6, 73; 6, 74; 6, 75; 6, ...
def __infer_setup_kwargs(module, kwargs): """ Implicitly build kwargs based on standard info """ # Get project name from the module #if 'name' not in kwargs: # kwargs['name'] = module.__name__ #else: # raise AssertionError('must specify module name!') name = kwargs['name'] # Our pr...
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): """ If an error is thrown in the scope of this function's stack frame then the decorated function name and the arguments passed to it will be printed to the utool print function. """ def _closure_onexceptreport(func): if ...
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, 8; 5, 9; 5, 76; 5, 84; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, decorated_definition; 9, 10; 9, 17; 9, 18; 10, decorator; 10, 11; 11, call; 11, 1...
def accepts_scalar_input(func): """ DEPRICATE in favor of accepts_scalar_input2 only accepts one input as vector accepts_scalar_input is a decorator which expects to be used on class methods. It lets the user pass either a vector or a scalar to a function, as long as the function treats everyt...
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, 12; 9, 13; 9, 14; 9, 15; 9, 21; 9, 26; 9, 31; 9, 39; 9, 48; 9, 5...
def preserve_sig(wrapper, orig_func, force=False): """ Decorates a wrapper function. It seems impossible to presever signatures in python 2 without eval (Maybe another option is to write to a temporary module?) Args: wrapper: the function wrapping orig_func to change the signature of ...
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""" pip install delorean Args: timestamp (str): timestampe string zone (bool): assumes input is zone (only if not specified) and gives output in zone. CommandLine: python -m utool.util_time --test-p...
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): """ Loads data using util_io, but smartly constructs a filename """ if verbose is None: verbose = VERBOSE_CACHE if not USE_CACHE or not enabled: if verbose > 1: print('[util_cache] ... cache di...
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""" Wraps a function with a Cacher object uses a hash of arguments as input Args: fname (str): file name (defaults to function name) cache_di...
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""" Shows only a little bit of the path. Up to the n bottom-level directories TODO: rename to path_tail? ndir_split? Returns: (str) the trailing n paths of path. CommandLine: python3 -m utool.util_path -...
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): """ Removes files matching a pattern from a directory """ if isinstance(fname_pattern_list, six.string_types): fname_pattern_list = [fname_pattern_list] ...
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'): """ Removes multiple file paths """ import utool as ut if print_caller: print(util_dbg.get_caller_name(range(1, 4)) + ' called remove_fpaths') n_total = len(fp...
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""" verbose wrapper around ``os.path.exists`` Returns: true if ``path_`` exists on the filesystem show only the top `n` directories Args: path_ (str): path string verbose (bool): verbosity flag(default = ...
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""" Globs directory for pattern DEPRICATED: use pathlib.glob instead Args: dpath (str): directory path or pattern pattern (str or ...
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""" Returns a list of images in a directory. By default returns relative paths. TODO: rename to ls_images TODO: Change all instances of fullpath to full Args: img_dpath_ (st...
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""" walks dpath lists returning all directories that match the requested pattern. Args: dpath_list (list): inc...
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=[]): """ Python implementation of sed. NOT FINISHED searches and replaces text in files Args: regexpr (str): regx patterns to find ...
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""" greps for patterns Python implementation of grep. NOT FINISHE...
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): """ Search for the library """ def get_lib_fname_list(libname): """ input <libname>: library name (e.g. 'hesaff', not 'libhesaff') returns <libnames>: list of plausible library file names """ ...
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): """ searches for existing paths that meed a requirement Args: candidate_path_list (list): list of paths to check....
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): """ Attempt to create a symbolic link. TODO: Can this be fixed on windows? Args: path (str): path to real file or directory link_path (str): path to desired location for symlink ...
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): """ View a directory in the operating system file browser. Currently supports windows explorer, mac open, and linux nautlius. Args: dname (str): directory name fname (str): a filename to select in the directory (nautlius only) ...
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, 10; 7, 11; 7, 39; 7, 234; 7, 276; 7, 277; 7, 278; 7, 279; 7, 280; 7, 281; 7, 317; 8, expression_statement; 8, 9; ...
def __parse_cmd_args(args, sudo, shell): """ When shell is True, Popen will only accept strings. No tuples Shell really should not be true. Returns: args suitable for subprocess.Popen I'm not quite sure what those are yet. Plain old string seem to work well? But I remember need...
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): """ Trying to clean up cmd Args: command (str): string command shell (bool): if True, process is run in shell detatch (bool): if True, process is run in background verbose (int): verbosity mode ...
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""" Searches your PATH to see if fname exists Args: fname (str): file name to search for (can be glob pattern) CommandLine: python -m utool search_env_paths --fname msvcr*.dll python -m utool search_env_paths --fname '*...
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""" Separates varied from non-varied parameters in a list of configs TODO: partition nested configs CommandLine: python -m utool.util_gridsearch --exec-partition_varied_cfg_list:0 Example: >>> # ENABLE_DO...
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""" Parses config strings. By looki...
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): """ Times a series of functions on a series of inputs args_list is a list should vary the input sizes can also be a func that take a count param items in args_list list or returned by the func should be a tuple so it can be u...
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; 11, 14; 12, exp...
def to_string_monkey(df, highlight_cols=None, latex=False): """ monkey patch to pandas to highlight the maximum value in specified cols of a row Example: >>> from utool.experimental.pandas_highlight import * >>> import pandas as pd >>> df = pd.DataFrame( >>> np.array([[...
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, 8; 5, 17; 5, 26; 5, 38; 5, 65; 5, 124; 5, 216; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, call; 9, 10; 9, 11; 10, identifier:isinstance; 11...
def translate(value): """ Translates given schema from "pythonic" syntax to a validator. Usage:: >>> translate(str) IsA(str) >>> translate('hello') IsA(str, default='hello') """ if isinstance(value, BaseValidator): return value if value is None: ...
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 = stri...
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): """ Checks if the commandline has a flag or a corresponding noflag Args: argstr_ (str, list, or tu...
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""" Yet another way for parsing args CommandLine: python -m utool.util_arg --exec-get_arg_dict python -m utool.util_arg --test-get_arg_dict Example: >>> # ENABLE_DOCTEST >>> from utool.util_arg import * #...
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): """ Logic for controlling if a function gets called based on command line """ from utool import util_decor flagname = meta_util_six.get_funcname(func) if flagname.find('no') == 0: flagname = flagname[2:] flags = ( ...
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; 9, 12; 10, expression_statement; 10, 11; 11, comment; 12, if_state...
def include_file(self, path, include_dirs = []): """ Includes a file into the current model. @param path: Path to the file to be included. @type path: str @param include_dirs: Optional alternate include search path. @type include_dirs: list(str) """ if s...
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, 10; 7, 75; 7, 147; 7, 200; 7, 264; 7, 344; 8, expression_statement; 8, 9; 9, comment; 10, for_statement; 10, 11; 10,...
def resolve_simulation(self, fc, ct): """ Resolve simulation specifications. """ for run in ct.simulation.runs: try: run2 = Run(fc.component_references[run.component].referenced_component, run.variable, fc...
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, 8; 5, 20; 5, 24; 5, 28; 5, 43; 5, 47; 5, 51; 5, 127; 5, 145; 5, 146; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 17; 9, comparis...
def order_derived_parameters(component): """ Finds ordering of derived_parameters. @param component: Component containing derived parameters. @type component: lems.model.component.Component @return: Returns ordered list of derived parameters. @rtype: list(string) @raise SimBuildError: Rai...
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, 8; 5, 12; 5, 16; 5, 20; 5, 24; 5, 57; 5, 93; 5, 97; 5, 240; 5, 260; 5, 261; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assi...
def order_derived_variables(regime): """ Finds ordering of derived_variables. @param regime: Dynamics Regime containing derived variables. @type regime: lems.model.dynamics.regime @return: Returns ordered list of derived variables. @rtype: list(string) @raise SimBuildError: Raised when a ...
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, 11; 8, 32; 8, 33; 9, expression_statement; 9, 10; 10, comment; 11, ...
def build_event_connections(self, component, runnable, structure): """ Adds event connections to a runnable component based on the structure specifications in the component model. @param component: Component model containing structure specifications. @type component: lems.model....
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 = {}): """ Iterate over ForEach constructs and process nested elements. @param component: Component model containing structure specifications. @type component: lems.model.component.FatComponent @param runnable:...
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, 14; 1...
def check_static_member_vars(class_, fpath=None, only_init=True): """ class_ can either be live object or a classname # fpath = ut.truepath('~/code/ibeis/ibeis/viz/viz_graph2.py') # classname = 'AnnotGraphWidget' """ #import ast #import astor import utool as ut if isinstance(class_...
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, 11; 8, 16; 8, 169; 9, expression_statement; 9, 10; 10, comment; 11, impor...
def get_funcnames_from_modpath(modpath, include_methods=True): """ Get all functions defined in module """ import utool as ut if True: import jedi source = ut.read_from(modpath) #script = jedi.Script(source=source, source_path=modpath, line=source.count('\n') + 1) def...
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, 12; 9, 16; 9, 281; 10, expression_statement; 10, 11; 11, comme...
def is_defined_by_module(item, module, parent=None): """ Check if item is directly defined by a module. This check may be prone to errors. """ flag = False if isinstance(item, types.ModuleType): if not hasattr(item, '__file__'): try: # hack for cv2 and xfeatur...
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, 405;...
def find_funcs_called_with_kwargs(sourcecode, target_kwargs_name='kwargs'): r""" Finds functions that are called with the keyword `kwargs` variable CommandLine: python3 -m utool.util_inspect find_funcs_called_with_kwargs Example: >>> # ENABLE_DOCTEST >>> import utool as ut ...
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, 9; 6, 79; 6, 93; 6, 487; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 11; 10, identifier:VERBOSE_PREF; 11, block; ...
def _qt_set_leaf_data(self, qvar): """ Sets backend data using QVariants """ 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('[pre...
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): """ dynamically injects registered module methods into a class instance FIXME: naming convention and use this in all places where this clas is ...
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): """ Injects a function into an object as a method Wraps func as a bound method of self. Then injects func i...
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, 14; 11, 19; 1...
def reload_class(self, verbose=True, reload_module=True): """ special class reloading function This function is often injected as rrr of classes """ import utool as ut verbose = verbose or VERBOSE_CLASS classname = self.__class__.__name__ try: modname = self.__class__.__module__ ...
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, 10; 7, 21; 7, 201; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11; 10, 12; 11, identifier:DEBUG_JOIN; 12,...
def avl_join(t1, t2, node): """ Joins two trees `t1` and `t1` with an intermediate key-value pair CommandLine: python -m utool.experimental.euler_tour_tree_avl avl_join Example: >>> # DISABLE_DOCTEST >>> from utool.experimental.euler_tour_tree_avl import * # NOQA >>> s...
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, 9; 5, 14; 5, 23; 5, 24; 5, 29; 5, 30; 5, 31; 5, 32; 5, 33; 5, 34; 5, 35; 5, 36; 5, 40; 5, 44; 5, 48; 5, 106; 5, 302; 5, 311; 5, 338; 5, 339; 5, 340; ...
def git_sequence_editor_squash(fpath): r""" squashes wip messages CommandLine: python -m utool.util_git --exec-git_sequence_editor_squash Example: >>> # DISABLE_DOCTEST >>> # SCRIPT >>> import utool as ut >>> from utool.util_git import * # NOQA >>> fpat...
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): """Fetches proteins and quants from joined lookup table, loops through them and when all of a protein's quants have ...
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""" Overwrites utool print functions to use a logger CommandLine: python -m utool.util_logging --test-start_logging:0 python -m utool.util_logging --test-start_logging:1 Example0: >>> # DISABLE_DOCTE...
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, 12; 9, 41; 10, expression_statement; 10, 11; 11, comment; 12, if_state...
def list_all_eq_to(list_, val, strict=True): """ checks to see if list is equal everywhere to a value Args: list_ (list): val : value to check against Returns: True if all items in the list are equal to val """ if util_type.HAVE_NUMPY and isinstance(val, np.ndarray): ...
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, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:set2; 12, call; 1...
def isect(list1, list2): r""" returns list1 elements that are also in list2. preserves order of list1 intersect_ordered Args: list1 (list): list2 (list): Returns: list: new_list Example: >>> # DISABLE_DOCTEST >>> from utool.util_list import * # NOQA ...
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; 8, 11; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 11, 26; ...
def argsort(*args, **kwargs): """ like np.argsort but for lists Args: *args: multiple lists to sort by **kwargs: reverse (bool): sort order is descending if True else acscending CommandLine: python -m utool.util_list argsort Example: >>> # DISABLE_DOCTE...
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, 14; 11, 15; 11, 55; 1...
def argsort2(indexable, key=None, reverse=False): """ Returns the indices that would sort a indexable object. This is similar to np.argsort, but it is written in pure python and works on both lists and dictionaries. Args: indexable (list or dict): indexable to sort by Returns: ...
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; 10, 13; 11, expression_statement; 11, 12; 12, ...
def issorted(list_, op=operator.le): """ Determines if a list is sorted Args: list_ (list): op (func): sorted operation (default=operator.le) Returns: bool : True if the list is sorted """ 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""" Returns a nested list corresponding the shape of the nested structures lists represent depth, tuples represent shape. The values of the items do not matter. only the lengths. Args: ...
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, 12; 9, 17; 9, 24; 9, 50; 10, expression_statement; 10, 11; 11, com...
def list_alignment(list1, list2, missing=False): """ Assumes list items are unique Args: list1 (list): a list of unique items to be aligned list2 (list): a list of unique items in a desired ordering missing (bool): True if list2 can contain items not in list1 Returns: l...
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, 9; 6, 56; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 18; 9, 23; 9, 50; 10, call; 10, 11; 10, 12; 11, identifier:i...
def _update_hasher(hasher, data): """ This is the clear winner over the generate version. Used by hash_data Ignore: import utool rng = np.random.RandomState(0) # str1 = rng.rand(0).dumps() str1 = b'SEP' str2 = rng.rand(10000).dumps() for timer in utool.Ti...
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""" Get a unique hash depending on the state of the data. Args: data (object): any sort of loosely organized data hashlen (None): (default = None) alphabet (None): (default = None) Returns: str: text - hash string ...
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): """ Quick search method that allows you to search for a game using only the title and the platform :param name: string :param platform: int :param sort_by: string :param desc: bool :ret...
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, 9; 6, 10; 6, 11; 6, 12; 6, 13; 6, 14; 6, 15; 6, 16; 6, 27; 6, 28; 6, 46; 6, 164; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, commen...
def smart_cast(var, type_): """ casts var to type, and tries to be clever when var is a string Args: var (object): variable to cast type_ (type or str): type to attempt to cast to Returns: object: CommandLine: python -m utool.util_type --exec-smart_cast Exampl...
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): """ Helper that write a file if -w is given on command line, otherwise it just prints it out. It has the opption of comparing a diff to the file. """ import utool as ut ...
0, module; 0, 1; 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, 9; 8, 10; 9, identifier:with_ret; 10, True; 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""" Tries to make a sensible default docstr so the user can fill things in without typing too much # TODO: Interl...
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, 10; 7, 14; 7, 23; 7, 27; 7, 67; 8, expression_statement; 8, 9; 9, comment; 10, expression_s...
def sort_protein_group(pgroup, sortfunctions, sortfunc_index): """Recursive function that sorts protein group by a number of sorting functions.""" pgroup_out = [] subgroups = sortfunctions[sortfunc_index](pgroup) sortfunc_index += 1 for subgroup in subgroups: if len(subgroup) > 1 and sor...
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, 9; 6, 13; 6, 44; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identi...
def sort_amounts(proteins, sort_index): """Generic function for sorting peptides and psms. Assumes a higher number is better for what is passed at sort_index position in protein.""" amounts = {} for protein in proteins: amount_x_for_protein = protein[sort_index] try: amounts[...
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, 37; 6, 46; 6, 55; 6, 64; 6, 65; 6, 81; 6, 97; 6, 98; 6, 99; 6, 103; 6, 107; 6, 156; 6, 157; 6, 161; 6...
def compare_groups(true_groups, pred_groups): r""" Finds how predictions need to be modified to match the true grouping. Notes: pred_merges - the merges needed that would need to be done for the pred_groups to match true_groups. pred_hybrid - the hybrid split/merges needed that ...
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, 12; 8, 13; 8, 14; 8, 19; 8, 39; 8, 40; 8, 41; 8, 74; 8, 75; 8, 76; 9, expression_stat...
def colwise_diag_idxs(size, num=2): r""" dont trust this implementation or this function name Args: size (int): Returns: ?: upper_diag_idxs CommandLine: python -m utool.util_alg --exec-colwise_diag_idxs --size=5 --num=2 python -m utool.util_alg --exec-colwise_diag_...