repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
quikmile/trellio | trellio/utils/decorators.py | retry | def retry(exceptions, tries=5, delay=1, backoff=2, logger=None):
"""
Retry calling the decorated function using an exponential backoff.
Args:
exceptions: The exception to check. may be a tuple of
exceptions to check.
tries: Number of times to try (not retry) before giving up.
... | python | def retry(exceptions, tries=5, delay=1, backoff=2, logger=None):
"""
Retry calling the decorated function using an exponential backoff.
Args:
exceptions: The exception to check. may be a tuple of
exceptions to check.
tries: Number of times to try (not retry) before giving up.
... | [
"def",
"retry",
"(",
"exceptions",
",",
"tries",
"=",
"5",
",",
"delay",
"=",
"1",
",",
"backoff",
"=",
"2",
",",
"logger",
"=",
"None",
")",
":",
"def",
"deco_retry",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"async",
"def",
"f_retr... | Retry calling the decorated function using an exponential backoff.
Args:
exceptions: The exception to check. may be a tuple of
exceptions to check.
tries: Number of times to try (not retry) before giving up.
delay: Initial delay between retries in seconds.
backoff: Backo... | [
"Retry",
"calling",
"the",
"decorated",
"function",
"using",
"an",
"exponential",
"backoff",
"."
] | e8b050077562acf32805fcbb9c0c162248a23c62 | https://github.com/quikmile/trellio/blob/e8b050077562acf32805fcbb9c0c162248a23c62/trellio/utils/decorators.py#L21-L57 | train | Decorator to retry a function in a sequence of exceptions. |
glormph/msstitch | src/app/lookups/sqlite/protpeptable.py | ProtPepTable.get_unique_gene_psms | def get_unique_gene_psms(self, genetable, fields, firstjoin):
"""Uniques the results from get_proteins_psms so each PSM as defined
by gene ID / setname / psm_id will only occur once"""
lastgene = None
gpsms_out, gp_ids = [], []
for gpsm in self.get_proteins_psms(genetable, fields... | python | def get_unique_gene_psms(self, genetable, fields, firstjoin):
"""Uniques the results from get_proteins_psms so each PSM as defined
by gene ID / setname / psm_id will only occur once"""
lastgene = None
gpsms_out, gp_ids = [], []
for gpsm in self.get_proteins_psms(genetable, fields... | [
"def",
"get_unique_gene_psms",
"(",
"self",
",",
"genetable",
",",
"fields",
",",
"firstjoin",
")",
":",
"lastgene",
"=",
"None",
"gpsms_out",
",",
"gp_ids",
"=",
"[",
"]",
",",
"[",
"]",
"for",
"gpsm",
"in",
"self",
".",
"get_proteins_psms",
"(",
"genet... | Uniques the results from get_proteins_psms so each PSM as defined
by gene ID / setname / psm_id will only occur once | [
"Uniques",
"the",
"results",
"from",
"get_proteins_psms",
"so",
"each",
"PSM",
"as",
"defined",
"by",
"gene",
"ID",
"/",
"setname",
"/",
"psm_id",
"will",
"only",
"occur",
"once"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/lookups/sqlite/protpeptable.py#L182-L198 | train | Yields the unique PSM IDs for each gene. |
glormph/msstitch | src/app/lookups/sqlite/protpeptable.py | ProtPepTable.prepare_mergetable_sql | def prepare_mergetable_sql(self, precursor=False, isobaric=False,
probability=False, fdr=False, pep=False):
"""Dynamically build SQL query to generate entries for the multi-set
merged protein and peptide tables. E.g.
SELECT g.gene_acc, pc.channel_name, pc.amount_p... | python | def prepare_mergetable_sql(self, precursor=False, isobaric=False,
probability=False, fdr=False, pep=False):
"""Dynamically build SQL query to generate entries for the multi-set
merged protein and peptide tables. E.g.
SELECT g.gene_acc, pc.channel_name, pc.amount_p... | [
"def",
"prepare_mergetable_sql",
"(",
"self",
",",
"precursor",
"=",
"False",
",",
"isobaric",
"=",
"False",
",",
"probability",
"=",
"False",
",",
"fdr",
"=",
"False",
",",
"pep",
"=",
"False",
")",
":",
"featcol",
"=",
"self",
".",
"colmap",
"[",
"se... | Dynamically build SQL query to generate entries for the multi-set
merged protein and peptide tables. E.g.
SELECT g.gene_acc, pc.channel_name, pc.amount_psms_name,
giq.quantvalue giq.amount_psms gfdr.fdr
FROM genes AS g
JOIN biosets AS bs
JOIN gene_tables AS gt ON ... | [
"Dynamically",
"build",
"SQL",
"query",
"to",
"generate",
"entries",
"for",
"the",
"multi",
"-",
"set",
"merged",
"protein",
"and",
"peptide",
"tables",
".",
"E",
".",
"g",
"."
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/lookups/sqlite/protpeptable.py#L224-L298 | train | Dynamically build the SQL query to generate the entries for the multi - set
merged protein and peptide tables. |
Erotemic/utool | utool/util_iter.py | wrap_iterable | def wrap_iterable(obj):
"""
Returns:
wrapped_obj, was_scalar
"""
was_scalar = not isiterable(obj)
wrapped_obj = [obj] if was_scalar else obj
return wrapped_obj, was_scalar | python | def wrap_iterable(obj):
"""
Returns:
wrapped_obj, was_scalar
"""
was_scalar = not isiterable(obj)
wrapped_obj = [obj] if was_scalar else obj
return wrapped_obj, was_scalar | [
"def",
"wrap_iterable",
"(",
"obj",
")",
":",
"was_scalar",
"=",
"not",
"isiterable",
"(",
"obj",
")",
"wrapped_obj",
"=",
"[",
"obj",
"]",
"if",
"was_scalar",
"else",
"obj",
"return",
"wrapped_obj",
",",
"was_scalar"
] | Returns:
wrapped_obj, was_scalar | [
"Returns",
":",
"wrapped_obj",
"was_scalar"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L17-L24 | train | Wrap an iterable into a list. |
Erotemic/utool | utool/util_iter.py | next_counter | def next_counter(start=0, step=1):
r"""
Args:
start (int): (default = 0)
step (int): (default = 1)
Returns:
func: next_
CommandLine:
python -m utool.util_iter --test-next_counter
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQ... | python | def next_counter(start=0, step=1):
r"""
Args:
start (int): (default = 0)
step (int): (default = 1)
Returns:
func: next_
CommandLine:
python -m utool.util_iter --test-next_counter
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQ... | [
"def",
"next_counter",
"(",
"start",
"=",
"0",
",",
"step",
"=",
"1",
")",
":",
"count_gen",
"=",
"it",
".",
"count",
"(",
"start",
",",
"step",
")",
"next_",
"=",
"functools",
".",
"partial",
"(",
"six",
".",
"next",
",",
"count_gen",
")",
"return... | r"""
Args:
start (int): (default = 0)
step (int): (default = 1)
Returns:
func: next_
CommandLine:
python -m utool.util_iter --test-next_counter
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> start = 1
>>> ste... | [
"r",
"Args",
":",
"start",
"(",
"int",
")",
":",
"(",
"default",
"=",
"0",
")",
"step",
"(",
"int",
")",
":",
"(",
"default",
"=",
"1",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L27-L51 | train | r Returns the next counter of the next item in the list |
Erotemic/utool | utool/util_iter.py | itake_column | def itake_column(list_, colx):
""" iterator version of get_list_column """
if isinstance(colx, list):
# multi select
return ([row[colx_] for colx_ in colx] for row in list_)
else:
return (row[colx] for row in list_) | python | def itake_column(list_, colx):
""" iterator version of get_list_column """
if isinstance(colx, list):
# multi select
return ([row[colx_] for colx_ in colx] for row in list_)
else:
return (row[colx] for row in list_) | [
"def",
"itake_column",
"(",
"list_",
",",
"colx",
")",
":",
"if",
"isinstance",
"(",
"colx",
",",
"list",
")",
":",
"# multi select",
"return",
"(",
"[",
"row",
"[",
"colx_",
"]",
"for",
"colx_",
"in",
"colx",
"]",
"for",
"row",
"in",
"list_",
")",
... | iterator version of get_list_column | [
"iterator",
"version",
"of",
"get_list_column"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L68-L74 | train | iterator version of get_list_column |
Erotemic/utool | utool/util_iter.py | iget_list_column_slice | def iget_list_column_slice(list_, start=None, stop=None, stride=None):
""" iterator version of get_list_column """
if isinstance(start, slice):
slice_ = start
else:
slice_ = slice(start, stop, stride)
return (row[slice_] for row in list_) | python | def iget_list_column_slice(list_, start=None, stop=None, stride=None):
""" iterator version of get_list_column """
if isinstance(start, slice):
slice_ = start
else:
slice_ = slice(start, stop, stride)
return (row[slice_] for row in list_) | [
"def",
"iget_list_column_slice",
"(",
"list_",
",",
"start",
"=",
"None",
",",
"stop",
"=",
"None",
",",
"stride",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"start",
",",
"slice",
")",
":",
"slice_",
"=",
"start",
"else",
":",
"slice_",
"=",
"s... | iterator version of get_list_column | [
"iterator",
"version",
"of",
"get_list_column"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L80-L86 | train | iterator version of get_list_column |
Erotemic/utool | utool/util_iter.py | iter_window | def iter_window(iterable, size=2, step=1, wrap=False):
r"""
iterates through iterable with a window size
generalizeation of itertwo
Args:
iterable (iter): an iterable sequence
size (int): window size (default = 2)
wrap (bool): wraparound (default = False)
Returns:
i... | python | def iter_window(iterable, size=2, step=1, wrap=False):
r"""
iterates through iterable with a window size
generalizeation of itertwo
Args:
iterable (iter): an iterable sequence
size (int): window size (default = 2)
wrap (bool): wraparound (default = False)
Returns:
i... | [
"def",
"iter_window",
"(",
"iterable",
",",
"size",
"=",
"2",
",",
"step",
"=",
"1",
",",
"wrap",
"=",
"False",
")",
":",
"# it.tee may be slow, but works on all iterables",
"iter_list",
"=",
"it",
".",
"tee",
"(",
"iterable",
",",
"size",
")",
"if",
"wrap... | r"""
iterates through iterable with a window size
generalizeation of itertwo
Args:
iterable (iter): an iterable sequence
size (int): window size (default = 2)
wrap (bool): wraparound (default = False)
Returns:
iter: returns windows in a sequence
CommandLine:
... | [
"r",
"iterates",
"through",
"iterable",
"with",
"a",
"window",
"size",
"generalizeation",
"of",
"itertwo"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L89-L143 | train | r Returns an iterator over the items in a sequence of size with a generalization of itertwo
|
Erotemic/utool | utool/util_iter.py | iter_compress | def iter_compress(item_iter, flag_iter):
"""
iter_compress - like numpy compress
Args:
item_iter (list):
flag_iter (list): of bools
Returns:
list: true_items
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1,... | python | def iter_compress(item_iter, flag_iter):
"""
iter_compress - like numpy compress
Args:
item_iter (list):
flag_iter (list): of bools
Returns:
list: true_items
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1,... | [
"def",
"iter_compress",
"(",
"item_iter",
",",
"flag_iter",
")",
":",
"# TODO: Just use it.compress",
"true_items",
"=",
"(",
"item",
"for",
"(",
"item",
",",
"flag",
")",
"in",
"zip",
"(",
"item_iter",
",",
"flag_iter",
")",
"if",
"flag",
")",
"return",
"... | iter_compress - like numpy compress
Args:
item_iter (list):
flag_iter (list): of bools
Returns:
list: true_items
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1, 2, 3, 4, 5]
>>> flag_iter = [False, True, Tr... | [
"iter_compress",
"-",
"like",
"numpy",
"compress"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L232-L255 | train | iter_compress - like numpy compress
|
Erotemic/utool | utool/util_iter.py | ifilterfalse_items | def ifilterfalse_items(item_iter, flag_iter):
"""
ifilterfalse_items
Args:
item_iter (list):
flag_iter (list): of bools
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1, 2, 3, 4, 5]
>>> flag_iter = [False, True, ... | python | def ifilterfalse_items(item_iter, flag_iter):
"""
ifilterfalse_items
Args:
item_iter (list):
flag_iter (list): of bools
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1, 2, 3, 4, 5]
>>> flag_iter = [False, True, ... | [
"def",
"ifilterfalse_items",
"(",
"item_iter",
",",
"flag_iter",
")",
":",
"false_items",
"=",
"(",
"item",
"for",
"(",
"item",
",",
"flag",
")",
"in",
"zip",
"(",
"item_iter",
",",
"flag_iter",
")",
"if",
"not",
"flag",
")",
"return",
"false_items"
] | ifilterfalse_items
Args:
item_iter (list):
flag_iter (list): of bools
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> item_iter = [1, 2, 3, 4, 5]
>>> flag_iter = [False, True, True, False, True]
>>> false_items = ifilterfalse_... | [
"ifilterfalse_items"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L261-L280 | train | Function to filter false items in the node tree |
Erotemic/utool | utool/util_iter.py | iter_multichunks | def iter_multichunks(iterable, chunksizes, bordermode=None):
"""
CommandLine:
python -m utool.util_iter --test-iter_multichunks
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> import utool as ut
>>> iterable = list(range(20))
>>> c... | python | def iter_multichunks(iterable, chunksizes, bordermode=None):
"""
CommandLine:
python -m utool.util_iter --test-iter_multichunks
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> import utool as ut
>>> iterable = list(range(20))
>>> c... | [
"def",
"iter_multichunks",
"(",
"iterable",
",",
"chunksizes",
",",
"bordermode",
"=",
"None",
")",
":",
"chunksize",
"=",
"reduce",
"(",
"operator",
".",
"mul",
",",
"chunksizes",
")",
"for",
"chunk",
"in",
"ichunks",
"(",
"iterable",
",",
"chunksize",
",... | CommandLine:
python -m utool.util_iter --test-iter_multichunks
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_iter import * # NOQA
>>> import utool as ut
>>> iterable = list(range(20))
>>> chunksizes = (3, 2, 3)
>>> bordermode = 'cycle'
>>> genres... | [
"CommandLine",
":",
"python",
"-",
"m",
"utool",
".",
"util_iter",
"--",
"test",
"-",
"iter_multichunks"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L295-L337 | train | This function returns a generator that yields multichunks in the given iterable. |
Erotemic/utool | utool/util_iter.py | ichunks | def ichunks(iterable, chunksize, bordermode=None):
r"""
generates successive n-sized chunks from ``iterable``.
Args:
iterable (list): input to iterate over
chunksize (int): size of sublist to return
bordermode (str): None, 'cycle', or 'replicate'
References:
http://stac... | python | def ichunks(iterable, chunksize, bordermode=None):
r"""
generates successive n-sized chunks from ``iterable``.
Args:
iterable (list): input to iterate over
chunksize (int): size of sublist to return
bordermode (str): None, 'cycle', or 'replicate'
References:
http://stac... | [
"def",
"ichunks",
"(",
"iterable",
",",
"chunksize",
",",
"bordermode",
"=",
"None",
")",
":",
"if",
"bordermode",
"is",
"None",
":",
"return",
"ichunks_noborder",
"(",
"iterable",
",",
"chunksize",
")",
"elif",
"bordermode",
"==",
"'cycle'",
":",
"return",
... | r"""
generates successive n-sized chunks from ``iterable``.
Args:
iterable (list): input to iterate over
chunksize (int): size of sublist to return
bordermode (str): None, 'cycle', or 'replicate'
References:
http://stackoverflow.com/questions/434287/iterate-over-a-list-in-c... | [
"r",
"generates",
"successive",
"n",
"-",
"sized",
"chunks",
"from",
"iterable",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L340-L411 | train | r This function generates successive n - sized chunks from an iterable. |
Erotemic/utool | utool/util_iter.py | ichunks_list | def ichunks_list(list_, chunksize):
"""
input must be a list.
SeeAlso:
ichunks
References:
http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks
"""
return (list_[ix:ix + chunksize] for ix in range(0, len(list_), chunksize)) | python | def ichunks_list(list_, chunksize):
"""
input must be a list.
SeeAlso:
ichunks
References:
http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks
"""
return (list_[ix:ix + chunksize] for ix in range(0, len(list_), chunksize)) | [
"def",
"ichunks_list",
"(",
"list_",
",",
"chunksize",
")",
":",
"return",
"(",
"list_",
"[",
"ix",
":",
"ix",
"+",
"chunksize",
"]",
"for",
"ix",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"list_",
")",
",",
"chunksize",
")",
")"
] | input must be a list.
SeeAlso:
ichunks
References:
http://stackoverflow.com/questions/434287/iterate-over-a-list-in-chunks | [
"input",
"must",
"be",
"a",
"list",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L458-L468 | train | Iterate over a list of chunks. |
Erotemic/utool | utool/util_iter.py | interleave | def interleave(args):
r"""
zip followed by flatten
Args:
args (tuple): tuple of lists to interleave
SeeAlso:
You may actually be better off doing something like this:
a, b, = args
ut.flatten(ut.bzip(a, b))
ut.flatten(ut.bzip([1, 2, 3], ['-']))
... | python | def interleave(args):
r"""
zip followed by flatten
Args:
args (tuple): tuple of lists to interleave
SeeAlso:
You may actually be better off doing something like this:
a, b, = args
ut.flatten(ut.bzip(a, b))
ut.flatten(ut.bzip([1, 2, 3], ['-']))
... | [
"def",
"interleave",
"(",
"args",
")",
":",
"arg_iters",
"=",
"list",
"(",
"map",
"(",
"iter",
",",
"args",
")",
")",
"cycle_iter",
"=",
"it",
".",
"cycle",
"(",
"arg_iters",
")",
"for",
"iter_",
"in",
"cycle_iter",
":",
"yield",
"six",
".",
"next",
... | r"""
zip followed by flatten
Args:
args (tuple): tuple of lists to interleave
SeeAlso:
You may actually be better off doing something like this:
a, b, = args
ut.flatten(ut.bzip(a, b))
ut.flatten(ut.bzip([1, 2, 3], ['-']))
[1, '-', 2, '-', 3,... | [
"r",
"zip",
"followed",
"by",
"flatten"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L477-L505 | train | r Returns a generator that yields the elements of the passed in list that are not in the order of the elements in the original list. |
Erotemic/utool | utool/util_iter.py | random_product | def random_product(items, num=None, rng=None):
"""
Yields `num` items from the cartesian product of items in a random order.
Args:
items (list of sequences): items to get caresian product of
packed in a list or tuple.
(note this deviates from api of it.product)
Example:... | python | def random_product(items, num=None, rng=None):
"""
Yields `num` items from the cartesian product of items in a random order.
Args:
items (list of sequences): items to get caresian product of
packed in a list or tuple.
(note this deviates from api of it.product)
Example:... | [
"def",
"random_product",
"(",
"items",
",",
"num",
"=",
"None",
",",
"rng",
"=",
"None",
")",
":",
"import",
"utool",
"as",
"ut",
"rng",
"=",
"ut",
".",
"ensure_rng",
"(",
"rng",
",",
"'python'",
")",
"seen",
"=",
"set",
"(",
")",
"items",
"=",
"... | Yields `num` items from the cartesian product of items in a random order.
Args:
items (list of sequences): items to get caresian product of
packed in a list or tuple.
(note this deviates from api of it.product)
Example:
import utool as ut
items = [(1, 2, 3), (4,... | [
"Yields",
"num",
"items",
"from",
"the",
"cartesian",
"product",
"of",
"items",
"in",
"a",
"random",
"order",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L512-L549 | train | Yields num items from the cartesian product of items in a random order. |
Erotemic/utool | utool/util_iter.py | random_combinations | def random_combinations(items, size, num=None, rng=None):
"""
Yields `num` combinations of length `size` from items in random order
Args:
items (?):
size (?):
num (None): (default = None)
rng (RandomState): random number generator(default = None)
Yields:
tuple:... | python | def random_combinations(items, size, num=None, rng=None):
"""
Yields `num` combinations of length `size` from items in random order
Args:
items (?):
size (?):
num (None): (default = None)
rng (RandomState): random number generator(default = None)
Yields:
tuple:... | [
"def",
"random_combinations",
"(",
"items",
",",
"size",
",",
"num",
"=",
"None",
",",
"rng",
"=",
"None",
")",
":",
"import",
"scipy",
".",
"misc",
"import",
"numpy",
"as",
"np",
"import",
"utool",
"as",
"ut",
"rng",
"=",
"ut",
".",
"ensure_rng",
"(... | Yields `num` combinations of length `size` from items in random order
Args:
items (?):
size (?):
num (None): (default = None)
rng (RandomState): random number generator(default = None)
Yields:
tuple: combo
CommandLine:
python -m utool.util_iter random_comb... | [
"Yields",
"num",
"combinations",
"of",
"length",
"size",
"from",
"items",
"in",
"random",
"order"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_iter.py#L552-L616 | train | Returns num combinations of length size from items in random order |
chriso/gauged | gauged/drivers/__init__.py | parse_dsn | def parse_dsn(dsn_string):
"""Parse a connection string and return the associated driver"""
dsn = urlparse(dsn_string)
scheme = dsn.scheme.split('+')[0]
username = password = host = port = None
host = dsn.netloc
if '@' in host:
username, host = host.split('@')
if ':' in username:... | python | def parse_dsn(dsn_string):
"""Parse a connection string and return the associated driver"""
dsn = urlparse(dsn_string)
scheme = dsn.scheme.split('+')[0]
username = password = host = port = None
host = dsn.netloc
if '@' in host:
username, host = host.split('@')
if ':' in username:... | [
"def",
"parse_dsn",
"(",
"dsn_string",
")",
":",
"dsn",
"=",
"urlparse",
"(",
"dsn_string",
")",
"scheme",
"=",
"dsn",
".",
"scheme",
".",
"split",
"(",
"'+'",
")",
"[",
"0",
"]",
"username",
"=",
"password",
"=",
"host",
"=",
"port",
"=",
"None",
... | Parse a connection string and return the associated driver | [
"Parse",
"a",
"connection",
"string",
"and",
"return",
"the",
"associated",
"driver"
] | cda3bba2f3e92ce2fb4aa92132dcc0e689bf7976 | https://github.com/chriso/gauged/blob/cda3bba2f3e92ce2fb4aa92132dcc0e689bf7976/gauged/drivers/__init__.py#L14-L57 | train | Parse a connection string and return the associated driver |
Thermondo/django-heroku-connect | heroku_connect/db/router.py | HerokuConnectRouter.db_for_write | def db_for_write(self, model, **hints):
"""
Prevent write actions on read-only tables.
Raises:
WriteNotSupportedError: If models.sf_access is ``read_only``.
"""
try:
if model.sf_access == READ_ONLY:
raise WriteNotSupportedError("%r is a r... | python | def db_for_write(self, model, **hints):
"""
Prevent write actions on read-only tables.
Raises:
WriteNotSupportedError: If models.sf_access is ``read_only``.
"""
try:
if model.sf_access == READ_ONLY:
raise WriteNotSupportedError("%r is a r... | [
"def",
"db_for_write",
"(",
"self",
",",
"model",
",",
"*",
"*",
"hints",
")",
":",
"try",
":",
"if",
"model",
".",
"sf_access",
"==",
"READ_ONLY",
":",
"raise",
"WriteNotSupportedError",
"(",
"\"%r is a read-only model.\"",
"%",
"model",
")",
"except",
"Att... | Prevent write actions on read-only tables.
Raises:
WriteNotSupportedError: If models.sf_access is ``read_only``. | [
"Prevent",
"write",
"actions",
"on",
"read",
"-",
"only",
"tables",
"."
] | f390e0fbf256ee79b30bb88f9a8c9576c6c8d9b5 | https://github.com/Thermondo/django-heroku-connect/blob/f390e0fbf256ee79b30bb88f9a8c9576c6c8d9b5/heroku_connect/db/router.py#L26-L39 | train | Returns the database for the given model. |
jeppe742/AutoDiff | autodiff/AdFloat_py.py | partial | def partial(f, x, i):
"""
Computes the partial derivative of f(x) with respect to x_i
This is done by setting d/dx_j (x)=0 forall j != i
"""
result = f(*[AdFloat(x_j, j == i) for j, x_j in enumerate(x)])
return result.dx | python | def partial(f, x, i):
"""
Computes the partial derivative of f(x) with respect to x_i
This is done by setting d/dx_j (x)=0 forall j != i
"""
result = f(*[AdFloat(x_j, j == i) for j, x_j in enumerate(x)])
return result.dx | [
"def",
"partial",
"(",
"f",
",",
"x",
",",
"i",
")",
":",
"result",
"=",
"f",
"(",
"*",
"[",
"AdFloat",
"(",
"x_j",
",",
"j",
"==",
"i",
")",
"for",
"j",
",",
"x_j",
"in",
"enumerate",
"(",
"x",
")",
"]",
")",
"return",
"result",
".",
"dx"
... | Computes the partial derivative of f(x) with respect to x_i
This is done by setting d/dx_j (x)=0 forall j != i | [
"Computes",
"the",
"partial",
"derivative",
"of",
"f",
"(",
"x",
")",
"with",
"respect",
"to",
"x_i",
"This",
"is",
"done",
"by",
"setting",
"d",
"/",
"dx_j",
"(",
"x",
")",
"=",
"0",
"forall",
"j",
"!",
"=",
"i"
] | 45825286c5478771aacef85da36a1852e577c55a | https://github.com/jeppe742/AutoDiff/blob/45825286c5478771aacef85da36a1852e577c55a/autodiff/AdFloat_py.py#L145-L151 | train | Computes the partial derivative of f with respect to x_i
|
jeppe742/AutoDiff | autodiff/AdFloat_py.py | jacobian | def jacobian(f, x, param):
"""
Calculates the jacobian matrix for d/dx_i (f(x))
"""
N = len(x)
M = len(param)
J = np.zeros((N, M))
for i, x_i in enumerate(x):
for j in range(M):
parameters=[]
for k, p_k in enumerate(param):
parameters.appe... | python | def jacobian(f, x, param):
"""
Calculates the jacobian matrix for d/dx_i (f(x))
"""
N = len(x)
M = len(param)
J = np.zeros((N, M))
for i, x_i in enumerate(x):
for j in range(M):
parameters=[]
for k, p_k in enumerate(param):
parameters.appe... | [
"def",
"jacobian",
"(",
"f",
",",
"x",
",",
"param",
")",
":",
"N",
"=",
"len",
"(",
"x",
")",
"M",
"=",
"len",
"(",
"param",
")",
"J",
"=",
"np",
".",
"zeros",
"(",
"(",
"N",
",",
"M",
")",
")",
"for",
"i",
",",
"x_i",
"in",
"enumerate",... | Calculates the jacobian matrix for d/dx_i (f(x)) | [
"Calculates",
"the",
"jacobian",
"matrix",
"for",
"d",
"/",
"dx_i",
"(",
"f",
"(",
"x",
"))"
] | 45825286c5478771aacef85da36a1852e577c55a | https://github.com/jeppe742/AutoDiff/blob/45825286c5478771aacef85da36a1852e577c55a/autodiff/AdFloat_py.py#L154-L171 | train | Calculates the jacobian matrix for d_i f |
product-definition-center/pdc-client | pdc_client/runner.py | Runner.run_hook | def run_hook(self, hook, *args, **kwargs):
"""
Loop over all plugins and invoke function `hook` with `args` and
`kwargs` in each of them. If the plugin does not have the function, it
is skipped.
"""
for plugin in self.raw_plugins:
if hasattr(plugin, hook):
... | python | def run_hook(self, hook, *args, **kwargs):
"""
Loop over all plugins and invoke function `hook` with `args` and
`kwargs` in each of them. If the plugin does not have the function, it
is skipped.
"""
for plugin in self.raw_plugins:
if hasattr(plugin, hook):
... | [
"def",
"run_hook",
"(",
"self",
",",
"hook",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"plugin",
"in",
"self",
".",
"raw_plugins",
":",
"if",
"hasattr",
"(",
"plugin",
",",
"hook",
")",
":",
"self",
".",
"logger",
".",
"debug",
... | Loop over all plugins and invoke function `hook` with `args` and
`kwargs` in each of them. If the plugin does not have the function, it
is skipped. | [
"Loop",
"over",
"all",
"plugins",
"and",
"invoke",
"function",
"hook",
"with",
"args",
"and",
"kwargs",
"in",
"each",
"of",
"them",
".",
"If",
"the",
"plugin",
"does",
"not",
"have",
"the",
"function",
"it",
"is",
"skipped",
"."
] | 7236fd8b72e675ebb321bbe337289d9fbeb6119f | https://github.com/product-definition-center/pdc-client/blob/7236fd8b72e675ebb321bbe337289d9fbeb6119f/pdc_client/runner.py#L134-L143 | train | Run a hook in all the plugins and invoke it with args and kwargs. |
glormph/msstitch | src/app/writers/tsv.py | write_tsv | def write_tsv(headerfields, features, outfn):
"""Writes header and generator of lines to tab separated file.
headerfields - list of field names in header in correct order
features - generates 1 list per line that belong to header
outfn - filename to output to. Overwritten if exists
"""
with ope... | python | def write_tsv(headerfields, features, outfn):
"""Writes header and generator of lines to tab separated file.
headerfields - list of field names in header in correct order
features - generates 1 list per line that belong to header
outfn - filename to output to. Overwritten if exists
"""
with ope... | [
"def",
"write_tsv",
"(",
"headerfields",
",",
"features",
",",
"outfn",
")",
":",
"with",
"open",
"(",
"outfn",
",",
"'w'",
")",
"as",
"fp",
":",
"write_tsv_line_from_list",
"(",
"headerfields",
",",
"fp",
")",
"for",
"line",
"in",
"features",
":",
"writ... | Writes header and generator of lines to tab separated file.
headerfields - list of field names in header in correct order
features - generates 1 list per line that belong to header
outfn - filename to output to. Overwritten if exists | [
"Writes",
"header",
"and",
"generator",
"of",
"lines",
"to",
"tab",
"separated",
"file",
"."
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/writers/tsv.py#L1-L12 | train | Writes header and generator of lines to tab separated file. |
glormph/msstitch | src/app/writers/tsv.py | write_tsv_line_from_list | def write_tsv_line_from_list(linelist, outfp):
"""Utility method to convert list to tsv line with carriage return"""
line = '\t'.join(linelist)
outfp.write(line)
outfp.write('\n') | python | def write_tsv_line_from_list(linelist, outfp):
"""Utility method to convert list to tsv line with carriage return"""
line = '\t'.join(linelist)
outfp.write(line)
outfp.write('\n') | [
"def",
"write_tsv_line_from_list",
"(",
"linelist",
",",
"outfp",
")",
":",
"line",
"=",
"'\\t'",
".",
"join",
"(",
"linelist",
")",
"outfp",
".",
"write",
"(",
"line",
")",
"outfp",
".",
"write",
"(",
"'\\n'",
")"
] | Utility method to convert list to tsv line with carriage return | [
"Utility",
"method",
"to",
"convert",
"list",
"to",
"tsv",
"line",
"with",
"carriage",
"return"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/writers/tsv.py#L15-L19 | train | Utility method to convert list to tsv line with carriage return |
Erotemic/utool | utool/util_str.py | replace_between_tags | def replace_between_tags(text, repl_, start_tag, end_tag=None):
r"""
Replaces text between sentinal lines in a block of text.
Args:
text (str):
repl_ (str):
start_tag (str):
end_tag (str): (default=None)
Returns:
str: new_text
CommandLine:
python -m... | python | def replace_between_tags(text, repl_, start_tag, end_tag=None):
r"""
Replaces text between sentinal lines in a block of text.
Args:
text (str):
repl_ (str):
start_tag (str):
end_tag (str): (default=None)
Returns:
str: new_text
CommandLine:
python -m... | [
"def",
"replace_between_tags",
"(",
"text",
",",
"repl_",
",",
"start_tag",
",",
"end_tag",
"=",
"None",
")",
":",
"new_lines",
"=",
"[",
"]",
"editing",
"=",
"False",
"lines",
"=",
"text",
".",
"split",
"(",
"'\\n'",
")",
"for",
"line",
"in",
"lines",... | r"""
Replaces text between sentinal lines in a block of text.
Args:
text (str):
repl_ (str):
start_tag (str):
end_tag (str): (default=None)
Returns:
str: new_text
CommandLine:
python -m utool.util_str --exec-replace_between_tags
Example:
>>... | [
"r",
"Replaces",
"text",
"between",
"sentinal",
"lines",
"in",
"a",
"block",
"of",
"text",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L75-L128 | train | r Replaces text between sentinal lines in a block of text. |
Erotemic/utool | utool/util_str.py | theta_str | def theta_str(theta, taustr=TAUSTR, fmtstr='{coeff:,.1f}{taustr}'):
r"""
Format theta so it is interpretable in base 10
Args:
theta (float) angle in radians
taustr (str): default 2pi
Returns:
str : theta_str - the angle in tau units
Example1:
>>> # ENABLE_DOCTEST
... | python | def theta_str(theta, taustr=TAUSTR, fmtstr='{coeff:,.1f}{taustr}'):
r"""
Format theta so it is interpretable in base 10
Args:
theta (float) angle in radians
taustr (str): default 2pi
Returns:
str : theta_str - the angle in tau units
Example1:
>>> # ENABLE_DOCTEST
... | [
"def",
"theta_str",
"(",
"theta",
",",
"taustr",
"=",
"TAUSTR",
",",
"fmtstr",
"=",
"'{coeff:,.1f}{taustr}'",
")",
":",
"coeff",
"=",
"theta",
"/",
"TAU",
"theta_str",
"=",
"fmtstr",
".",
"format",
"(",
"coeff",
"=",
"coeff",
",",
"taustr",
"=",
"taustr"... | r"""
Format theta so it is interpretable in base 10
Args:
theta (float) angle in radians
taustr (str): default 2pi
Returns:
str : theta_str - the angle in tau units
Example1:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> theta = 3.14... | [
"r",
"Format",
"theta",
"so",
"it",
"is",
"interpretable",
"in",
"base",
"10"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L131-L161 | train | r Returns a string representation of the theta in tau units |
Erotemic/utool | utool/util_str.py | bbox_str | def bbox_str(bbox, pad=4, sep=', '):
r""" makes a string from an integer bounding box """
if bbox is None:
return 'None'
fmtstr = sep.join(['%' + six.text_type(pad) + 'd'] * 4)
return '(' + fmtstr % tuple(bbox) + ')' | python | def bbox_str(bbox, pad=4, sep=', '):
r""" makes a string from an integer bounding box """
if bbox is None:
return 'None'
fmtstr = sep.join(['%' + six.text_type(pad) + 'd'] * 4)
return '(' + fmtstr % tuple(bbox) + ')' | [
"def",
"bbox_str",
"(",
"bbox",
",",
"pad",
"=",
"4",
",",
"sep",
"=",
"', '",
")",
":",
"if",
"bbox",
"is",
"None",
":",
"return",
"'None'",
"fmtstr",
"=",
"sep",
".",
"join",
"(",
"[",
"'%'",
"+",
"six",
".",
"text_type",
"(",
"pad",
")",
"+"... | r""" makes a string from an integer bounding box | [
"r",
"makes",
"a",
"string",
"from",
"an",
"integer",
"bounding",
"box"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L164-L169 | train | r makes a string from an integer bounding box |
Erotemic/utool | utool/util_str.py | verts_str | def verts_str(verts, pad=1):
r""" makes a string from a list of integer verticies """
if verts is None:
return 'None'
fmtstr = ', '.join(['%' + six.text_type(pad) + 'd' +
', %' + six.text_type(pad) + 'd'] * 1)
return ', '.join(['(' + fmtstr % vert + ')' for vert in verts]... | python | def verts_str(verts, pad=1):
r""" makes a string from a list of integer verticies """
if verts is None:
return 'None'
fmtstr = ', '.join(['%' + six.text_type(pad) + 'd' +
', %' + six.text_type(pad) + 'd'] * 1)
return ', '.join(['(' + fmtstr % vert + ')' for vert in verts]... | [
"def",
"verts_str",
"(",
"verts",
",",
"pad",
"=",
"1",
")",
":",
"if",
"verts",
"is",
"None",
":",
"return",
"'None'",
"fmtstr",
"=",
"', '",
".",
"join",
"(",
"[",
"'%'",
"+",
"six",
".",
"text_type",
"(",
"pad",
")",
"+",
"'d'",
"+",
"', %'",
... | r""" makes a string from a list of integer verticies | [
"r",
"makes",
"a",
"string",
"from",
"a",
"list",
"of",
"integer",
"verticies"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L172-L178 | train | r makes a string from a list of integer verticies |
Erotemic/utool | utool/util_str.py | remove_chars | def remove_chars(str_, char_list):
"""
removes all chars in char_list from str_
Args:
str_ (str):
char_list (list):
Returns:
str: outstr
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> str_ = '1, 2, 3, 4'
>>> char_... | python | def remove_chars(str_, char_list):
"""
removes all chars in char_list from str_
Args:
str_ (str):
char_list (list):
Returns:
str: outstr
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> str_ = '1, 2, 3, 4'
>>> char_... | [
"def",
"remove_chars",
"(",
"str_",
",",
"char_list",
")",
":",
"outstr",
"=",
"str_",
"[",
":",
"]",
"for",
"char",
"in",
"char_list",
":",
"outstr",
"=",
"outstr",
".",
"replace",
"(",
"char",
",",
"''",
")",
"return",
"outstr"
] | removes all chars in char_list from str_
Args:
str_ (str):
char_list (list):
Returns:
str: outstr
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> str_ = '1, 2, 3, 4'
>>> char_list = [',']
>>> result = remove_chars(... | [
"removes",
"all",
"chars",
"in",
"char_list",
"from",
"str_"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L195-L218 | train | Removes all chars in char_list from str_
|
Erotemic/utool | utool/util_str.py | get_minimum_indentation | def get_minimum_indentation(text):
r"""
returns the number of preceding spaces
Args:
text (str): unicode text
Returns:
int: indentation
CommandLine:
python -m utool.util_str --exec-get_minimum_indentation --show
Example:
>>> # ENABLE_DOCTEST
>>> from u... | python | def get_minimum_indentation(text):
r"""
returns the number of preceding spaces
Args:
text (str): unicode text
Returns:
int: indentation
CommandLine:
python -m utool.util_str --exec-get_minimum_indentation --show
Example:
>>> # ENABLE_DOCTEST
>>> from u... | [
"def",
"get_minimum_indentation",
"(",
"text",
")",
":",
"lines",
"=",
"text",
".",
"split",
"(",
"'\\n'",
")",
"indentations",
"=",
"[",
"get_indentation",
"(",
"line_",
")",
"for",
"line_",
"in",
"lines",
"if",
"len",
"(",
"line_",
".",
"strip",
"(",
... | r"""
returns the number of preceding spaces
Args:
text (str): unicode text
Returns:
int: indentation
CommandLine:
python -m utool.util_str --exec-get_minimum_indentation --show
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
... | [
"r",
"returns",
"the",
"number",
"of",
"preceding",
"spaces"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L228-L255 | train | r Returns the minimum indentation of the text |
Erotemic/utool | utool/util_str.py | textblock | def textblock(multiline_text):
r"""
Args:
block_str (str):
CommandLine:
python -m utool.util_str --test-textblock
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> # build test data
>>> multiline_text = ''' a big string
... | python | def textblock(multiline_text):
r"""
Args:
block_str (str):
CommandLine:
python -m utool.util_str --test-textblock
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> # build test data
>>> multiline_text = ''' a big string
... | [
"def",
"textblock",
"(",
"multiline_text",
")",
":",
"new_lines",
"=",
"list",
"(",
"map",
"(",
"flatten_textlines",
",",
"multiline_text",
".",
"split",
"(",
"'\\n\\n'",
")",
")",
")",
"new_text",
"=",
"'\\n\\n'",
".",
"join",
"(",
"new_lines",
")",
"retu... | r"""
Args:
block_str (str):
CommandLine:
python -m utool.util_str --test-textblock
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> # build test data
>>> multiline_text = ''' a big string
that should be layed out flat
... | [
"r",
"Args",
":",
"block_str",
"(",
"str",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L294-L322 | train | r Textblock function that returns a single string |
Erotemic/utool | utool/util_str.py | indentjoin | def indentjoin(strlist, indent='\n ', suffix=''):
r"""
Convineince indentjoin
similar to '\n '.join(strlist) but indent is also prefixed
Args:
strlist (?):
indent (str):
suffix (str):
Returns:
str: joined list
"""
indent_ = indent
strlist = list... | python | def indentjoin(strlist, indent='\n ', suffix=''):
r"""
Convineince indentjoin
similar to '\n '.join(strlist) but indent is also prefixed
Args:
strlist (?):
indent (str):
suffix (str):
Returns:
str: joined list
"""
indent_ = indent
strlist = list... | [
"def",
"indentjoin",
"(",
"strlist",
",",
"indent",
"=",
"'\\n '",
",",
"suffix",
"=",
"''",
")",
":",
"indent_",
"=",
"indent",
"strlist",
"=",
"list",
"(",
"strlist",
")",
"if",
"len",
"(",
"strlist",
")",
"==",
"0",
":",
"return",
"''",
"return... | r"""
Convineince indentjoin
similar to '\n '.join(strlist) but indent is also prefixed
Args:
strlist (?):
indent (str):
suffix (str):
Returns:
str: joined list | [
"r",
"Convineince",
"indentjoin"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L357-L376 | train | r Used to join a list of strings with indent and suffix |
Erotemic/utool | utool/util_str.py | truncate_str | def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '):
"""
Removes the middle part of any string over maxlen characters.
"""
if NO_TRUNCATE:
return str_
if maxlen is None or maxlen == -1 or len(str_) < maxlen:
return str_
else:
maxlen_ = maxlen - len(truncmsg)
... | python | def truncate_str(str_, maxlen=110, truncmsg=' ~~~TRUNCATED~~~ '):
"""
Removes the middle part of any string over maxlen characters.
"""
if NO_TRUNCATE:
return str_
if maxlen is None or maxlen == -1 or len(str_) < maxlen:
return str_
else:
maxlen_ = maxlen - len(truncmsg)
... | [
"def",
"truncate_str",
"(",
"str_",
",",
"maxlen",
"=",
"110",
",",
"truncmsg",
"=",
"' ~~~TRUNCATED~~~ '",
")",
":",
"if",
"NO_TRUNCATE",
":",
"return",
"str_",
"if",
"maxlen",
"is",
"None",
"or",
"maxlen",
"==",
"-",
"1",
"or",
"len",
"(",
"str_",
")... | Removes the middle part of any string over maxlen characters. | [
"Removes",
"the",
"middle",
"part",
"of",
"any",
"string",
"over",
"maxlen",
"characters",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L379-L392 | train | Truncates the middle part of any string over maxlen characters. |
Erotemic/utool | utool/util_str.py | pack_into | def pack_into(text, textwidth=160, breakchars=' ', break_words=True,
newline_prefix='', wordsep=' ', remove_newlines=True):
r"""
DEPRICATE IN FAVOR OF textwrap.wrap
TODO: Look into textwrap.wrap
Inserts newlines into a string enforcing a maximum textwidth.
Similar to vim's gq comman... | python | def pack_into(text, textwidth=160, breakchars=' ', break_words=True,
newline_prefix='', wordsep=' ', remove_newlines=True):
r"""
DEPRICATE IN FAVOR OF textwrap.wrap
TODO: Look into textwrap.wrap
Inserts newlines into a string enforcing a maximum textwidth.
Similar to vim's gq comman... | [
"def",
"pack_into",
"(",
"text",
",",
"textwidth",
"=",
"160",
",",
"breakchars",
"=",
"' '",
",",
"break_words",
"=",
"True",
",",
"newline_prefix",
"=",
"''",
",",
"wordsep",
"=",
"' '",
",",
"remove_newlines",
"=",
"True",
")",
":",
"#FIXME: messy code"... | r"""
DEPRICATE IN FAVOR OF textwrap.wrap
TODO: Look into textwrap.wrap
Inserts newlines into a string enforcing a maximum textwidth.
Similar to vim's gq command in visual select mode.
breakchars is a string containing valid characters to insert a newline
before or after.
break_words is ... | [
"r"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L395-L465 | train | r Packs a string into a single word or line of text. |
Erotemic/utool | utool/util_str.py | packstr | def packstr(instr, textwidth=160, breakchars=' ', break_words=True,
newline_prefix='', indentation='', nlprefix=None, wordsep=' ',
remove_newlines=True):
""" alias for pack_into. has more up to date kwargs """
if not isinstance(instr, six.string_types):
instr = repr(instr)
if... | python | def packstr(instr, textwidth=160, breakchars=' ', break_words=True,
newline_prefix='', indentation='', nlprefix=None, wordsep=' ',
remove_newlines=True):
""" alias for pack_into. has more up to date kwargs """
if not isinstance(instr, six.string_types):
instr = repr(instr)
if... | [
"def",
"packstr",
"(",
"instr",
",",
"textwidth",
"=",
"160",
",",
"breakchars",
"=",
"' '",
",",
"break_words",
"=",
"True",
",",
"newline_prefix",
"=",
"''",
",",
"indentation",
"=",
"''",
",",
"nlprefix",
"=",
"None",
",",
"wordsep",
"=",
"' '",
","... | alias for pack_into. has more up to date kwargs | [
"alias",
"for",
"pack_into",
".",
"has",
"more",
"up",
"to",
"date",
"kwargs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L468-L480 | train | packs a string into a new file |
Erotemic/utool | utool/util_str.py | packtext | def packtext(text, width=80):
r"""
Args:
text (str):
CommandLine:
python -m utool.util_str --exec-pack_paragraph --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> width = 80
>>> text = loriu... | python | def packtext(text, width=80):
r"""
Args:
text (str):
CommandLine:
python -m utool.util_str --exec-pack_paragraph --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> width = 80
>>> text = loriu... | [
"def",
"packtext",
"(",
"text",
",",
"width",
"=",
"80",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"textwrap",
"new_text",
"=",
"'\\n'",
".",
"join",
"(",
"textwrap",
".",
"wrap",
"(",
"text",
",",
"width",
")",
")",
"new_text",
"=",
"ut",
... | r"""
Args:
text (str):
CommandLine:
python -m utool.util_str --exec-pack_paragraph --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> width = 80
>>> text = lorium_ipsum()
>>> result = pac... | [
"r",
"Args",
":",
"text",
"(",
"str",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L483-L504 | train | r Packs a text into a single nparray tree |
Erotemic/utool | utool/util_str.py | seconds_str | def seconds_str(num, prefix=None):
r"""
Returns:
str
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> num_list = sorted([4.2 / (10.0 ** exp_)
>>> for exp_ in range(-13, 13, 4)])
>>> s... | python | def seconds_str(num, prefix=None):
r"""
Returns:
str
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> num_list = sorted([4.2 / (10.0 ** exp_)
>>> for exp_ in range(-13, 13, 4)])
>>> s... | [
"def",
"seconds_str",
"(",
"num",
",",
"prefix",
"=",
"None",
")",
":",
"exponent_list",
"=",
"[",
"-",
"12",
",",
"-",
"9",
",",
"-",
"6",
",",
"-",
"3",
",",
"0",
",",
"3",
",",
"6",
",",
"9",
",",
"12",
"]",
"small_prefix_list",
"=",
"[",
... | r"""
Returns:
str
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> num_list = sorted([4.2 / (10.0 ** exp_)
>>> for exp_ in range(-13, 13, 4)])
>>> secstr_list = [seconds_str(num, prefix=N... | [
"r",
"Returns",
":",
"str"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L525-L552 | train | r Returns a string representation of the current time in the order of magnitude of the current time. |
Erotemic/utool | utool/util_str.py | order_of_magnitude_str | def order_of_magnitude_str(num, base=10.0,
prefix_list=None,
exponent_list=None,
suffix='', prefix=None):
"""
TODO: Rewrite byte_str to use this func
Returns:
str
"""
abs_num = abs(num)
# Find the right magn... | python | def order_of_magnitude_str(num, base=10.0,
prefix_list=None,
exponent_list=None,
suffix='', prefix=None):
"""
TODO: Rewrite byte_str to use this func
Returns:
str
"""
abs_num = abs(num)
# Find the right magn... | [
"def",
"order_of_magnitude_str",
"(",
"num",
",",
"base",
"=",
"10.0",
",",
"prefix_list",
"=",
"None",
",",
"exponent_list",
"=",
"None",
",",
"suffix",
"=",
"''",
",",
"prefix",
"=",
"None",
")",
":",
"abs_num",
"=",
"abs",
"(",
"num",
")",
"# Find t... | TODO: Rewrite byte_str to use this func
Returns:
str | [
"TODO",
":",
"Rewrite",
"byte_str",
"to",
"use",
"this",
"func",
"Returns",
":",
"str"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L555-L580 | train | Returns a string that is the order of the magnitude of the current object. |
Erotemic/utool | utool/util_str.py | parse_bytes | def parse_bytes(bytes_str):
"""
uint8_size = ut.parse_bytes('1B')
image_size = ut.parse_bytes('3.5MB')
float32_size = ut.parse_bytes('32bit')
desc_size = 128 * uint8_size
kpts_size = 6 * float32_size
chip_size = ut.parse_bytes('400 KB')
probchip_size = ut.parse_bytes('50 KB')
nImgs =... | python | def parse_bytes(bytes_str):
"""
uint8_size = ut.parse_bytes('1B')
image_size = ut.parse_bytes('3.5MB')
float32_size = ut.parse_bytes('32bit')
desc_size = 128 * uint8_size
kpts_size = 6 * float32_size
chip_size = ut.parse_bytes('400 KB')
probchip_size = ut.parse_bytes('50 KB')
nImgs =... | [
"def",
"parse_bytes",
"(",
"bytes_str",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"re",
"numstr",
"=",
"ut",
".",
"named_field",
"(",
"'num'",
",",
"r'\\d\\.?\\d*'",
")",
"unitstr",
"=",
"ut",
".",
"named_field",
"(",
"'unit'",
",",
"r'[a-zA-Z]+'"... | uint8_size = ut.parse_bytes('1B')
image_size = ut.parse_bytes('3.5MB')
float32_size = ut.parse_bytes('32bit')
desc_size = 128 * uint8_size
kpts_size = 6 * float32_size
chip_size = ut.parse_bytes('400 KB')
probchip_size = ut.parse_bytes('50 KB')
nImgs = 80000 # 80,000
nAnnots = nImgs * 2
... | [
"uint8_size",
"=",
"ut",
".",
"parse_bytes",
"(",
"1B",
")",
"image_size",
"=",
"ut",
".",
"parse_bytes",
"(",
"3",
".",
"5MB",
")",
"float32_size",
"=",
"ut",
".",
"parse_bytes",
"(",
"32bit",
")",
"desc_size",
"=",
"128",
"*",
"uint8_size",
"kpts_size"... | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L590-L620 | train | parse the bytes into a list of bytes |
Erotemic/utool | utool/util_str.py | byte_str2 | def byte_str2(nBytes, precision=2):
"""
Automatically chooses relevant unit (KB, MB, or GB) for displaying some
number of bytes.
Args:
nBytes (int):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-byte_str2
Example:
>>> # ENABLE_DOCTEST
... | python | def byte_str2(nBytes, precision=2):
"""
Automatically chooses relevant unit (KB, MB, or GB) for displaying some
number of bytes.
Args:
nBytes (int):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-byte_str2
Example:
>>> # ENABLE_DOCTEST
... | [
"def",
"byte_str2",
"(",
"nBytes",
",",
"precision",
"=",
"2",
")",
":",
"nAbsBytes",
"=",
"abs",
"(",
"nBytes",
")",
"if",
"nAbsBytes",
"<",
"2.0",
"**",
"10",
":",
"return",
"byte_str",
"(",
"nBytes",
",",
"'KB'",
",",
"precision",
"=",
"precision",
... | Automatically chooses relevant unit (KB, MB, or GB) for displaying some
number of bytes.
Args:
nBytes (int):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-byte_str2
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
... | [
"Automatically",
"chooses",
"relevant",
"unit",
"(",
"KB",
"MB",
"or",
"GB",
")",
"for",
"displaying",
"some",
"number",
"of",
"bytes",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L635-L668 | train | Prints out some bytes in a unicode string |
Erotemic/utool | utool/util_str.py | byte_str | def byte_str(nBytes, unit='bytes', precision=2):
"""
representing the number of bytes with the chosen unit
Returns:
str
"""
#return (nBytes * ureg.byte).to(unit.upper())
if unit.lower().startswith('b'):
nUnit = nBytes
elif unit.lower().startswith('k'):
nUnit = nByte... | python | def byte_str(nBytes, unit='bytes', precision=2):
"""
representing the number of bytes with the chosen unit
Returns:
str
"""
#return (nBytes * ureg.byte).to(unit.upper())
if unit.lower().startswith('b'):
nUnit = nBytes
elif unit.lower().startswith('k'):
nUnit = nByte... | [
"def",
"byte_str",
"(",
"nBytes",
",",
"unit",
"=",
"'bytes'",
",",
"precision",
"=",
"2",
")",
":",
"#return (nBytes * ureg.byte).to(unit.upper())",
"if",
"unit",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"'b'",
")",
":",
"nUnit",
"=",
"nBytes",
"el... | representing the number of bytes with the chosen unit
Returns:
str | [
"representing",
"the",
"number",
"of",
"bytes",
"with",
"the",
"chosen",
"unit"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L671-L691 | train | Returns a string representation of the number of bytes with the chosen unit |
Erotemic/utool | utool/util_str.py | func_str | def func_str(func, args=[], kwargs={}, type_aliases=[], packed=False,
packkw=None, truncate=False):
"""
string representation of function definition
Returns:
str: a representation of func with args, kwargs, and type_aliases
Args:
func (function):
args (list): argum... | python | def func_str(func, args=[], kwargs={}, type_aliases=[], packed=False,
packkw=None, truncate=False):
"""
string representation of function definition
Returns:
str: a representation of func with args, kwargs, and type_aliases
Args:
func (function):
args (list): argum... | [
"def",
"func_str",
"(",
"func",
",",
"args",
"=",
"[",
"]",
",",
"kwargs",
"=",
"{",
"}",
",",
"type_aliases",
"=",
"[",
"]",
",",
"packed",
"=",
"False",
",",
"packkw",
"=",
"None",
",",
"truncate",
"=",
"False",
")",
":",
"import",
"utool",
"as... | string representation of function definition
Returns:
str: a representation of func with args, kwargs, and type_aliases
Args:
func (function):
args (list): argument values (default = [])
kwargs (dict): kwargs values (default = {})
type_aliases (list): (default = [])
... | [
"string",
"representation",
"of",
"function",
"definition"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L720-L778 | train | Function to get a string representation of a function definition |
Erotemic/utool | utool/util_str.py | func_defsig | def func_defsig(func, with_name=True):
"""
String of function definition signature
Args:
func (function): live python function
Returns:
str: defsig
CommandLine:
python -m utool.util_str --exec-func_defsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.ut... | python | def func_defsig(func, with_name=True):
"""
String of function definition signature
Args:
func (function): live python function
Returns:
str: defsig
CommandLine:
python -m utool.util_str --exec-func_defsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.ut... | [
"def",
"func_defsig",
"(",
"func",
",",
"with_name",
"=",
"True",
")",
":",
"import",
"inspect",
"argspec",
"=",
"inspect",
".",
"getargspec",
"(",
"func",
")",
"(",
"args",
",",
"varargs",
",",
"varkw",
",",
"defaults",
")",
"=",
"argspec",
"defsig",
... | String of function definition signature
Args:
func (function): live python function
Returns:
str: defsig
CommandLine:
python -m utool.util_str --exec-func_defsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> func = func_str... | [
"String",
"of",
"function",
"definition",
"signature"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L781-L809 | train | Returns a string of function definition signature |
Erotemic/utool | utool/util_str.py | func_callsig | def func_callsig(func, with_name=True):
"""
String of function call signature
Args:
func (function): live python function
Returns:
str: callsig
CommandLine:
python -m utool.util_str --exec-func_callsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_... | python | def func_callsig(func, with_name=True):
"""
String of function call signature
Args:
func (function): live python function
Returns:
str: callsig
CommandLine:
python -m utool.util_str --exec-func_callsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_... | [
"def",
"func_callsig",
"(",
"func",
",",
"with_name",
"=",
"True",
")",
":",
"import",
"inspect",
"argspec",
"=",
"inspect",
".",
"getargspec",
"(",
"func",
")",
"(",
"args",
",",
"varargs",
",",
"varkw",
",",
"defaults",
")",
"=",
"argspec",
"callsig",
... | String of function call signature
Args:
func (function): live python function
Returns:
str: callsig
CommandLine:
python -m utool.util_str --exec-func_callsig
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> func = func_str
... | [
"String",
"of",
"function",
"call",
"signature"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L812-L840 | train | Function to call the function with signature |
Erotemic/utool | utool/util_str.py | numpy_str | def numpy_str(arr, strvals=False, precision=None, pr=None,
force_dtype=False,
with_dtype=None, suppress_small=None, max_line_width=None,
threshold=None, **kwargs):
"""
suppress_small = False turns off scientific representation
"""
# strvals = kwargs.get('strvals... | python | def numpy_str(arr, strvals=False, precision=None, pr=None,
force_dtype=False,
with_dtype=None, suppress_small=None, max_line_width=None,
threshold=None, **kwargs):
"""
suppress_small = False turns off scientific representation
"""
# strvals = kwargs.get('strvals... | [
"def",
"numpy_str",
"(",
"arr",
",",
"strvals",
"=",
"False",
",",
"precision",
"=",
"None",
",",
"pr",
"=",
"None",
",",
"force_dtype",
"=",
"False",
",",
"with_dtype",
"=",
"None",
",",
"suppress_small",
"=",
"None",
",",
"max_line_width",
"=",
"None",... | suppress_small = False turns off scientific representation | [
"suppress_small",
"=",
"False",
"turns",
"off",
"scientific",
"representation"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1112-L1170 | train | Return a string representation of a numpy array. |
Erotemic/utool | utool/util_str.py | reprfunc | def reprfunc(val, precision=None):
r"""
Args:
val (?):
precision (None): (default = None)
Returns:
str:
CommandLine:
python -m utool.util_str reprfunc --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import ... | python | def reprfunc(val, precision=None):
r"""
Args:
val (?):
precision (None): (default = None)
Returns:
str:
CommandLine:
python -m utool.util_str reprfunc --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import ... | [
"def",
"reprfunc",
"(",
"val",
",",
"precision",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"six",
".",
"string_types",
")",
":",
"repr_",
"=",
"repr",
"(",
"val",
")",
"if",
"repr_",
".",
"startswith",
"(",
"'u\\''",
")",
"or",
"r... | r"""
Args:
val (?):
precision (None): (default = None)
Returns:
str:
CommandLine:
python -m utool.util_str reprfunc --show
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> #vals = [{'foo'... | [
"r",
"Args",
":",
"val",
"(",
"?",
")",
":",
"precision",
"(",
"None",
")",
":",
"(",
"default",
"=",
"None",
")"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1206-L1248 | train | r Represents a value in a node - level tree structure |
Erotemic/utool | utool/util_str.py | list_str_summarized | def list_str_summarized(list_, list_name, maxlen=5):
"""
prints the list members when the list is small and the length when it is
large
"""
if len(list_) > maxlen:
return 'len(%s)=%d' % (list_name, len(list_))
else:
return '%s=%r' % (list_name, list_) | python | def list_str_summarized(list_, list_name, maxlen=5):
"""
prints the list members when the list is small and the length when it is
large
"""
if len(list_) > maxlen:
return 'len(%s)=%d' % (list_name, len(list_))
else:
return '%s=%r' % (list_name, list_) | [
"def",
"list_str_summarized",
"(",
"list_",
",",
"list_name",
",",
"maxlen",
"=",
"5",
")",
":",
"if",
"len",
"(",
"list_",
")",
">",
"maxlen",
":",
"return",
"'len(%s)=%d'",
"%",
"(",
"list_name",
",",
"len",
"(",
"list_",
")",
")",
"else",
":",
"re... | prints the list members when the list is small and the length when it is
large | [
"prints",
"the",
"list",
"members",
"when",
"the",
"list",
"is",
"small",
"and",
"the",
"length",
"when",
"it",
"is",
"large"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1251-L1259 | train | Returns a string that can be used to summarize a list of items. |
Erotemic/utool | utool/util_str.py | _rectify_countdown_or_bool | def _rectify_countdown_or_bool(count_or_bool):
"""
used by recrusive functions to specify which level to turn a bool on in
counting down yeilds True, True, ..., False
conting up yeilds False, False, False, ... True
Args:
count_or_bool (bool or int): if positive will count down, if negative
... | python | def _rectify_countdown_or_bool(count_or_bool):
"""
used by recrusive functions to specify which level to turn a bool on in
counting down yeilds True, True, ..., False
conting up yeilds False, False, False, ... True
Args:
count_or_bool (bool or int): if positive will count down, if negative
... | [
"def",
"_rectify_countdown_or_bool",
"(",
"count_or_bool",
")",
":",
"if",
"count_or_bool",
"is",
"True",
"or",
"count_or_bool",
"is",
"False",
":",
"count_or_bool_",
"=",
"count_or_bool",
"elif",
"isinstance",
"(",
"count_or_bool",
",",
"int",
")",
":",
"if",
"... | used by recrusive functions to specify which level to turn a bool on in
counting down yeilds True, True, ..., False
conting up yeilds False, False, False, ... True
Args:
count_or_bool (bool or int): if positive will count down, if negative
will count up, if bool will remain same
Re... | [
"used",
"by",
"recrusive",
"functions",
"to",
"specify",
"which",
"level",
"to",
"turn",
"a",
"bool",
"on",
"in",
"counting",
"down",
"yeilds",
"True",
"True",
"...",
"False",
"conting",
"up",
"yeilds",
"False",
"False",
"False",
"...",
"True"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1266-L1310 | train | This function will count down or count up a single entry in a resource tree. |
Erotemic/utool | utool/util_str.py | repr2 | def repr2(obj_, **kwargs):
"""
Attempt to replace repr more configurable
pretty version that works the same in both 2 and 3
"""
kwargs['nl'] = kwargs.pop('nl', kwargs.pop('newlines', False))
val_str = _make_valstr(**kwargs)
return val_str(obj_) | python | def repr2(obj_, **kwargs):
"""
Attempt to replace repr more configurable
pretty version that works the same in both 2 and 3
"""
kwargs['nl'] = kwargs.pop('nl', kwargs.pop('newlines', False))
val_str = _make_valstr(**kwargs)
return val_str(obj_) | [
"def",
"repr2",
"(",
"obj_",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"'nl'",
"]",
"=",
"kwargs",
".",
"pop",
"(",
"'nl'",
",",
"kwargs",
".",
"pop",
"(",
"'newlines'",
",",
"False",
")",
")",
"val_str",
"=",
"_make_valstr",
"(",
"*",
"*... | Attempt to replace repr more configurable
pretty version that works the same in both 2 and 3 | [
"Attempt",
"to",
"replace",
"repr",
"more",
"configurable",
"pretty",
"version",
"that",
"works",
"the",
"same",
"in",
"both",
"2",
"and",
"3"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1317-L1324 | train | Return a pretty version of obj_. |
Erotemic/utool | utool/util_str.py | repr2_json | def repr2_json(obj_, **kwargs):
""" hack for json reprs """
import utool as ut
kwargs['trailing_sep'] = False
json_str = ut.repr2(obj_, **kwargs)
json_str = str(json_str.replace('\'', '"'))
json_str = json_str.replace('(', '[')
json_str = json_str.replace(')', ']')
json_str = json_str.re... | python | def repr2_json(obj_, **kwargs):
""" hack for json reprs """
import utool as ut
kwargs['trailing_sep'] = False
json_str = ut.repr2(obj_, **kwargs)
json_str = str(json_str.replace('\'', '"'))
json_str = json_str.replace('(', '[')
json_str = json_str.replace(')', ']')
json_str = json_str.re... | [
"def",
"repr2_json",
"(",
"obj_",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"utool",
"as",
"ut",
"kwargs",
"[",
"'trailing_sep'",
"]",
"=",
"False",
"json_str",
"=",
"ut",
".",
"repr2",
"(",
"obj_",
",",
"*",
"*",
"kwargs",
")",
"json_str",
"=",
... | hack for json reprs | [
"hack",
"for",
"json",
"reprs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1327-L1336 | train | converts a python object to json |
Erotemic/utool | utool/util_str.py | dict_str | def dict_str(dict_, **dictkw):
r"""
Makes a pretty printable / human-readable string representation of a
dictionary. In most cases this string could be evaled.
Args:
dict_ (dict_): a dictionary
Args:
dict_ (dict_): a dictionary
**dictkw: stritems, strkeys, strvals, nl, new... | python | def dict_str(dict_, **dictkw):
r"""
Makes a pretty printable / human-readable string representation of a
dictionary. In most cases this string could be evaled.
Args:
dict_ (dict_): a dictionary
Args:
dict_ (dict_): a dictionary
**dictkw: stritems, strkeys, strvals, nl, new... | [
"def",
"dict_str",
"(",
"dict_",
",",
"*",
"*",
"dictkw",
")",
":",
"import",
"utool",
"as",
"ut",
"stritems",
"=",
"dictkw",
".",
"pop",
"(",
"'si'",
",",
"dictkw",
".",
"pop",
"(",
"'stritems'",
",",
"False",
")",
")",
"if",
"stritems",
":",
"dic... | r"""
Makes a pretty printable / human-readable string representation of a
dictionary. In most cases this string could be evaled.
Args:
dict_ (dict_): a dictionary
Args:
dict_ (dict_): a dictionary
**dictkw: stritems, strkeys, strvals, nl, newlines, truncate, nobr,
... | [
"r",
"Makes",
"a",
"pretty",
"printable",
"/",
"human",
"-",
"readable",
"string",
"representation",
"of",
"a",
"dictionary",
".",
"In",
"most",
"cases",
"this",
"string",
"could",
"be",
"evaled",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1350-L1494 | train | r Converts a dictionary into a pretty printable string representation of a
Taxonomy dictionary. |
Erotemic/utool | utool/util_str.py | dict_itemstr_list | def dict_itemstr_list(dict_, **dictkw):
r"""
Returns:
list: a list of human-readable dictionary items
Args:
explicit : if True uses dict(key=val,...) format instead of {key:val,...}
"""
import utool as ut
explicit = dictkw.get('explicit', False)
dictkw['explicit'] = _rectif... | python | def dict_itemstr_list(dict_, **dictkw):
r"""
Returns:
list: a list of human-readable dictionary items
Args:
explicit : if True uses dict(key=val,...) format instead of {key:val,...}
"""
import utool as ut
explicit = dictkw.get('explicit', False)
dictkw['explicit'] = _rectif... | [
"def",
"dict_itemstr_list",
"(",
"dict_",
",",
"*",
"*",
"dictkw",
")",
":",
"import",
"utool",
"as",
"ut",
"explicit",
"=",
"dictkw",
".",
"get",
"(",
"'explicit'",
",",
"False",
")",
"dictkw",
"[",
"'explicit'",
"]",
"=",
"_rectify_countdown_or_bool",
"(... | r"""
Returns:
list: a list of human-readable dictionary items
Args:
explicit : if True uses dict(key=val,...) format instead of {key:val,...} | [
"r",
"Returns",
":",
"list",
":",
"a",
"list",
"of",
"human",
"-",
"readable",
"dictionary",
"items"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1497-L1579 | train | r Returns a list of human - readable items from a dictionary |
Erotemic/utool | utool/util_str.py | list_str | def list_str(list_, **listkw):
r"""
Makes a pretty list string
Args:
list_ (list): input list
**listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep,
trailing_sep, truncatekw, strvals, recursive,
indent_, precision, use_numpy, with_dtype, force... | python | def list_str(list_, **listkw):
r"""
Makes a pretty list string
Args:
list_ (list): input list
**listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep,
trailing_sep, truncatekw, strvals, recursive,
indent_, precision, use_numpy, with_dtype, force... | [
"def",
"list_str",
"(",
"list_",
",",
"*",
"*",
"listkw",
")",
":",
"import",
"utool",
"as",
"ut",
"newlines",
"=",
"listkw",
".",
"pop",
"(",
"'nl'",
",",
"listkw",
".",
"pop",
"(",
"'newlines'",
",",
"1",
")",
")",
"packed",
"=",
"listkw",
".",
... | r"""
Makes a pretty list string
Args:
list_ (list): input list
**listkw: nl, newlines, packed, truncate, nobr, nobraces, itemsep,
trailing_sep, truncatekw, strvals, recursive,
indent_, precision, use_numpy, with_dtype, force_dtype,
stritems,... | [
"r",
"Makes",
"a",
"pretty",
"list",
"string"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1582-L1694 | train | r Returns a pretty list of the names of the items in the list |
Erotemic/utool | utool/util_str.py | get_itemstr_list | def get_itemstr_list(list_, **listkw):
"""
TODO: have this replace dict_itemstr list or at least most functionality in
it. have it make two itemstr lists over keys and values and then combine
them.
"""
import utool as ut
_valstr = _make_valstr(**listkw)
def make_item_str(item):
... | python | def get_itemstr_list(list_, **listkw):
"""
TODO: have this replace dict_itemstr list or at least most functionality in
it. have it make two itemstr lists over keys and values and then combine
them.
"""
import utool as ut
_valstr = _make_valstr(**listkw)
def make_item_str(item):
... | [
"def",
"get_itemstr_list",
"(",
"list_",
",",
"*",
"*",
"listkw",
")",
":",
"import",
"utool",
"as",
"ut",
"_valstr",
"=",
"_make_valstr",
"(",
"*",
"*",
"listkw",
")",
"def",
"make_item_str",
"(",
"item",
")",
":",
"item_str",
"=",
"_valstr",
"(",
"it... | TODO: have this replace dict_itemstr list or at least most functionality in
it. have it make two itemstr lists over keys and values and then combine
them. | [
"TODO",
":",
"have",
"this",
"replace",
"dict_itemstr",
"list",
"or",
"at",
"least",
"most",
"functionality",
"in",
"it",
".",
"have",
"it",
"make",
"two",
"itemstr",
"lists",
"over",
"keys",
"and",
"values",
"and",
"then",
"combine",
"them",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1750-L1781 | train | Get a list of itemstr strings for a node in the order they appear in the tree. |
Erotemic/utool | utool/util_str.py | horiz_string | def horiz_string(*args, **kwargs):
"""
Horizontally concatenates strings reprs preserving indentation
Concats a list of objects ensuring that the next item in the list
is all the way to the right of any previous items.
Args:
*args: list of strings to concat
**kwargs: precision, sep... | python | def horiz_string(*args, **kwargs):
"""
Horizontally concatenates strings reprs preserving indentation
Concats a list of objects ensuring that the next item in the list
is all the way to the right of any previous items.
Args:
*args: list of strings to concat
**kwargs: precision, sep... | [
"def",
"horiz_string",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"unicodedata",
"precision",
"=",
"kwargs",
".",
"get",
"(",
"'precision'",
",",
"None",
")",
"sep",
"=",
"kwargs",
".",
"get",
"(",
"'sep'",
",",
"''",
")",
"if",
... | Horizontally concatenates strings reprs preserving indentation
Concats a list of objects ensuring that the next item in the list
is all the way to the right of any previous items.
Args:
*args: list of strings to concat
**kwargs: precision, sep
CommandLine:
python -m utool.util... | [
"Horizontally",
"concatenates",
"strings",
"reprs",
"preserving",
"indentation"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1795-L1879 | train | Horizontally concatenates strings reprs preserving indentation and prints the result |
Erotemic/utool | utool/util_str.py | str_between | def str_between(str_, startstr, endstr):
r"""
gets substring between two sentianl strings
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> str_ = '\n INSERT INTO vsone(\n'
>>> startstr = 'INSERT'
>>> en... | python | def str_between(str_, startstr, endstr):
r"""
gets substring between two sentianl strings
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> str_ = '\n INSERT INTO vsone(\n'
>>> startstr = 'INSERT'
>>> en... | [
"def",
"str_between",
"(",
"str_",
",",
"startstr",
",",
"endstr",
")",
":",
"if",
"startstr",
"is",
"None",
":",
"startpos",
"=",
"0",
"else",
":",
"startpos",
"=",
"str_",
".",
"find",
"(",
"startstr",
")",
"+",
"len",
"(",
"startstr",
")",
"if",
... | r"""
gets substring between two sentianl strings
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> import utool as ut
>>> str_ = '\n INSERT INTO vsone(\n'
>>> startstr = 'INSERT'
>>> endstr = '('
>>> result = str_between(s... | [
"r",
"gets",
"substring",
"between",
"two",
"sentianl",
"strings"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1885-L1910 | train | r Returns a string that is a substring between two sentianl strings |
Erotemic/utool | utool/util_str.py | get_callable_name | def get_callable_name(func):
""" Works on must functionlike objects including str, which has no func_name
Args:
func (function):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-get_callable_name
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_... | python | def get_callable_name(func):
""" Works on must functionlike objects including str, which has no func_name
Args:
func (function):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-get_callable_name
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_... | [
"def",
"get_callable_name",
"(",
"func",
")",
":",
"try",
":",
"return",
"meta_util_six",
".",
"get_funcname",
"(",
"func",
")",
"except",
"AttributeError",
":",
"if",
"isinstance",
"(",
"func",
",",
"type",
")",
":",
"return",
"repr",
"(",
"func",
")",
... | Works on must functionlike objects including str, which has no func_name
Args:
func (function):
Returns:
str:
CommandLine:
python -m utool.util_str --exec-get_callable_name
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> func... | [
"Works",
"on",
"must",
"functionlike",
"objects",
"including",
"str",
"which",
"has",
"no",
"func_name"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1913-L1942 | train | Returns the name of the callable object |
Erotemic/utool | utool/util_str.py | align | def align(text, character='=', replchar=None, pos=0):
r"""
Left justifies text on the left side of character
align
Args:
text (str): text to align
character (str): character to align at
replchar (str): replacement character (default=None)
Returns:
str: new_text
... | python | def align(text, character='=', replchar=None, pos=0):
r"""
Left justifies text on the left side of character
align
Args:
text (str): text to align
character (str): character to align at
replchar (str): replacement character (default=None)
Returns:
str: new_text
... | [
"def",
"align",
"(",
"text",
",",
"character",
"=",
"'='",
",",
"replchar",
"=",
"None",
",",
"pos",
"=",
"0",
")",
":",
"line_list",
"=",
"text",
".",
"splitlines",
"(",
")",
"new_lines",
"=",
"align_lines",
"(",
"line_list",
",",
"character",
",",
... | r"""
Left justifies text on the left side of character
align
Args:
text (str): text to align
character (str): character to align at
replchar (str): replacement character (default=None)
Returns:
str: new_text
CommandLine:
python -m utool.util_str --test-ali... | [
"r",
"Left",
"justifies",
"text",
"on",
"the",
"left",
"side",
"of",
"character"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1945-L1977 | train | r Aligns text on the left side of a character at a given position |
Erotemic/utool | utool/util_str.py | align_lines | def align_lines(line_list, character='=', replchar=None, pos=0):
r"""
Left justifies text on the left side of character
align_lines
TODO:
clean up and move to ubelt?
Args:
line_list (list of strs):
character (str):
pos (int or list or None): does one alignment for ... | python | def align_lines(line_list, character='=', replchar=None, pos=0):
r"""
Left justifies text on the left side of character
align_lines
TODO:
clean up and move to ubelt?
Args:
line_list (list of strs):
character (str):
pos (int or list or None): does one alignment for ... | [
"def",
"align_lines",
"(",
"line_list",
",",
"character",
"=",
"'='",
",",
"replchar",
"=",
"None",
",",
"pos",
"=",
"0",
")",
":",
"# FIXME: continue to fix ansi",
"if",
"pos",
"is",
"None",
":",
"# Align all occurences",
"num_pos",
"=",
"max",
"(",
"[",
... | r"""
Left justifies text on the left side of character
align_lines
TODO:
clean up and move to ubelt?
Args:
line_list (list of strs):
character (str):
pos (int or list or None): does one alignment for all chars beyond this
column position. If pos is None, th... | [
"r",
"Left",
"justifies",
"text",
"on",
"the",
"left",
"side",
"of",
"character"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L1980-L2132 | train | r aligns a list of lines of text on the left side of a character |
Erotemic/utool | utool/util_str.py | long_fname_format | def long_fname_format(fmt_str, fmt_dict, hashable_keys=[], max_len=64,
hashlen=16, ABS_MAX_LEN=255, hack27=False):
r"""
DEPRICATE
Formats a string and hashes certain parts if the resulting string becomes
too long. Used for making filenames fit onto disk.
Args:
fmt_str... | python | def long_fname_format(fmt_str, fmt_dict, hashable_keys=[], max_len=64,
hashlen=16, ABS_MAX_LEN=255, hack27=False):
r"""
DEPRICATE
Formats a string and hashes certain parts if the resulting string becomes
too long. Used for making filenames fit onto disk.
Args:
fmt_str... | [
"def",
"long_fname_format",
"(",
"fmt_str",
",",
"fmt_dict",
",",
"hashable_keys",
"=",
"[",
"]",
",",
"max_len",
"=",
"64",
",",
"hashlen",
"=",
"16",
",",
"ABS_MAX_LEN",
"=",
"255",
",",
"hack27",
"=",
"False",
")",
":",
"from",
"utool",
"import",
"u... | r"""
DEPRICATE
Formats a string and hashes certain parts if the resulting string becomes
too long. Used for making filenames fit onto disk.
Args:
fmt_str (str): format of fname
fmt_dict (str): dict to format fname with
hashable_keys (list): list of dict keys you are willing to ... | [
"r",
"DEPRICATE"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2146-L2210 | train | r Formats a string and hashes certain parts if the resulting string becomes too long. |
Erotemic/utool | utool/util_str.py | multi_replace | def multi_replace(str_, search_list, repl_list):
r"""
Performs multiple replace functions foreach item in search_list and
repl_list.
Args:
str_ (str): string to search
search_list (list): list of search strings
repl_list (list or str): one or multiple replace strings
Return... | python | def multi_replace(str_, search_list, repl_list):
r"""
Performs multiple replace functions foreach item in search_list and
repl_list.
Args:
str_ (str): string to search
search_list (list): list of search strings
repl_list (list or str): one or multiple replace strings
Return... | [
"def",
"multi_replace",
"(",
"str_",
",",
"search_list",
",",
"repl_list",
")",
":",
"if",
"isinstance",
"(",
"repl_list",
",",
"six",
".",
"string_types",
")",
":",
"repl_list_",
"=",
"[",
"repl_list",
"]",
"*",
"len",
"(",
"search_list",
")",
"else",
"... | r"""
Performs multiple replace functions foreach item in search_list and
repl_list.
Args:
str_ (str): string to search
search_list (list): list of search strings
repl_list (list or str): one or multiple replace strings
Returns:
str: str_
CommandLine:
python... | [
"r",
"Performs",
"multiple",
"replace",
"functions",
"foreach",
"item",
"in",
"search_list",
"and",
"repl_list",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2213-L2248 | train | r Performs multiple replace functions for item in search_list and repl_list. |
Erotemic/utool | utool/util_str.py | pluralize | def pluralize(wordtext, num=2, plural_suffix='s'):
r"""
Heuristically changes a word to its plural form if `num` is not 1
Args:
wordtext (str): word in singular form
num (int): a length of an associated list if applicable (default = 2)
plural_suffix (str): heurstic plural form (defa... | python | def pluralize(wordtext, num=2, plural_suffix='s'):
r"""
Heuristically changes a word to its plural form if `num` is not 1
Args:
wordtext (str): word in singular form
num (int): a length of an associated list if applicable (default = 2)
plural_suffix (str): heurstic plural form (defa... | [
"def",
"pluralize",
"(",
"wordtext",
",",
"num",
"=",
"2",
",",
"plural_suffix",
"=",
"'s'",
")",
":",
"if",
"num",
"==",
"1",
":",
"return",
"wordtext",
"else",
":",
"if",
"wordtext",
".",
"endswith",
"(",
"'\\'s'",
")",
":",
"return",
"wordtext",
"... | r"""
Heuristically changes a word to its plural form if `num` is not 1
Args:
wordtext (str): word in singular form
num (int): a length of an associated list if applicable (default = 2)
plural_suffix (str): heurstic plural form (default = 's')
Returns:
str: pluralized form. ... | [
"r",
"Heuristically",
"changes",
"a",
"word",
"to",
"its",
"plural",
"form",
"if",
"num",
"is",
"not",
"1"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2251-L2281 | train | r Heuristically changes a word to its plural form if num is not 1 |
Erotemic/utool | utool/util_str.py | quantstr | def quantstr(typestr, num, plural_suffix='s'):
r"""
Heuristically generates an english phrase relating to the quantity of
something. This is useful for writing user messages.
Args:
typestr (str): singular form of the word
num (int): quanity of the type
plural_suffix (str): heur... | python | def quantstr(typestr, num, plural_suffix='s'):
r"""
Heuristically generates an english phrase relating to the quantity of
something. This is useful for writing user messages.
Args:
typestr (str): singular form of the word
num (int): quanity of the type
plural_suffix (str): heur... | [
"def",
"quantstr",
"(",
"typestr",
",",
"num",
",",
"plural_suffix",
"=",
"'s'",
")",
":",
"return",
"six",
".",
"text_type",
"(",
"num",
")",
"+",
"' '",
"+",
"pluralize",
"(",
"typestr",
",",
"num",
",",
"plural_suffix",
")"
] | r"""
Heuristically generates an english phrase relating to the quantity of
something. This is useful for writing user messages.
Args:
typestr (str): singular form of the word
num (int): quanity of the type
plural_suffix (str): heurstic plural form (default = 's')
Returns:
... | [
"r",
"Heuristically",
"generates",
"an",
"english",
"phrase",
"relating",
"to",
"the",
"quantity",
"of",
"something",
".",
"This",
"is",
"useful",
"for",
"writing",
"user",
"messages",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2284-L2314 | train | r Quuristically generates an english phrase relating to the quantity of the given type and number |
Erotemic/utool | utool/util_str.py | msgblock | def msgblock(key, text, side='|'):
""" puts text inside a visual ascii block """
blocked_text = ''.join(
[' + --- ', key, ' ---\n'] +
[' ' + side + ' ' + line + '\n' for line in text.split('\n')] +
[' L ___ ', key, ' ___\n']
)
return blocked_text | python | def msgblock(key, text, side='|'):
""" puts text inside a visual ascii block """
blocked_text = ''.join(
[' + --- ', key, ' ---\n'] +
[' ' + side + ' ' + line + '\n' for line in text.split('\n')] +
[' L ___ ', key, ' ___\n']
)
return blocked_text | [
"def",
"msgblock",
"(",
"key",
",",
"text",
",",
"side",
"=",
"'|'",
")",
":",
"blocked_text",
"=",
"''",
".",
"join",
"(",
"[",
"' + --- '",
",",
"key",
",",
"' ---\\n'",
"]",
"+",
"[",
"' '",
"+",
"side",
"+",
"' '",
"+",
"line",
"+",
"'\\n'",
... | puts text inside a visual ascii block | [
"puts",
"text",
"inside",
"a",
"visual",
"ascii",
"block"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2317-L2324 | train | puts text inside a visual ascii block |
Erotemic/utool | utool/util_str.py | number_text_lines | def number_text_lines(text):
r"""
Args:
text (str):
Returns:
str: text_with_lineno - string with numbered lines
"""
numbered_linelist = [
''.join((('%2d' % (count + 1)), ' >>> ', line))
for count, line in enumerate(text.splitlines())
]
text_with_lineno = '\n'... | python | def number_text_lines(text):
r"""
Args:
text (str):
Returns:
str: text_with_lineno - string with numbered lines
"""
numbered_linelist = [
''.join((('%2d' % (count + 1)), ' >>> ', line))
for count, line in enumerate(text.splitlines())
]
text_with_lineno = '\n'... | [
"def",
"number_text_lines",
"(",
"text",
")",
":",
"numbered_linelist",
"=",
"[",
"''",
".",
"join",
"(",
"(",
"(",
"'%2d'",
"%",
"(",
"count",
"+",
"1",
")",
")",
",",
"' >>> '",
",",
"line",
")",
")",
"for",
"count",
",",
"line",
"in",
"enumerate... | r"""
Args:
text (str):
Returns:
str: text_with_lineno - string with numbered lines | [
"r",
"Args",
":",
"text",
"(",
"str",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2327-L2340 | train | r Numberes the lines of a text string. |
Erotemic/utool | utool/util_str.py | get_textdiff | def get_textdiff(text1, text2, num_context_lines=0, ignore_whitespace=False):
r"""
Uses difflib to return a difference string between two similar texts
Args:
text1 (str):
text2 (str):
Returns:
str: formatted difference text message
SeeAlso:
ut.color_diff_text
... | python | def get_textdiff(text1, text2, num_context_lines=0, ignore_whitespace=False):
r"""
Uses difflib to return a difference string between two similar texts
Args:
text1 (str):
text2 (str):
Returns:
str: formatted difference text message
SeeAlso:
ut.color_diff_text
... | [
"def",
"get_textdiff",
"(",
"text1",
",",
"text2",
",",
"num_context_lines",
"=",
"0",
",",
"ignore_whitespace",
"=",
"False",
")",
":",
"import",
"difflib",
"text1",
"=",
"ensure_unicode",
"(",
"text1",
")",
"text2",
"=",
"ensure_unicode",
"(",
"text2",
")"... | r"""
Uses difflib to return a difference string between two similar texts
Args:
text1 (str):
text2 (str):
Returns:
str: formatted difference text message
SeeAlso:
ut.color_diff_text
References:
http://www.java2s.com/Code/Python/Utility/Intelligentdiffbetwe... | [
"r",
"Uses",
"difflib",
"to",
"return",
"a",
"difference",
"string",
"between",
"two",
"similar",
"texts"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2343-L2433 | train | r Returns a string that is the difference between two texts |
Erotemic/utool | utool/util_str.py | conj_phrase | def conj_phrase(list_, cond='or'):
"""
Joins a list of words using English conjunction rules
Args:
list_ (list): of strings
cond (str): a conjunction (or, and, but)
Returns:
str: the joined cconjunction phrase
References:
http://en.wikipedia.org/wiki/Conjunction_(... | python | def conj_phrase(list_, cond='or'):
"""
Joins a list of words using English conjunction rules
Args:
list_ (list): of strings
cond (str): a conjunction (or, and, but)
Returns:
str: the joined cconjunction phrase
References:
http://en.wikipedia.org/wiki/Conjunction_(... | [
"def",
"conj_phrase",
"(",
"list_",
",",
"cond",
"=",
"'or'",
")",
":",
"if",
"len",
"(",
"list_",
")",
"==",
"0",
":",
"return",
"''",
"elif",
"len",
"(",
"list_",
")",
"==",
"1",
":",
"return",
"list_",
"[",
"0",
"]",
"elif",
"len",
"(",
"lis... | Joins a list of words using English conjunction rules
Args:
list_ (list): of strings
cond (str): a conjunction (or, and, but)
Returns:
str: the joined cconjunction phrase
References:
http://en.wikipedia.org/wiki/Conjunction_(grammar)
Example:
>>> # ENABLE_DOC... | [
"Joins",
"a",
"list",
"of",
"words",
"using",
"English",
"conjunction",
"rules"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2439-L2477 | train | Joins a list of words using English conjunction rules |
Erotemic/utool | utool/util_str.py | format_text_as_docstr | def format_text_as_docstr(text):
r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docstr(text)
... | python | def format_text_as_docstr(text):
r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docstr(text)
... | [
"def",
"format_text_as_docstr",
"(",
"text",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"re",
"min_indent",
"=",
"ut",
".",
"get_minimum_indentation",
"(",
"text",
")",
"indent_",
"=",
"' '",
"*",
"min_indent",
"formated_text",
"=",
"re",
".",
"sub",... | r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docstr(text)
>>> result = ('formated_text = \... | [
"r"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2501-L2523 | train | r Format text as docstr |
Erotemic/utool | utool/util_str.py | unformat_text_as_docstr | def unformat_text_as_docstr(formated_text):
r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-unformat_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docs... | python | def unformat_text_as_docstr(formated_text):
r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-unformat_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docs... | [
"def",
"unformat_text_as_docstr",
"(",
"formated_text",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"re",
"min_indent",
"=",
"ut",
".",
"get_minimum_indentation",
"(",
"formated_text",
")",
"indent_",
"=",
"' '",
"*",
"min_indent",
"unformated_text",
"=",
... | r"""
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-unformat_text_as_docstr
Example:
>>> # DISABLE_DOCTEST
>>> from pyvim_funcs import * # NOQA
>>> text = testdata_text()
>>> formated_text = format_text_as_docstr(text)
>>> unformated_text = unformat_... | [
"r",
"CommandLine",
":",
"python",
"~",
"/",
"local",
"/",
"vim",
"/",
"rc",
"/",
"pyvim_funcs",
".",
"py",
"--",
"test",
"-",
"unformat_text_as_docstr"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2526-L2546 | train | r Unformat the text of a cluster node as a docstr |
Erotemic/utool | utool/util_str.py | bubbletext | def bubbletext(text, font='cybermedium'):
r"""
Uses pyfiglet to create bubble text.
Args:
font (str): default=cybermedium, other fonts include: cybersmall and
cyberlarge.
References:
http://www.figlet.org/
Example:
>>> # ENABLE_DOCTEST
>>> import utool ... | python | def bubbletext(text, font='cybermedium'):
r"""
Uses pyfiglet to create bubble text.
Args:
font (str): default=cybermedium, other fonts include: cybersmall and
cyberlarge.
References:
http://www.figlet.org/
Example:
>>> # ENABLE_DOCTEST
>>> import utool ... | [
"def",
"bubbletext",
"(",
"text",
",",
"font",
"=",
"'cybermedium'",
")",
":",
"import",
"utool",
"as",
"ut",
"pyfiglet",
"=",
"ut",
".",
"tryimport",
"(",
"'pyfiglet'",
",",
"'git+https://github.com/pwaller/pyfiglet'",
")",
"if",
"pyfiglet",
"is",
"None",
":"... | r"""
Uses pyfiglet to create bubble text.
Args:
font (str): default=cybermedium, other fonts include: cybersmall and
cyberlarge.
References:
http://www.figlet.org/
Example:
>>> # ENABLE_DOCTEST
>>> import utool as ut
>>> bubble_text = ut.bubbletext(... | [
"r",
"Uses",
"pyfiglet",
"to",
"create",
"bubble",
"text",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2563-L2586 | train | r Creates a bubble text from a string. |
Erotemic/utool | utool/util_str.py | to_title_caps | def to_title_caps(underscore_case):
r"""
Args:
underscore_case (?):
Returns:
str: title_str
CommandLine:
python -m utool.util_str --exec-to_title_caps
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> underscore_case = 'the... | python | def to_title_caps(underscore_case):
r"""
Args:
underscore_case (?):
Returns:
str: title_str
CommandLine:
python -m utool.util_str --exec-to_title_caps
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> underscore_case = 'the... | [
"def",
"to_title_caps",
"(",
"underscore_case",
")",
":",
"words",
"=",
"underscore_case",
".",
"split",
"(",
"'_'",
")",
"words2",
"=",
"[",
"word",
"[",
"0",
"]",
".",
"upper",
"(",
")",
"+",
"word",
"[",
"1",
":",
"]",
"for",
"count",
",",
"word... | r"""
Args:
underscore_case (?):
Returns:
str: title_str
CommandLine:
python -m utool.util_str --exec-to_title_caps
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> underscore_case = 'the_foo_bar_func'
>>> title_str = t... | [
"r",
"Args",
":",
"underscore_case",
"(",
"?",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2603-L2629 | train | r Converts the underscore_case to title_caps |
Erotemic/utool | utool/util_str.py | to_underscore_case | def to_underscore_case(camelcase_str):
r"""
References:
http://stackoverflow.com/questions/1175208/convert-camelcase
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> camelcase_str = 'UnderscoreFuncname'
>>> camel_case_str = to_underscore_cas... | python | def to_underscore_case(camelcase_str):
r"""
References:
http://stackoverflow.com/questions/1175208/convert-camelcase
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> camelcase_str = 'UnderscoreFuncname'
>>> camel_case_str = to_underscore_cas... | [
"def",
"to_underscore_case",
"(",
"camelcase_str",
")",
":",
"s1",
"=",
"re",
".",
"sub",
"(",
"'(.)([A-Z][a-z]+)'",
",",
"r'\\1_\\2'",
",",
"camelcase_str",
")",
"return",
"re",
".",
"sub",
"(",
"'([a-z0-9])([A-Z])'",
",",
"r'\\1_\\2'",
",",
"s1",
")",
".",... | r"""
References:
http://stackoverflow.com/questions/1175208/convert-camelcase
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
>>> camelcase_str = 'UnderscoreFuncname'
>>> camel_case_str = to_underscore_case(camelcase_str)
>>> result = ('und... | [
"r",
"References",
":",
"http",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"1175208",
"/",
"convert",
"-",
"camelcase"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2632-L2647 | train | r Converts a camelcase string to underscore_str |
Erotemic/utool | utool/util_str.py | to_camel_case | def to_camel_case(underscore_case, mixed=False):
r"""
Args:
underscore_case (?):
Returns:
str: camel_case_str
CommandLine:
python -m utool.util_str --exec-to_camel_case
References:
https://en.wikipedia.org/wiki/CamelCase
Example:
>>> # ENABLE_DOCTEST
... | python | def to_camel_case(underscore_case, mixed=False):
r"""
Args:
underscore_case (?):
Returns:
str: camel_case_str
CommandLine:
python -m utool.util_str --exec-to_camel_case
References:
https://en.wikipedia.org/wiki/CamelCase
Example:
>>> # ENABLE_DOCTEST
... | [
"def",
"to_camel_case",
"(",
"underscore_case",
",",
"mixed",
"=",
"False",
")",
":",
"thresh",
"=",
"0",
"if",
"mixed",
"else",
"-",
"1",
"words",
"=",
"underscore_case",
".",
"split",
"(",
"'_'",
")",
"words2",
"=",
"[",
"word",
"[",
"0",
"]",
".",... | r"""
Args:
underscore_case (?):
Returns:
str: camel_case_str
CommandLine:
python -m utool.util_str --exec-to_camel_case
References:
https://en.wikipedia.org/wiki/CamelCase
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_str import * # NOQA
... | [
"r",
"Args",
":",
"underscore_case",
"(",
"?",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2650-L2682 | train | r Converts a string from the underscore_case to the camel_case_str |
Erotemic/utool | utool/util_str.py | is_url | def is_url(str_):
""" heuristic check if str is url formatted """
return any([
str_.startswith('http://'),
str_.startswith('https://'),
str_.startswith('www.'),
'.org/' in str_,
'.com/' in str_,
]) | python | def is_url(str_):
""" heuristic check if str is url formatted """
return any([
str_.startswith('http://'),
str_.startswith('https://'),
str_.startswith('www.'),
'.org/' in str_,
'.com/' in str_,
]) | [
"def",
"is_url",
"(",
"str_",
")",
":",
"return",
"any",
"(",
"[",
"str_",
".",
"startswith",
"(",
"'http://'",
")",
",",
"str_",
".",
"startswith",
"(",
"'https://'",
")",
",",
"str_",
".",
"startswith",
"(",
"'www.'",
")",
",",
"'.org/'",
"in",
"st... | heuristic check if str is url formatted | [
"heuristic",
"check",
"if",
"str",
"is",
"url",
"formatted"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2685-L2693 | train | heuristic check if str is url formatted |
Erotemic/utool | utool/util_str.py | autoformat_pep8 | def autoformat_pep8(sourcecode, **kwargs):
r"""
Args:
code (str):
CommandLine:
python -m utool.util_str --exec-autoformat_pep8
Kwargs:
'aggressive': 0,
'diff': False,
'exclude': [],
'experimental': False,
'files': [u''],
'global_config': ... | python | def autoformat_pep8(sourcecode, **kwargs):
r"""
Args:
code (str):
CommandLine:
python -m utool.util_str --exec-autoformat_pep8
Kwargs:
'aggressive': 0,
'diff': False,
'exclude': [],
'experimental': False,
'files': [u''],
'global_config': ... | [
"def",
"autoformat_pep8",
"(",
"sourcecode",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"autopep8",
"default_ignore",
"=",
"{",
"'E126'",
",",
"# continuation line hanging-indent",
"'E127'",
",",
"# continuation line over-indented for visual indent",
"'E201'",
",",
"#... | r"""
Args:
code (str):
CommandLine:
python -m utool.util_str --exec-autoformat_pep8
Kwargs:
'aggressive': 0,
'diff': False,
'exclude': [],
'experimental': False,
'files': [u''],
'global_config': ~/.config/pep8,
'ignore': set([u'E24'])... | [
"r",
"Args",
":",
"code",
"(",
"str",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2696-L2757 | train | r Automatically formats the source code for PEP - 8. |
Erotemic/utool | utool/util_str.py | chr_range | def chr_range(*args, **kw):
r"""
Like range but returns characters
Args:
start (None): (default = None)
stop (None): (default = None)
step (None): (default = None)
Kwargs:
base (str): charater to start with (default='a')
Returns:
list: list of characters
... | python | def chr_range(*args, **kw):
r"""
Like range but returns characters
Args:
start (None): (default = None)
stop (None): (default = None)
step (None): (default = None)
Kwargs:
base (str): charater to start with (default='a')
Returns:
list: list of characters
... | [
"def",
"chr_range",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"if",
"len",
"(",
"args",
")",
"==",
"1",
":",
"stop",
",",
"=",
"args",
"start",
",",
"step",
"=",
"0",
",",
"1",
"elif",
"len",
"(",
"args",
")",
"==",
"2",
":",
"start"... | r"""
Like range but returns characters
Args:
start (None): (default = None)
stop (None): (default = None)
step (None): (default = None)
Kwargs:
base (str): charater to start with (default='a')
Returns:
list: list of characters
CommandLine:
python -... | [
"r",
"Like",
"range",
"but",
"returns",
"characters"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2772-L2828 | train | r Like range but returns characters
|
Erotemic/utool | utool/util_str.py | highlight_text | def highlight_text(text, lexer_name='python', **kwargs):
r"""
SeeAlso:
color_text
"""
# Resolve extensions to languages
lexer_name = {
'py': 'python',
'h': 'cpp',
'cpp': 'cpp',
'c': 'cpp',
}.get(lexer_name.replace('.', ''), lexer_name)
if lexer_name in... | python | def highlight_text(text, lexer_name='python', **kwargs):
r"""
SeeAlso:
color_text
"""
# Resolve extensions to languages
lexer_name = {
'py': 'python',
'h': 'cpp',
'cpp': 'cpp',
'c': 'cpp',
}.get(lexer_name.replace('.', ''), lexer_name)
if lexer_name in... | [
"def",
"highlight_text",
"(",
"text",
",",
"lexer_name",
"=",
"'python'",
",",
"*",
"*",
"kwargs",
")",
":",
"# Resolve extensions to languages",
"lexer_name",
"=",
"{",
"'py'",
":",
"'python'",
",",
"'h'",
":",
"'cpp'",
",",
"'cpp'",
":",
"'cpp'",
",",
"'... | r"""
SeeAlso:
color_text | [
"r",
"SeeAlso",
":",
"color_text"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2839-L2877 | train | r Highlights text with lexer_name. |
Erotemic/utool | utool/util_str.py | color_text | def color_text(text, color):
r"""
SeeAlso:
highlight_text
lexer_shortnames = sorted(ut.flatten(ut.take_column(pygments.lexers.LEXERS.values(), 2)))
"""
import utool as ut
if color is None or not ENABLE_COLORS:
return text
elif color == 'python':
return highlight_t... | python | def color_text(text, color):
r"""
SeeAlso:
highlight_text
lexer_shortnames = sorted(ut.flatten(ut.take_column(pygments.lexers.LEXERS.values(), 2)))
"""
import utool as ut
if color is None or not ENABLE_COLORS:
return text
elif color == 'python':
return highlight_t... | [
"def",
"color_text",
"(",
"text",
",",
"color",
")",
":",
"import",
"utool",
"as",
"ut",
"if",
"color",
"is",
"None",
"or",
"not",
"ENABLE_COLORS",
":",
"return",
"text",
"elif",
"color",
"==",
"'python'",
":",
"return",
"highlight_text",
"(",
"text",
",... | r"""
SeeAlso:
highlight_text
lexer_shortnames = sorted(ut.flatten(ut.take_column(pygments.lexers.LEXERS.values(), 2))) | [
"r",
"SeeAlso",
":",
"highlight_text",
"lexer_shortnames",
"=",
"sorted",
"(",
"ut",
".",
"flatten",
"(",
"ut",
".",
"take_column",
"(",
"pygments",
".",
"lexers",
".",
"LEXERS",
".",
"values",
"()",
"2",
")))"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2880-L2909 | train | r Colorize text using pygments. |
Erotemic/utool | utool/util_str.py | highlight_regex | def highlight_regex(str_, pat, reflags=0, color='red'):
"""
FIXME Use pygments instead
"""
#import colorama
# from colorama import Fore, Style
#color = Fore.MAGENTA
# color = Fore.RED
#match = re.search(pat, str_, flags=reflags)
matches = list(re.finditer(pat, str_, flags=reflags))
... | python | def highlight_regex(str_, pat, reflags=0, color='red'):
"""
FIXME Use pygments instead
"""
#import colorama
# from colorama import Fore, Style
#color = Fore.MAGENTA
# color = Fore.RED
#match = re.search(pat, str_, flags=reflags)
matches = list(re.finditer(pat, str_, flags=reflags))
... | [
"def",
"highlight_regex",
"(",
"str_",
",",
"pat",
",",
"reflags",
"=",
"0",
",",
"color",
"=",
"'red'",
")",
":",
"#import colorama",
"# from colorama import Fore, Style",
"#color = Fore.MAGENTA",
"# color = Fore.RED",
"#match = re.search(pat, str_, flags=reflags)",
"match... | FIXME Use pygments instead | [
"FIXME",
"Use",
"pygments",
"instead"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2912-L2938 | train | Highlights a string by regex pattern. |
Erotemic/utool | utool/util_str.py | highlight_multi_regex | def highlight_multi_regex(str_, pat_to_color, reflags=0):
"""
FIXME Use pygments instead. must be mututally exclusive
"""
#import colorama
# from colorama import Fore, Style
#color = Fore.MAGENTA
# color = Fore.RED
#match = re.search(pat, str_, flags=reflags)
colored = str_
to_... | python | def highlight_multi_regex(str_, pat_to_color, reflags=0):
"""
FIXME Use pygments instead. must be mututally exclusive
"""
#import colorama
# from colorama import Fore, Style
#color = Fore.MAGENTA
# color = Fore.RED
#match = re.search(pat, str_, flags=reflags)
colored = str_
to_... | [
"def",
"highlight_multi_regex",
"(",
"str_",
",",
"pat_to_color",
",",
"reflags",
"=",
"0",
")",
":",
"#import colorama",
"# from colorama import Fore, Style",
"#color = Fore.MAGENTA",
"# color = Fore.RED",
"#match = re.search(pat, str_, flags=reflags)",
"colored",
"=",
"str_",... | FIXME Use pygments instead. must be mututally exclusive | [
"FIXME",
"Use",
"pygments",
"instead",
".",
"must",
"be",
"mututally",
"exclusive"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L2941-L2967 | train | Highlights a string by a set of patterns. |
Erotemic/utool | utool/util_str.py | format_multiple_paragraph_sentences | def format_multiple_paragraph_sentences(text, debug=False, **kwargs):
"""
FIXME: funky things happen when multiple newlines in the middle of
paragraphs
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_multiple_paragraph_sentences
CommandLine:
python -m utool.util_str... | python | def format_multiple_paragraph_sentences(text, debug=False, **kwargs):
"""
FIXME: funky things happen when multiple newlines in the middle of
paragraphs
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_multiple_paragraph_sentences
CommandLine:
python -m utool.util_str... | [
"def",
"format_multiple_paragraph_sentences",
"(",
"text",
",",
"debug",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"debug",
"=",
"_rectify_countdown_or_bool",
"(",
"debug",
")",
"import",
"utool",
"as",
"ut",
"# Hack",
"text",
"=",
"re",
".",
"sub",
... | FIXME: funky things happen when multiple newlines in the middle of
paragraphs
CommandLine:
python ~/local/vim/rc/pyvim_funcs.py --test-format_multiple_paragraph_sentences
CommandLine:
python -m utool.util_str --exec-format_multiple_paragraph_sentences --show
Example:
>>> # DIS... | [
"FIXME",
":",
"funky",
"things",
"happen",
"when",
"multiple",
"newlines",
"in",
"the",
"middle",
"of",
"paragraphs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L3098-L3220 | train | This function formats the text in a single paragraph. |
Erotemic/utool | utool/util_str.py | format_single_paragraph_sentences | def format_single_paragraph_sentences(text, debug=False, myprefix=True,
sentence_break=True, max_width=73,
sepcolon=True):
r"""
helps me separatate sentences grouped in paragraphs that I have a
difficult time reading due to dyslexia... | python | def format_single_paragraph_sentences(text, debug=False, myprefix=True,
sentence_break=True, max_width=73,
sepcolon=True):
r"""
helps me separatate sentences grouped in paragraphs that I have a
difficult time reading due to dyslexia... | [
"def",
"format_single_paragraph_sentences",
"(",
"text",
",",
"debug",
"=",
"False",
",",
"myprefix",
"=",
"True",
",",
"sentence_break",
"=",
"True",
",",
"max_width",
"=",
"73",
",",
"sepcolon",
"=",
"True",
")",
":",
"import",
"utool",
"as",
"ut",
"#ut.... | r"""
helps me separatate sentences grouped in paragraphs that I have a
difficult time reading due to dyslexia
Args:
text (str):
Returns:
str: wrapped_text
CommandLine:
python -m utool.util_str --exec-format_single_paragraph_sentences --show
python -m utool.util_str... | [
"r",
"helps",
"me",
"separatate",
"sentences",
"grouped",
"in",
"paragraphs",
"that",
"I",
"have",
"a",
"difficult",
"time",
"reading",
"due",
"to",
"dyslexia"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L3293-L3489 | train | r This function will wrap the given text in a single paragraph and return a list of sentences. |
Erotemic/utool | utool/util_str.py | find_block_end | def find_block_end(row, line_list, sentinal, direction=1):
"""
Searches up and down until it finds the endpoints of a block Rectify
with find_paragraph_end in pyvim_funcs
"""
import re
row_ = row
line_ = line_list[row_]
flag1 = row_ == 0 or row_ == len(line_list) - 1
flag2 = re.match... | python | def find_block_end(row, line_list, sentinal, direction=1):
"""
Searches up and down until it finds the endpoints of a block Rectify
with find_paragraph_end in pyvim_funcs
"""
import re
row_ = row
line_ = line_list[row_]
flag1 = row_ == 0 or row_ == len(line_list) - 1
flag2 = re.match... | [
"def",
"find_block_end",
"(",
"row",
",",
"line_list",
",",
"sentinal",
",",
"direction",
"=",
"1",
")",
":",
"import",
"re",
"row_",
"=",
"row",
"line_",
"=",
"line_list",
"[",
"row_",
"]",
"flag1",
"=",
"row_",
"==",
"0",
"or",
"row_",
"==",
"len",... | Searches up and down until it finds the endpoints of a block Rectify
with find_paragraph_end in pyvim_funcs | [
"Searches",
"up",
"and",
"down",
"until",
"it",
"finds",
"the",
"endpoints",
"of",
"a",
"block",
"Rectify",
"with",
"find_paragraph_end",
"in",
"pyvim_funcs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_str.py#L3492-L3510 | train | Finds the end of a block in a line_list |
Erotemic/utool | utool/util_latex.py | compress_pdf | def compress_pdf(pdf_fpath, output_fname=None):
""" uses ghostscript to write a pdf """
import utool as ut
ut.assertpath(pdf_fpath)
suffix = '_' + ut.get_datestamp(False) + '_compressed'
print('pdf_fpath = %r' % (pdf_fpath,))
output_pdf_fpath = ut.augpath(pdf_fpath, suffix, newfname=output_fname... | python | def compress_pdf(pdf_fpath, output_fname=None):
""" uses ghostscript to write a pdf """
import utool as ut
ut.assertpath(pdf_fpath)
suffix = '_' + ut.get_datestamp(False) + '_compressed'
print('pdf_fpath = %r' % (pdf_fpath,))
output_pdf_fpath = ut.augpath(pdf_fpath, suffix, newfname=output_fname... | [
"def",
"compress_pdf",
"(",
"pdf_fpath",
",",
"output_fname",
"=",
"None",
")",
":",
"import",
"utool",
"as",
"ut",
"ut",
".",
"assertpath",
"(",
"pdf_fpath",
")",
"suffix",
"=",
"'_'",
"+",
"ut",
".",
"get_datestamp",
"(",
"False",
")",
"+",
"'_compress... | uses ghostscript to write a pdf | [
"uses",
"ghostscript",
"to",
"write",
"a",
"pdf"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L37-L57 | train | uses ghostscript to write a pdf |
Erotemic/utool | utool/util_latex.py | make_full_document | def make_full_document(text, title=None, preamp_decl={}, preamb_extra=None):
r"""
dummy preamble and document to wrap around latex fragment
Args:
text (str):
title (str):
Returns:
str: text_
CommandLine:
python -m utool.util_latex --test-make_full_document
Exa... | python | def make_full_document(text, title=None, preamp_decl={}, preamb_extra=None):
r"""
dummy preamble and document to wrap around latex fragment
Args:
text (str):
title (str):
Returns:
str: text_
CommandLine:
python -m utool.util_latex --test-make_full_document
Exa... | [
"def",
"make_full_document",
"(",
"text",
",",
"title",
"=",
"None",
",",
"preamp_decl",
"=",
"{",
"}",
",",
"preamb_extra",
"=",
"None",
")",
":",
"import",
"utool",
"as",
"ut",
"doc_preamb",
"=",
"ut",
".",
"codeblock",
"(",
"'''\n %\\\\documentclass{ar... | r"""
dummy preamble and document to wrap around latex fragment
Args:
text (str):
title (str):
Returns:
str: text_
CommandLine:
python -m utool.util_latex --test-make_full_document
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * #... | [
"r",
"dummy",
"preamble",
"and",
"document",
"to",
"wrap",
"around",
"latex",
"fragment"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L60-L125 | train | r This function creates a full document with the given text and title. |
Erotemic/utool | utool/util_latex.py | render_latex_text | def render_latex_text(input_text, nest_in_doc=False, preamb_extra=None,
appname='utool', verbose=None):
""" compiles latex and shows the result """
import utool as ut
if verbose is None:
verbose = ut.VERBOSE
dpath = ut.ensure_app_resource_dir(appname, 'latex_tmp')
# put... | python | def render_latex_text(input_text, nest_in_doc=False, preamb_extra=None,
appname='utool', verbose=None):
""" compiles latex and shows the result """
import utool as ut
if verbose is None:
verbose = ut.VERBOSE
dpath = ut.ensure_app_resource_dir(appname, 'latex_tmp')
# put... | [
"def",
"render_latex_text",
"(",
"input_text",
",",
"nest_in_doc",
"=",
"False",
",",
"preamb_extra",
"=",
"None",
",",
"appname",
"=",
"'utool'",
",",
"verbose",
"=",
"None",
")",
":",
"import",
"utool",
"as",
"ut",
"if",
"verbose",
"is",
"None",
":",
"... | compiles latex and shows the result | [
"compiles",
"latex",
"and",
"shows",
"the",
"result"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L128-L142 | train | compiles latex and shows the result |
Erotemic/utool | utool/util_latex.py | compile_latex_text | def compile_latex_text(input_text, dpath=None, fname=None, verbose=True,
move=True, nest_in_doc=None, title=None,
preamb_extra=None):
r"""
CommandLine:
python -m utool.util_latex --test-compile_latex_text --show
Ignore:
pdflatex -shell-escape --... | python | def compile_latex_text(input_text, dpath=None, fname=None, verbose=True,
move=True, nest_in_doc=None, title=None,
preamb_extra=None):
r"""
CommandLine:
python -m utool.util_latex --test-compile_latex_text --show
Ignore:
pdflatex -shell-escape --... | [
"def",
"compile_latex_text",
"(",
"input_text",
",",
"dpath",
"=",
"None",
",",
"fname",
"=",
"None",
",",
"verbose",
"=",
"True",
",",
"move",
"=",
"True",
",",
"nest_in_doc",
"=",
"None",
",",
"title",
"=",
"None",
",",
"preamb_extra",
"=",
"None",
"... | r"""
CommandLine:
python -m utool.util_latex --test-compile_latex_text --show
Ignore:
pdflatex -shell-escape --synctex=-1 -src-specials -interaction=nonstopmode\
~/code/ibeis/tmptex/latex_formatter_temp.tex
Example1:
>>> # DISABLE_DOCTEST
>>> from utool.util_lat... | [
"r",
"CommandLine",
":",
"python",
"-",
"m",
"utool",
".",
"util_latex",
"--",
"test",
"-",
"compile_latex_text",
"--",
"show"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L145-L217 | train | r Compile a LaTeX text file into a PDF file. |
Erotemic/utool | utool/util_latex.py | render_latex | def render_latex(input_text, dpath=None, fname=None, preamb_extra=None,
verbose=1, **kwargs):
"""
Renders latex text into a jpeg.
Whitespace that would have appeared in the PDF is removed, so the jpeg is
cropped only the the relevant part. This is ideal for figures that only
take ... | python | def render_latex(input_text, dpath=None, fname=None, preamb_extra=None,
verbose=1, **kwargs):
"""
Renders latex text into a jpeg.
Whitespace that would have appeared in the PDF is removed, so the jpeg is
cropped only the the relevant part. This is ideal for figures that only
take ... | [
"def",
"render_latex",
"(",
"input_text",
",",
"dpath",
"=",
"None",
",",
"fname",
"=",
"None",
",",
"preamb_extra",
"=",
"None",
",",
"verbose",
"=",
"1",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"vtool",
"as",
"vt... | Renders latex text into a jpeg.
Whitespace that would have appeared in the PDF is removed, so the jpeg is
cropped only the the relevant part. This is ideal for figures that only
take a single page.
Args:
input_text (?):
dpath (str): directory path(default = None)
fname (str):... | [
"Renders",
"latex",
"text",
"into",
"a",
"jpeg",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L240-L290 | train | Render a latex text into a jpg file. |
Erotemic/utool | utool/util_latex.py | make_score_tabular | def make_score_tabular(
row_lbls, col_lbls, values, title=None, out_of=None, bold_best=False,
flip=False, bigger_is_better=True, multicol_lbls=None, FORCE_INT=False,
precision=None, SHORTEN_ROW_LBLS=False, col_align='l', col_sep='|',
multicol_sep='|', centerline=True, astable=False, tabl... | python | def make_score_tabular(
row_lbls, col_lbls, values, title=None, out_of=None, bold_best=False,
flip=False, bigger_is_better=True, multicol_lbls=None, FORCE_INT=False,
precision=None, SHORTEN_ROW_LBLS=False, col_align='l', col_sep='|',
multicol_sep='|', centerline=True, astable=False, tabl... | [
"def",
"make_score_tabular",
"(",
"row_lbls",
",",
"col_lbls",
",",
"values",
",",
"title",
"=",
"None",
",",
"out_of",
"=",
"None",
",",
"bold_best",
"=",
"False",
",",
"flip",
"=",
"False",
",",
"bigger_is_better",
"=",
"True",
",",
"multicol_lbls",
"=",... | r"""
makes a LaTeX tabular for displaying scores or errors
Args:
row_lbls (list of str):
col_lbls (list of str):
values (ndarray):
title (str): (default = None)
out_of (None): (default = None)
bold_best (bool): (default = True)
flip (bool): (default = Fa... | [
"r",
"makes",
"a",
"LaTeX",
"tabular",
"for",
"displaying",
"scores",
"or",
"errors"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L401-L708 | train | r This function makes a LaTeX tabular for displaying scores or errors. |
Erotemic/utool | utool/util_latex.py | get_latex_figure_str2 | def get_latex_figure_str2(fpath_list, cmdname, **kwargs):
""" hack for candidacy """
import utool as ut
from os.path import relpath
# Make relative paths
if kwargs.pop('relpath', True):
start = ut.truepath('~/latex/crall-candidacy-2015')
fpath_list = [relpath(fpath, start) for fpath ... | python | def get_latex_figure_str2(fpath_list, cmdname, **kwargs):
""" hack for candidacy """
import utool as ut
from os.path import relpath
# Make relative paths
if kwargs.pop('relpath', True):
start = ut.truepath('~/latex/crall-candidacy-2015')
fpath_list = [relpath(fpath, start) for fpath ... | [
"def",
"get_latex_figure_str2",
"(",
"fpath_list",
",",
"cmdname",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"utool",
"as",
"ut",
"from",
"os",
".",
"path",
"import",
"relpath",
"# Make relative paths",
"if",
"kwargs",
".",
"pop",
"(",
"'relpath'",
",",
... | hack for candidacy | [
"hack",
"for",
"candidacy"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L711-L724 | train | get_latex_figure_str2 - get a LaTeX figure string from a list of files |
Erotemic/utool | utool/util_latex.py | get_latex_figure_str | def get_latex_figure_str(fpath_list, caption_str=None, label_str=None,
width_str=r'\textwidth', height_str=None, nCols=None,
dpath=None, colpos_sep=' ', nlsep='',
use_sublbls=None, use_frame=False):
r"""
Args:
fpath_list (list):
... | python | def get_latex_figure_str(fpath_list, caption_str=None, label_str=None,
width_str=r'\textwidth', height_str=None, nCols=None,
dpath=None, colpos_sep=' ', nlsep='',
use_sublbls=None, use_frame=False):
r"""
Args:
fpath_list (list):
... | [
"def",
"get_latex_figure_str",
"(",
"fpath_list",
",",
"caption_str",
"=",
"None",
",",
"label_str",
"=",
"None",
",",
"width_str",
"=",
"r'\\textwidth'",
",",
"height_str",
"=",
"None",
",",
"nCols",
"=",
"None",
",",
"dpath",
"=",
"None",
",",
"colpos_sep"... | r"""
Args:
fpath_list (list):
dpath (str): directory relative to main tex file
Returns:
str: figure_str
CommandLine:
python -m utool.util_latex --test-get_latex_figure_str
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * # NOQA
... | [
"r",
"Args",
":",
"fpath_list",
"(",
"list",
")",
":",
"dpath",
"(",
"str",
")",
":",
"directory",
"relative",
"to",
"main",
"tex",
"file"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L727-L875 | train | r Get a LaTeX figure string from a list of files |
Erotemic/utool | utool/util_latex.py | latex_sanitize_command_name | def latex_sanitize_command_name(_cmdname):
r"""
Args:
_cmdname (?):
Returns:
?: command_name
CommandLine:
python -m utool.util_latex --exec-latex_sanitize_command_name
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * # NOQA
>>> _cm... | python | def latex_sanitize_command_name(_cmdname):
r"""
Args:
_cmdname (?):
Returns:
?: command_name
CommandLine:
python -m utool.util_latex --exec-latex_sanitize_command_name
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * # NOQA
>>> _cm... | [
"def",
"latex_sanitize_command_name",
"(",
"_cmdname",
")",
":",
"import",
"utool",
"as",
"ut",
"command_name",
"=",
"_cmdname",
"try",
":",
"def",
"subroman",
"(",
"match",
")",
":",
"import",
"roman",
"try",
":",
"groupdict",
"=",
"match",
".",
"groupdict"... | r"""
Args:
_cmdname (?):
Returns:
?: command_name
CommandLine:
python -m utool.util_latex --exec-latex_sanitize_command_name
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_latex import * # NOQA
>>> _cmdname = '#foo bar.'
>>> command_name = ... | [
"r",
"Args",
":",
"_cmdname",
"(",
"?",
")",
":"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_latex.py#L927-L976 | train | r Sanitize a LaTeX command name. |
glormph/msstitch | src/app/actions/headers/prottable.py | generate_protein_header | def generate_protein_header(headerfields, oldheader, group_by_field, genecentric):
"""Returns a header as a list, ready to write to TSV file"""
fieldtypes = ['proteindata', 'probability', 'proteinfdr', 'proteinpep',
'precursorquant', 'isoquant', 'bestpepscore']
firstfield = prottabledata.A... | python | def generate_protein_header(headerfields, oldheader, group_by_field, genecentric):
"""Returns a header as a list, ready to write to TSV file"""
fieldtypes = ['proteindata', 'probability', 'proteinfdr', 'proteinpep',
'precursorquant', 'isoquant', 'bestpepscore']
firstfield = prottabledata.A... | [
"def",
"generate_protein_header",
"(",
"headerfields",
",",
"oldheader",
",",
"group_by_field",
",",
"genecentric",
")",
":",
"fieldtypes",
"=",
"[",
"'proteindata'",
",",
"'probability'",
",",
"'proteinfdr'",
",",
"'proteinpep'",
",",
"'precursorquant'",
",",
"'iso... | Returns a header as a list, ready to write to TSV file | [
"Returns",
"a",
"header",
"as",
"a",
"list",
"ready",
"to",
"write",
"to",
"TSV",
"file"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/prottable.py#L9-L15 | train | Generates a header for a given set of fields |
glormph/msstitch | src/app/actions/headers/prottable.py | get_prottable_headerfields | def get_prottable_headerfields(headertypes, lookup=False, poolnames=False, genecentric=False):
"""Called by driver to generate headerfields object"""
field_defs = {'isoquant': get_isoquant_fields,
'precursorquant': get_precursorquant_fields,
'probability': get_probability_fie... | python | def get_prottable_headerfields(headertypes, lookup=False, poolnames=False, genecentric=False):
"""Called by driver to generate headerfields object"""
field_defs = {'isoquant': get_isoquant_fields,
'precursorquant': get_precursorquant_fields,
'probability': get_probability_fie... | [
"def",
"get_prottable_headerfields",
"(",
"headertypes",
",",
"lookup",
"=",
"False",
",",
"poolnames",
"=",
"False",
",",
"genecentric",
"=",
"False",
")",
":",
"field_defs",
"=",
"{",
"'isoquant'",
":",
"get_isoquant_fields",
",",
"'precursorquant'",
":",
"get... | Called by driver to generate headerfields object | [
"Called",
"by",
"driver",
"to",
"generate",
"headerfields",
"object"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/prottable.py#L18-L28 | train | Returns a generator object that can be used to generate headerfields for a proteins table. |
glormph/msstitch | src/app/actions/headers/prottable.py | get_proteininfo_fields | def get_proteininfo_fields(poolnames=False, genecentric=False):
"""Returns header fields for protein (group) information.
Some fields are shared between pools, others are specific
for a pool"""
allfields = OrderedDict()
basefields = {
False: [
prottabledata.HEADER_GENEID,... | python | def get_proteininfo_fields(poolnames=False, genecentric=False):
"""Returns header fields for protein (group) information.
Some fields are shared between pools, others are specific
for a pool"""
allfields = OrderedDict()
basefields = {
False: [
prottabledata.HEADER_GENEID,... | [
"def",
"get_proteininfo_fields",
"(",
"poolnames",
"=",
"False",
",",
"genecentric",
"=",
"False",
")",
":",
"allfields",
"=",
"OrderedDict",
"(",
")",
"basefields",
"=",
"{",
"False",
":",
"[",
"prottabledata",
".",
"HEADER_GENEID",
",",
"prottabledata",
".",... | Returns header fields for protein (group) information.
Some fields are shared between pools, others are specific
for a pool | [
"Returns",
"header",
"fields",
"for",
"protein",
"(",
"group",
")",
"information",
".",
"Some",
"fields",
"are",
"shared",
"between",
"pools",
"others",
"are",
"specific",
"for",
"a",
"pool"
] | ded7e5cbd813d7797dc9d42805778266e59ff042 | https://github.com/glormph/msstitch/blob/ded7e5cbd813d7797dc9d42805778266e59ff042/src/app/actions/headers/prottable.py#L47-L73 | train | Returns header fields for protein group information. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._validate_return_fields | def _validate_return_fields(self, return_fields):
"""
:param return_fields: tuple
:raises: pybomb.exceptions.InvalidReturnFieldException
"""
for return_field in return_fields:
if return_field not in self.RESPONSE_FIELD_MAP:
raise InvalidReturnFieldExce... | python | def _validate_return_fields(self, return_fields):
"""
:param return_fields: tuple
:raises: pybomb.exceptions.InvalidReturnFieldException
"""
for return_field in return_fields:
if return_field not in self.RESPONSE_FIELD_MAP:
raise InvalidReturnFieldExce... | [
"def",
"_validate_return_fields",
"(",
"self",
",",
"return_fields",
")",
":",
"for",
"return_field",
"in",
"return_fields",
":",
"if",
"return_field",
"not",
"in",
"self",
".",
"RESPONSE_FIELD_MAP",
":",
"raise",
"InvalidReturnFieldException",
"(",
"'\"{0}\" is an in... | :param return_fields: tuple
:raises: pybomb.exceptions.InvalidReturnFieldException | [
":",
"param",
"return_fields",
":",
"tuple",
":",
"raises",
":",
"pybomb",
".",
"exceptions",
".",
"InvalidReturnFieldException"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L78-L87 | train | Validate the return_fields. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._validate_sort_field | def _validate_sort_field(self, sort_by):
"""
:param sort_by: string
:raises: pybomb.exceptions.InvalidSortFieldException
"""
if (
sort_by not in self.RESPONSE_FIELD_MAP
or not self.RESPONSE_FIELD_MAP[sort_by].is_sort
):
raise InvalidSor... | python | def _validate_sort_field(self, sort_by):
"""
:param sort_by: string
:raises: pybomb.exceptions.InvalidSortFieldException
"""
if (
sort_by not in self.RESPONSE_FIELD_MAP
or not self.RESPONSE_FIELD_MAP[sort_by].is_sort
):
raise InvalidSor... | [
"def",
"_validate_sort_field",
"(",
"self",
",",
"sort_by",
")",
":",
"if",
"(",
"sort_by",
"not",
"in",
"self",
".",
"RESPONSE_FIELD_MAP",
"or",
"not",
"self",
".",
"RESPONSE_FIELD_MAP",
"[",
"sort_by",
"]",
".",
"is_sort",
")",
":",
"raise",
"InvalidSortFi... | :param sort_by: string
:raises: pybomb.exceptions.InvalidSortFieldException | [
":",
"param",
"sort_by",
":",
"string",
":",
"raises",
":",
"pybomb",
".",
"exceptions",
".",
"InvalidSortFieldException"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L89-L100 | train | Validate that the sort_by is valid. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._validate_filter_fields | def _validate_filter_fields(self, filter_by):
"""
:param filter_by: dict
:raises: pybomb.exceptions.InvalidFilterFieldException
"""
for filter_field in filter_by:
if (
filter_field not in self.RESPONSE_FIELD_MAP
or not self.RESPONSE_FIE... | python | def _validate_filter_fields(self, filter_by):
"""
:param filter_by: dict
:raises: pybomb.exceptions.InvalidFilterFieldException
"""
for filter_field in filter_by:
if (
filter_field not in self.RESPONSE_FIELD_MAP
or not self.RESPONSE_FIE... | [
"def",
"_validate_filter_fields",
"(",
"self",
",",
"filter_by",
")",
":",
"for",
"filter_field",
"in",
"filter_by",
":",
"if",
"(",
"filter_field",
"not",
"in",
"self",
".",
"RESPONSE_FIELD_MAP",
"or",
"not",
"self",
".",
"RESPONSE_FIELD_MAP",
"[",
"filter_fiel... | :param filter_by: dict
:raises: pybomb.exceptions.InvalidFilterFieldException | [
":",
"param",
"filter_by",
":",
"dict",
":",
"raises",
":",
"pybomb",
".",
"exceptions",
".",
"InvalidFilterFieldException"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L102-L114 | train | Validate the filter_by dict. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._create_search_filter | def _create_search_filter(filter_by):
"""
:param filter_by:
:return: dict
"""
return ",".join(
[
"{0}:{1}".format(key, value)
for key, value in filter_by.items()
if value is not None
]
) | python | def _create_search_filter(filter_by):
"""
:param filter_by:
:return: dict
"""
return ",".join(
[
"{0}:{1}".format(key, value)
for key, value in filter_by.items()
if value is not None
]
) | [
"def",
"_create_search_filter",
"(",
"filter_by",
")",
":",
"return",
"\",\"",
".",
"join",
"(",
"[",
"\"{0}:{1}\"",
".",
"format",
"(",
"key",
",",
"value",
")",
"for",
"key",
",",
"value",
"in",
"filter_by",
".",
"items",
"(",
")",
"if",
"value",
"is... | :param filter_by:
:return: dict | [
":",
"param",
"filter_by",
":",
":",
"return",
":",
"dict"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L117-L128 | train | Create a search filter for the related items in the database. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._query | def _query(self, params, direct=False):
"""
:param params: dict
:return: pybomb.clients.response
"""
params["api_key"] = self._api_key
if "format" not in params:
params["format"] = self._default_format
response = self._query_api(params, direct)
... | python | def _query(self, params, direct=False):
"""
:param params: dict
:return: pybomb.clients.response
"""
params["api_key"] = self._api_key
if "format" not in params:
params["format"] = self._default_format
response = self._query_api(params, direct)
... | [
"def",
"_query",
"(",
"self",
",",
"params",
",",
"direct",
"=",
"False",
")",
":",
"params",
"[",
"\"api_key\"",
"]",
"=",
"self",
".",
"_api_key",
"if",
"\"format\"",
"not",
"in",
"params",
":",
"params",
"[",
"\"format\"",
"]",
"=",
"self",
".",
"... | :param params: dict
:return: pybomb.clients.response | [
":",
"param",
"params",
":",
"dict",
":",
"return",
":",
"pybomb",
".",
"clients",
".",
"response"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L130-L143 | train | Query the related resources. |
steveYeah/PyBomb | pybomb/clients/base_client.py | BaseClient._query_api | def _query_api(self, params, direct=False):
"""
:param params: dict
:return: requests.models.Response
"""
if not direct:
return get(
self.URI_BASE + self.RESOURCE_NAME, params=params, headers=self._headers
)
id = params.pop("id")
... | python | def _query_api(self, params, direct=False):
"""
:param params: dict
:return: requests.models.Response
"""
if not direct:
return get(
self.URI_BASE + self.RESOURCE_NAME, params=params, headers=self._headers
)
id = params.pop("id")
... | [
"def",
"_query_api",
"(",
"self",
",",
"params",
",",
"direct",
"=",
"False",
")",
":",
"if",
"not",
"direct",
":",
"return",
"get",
"(",
"self",
".",
"URI_BASE",
"+",
"self",
".",
"RESOURCE_NAME",
",",
"params",
"=",
"params",
",",
"headers",
"=",
"... | :param params: dict
:return: requests.models.Response | [
":",
"param",
"params",
":",
"dict",
":",
"return",
":",
"requests",
".",
"models",
".",
"Response"
] | 54045d74e642f8a1c4366c24bd6a330ae3da6257 | https://github.com/steveYeah/PyBomb/blob/54045d74e642f8a1c4366c24bd6a330ae3da6257/pybomb/clients/base_client.py#L145-L160 | train | Query the API for the related resource. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.