repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
architv/harvey | harvey/harvey.py | _get_license_description | def _get_license_description(license_code):
""" Gets the body for a license based on a license code """
req = requests.get("{base_url}/licenses/{license_code}".format(
base_url=BASE_URL, license_code=license_code), headers=_HEADERS)
if req.status_code == requests.codes.ok:
s = req.json()["body"]
se... | python | def _get_license_description(license_code):
""" Gets the body for a license based on a license code """
req = requests.get("{base_url}/licenses/{license_code}".format(
base_url=BASE_URL, license_code=license_code), headers=_HEADERS)
if req.status_code == requests.codes.ok:
s = req.json()["body"]
se... | [
"def",
"_get_license_description",
"(",
"license_code",
")",
":",
"req",
"=",
"requests",
".",
"get",
"(",
"\"{base_url}/licenses/{license_code}\"",
".",
"format",
"(",
"base_url",
"=",
"BASE_URL",
",",
"license_code",
"=",
"license_code",
")",
",",
"headers",
"="... | Gets the body for a license based on a license code | [
"Gets",
"the",
"body",
"for",
"a",
"license",
"based",
"on",
"a",
"license",
"code"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L70-L94 | train |
architv/harvey | harvey/harvey.py | get_license_summary | def get_license_summary(license_code):
""" Gets the license summary and permitted, forbidden and required
behaviour """
try:
abs_file = os.path.join(_ROOT, "summary.json")
with open(abs_file, 'r') as f:
summary_license = json.loads(f.read())[license_code]
# prints summary
print(Fore.YELLOW ... | python | def get_license_summary(license_code):
""" Gets the license summary and permitted, forbidden and required
behaviour """
try:
abs_file = os.path.join(_ROOT, "summary.json")
with open(abs_file, 'r') as f:
summary_license = json.loads(f.read())[license_code]
# prints summary
print(Fore.YELLOW ... | [
"def",
"get_license_summary",
"(",
"license_code",
")",
":",
"try",
":",
"abs_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"_ROOT",
",",
"\"summary.json\"",
")",
"with",
"open",
"(",
"abs_file",
",",
"'r'",
")",
"as",
"f",
":",
"summary_license",
"="... | Gets the license summary and permitted, forbidden and required
behaviour | [
"Gets",
"the",
"license",
"summary",
"and",
"permitted",
"forbidden",
"and",
"required",
"behaviour"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L97-L139 | train |
architv/harvey | harvey/harvey.py | main | def main():
''' harvey helps you manage and add license from the command line '''
arguments = docopt(__doc__, version=__version__)
if arguments['ls'] or arguments['list']:
_get_licences()
elif arguments['--tldr'] and arguments['<NAME>']:
get_license_summary(arguments['<NAME>'].lower())
elif arguments... | python | def main():
''' harvey helps you manage and add license from the command line '''
arguments = docopt(__doc__, version=__version__)
if arguments['ls'] or arguments['list']:
_get_licences()
elif arguments['--tldr'] and arguments['<NAME>']:
get_license_summary(arguments['<NAME>'].lower())
elif arguments... | [
"def",
"main",
"(",
")",
":",
"arguments",
"=",
"docopt",
"(",
"__doc__",
",",
"version",
"=",
"__version__",
")",
"if",
"arguments",
"[",
"'ls'",
"]",
"or",
"arguments",
"[",
"'list'",
"]",
":",
"_get_licences",
"(",
")",
"elif",
"arguments",
"[",
"'-... | harvey helps you manage and add license from the command line | [
"harvey",
"helps",
"you",
"manage",
"and",
"add",
"license",
"from",
"the",
"command",
"line"
] | 2b96d57b7a1e0dd706f1f00aba3d92a7ae702960 | https://github.com/architv/harvey/blob/2b96d57b7a1e0dd706f1f00aba3d92a7ae702960/harvey/harvey.py#L152-L165 | train |
rfverbruggen/rachiopy | rachiopy/person.py | Person.get | def get(self, user_id):
"""Retrieve the information for a person entity."""
path = '/'.join(['person', user_id])
return self.rachio.get(path) | python | def get(self, user_id):
"""Retrieve the information for a person entity."""
path = '/'.join(['person', user_id])
return self.rachio.get(path) | [
"def",
"get",
"(",
"self",
",",
"user_id",
")",
":",
"path",
"=",
"'/'",
".",
"join",
"(",
"[",
"'person'",
",",
"user_id",
"]",
")",
"return",
"self",
".",
"rachio",
".",
"get",
"(",
"path",
")"
] | Retrieve the information for a person entity. | [
"Retrieve",
"the",
"information",
"for",
"a",
"person",
"entity",
"."
] | c91abc9984f0f453e60fa905285c1b640c3390ae | https://github.com/rfverbruggen/rachiopy/blob/c91abc9984f0f453e60fa905285c1b640c3390ae/rachiopy/person.py#L16-L19 | train |
ptmcg/littletable | littletable.py | Table.copy_template | def copy_template(self, name=None):
"""Create empty copy of the current table, with copies of all
index definitions.
"""
ret = Table(self.table_name)
ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items()))
ret(name)
return ret | python | def copy_template(self, name=None):
"""Create empty copy of the current table, with copies of all
index definitions.
"""
ret = Table(self.table_name)
ret._indexes.update(dict((k, v.copy_template()) for k, v in self._indexes.items()))
ret(name)
return ret | [
"def",
"copy_template",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"ret",
"=",
"Table",
"(",
"self",
".",
"table_name",
")",
"ret",
".",
"_indexes",
".",
"update",
"(",
"dict",
"(",
"(",
"k",
",",
"v",
".",
"copy_template",
"(",
")",
")",
"... | Create empty copy of the current table, with copies of all
index definitions. | [
"Create",
"empty",
"copy",
"of",
"the",
"current",
"table",
"with",
"copies",
"of",
"all",
"index",
"definitions",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L632-L639 | train |
ptmcg/littletable | littletable.py | Table.clone | def clone(self, name=None):
"""Create full copy of the current table, including table contents
and index definitions.
"""
ret = self.copy_template().insert_many(self.obs)(name)
return ret | python | def clone(self, name=None):
"""Create full copy of the current table, including table contents
and index definitions.
"""
ret = self.copy_template().insert_many(self.obs)(name)
return ret | [
"def",
"clone",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"ret",
"=",
"self",
".",
"copy_template",
"(",
")",
".",
"insert_many",
"(",
"self",
".",
"obs",
")",
"(",
"name",
")",
"return",
"ret"
] | Create full copy of the current table, including table contents
and index definitions. | [
"Create",
"full",
"copy",
"of",
"the",
"current",
"table",
"including",
"table",
"contents",
"and",
"index",
"definitions",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L641-L646 | train |
ptmcg/littletable | littletable.py | Table.delete_index | def delete_index(self, attr):
"""Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string
"""
if attr in self._index... | python | def delete_index(self, attr):
"""Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string
"""
if attr in self._index... | [
"def",
"delete_index",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"in",
"self",
".",
"_indexes",
":",
"del",
"self",
".",
"_indexes",
"[",
"attr",
"]",
"self",
".",
"_uniqueIndexes",
"=",
"[",
"ind",
"for",
"ind",
"in",
"self",
".",
"_indexes"... | Deletes an index from the Table. Can be used to drop and rebuild an index,
or to convert a non-unique index to a unique index, or vice versa.
@param attr: name of an indexed attribute
@type attr: string | [
"Deletes",
"an",
"index",
"from",
"the",
"Table",
".",
"Can",
"be",
"used",
"to",
"drop",
"and",
"rebuild",
"an",
"index",
"or",
"to",
"convert",
"a",
"non",
"-",
"unique",
"index",
"to",
"a",
"unique",
"index",
"or",
"vice",
"versa",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L689-L698 | train |
ptmcg/littletable | littletable.py | Table.insert_many | def insert_many(self, it):
"""Inserts a collection of objects into the table."""
unique_indexes = self._uniqueIndexes # [ind for ind in self._indexes.values() if ind.is_unique]
NO_SUCH_ATTR = object()
new_objs = list(it)
if unique_indexes:
for ind in unique_indexes:
... | python | def insert_many(self, it):
"""Inserts a collection of objects into the table."""
unique_indexes = self._uniqueIndexes # [ind for ind in self._indexes.values() if ind.is_unique]
NO_SUCH_ATTR = object()
new_objs = list(it)
if unique_indexes:
for ind in unique_indexes:
... | [
"def",
"insert_many",
"(",
"self",
",",
"it",
")",
":",
"unique_indexes",
"=",
"self",
".",
"_uniqueIndexes",
"NO_SUCH_ATTR",
"=",
"object",
"(",
")",
"new_objs",
"=",
"list",
"(",
"it",
")",
"if",
"unique_indexes",
":",
"for",
"ind",
"in",
"unique_indexes... | Inserts a collection of objects into the table. | [
"Inserts",
"a",
"collection",
"of",
"objects",
"into",
"the",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L720-L746 | train |
ptmcg/littletable | littletable.py | Table.remove_many | def remove_many(self, it):
"""Removes a collection of objects from the table."""
# find indicies of objects in iterable
to_be_deleted = list(it)
del_indices = []
for i, ob in enumerate(self.obs):
try:
tbd_index = to_be_deleted.index(ob)
exc... | python | def remove_many(self, it):
"""Removes a collection of objects from the table."""
# find indicies of objects in iterable
to_be_deleted = list(it)
del_indices = []
for i, ob in enumerate(self.obs):
try:
tbd_index = to_be_deleted.index(ob)
exc... | [
"def",
"remove_many",
"(",
"self",
",",
"it",
")",
":",
"to_be_deleted",
"=",
"list",
"(",
"it",
")",
"del_indices",
"=",
"[",
"]",
"for",
"i",
",",
"ob",
"in",
"enumerate",
"(",
"self",
".",
"obs",
")",
":",
"try",
":",
"tbd_index",
"=",
"to_be_de... | Removes a collection of objects from the table. | [
"Removes",
"a",
"collection",
"of",
"objects",
"from",
"the",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L753-L774 | train |
ptmcg/littletable | littletable.py | Table._query_attr_sort_fn | def _query_attr_sort_fn(self, attr_val):
"""Used to order where keys by most selective key first"""
attr, v = attr_val
if attr in self._indexes:
idx = self._indexes[attr]
if v in idx:
return len(idx[v])
else:
return 0
el... | python | def _query_attr_sort_fn(self, attr_val):
"""Used to order where keys by most selective key first"""
attr, v = attr_val
if attr in self._indexes:
idx = self._indexes[attr]
if v in idx:
return len(idx[v])
else:
return 0
el... | [
"def",
"_query_attr_sort_fn",
"(",
"self",
",",
"attr_val",
")",
":",
"attr",
",",
"v",
"=",
"attr_val",
"if",
"attr",
"in",
"self",
".",
"_indexes",
":",
"idx",
"=",
"self",
".",
"_indexes",
"[",
"attr",
"]",
"if",
"v",
"in",
"idx",
":",
"return",
... | Used to order where keys by most selective key first | [
"Used",
"to",
"order",
"where",
"keys",
"by",
"most",
"selective",
"key",
"first"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L776-L786 | train |
ptmcg/littletable | littletable.py | Table.delete | def delete(self, **kwargs):
"""Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as a... | python | def delete(self, **kwargs):
"""Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as a... | [
"def",
"delete",
"(",
"self",
",",
"**",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
":",
"return",
"0",
"affected",
"=",
"self",
".",
"where",
"(",
"**",
"kwargs",
")",
"self",
".",
"remove_many",
"(",
"affected",
")",
"return",
"len",
"(",
"affected... | Deletes matching objects from the table, based on given
named parameters. If multiple named parameters are given, then
only objects that satisfy all of the query criteria will be removed.
@param kwargs: attributes for selecting records, given as additional
named argument... | [
"Deletes",
"matching",
"objects",
"from",
"the",
"table",
"based",
"on",
"given",
"named",
"parameters",
".",
"If",
"multiple",
"named",
"parameters",
"are",
"given",
"then",
"only",
"objects",
"that",
"satisfy",
"all",
"of",
"the",
"query",
"criteria",
"will"... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L835-L848 | train |
ptmcg/littletable | littletable.py | Table.sort | def sort(self, key, reverse=False):
"""Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a ... | python | def sort(self, key, reverse=False):
"""Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a ... | [
"def",
"sort",
"(",
"self",
",",
"key",
",",
"reverse",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"(",
"basestring",
",",
"list",
",",
"tuple",
")",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"basestring",
")",
":",
"attrdefs... | Sort Table in place, using given fields as sort key.
@param key: if this is a string, it is a comma-separated list of field names,
optionally followed by 'desc' to indicate descending sort instead of the
default ascending sort; if a list or tuple, it is a list or tuple of field n... | [
"Sort",
"Table",
"in",
"place",
"using",
"given",
"fields",
"as",
"sort",
"key",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L857-L895 | train |
ptmcg/littletable | littletable.py | Table.select | def select(self, fields, **exprs):
"""
Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
... | python | def select(self, fields, **exprs):
"""
Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
... | [
"def",
"select",
"(",
"self",
",",
"fields",
",",
"**",
"exprs",
")",
":",
"fields",
"=",
"self",
".",
"_parse_fields_string",
"(",
"fields",
")",
"def",
"_make_string_callable",
"(",
"expr",
")",
":",
"if",
"isinstance",
"(",
"expr",
",",
"basestring",
... | Create a new table containing a subset of attributes, with optionally
newly-added fields computed from each rec in the original table.
@param fields: list of strings, or single space-delimited string, listing attribute name to be included in the
output
@type fields: list, or space-deli... | [
"Create",
"a",
"new",
"table",
"containing",
"a",
"subset",
"of",
"attributes",
"with",
"optionally",
"newly",
"-",
"added",
"fields",
"computed",
"from",
"each",
"rec",
"in",
"the",
"original",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L897-L931 | train |
ptmcg/littletable | littletable.py | Table.formatted_table | def formatted_table(self, *fields, **exprs):
"""
Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (m... | python | def formatted_table(self, *fields, **exprs):
"""
Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (m... | [
"def",
"formatted_table",
"(",
"self",
",",
"*",
"fields",
",",
"**",
"exprs",
")",
":",
"fields",
"=",
"set",
"(",
"fields",
")",
"select_exprs",
"=",
"ODict",
"(",
"(",
"f",
",",
"lambda",
"r",
",",
"f",
"=",
"f",
":",
"str",
"(",
"getattr",
",... | Create a new table with all string formatted attribute values, typically in preparation for
formatted output.
@param fields: one or more strings, each string is an attribute name to be included in the output
@type fields: string (multiple)
@param exprs: one or more named string arguments... | [
"Create",
"a",
"new",
"table",
"with",
"all",
"string",
"formatted",
"attribute",
"values",
"typically",
"in",
"preparation",
"for",
"formatted",
"output",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L933-L958 | train |
ptmcg/littletable | littletable.py | Table.join_on | def join_on(self, attr):
"""Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
... | python | def join_on(self, attr):
"""Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
... | [
"def",
"join_on",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"not",
"in",
"self",
".",
"_indexes",
":",
"raise",
"ValueError",
"(",
"\"can only join on indexed attributes\"",
")",
"return",
"JoinTerm",
"(",
"self",
",",
"attr",
")"
] | Creates a JoinTerm in preparation for joining with another table, to
indicate what attribute should be used in the join. Only indexed attributes
may be used in a join.
@param attr: attribute name to join from this table (may be different
from the attribute name in the t... | [
"Creates",
"a",
"JoinTerm",
"in",
"preparation",
"for",
"joining",
"with",
"another",
"table",
"to",
"indicate",
"what",
"attribute",
"should",
"be",
"used",
"in",
"the",
"join",
".",
"Only",
"indexed",
"attributes",
"may",
"be",
"used",
"in",
"a",
"join",
... | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1075-L1085 | train |
ptmcg/littletable | littletable.py | Table.csv_import | def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file ... | python | def csv_import(self, csv_source, encoding='utf-8', transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file ... | [
"def",
"csv_import",
"(",
"self",
",",
"csv_source",
",",
"encoding",
"=",
"'utf-8'",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
",",
"**",
"kwargs",
")",
":",
"reader_args",
"=",
"dict",
"(",
"(",
"k",
",",
"v",
")",
"for",
... | Imports the contents of a CSV-formatted file into this table.
@param csv_source: CSV file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller to be closed.
... | [
"Imports",
"the",
"contents",
"of",
"a",
"CSV",
"-",
"formatted",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1136-L1161 | train |
ptmcg/littletable | littletable.py | Table.tsv_import | def tsv_import(self, xsv_source, encoding="UTF-8", transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, an... | python | def tsv_import(self, xsv_source, encoding="UTF-8", transforms=None, row_class=DataObject, **kwargs):
"""Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, an... | [
"def",
"tsv_import",
"(",
"self",
",",
"xsv_source",
",",
"encoding",
"=",
"\"UTF-8\"",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
",",
"**",
"kwargs",
")",
":",
"return",
"self",
".",
"_xsv_import",
"(",
"xsv_source",
",",
"encod... | Imports the contents of a tab-separated data file into this table.
@param xsv_source: tab-separated data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller... | [
"Imports",
"the",
"contents",
"of",
"a",
"tab",
"-",
"separated",
"data",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1171-L1185 | train |
ptmcg/littletable | littletable.py | Table.csv_export | def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | python | def csv_export(self, csv_dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | [
"def",
"csv_export",
"(",
"self",
",",
"csv_dest",
",",
"fieldnames",
"=",
"None",
",",
"encoding",
"=",
"\"UTF-8\"",
")",
":",
"close_on_exit",
"=",
"False",
"if",
"isinstance",
"(",
"csv_dest",
",",
"basestring",
")",
":",
"if",
"PY_3",
":",
"csv_dest",
... | Exports the contents of the table to a CSV-formatted file.
@param csv_dest: CSV file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
will be written as-is, and left for the caller to be closed.
... | [
"Exports",
"the",
"contents",
"of",
"the",
"table",
"to",
"a",
"CSV",
"-",
"formatted",
"file",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1187-L1222 | train |
ptmcg/littletable | littletable.py | Table.json_import | def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject):
"""Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given... | python | def json_import(self, source, encoding="UTF-8", transforms=None, row_class=DataObject):
"""Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given... | [
"def",
"json_import",
"(",
"self",
",",
"source",
",",
"encoding",
"=",
"\"UTF-8\"",
",",
"transforms",
"=",
"None",
",",
"row_class",
"=",
"DataObject",
")",
":",
"class",
"_JsonFileReader",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
... | Imports the contents of a JSON data file into this table.
@param source: JSON data file - if a string is given, the file with that name will be
opened, read, and closed; if a file object is given, then that object
will be read as-is, and left for the caller to be closed.
... | [
"Imports",
"the",
"contents",
"of",
"a",
"JSON",
"data",
"file",
"into",
"this",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1224-L1252 | train |
ptmcg/littletable | littletable.py | Table.json_export | def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | python | def json_export(self, dest, fieldnames=None, encoding="UTF-8"):
"""Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
... | [
"def",
"json_export",
"(",
"self",
",",
"dest",
",",
"fieldnames",
"=",
"None",
",",
"encoding",
"=",
"\"UTF-8\"",
")",
":",
"close_on_exit",
"=",
"False",
"if",
"isinstance",
"(",
"dest",
",",
"basestring",
")",
":",
"if",
"PY_3",
":",
"dest",
"=",
"o... | Exports the contents of the table to a JSON-formatted file.
@param dest: output file - if a string is given, the file with that name will be
opened, written, and closed; if a file object is given, then that object
will be written as-is, and left for the caller to be closed.
... | [
"Exports",
"the",
"contents",
"of",
"the",
"table",
"to",
"a",
"JSON",
"-",
"formatted",
"file",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1254-L1284 | train |
ptmcg/littletable | littletable.py | Table.add_field | def add_field(self, attrname, fn, default=None):
"""Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: functi... | python | def add_field(self, attrname, fn, default=None):
"""Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: functi... | [
"def",
"add_field",
"(",
"self",
",",
"attrname",
",",
"fn",
",",
"default",
"=",
"None",
")",
":",
"def",
"_add_field_to_rec",
"(",
"rec_",
",",
"fn_",
"=",
"fn",
",",
"default_",
"=",
"default",
")",
":",
"try",
":",
"val",
"=",
"fn_",
"(",
"rec_... | Computes a new attribute for each object in table, or replaces an
existing attribute in each record with a computed value
@param attrname: attribute to compute for each object
@type attrname: string
@param fn: function used to compute new attribute value, based on
... | [
"Computes",
"a",
"new",
"attribute",
"for",
"each",
"object",
"in",
"table",
"or",
"replaces",
"an",
"existing",
"attribute",
"in",
"each",
"record",
"with",
"a",
"computed",
"value"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1286-L1314 | train |
ptmcg/littletable | littletable.py | Table.groupby | def groupby(self, keyexpr, **outexprs):
"""simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: stri... | python | def groupby(self, keyexpr, **outexprs):
"""simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: stri... | [
"def",
"groupby",
"(",
"self",
",",
"keyexpr",
",",
"**",
"outexprs",
")",
":",
"if",
"isinstance",
"(",
"keyexpr",
",",
"basestring",
")",
":",
"keyattrs",
"=",
"keyexpr",
".",
"split",
"(",
")",
"keyfn",
"=",
"lambda",
"o",
":",
"tuple",
"(",
"geta... | simple prototype of group by, with support for expressions in the group-by clause
and outputs
@param keyexpr: grouping field and optional expression for computing the key value;
if a string is passed
@type keyexpr: string or tuple
@param outexprs: named argum... | [
"simple",
"prototype",
"of",
"group",
"by",
"with",
"support",
"for",
"expressions",
"in",
"the",
"group",
"-",
"by",
"clause",
"and",
"outputs"
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1316-L1347 | train |
ptmcg/littletable | littletable.py | Table.unique | def unique(self, key=None):
"""
Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the obj... | python | def unique(self, key=None):
"""
Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the obj... | [
"def",
"unique",
"(",
"self",
",",
"key",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"basestring",
")",
":",
"key",
"=",
"lambda",
"r",
",",
"attr",
"=",
"key",
":",
"getattr",
"(",
"r",
",",
"attr",
",",
"None",
")",
"ret",
"=... | Create a new table of objects,containing no duplicate values.
@param key: (default=None) optional callable for computing a representative unique key for each
object in the table. If None, then a key will be composed as a tuple of all the values in the object.
@type key: callable, takes the reco... | [
"Create",
"a",
"new",
"table",
"of",
"objects",
"containing",
"no",
"duplicate",
"values",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1349-L1374 | train |
ptmcg/littletable | littletable.py | Table.as_html | def as_html(self, fields='*'):
"""
Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name... | python | def as_html(self, fields='*'):
"""
Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name... | [
"def",
"as_html",
"(",
"self",
",",
"fields",
"=",
"'*'",
")",
":",
"fields",
"=",
"self",
".",
"_parse_fields_string",
"(",
"fields",
")",
"def",
"td_value",
"(",
"v",
")",
":",
"return",
"'<td><div align=\"{}\">{}</div></td>'",
".",
"format",
"(",
"(",
"... | Output the table as a rudimentary HTML table.
@param fields: fields in the table to be shown in the table
- listing '*' as a field will add all unnamed fields
- starting a field name with '-' will suppress that name
@type fields: list of strings or a single ... | [
"Output",
"the",
"table",
"as",
"a",
"rudimentary",
"HTML",
"table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1450-L1469 | train |
ptmcg/littletable | littletable.py | PivotTable.dump | def dump(self, out=sys.stdout, row_fn=repr, limit=-1, indent=0):
"""Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level ... | python | def dump(self, out=sys.stdout, row_fn=repr, limit=-1, indent=0):
"""Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level ... | [
"def",
"dump",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
",",
"row_fn",
"=",
"repr",
",",
"limit",
"=",
"-",
"1",
",",
"indent",
"=",
"0",
")",
":",
"NL",
"=",
"'\\n'",
"if",
"indent",
":",
"out",
".",
"write",
"(",
"\" \"",
"*",
"... | Dump out the contents of this table in a nested listing.
@param out: output stream to write to
@param row_fn: function to call to display individual rows
@param limit: number of records to show at deepest level of pivot (-1=show all)
@param indent: current nesting level | [
"Dump",
"out",
"the",
"contents",
"of",
"this",
"table",
"in",
"a",
"nested",
"listing",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1535-L1556 | train |
ptmcg/littletable | littletable.py | PivotTable.dump_counts | def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
"""Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colw... | python | def dump_counts(self, out=sys.stdout, count_fn=len, colwidth=10):
"""Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colw... | [
"def",
"dump_counts",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
",",
"count_fn",
"=",
"len",
",",
"colwidth",
"=",
"10",
")",
":",
"if",
"len",
"(",
"self",
".",
"_pivot_attrs",
")",
"==",
"1",
":",
"out",
".",
"write",
"(",
"\"Pivot: %s\... | Dump out the summary counts of entries in this pivot table as a tabular listing.
@param out: output stream to write to
@param count_fn: (default=len) function for computing value for each pivot cell
@param colwidth: (default=10) | [
"Dump",
"out",
"the",
"summary",
"counts",
"of",
"entries",
"in",
"this",
"pivot",
"table",
"as",
"a",
"tabular",
"listing",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1558-L1598 | train |
ptmcg/littletable | littletable.py | PivotTable.as_table | def as_table(self, fn=None, col=None, col_label=None):
"""Dump out the summary counts of this pivot table as a Table.
"""
if col_label is None:
col_label = col
if fn is None:
fn = len
if col_label is None:
col_label = 'count'
re... | python | def as_table(self, fn=None, col=None, col_label=None):
"""Dump out the summary counts of this pivot table as a Table.
"""
if col_label is None:
col_label = col
if fn is None:
fn = len
if col_label is None:
col_label = 'count'
re... | [
"def",
"as_table",
"(",
"self",
",",
"fn",
"=",
"None",
",",
"col",
"=",
"None",
",",
"col_label",
"=",
"None",
")",
":",
"if",
"col_label",
"is",
"None",
":",
"col_label",
"=",
"col",
"if",
"fn",
"is",
"None",
":",
"fn",
"=",
"len",
"if",
"col_l... | Dump out the summary counts of this pivot table as a Table. | [
"Dump",
"out",
"the",
"summary",
"counts",
"of",
"this",
"pivot",
"table",
"as",
"a",
"Table",
"."
] | 8352f7716e458e55a6997372dadf92e179d19f98 | https://github.com/ptmcg/littletable/blob/8352f7716e458e55a6997372dadf92e179d19f98/littletable.py#L1600-L1642 | train |
davidcarboni/Flask-Sleuth | sleuth/__init__.py | _update_record | def _update_record(record):
"""Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the mil... | python | def _update_record(record):
"""Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the mil... | [
"def",
"_update_record",
"(",
"record",
")",
":",
"dt",
"=",
"datetime",
".",
"fromtimestamp",
"(",
"record",
".",
"created",
")",
"record",
".",
"springtime",
"=",
"str",
"(",
"dt",
")",
"[",
":",
"-",
"3",
"]",
"record",
".",
"levelname_spring",
"=",... | Collates values needed by LOG_FORMAT
This adds additional information to the log record to implement the logging standard.
:return: A log record augmented with the values required by LOG_FORMAT:
* springtime: LogRecord.asctime, but with a `.` instead of a `,` as the millisecond separator
* levelname... | [
"Collates",
"values",
"needed",
"by",
"LOG_FORMAT"
] | 2191aa2a929ec43c0176ec51c7abef924b12d015 | https://github.com/davidcarboni/Flask-Sleuth/blob/2191aa2a929ec43c0176ec51c7abef924b12d015/sleuth/__init__.py#L41-L68 | train |
davidcarboni/Flask-Sleuth | sleuth/__init__.py | _tracing_information | def _tracing_information():
"""Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format.
"""
# We'll collate trace information if the B3 headers have been collected:
values = b3.values()
if values[b3.b3... | python | def _tracing_information():
"""Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format.
"""
# We'll collate trace information if the B3 headers have been collected:
values = b3.values()
if values[b3.b3... | [
"def",
"_tracing_information",
"(",
")",
":",
"values",
"=",
"b3",
".",
"values",
"(",
")",
"if",
"values",
"[",
"b3",
".",
"b3_trace_id",
"]",
":",
"return",
"[",
"current_app",
".",
"name",
"if",
"current_app",
".",
"name",
"else",
"\" - \"",
",",
"v... | Gets B3 distributed tracing information, if available.
This is returned as a list, ready to be formatted into Spring Cloud Sleuth compatible format. | [
"Gets",
"B3",
"distributed",
"tracing",
"information",
"if",
"available",
".",
"This",
"is",
"returned",
"as",
"a",
"list",
"ready",
"to",
"be",
"formatted",
"into",
"Spring",
"Cloud",
"Sleuth",
"compatible",
"format",
"."
] | 2191aa2a929ec43c0176ec51c7abef924b12d015 | https://github.com/davidcarboni/Flask-Sleuth/blob/2191aa2a929ec43c0176ec51c7abef924b12d015/sleuth/__init__.py#L71-L88 | train |
costastf/toonlib | toonlib/toonlib.py | Toon._authenticate | def _authenticate(self):
"""Authenticates to the api and sets up client information."""
data = {'username': self.username,
'password': self.password}
url = '{base}/client/login'.format(base=self.base_url)
response = self._session.get(url, params=data)
print(respon... | python | def _authenticate(self):
"""Authenticates to the api and sets up client information."""
data = {'username': self.username,
'password': self.password}
url = '{base}/client/login'.format(base=self.base_url)
response = self._session.get(url, params=data)
print(respon... | [
"def",
"_authenticate",
"(",
"self",
")",
":",
"data",
"=",
"{",
"'username'",
":",
"self",
".",
"username",
",",
"'password'",
":",
"self",
".",
"password",
"}",
"url",
"=",
"'{base}/client/login'",
".",
"format",
"(",
"base",
"=",
"self",
".",
"base_ur... | Authenticates to the api and sets up client information. | [
"Authenticates",
"to",
"the",
"api",
"and",
"sets",
"up",
"client",
"information",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L75-L85 | train |
costastf/toonlib | toonlib/toonlib.py | Toon._logout | def _logout(self, reset=True):
"""Log out of the API."""
url = '{base}/client/auth/logout'.format(base=self.base_url)
response = self._session.get(url, params=self._parameters)
if response.ok:
if reset:
self._reset()
return True
else:
... | python | def _logout(self, reset=True):
"""Log out of the API."""
url = '{base}/client/auth/logout'.format(base=self.base_url)
response = self._session.get(url, params=self._parameters)
if response.ok:
if reset:
self._reset()
return True
else:
... | [
"def",
"_logout",
"(",
"self",
",",
"reset",
"=",
"True",
")",
":",
"url",
"=",
"'{base}/client/auth/logout'",
".",
"format",
"(",
"base",
"=",
"self",
".",
"base_url",
")",
"response",
"=",
"self",
".",
"_session",
".",
"get",
"(",
"url",
",",
"params... | Log out of the API. | [
"Log",
"out",
"of",
"the",
"API",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L127-L136 | train |
costastf/toonlib | toonlib/toonlib.py | Toon._state | def _state(self):
"""The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state o... | python | def _state(self):
"""The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state o... | [
"def",
"_state",
"(",
"self",
")",
":",
"state",
"=",
"{",
"}",
"required_keys",
"=",
"(",
"'deviceStatusInfo'",
",",
"'gasUsage'",
",",
"'powerUsage'",
",",
"'thermostatInfo'",
",",
"'thermostatStates'",
")",
"try",
":",
"for",
"_",
"in",
"range",
"(",
"s... | The internal state of the object.
The api responses are not consistent so a retry is performed on every
call with information updating the internally saved state refreshing
the data. The info is cached for STATE_CACHING_SECONDS.
:return: The current state of the toons' information stat... | [
"The",
"internal",
"state",
"of",
"the",
"object",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L162-L188 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.get_smokedetector_by_name | def get_smokedetector_by_name(self, name):
"""Retrieves a smokedetector object by its name
:param name: The name of the smokedetector to return
:return: A smokedetector object
"""
return next((smokedetector for smokedetector in self.smokedetectors
if smokede... | python | def get_smokedetector_by_name(self, name):
"""Retrieves a smokedetector object by its name
:param name: The name of the smokedetector to return
:return: A smokedetector object
"""
return next((smokedetector for smokedetector in self.smokedetectors
if smokede... | [
"def",
"get_smokedetector_by_name",
"(",
"self",
",",
"name",
")",
":",
"return",
"next",
"(",
"(",
"smokedetector",
"for",
"smokedetector",
"in",
"self",
".",
"smokedetectors",
"if",
"smokedetector",
".",
"name",
".",
"lower",
"(",
")",
"==",
"name",
".",
... | Retrieves a smokedetector object by its name
:param name: The name of the smokedetector to return
:return: A smokedetector object | [
"Retrieves",
"a",
"smokedetector",
"object",
"by",
"its",
"name"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L236-L243 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.get_light_by_name | def get_light_by_name(self, name):
"""Retrieves a light object by its name
:param name: The name of the light to return
:return: A light object
"""
return next((light for light in self.lights
if light.name.lower() == name.lower()), None) | python | def get_light_by_name(self, name):
"""Retrieves a light object by its name
:param name: The name of the light to return
:return: A light object
"""
return next((light for light in self.lights
if light.name.lower() == name.lower()), None) | [
"def",
"get_light_by_name",
"(",
"self",
",",
"name",
")",
":",
"return",
"next",
"(",
"(",
"light",
"for",
"light",
"in",
"self",
".",
"lights",
"if",
"light",
".",
"name",
".",
"lower",
"(",
")",
"==",
"name",
".",
"lower",
"(",
")",
")",
",",
... | Retrieves a light object by its name
:param name: The name of the light to return
:return: A light object | [
"Retrieves",
"a",
"light",
"object",
"by",
"its",
"name"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L253-L260 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.get_smartplug_by_name | def get_smartplug_by_name(self, name):
"""Retrieves a smartplug object by its name
:param name: The name of the smartplug to return
:return: A smartplug object
"""
return next((plug for plug in self.smartplugs
if plug.name.lower() == name.lower()), None) | python | def get_smartplug_by_name(self, name):
"""Retrieves a smartplug object by its name
:param name: The name of the smartplug to return
:return: A smartplug object
"""
return next((plug for plug in self.smartplugs
if plug.name.lower() == name.lower()), None) | [
"def",
"get_smartplug_by_name",
"(",
"self",
",",
"name",
")",
":",
"return",
"next",
"(",
"(",
"plug",
"for",
"plug",
"in",
"self",
".",
"smartplugs",
"if",
"plug",
".",
"name",
".",
"lower",
"(",
")",
"==",
"name",
".",
"lower",
"(",
")",
")",
",... | Retrieves a smartplug object by its name
:param name: The name of the smartplug to return
:return: A smartplug object | [
"Retrieves",
"a",
"smartplug",
"object",
"by",
"its",
"name"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L270-L277 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.get_thermostat_state_by_name | def get_thermostat_state_by_name(self, name):
"""Retrieves a thermostat state object by its assigned name
:param name: The name of the thermostat state
:return: The thermostat state object
"""
self._validate_thermostat_state_name(name)
return next((state for state in sel... | python | def get_thermostat_state_by_name(self, name):
"""Retrieves a thermostat state object by its assigned name
:param name: The name of the thermostat state
:return: The thermostat state object
"""
self._validate_thermostat_state_name(name)
return next((state for state in sel... | [
"def",
"get_thermostat_state_by_name",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"_validate_thermostat_state_name",
"(",
"name",
")",
"return",
"next",
"(",
"(",
"state",
"for",
"state",
"in",
"self",
".",
"thermostat_states",
"if",
"state",
".",
"name"... | Retrieves a thermostat state object by its assigned name
:param name: The name of the thermostat state
:return: The thermostat state object | [
"Retrieves",
"a",
"thermostat",
"state",
"object",
"by",
"its",
"assigned",
"name"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L347-L355 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.get_thermostat_state_by_id | def get_thermostat_state_by_id(self, id_):
"""Retrieves a thermostat state object by its id
:param id_: The id of the thermostat state
:return: The thermostat state object
"""
return next((state for state in self.thermostat_states
if state.id == id_), None) | python | def get_thermostat_state_by_id(self, id_):
"""Retrieves a thermostat state object by its id
:param id_: The id of the thermostat state
:return: The thermostat state object
"""
return next((state for state in self.thermostat_states
if state.id == id_), None) | [
"def",
"get_thermostat_state_by_id",
"(",
"self",
",",
"id_",
")",
":",
"return",
"next",
"(",
"(",
"state",
"for",
"state",
"in",
"self",
".",
"thermostat_states",
"if",
"state",
".",
"id",
"==",
"id_",
")",
",",
"None",
")"
] | Retrieves a thermostat state object by its id
:param id_: The id of the thermostat state
:return: The thermostat state object | [
"Retrieves",
"a",
"thermostat",
"state",
"object",
"by",
"its",
"id"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L357-L364 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.thermostat_state | def thermostat_state(self):
"""The state of the thermostat programming
:return: A thermostat state object of the current setting
"""
current_state = self.thermostat_info.active_state
state = self.get_thermostat_state_by_id(current_state)
if not state:
self._l... | python | def thermostat_state(self):
"""The state of the thermostat programming
:return: A thermostat state object of the current setting
"""
current_state = self.thermostat_info.active_state
state = self.get_thermostat_state_by_id(current_state)
if not state:
self._l... | [
"def",
"thermostat_state",
"(",
"self",
")",
":",
"current_state",
"=",
"self",
".",
"thermostat_info",
".",
"active_state",
"state",
"=",
"self",
".",
"get_thermostat_state_by_id",
"(",
"current_state",
")",
"if",
"not",
"state",
":",
"self",
".",
"_logger",
... | The state of the thermostat programming
:return: A thermostat state object of the current setting | [
"The",
"state",
"of",
"the",
"thermostat",
"programming"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L377-L387 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.thermostat_state | def thermostat_state(self, name):
"""Changes the thermostat state to the one passed as an argument as name
:param name: The name of the thermostat state to change to.
"""
self._validate_thermostat_state_name(name)
id_ = next((key for key in STATES.keys()
if S... | python | def thermostat_state(self, name):
"""Changes the thermostat state to the one passed as an argument as name
:param name: The name of the thermostat state to change to.
"""
self._validate_thermostat_state_name(name)
id_ = next((key for key in STATES.keys()
if S... | [
"def",
"thermostat_state",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"_validate_thermostat_state_name",
"(",
"name",
")",
"id_",
"=",
"next",
"(",
"(",
"key",
"for",
"key",
"in",
"STATES",
".",
"keys",
"(",
")",
"if",
"STATES",
"[",
"key",
"]",
... | Changes the thermostat state to the one passed as an argument as name
:param name: The name of the thermostat state to change to. | [
"Changes",
"the",
"thermostat",
"state",
"to",
"the",
"one",
"passed",
"as",
"an",
"argument",
"as",
"name"
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L390-L403 | train |
costastf/toonlib | toonlib/toonlib.py | Toon.thermostat | def thermostat(self, temperature):
"""A temperature to set the thermostat to. Requires a float.
:param temperature: A float of the desired temperature to change to.
"""
target = int(temperature * 100)
data = copy.copy(self._parameters)
data.update({'value': target})
... | python | def thermostat(self, temperature):
"""A temperature to set the thermostat to. Requires a float.
:param temperature: A float of the desired temperature to change to.
"""
target = int(temperature * 100)
data = copy.copy(self._parameters)
data.update({'value': target})
... | [
"def",
"thermostat",
"(",
"self",
",",
"temperature",
")",
":",
"target",
"=",
"int",
"(",
"temperature",
"*",
"100",
")",
"data",
"=",
"copy",
".",
"copy",
"(",
"self",
".",
"_parameters",
")",
"data",
".",
"update",
"(",
"{",
"'value'",
":",
"targe... | A temperature to set the thermostat to. Requires a float.
:param temperature: A float of the desired temperature to change to. | [
"A",
"temperature",
"to",
"set",
"the",
"thermostat",
"to",
".",
"Requires",
"a",
"float",
"."
] | 2fa95430240d1a1c2a85a8827aecfcb1ca41c18c | https://github.com/costastf/toonlib/blob/2fa95430240d1a1c2a85a8827aecfcb1ca41c18c/toonlib/toonlib.py#L415-L425 | train |
Erotemic/utool | utool/experimental/dynamic_connectivity.py | euler_tour_dfs | def euler_tour_dfs(G, source=None):
""" adaptation of networkx dfs """
if source is None:
# produce edges for all components
nodes = G
else:
# produce edges for components with source
nodes = [source]
yielder = []
visited = set()
for start in nodes:
if sta... | python | def euler_tour_dfs(G, source=None):
""" adaptation of networkx dfs """
if source is None:
# produce edges for all components
nodes = G
else:
# produce edges for components with source
nodes = [source]
yielder = []
visited = set()
for start in nodes:
if sta... | [
"def",
"euler_tour_dfs",
"(",
"G",
",",
"source",
"=",
"None",
")",
":",
"if",
"source",
"is",
"None",
":",
"nodes",
"=",
"G",
"else",
":",
"nodes",
"=",
"[",
"source",
"]",
"yielder",
"=",
"[",
"]",
"visited",
"=",
"set",
"(",
")",
"for",
"start... | adaptation of networkx dfs | [
"adaptation",
"of",
"networkx",
"dfs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/experimental/dynamic_connectivity.py#L12-L41 | train |
Erotemic/utool | utool/experimental/dynamic_connectivity.py | EulerTourTree.reroot | def reroot(self, s):
"""
s = 3
s = 'B'
Let os denote any occurrence of s.
Splice out the first part of the sequence ending with the occurrence before os,
remove its first occurrence (or),
and tack this on to the end of the sequence which now begins with os.
... | python | def reroot(self, s):
"""
s = 3
s = 'B'
Let os denote any occurrence of s.
Splice out the first part of the sequence ending with the occurrence before os,
remove its first occurrence (or),
and tack this on to the end of the sequence which now begins with os.
... | [
"def",
"reroot",
"(",
"self",
",",
"s",
")",
":",
"o_s1",
"=",
"self",
".",
"first_lookup",
"[",
"s",
"]",
"splice1",
"=",
"self",
".",
"tour",
"[",
"1",
":",
"o_s1",
"]",
"rest",
"=",
"self",
".",
"tour",
"[",
"o_s1",
"+",
"1",
":",
"]",
"ne... | s = 3
s = 'B'
Let os denote any occurrence of s.
Splice out the first part of the sequence ending with the occurrence before os,
remove its first occurrence (or),
and tack this on to the end of the sequence which now begins with os.
Add a new occurrence os to the end. | [
"s",
"=",
"3",
"s",
"=",
"B"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/experimental/dynamic_connectivity.py#L521-L539 | train |
Erotemic/utool | utool/experimental/dynamic_connectivity.py | DynConnGraph.remove_edge | def remove_edge(self, u, v):
"""
Using notation where 0 is top level
Intuitively speaking, when the level of a nontree edge is increased, it
is because we have discovered that its end points are close enough in F
to fit in a smaller tree on a higher level.
"""
# ... | python | def remove_edge(self, u, v):
"""
Using notation where 0 is top level
Intuitively speaking, when the level of a nontree edge is increased, it
is because we have discovered that its end points are close enough in F
to fit in a smaller tree on a higher level.
"""
# ... | [
"def",
"remove_edge",
"(",
"self",
",",
"u",
",",
"v",
")",
":",
"print",
"(",
"'Dynamically removing uv=(%r, %r)'",
"%",
"(",
"u",
",",
"v",
")",
")",
"self",
".",
"graph",
".",
"remove_edge",
"(",
"u",
",",
"v",
")",
"e",
"=",
"(",
"u",
",",
"v... | Using notation where 0 is top level
Intuitively speaking, when the level of a nontree edge is increased, it
is because we have discovered that its end points are close enough in F
to fit in a smaller tree on a higher level. | [
"Using",
"notation",
"where",
"0",
"is",
"top",
"level"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/experimental/dynamic_connectivity.py#L853-L923 | train |
Erotemic/utool | utool/util_regex.py | extend_regex2 | def extend_regex2(regexpr, reflags=0):
"""
also preprocesses flags
"""
regexpr = extend_regex(regexpr)
IGNORE_CASE_PREF = '\\c'
if regexpr.startswith(IGNORE_CASE_PREF):
# hack for vim-like ignore case
regexpr = regexpr[len(IGNORE_CASE_PREF):]
reflags = reflags | re.IGNORE... | python | def extend_regex2(regexpr, reflags=0):
"""
also preprocesses flags
"""
regexpr = extend_regex(regexpr)
IGNORE_CASE_PREF = '\\c'
if regexpr.startswith(IGNORE_CASE_PREF):
# hack for vim-like ignore case
regexpr = regexpr[len(IGNORE_CASE_PREF):]
reflags = reflags | re.IGNORE... | [
"def",
"extend_regex2",
"(",
"regexpr",
",",
"reflags",
"=",
"0",
")",
":",
"regexpr",
"=",
"extend_regex",
"(",
"regexpr",
")",
"IGNORE_CASE_PREF",
"=",
"'\\\\c'",
"if",
"regexpr",
".",
"startswith",
"(",
"IGNORE_CASE_PREF",
")",
":",
"regexpr",
"=",
"regex... | also preprocesses flags | [
"also",
"preprocesses",
"flags"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_regex.py#L91-L101 | train |
Erotemic/utool | utool/util_regex.py | named_field | def named_field(key, regex, vim=False):
"""
Creates a named regex group that can be referend via a backref.
If key is None the backref is referenced by number.
References:
https://docs.python.org/2/library/re.html#regular-expression-syntax
"""
if key is None:
#return regex
... | python | def named_field(key, regex, vim=False):
"""
Creates a named regex group that can be referend via a backref.
If key is None the backref is referenced by number.
References:
https://docs.python.org/2/library/re.html#regular-expression-syntax
"""
if key is None:
#return regex
... | [
"def",
"named_field",
"(",
"key",
",",
"regex",
",",
"vim",
"=",
"False",
")",
":",
"if",
"key",
"is",
"None",
":",
"return",
"r'(%s)'",
"%",
"(",
"regex",
",",
")",
"if",
"vim",
":",
"return",
"r'\\(%s\\)'",
"%",
"(",
"regex",
")",
"else",
":",
... | Creates a named regex group that can be referend via a backref.
If key is None the backref is referenced by number.
References:
https://docs.python.org/2/library/re.html#regular-expression-syntax | [
"Creates",
"a",
"named",
"regex",
"group",
"that",
"can",
"be",
"referend",
"via",
"a",
"backref",
".",
"If",
"key",
"is",
"None",
"the",
"backref",
"is",
"referenced",
"by",
"number",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_regex.py#L124-L138 | train |
Erotemic/utool | utool/util_regex.py | regex_replace | def regex_replace(regex, repl, text):
r"""
thin wrapper around re.sub
regex_replace
MULTILINE and DOTALL are on by default in all util_regex functions
Args:
regex (str): pattern to find
repl (str): replace pattern with this
text (str): text to modify
Returns:
s... | python | def regex_replace(regex, repl, text):
r"""
thin wrapper around re.sub
regex_replace
MULTILINE and DOTALL are on by default in all util_regex functions
Args:
regex (str): pattern to find
repl (str): replace pattern with this
text (str): text to modify
Returns:
s... | [
"def",
"regex_replace",
"(",
"regex",
",",
"repl",
",",
"text",
")",
":",
"r",
"return",
"re",
".",
"sub",
"(",
"regex",
",",
"repl",
",",
"text",
",",
"**",
"RE_KWARGS",
")"
] | r"""
thin wrapper around re.sub
regex_replace
MULTILINE and DOTALL are on by default in all util_regex functions
Args:
regex (str): pattern to find
repl (str): replace pattern with this
text (str): text to modify
Returns:
str: modified text
Example1:
>... | [
"r",
"thin",
"wrapper",
"around",
"re",
".",
"sub",
"regex_replace"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_regex.py#L203-L243 | train |
timedata-org/loady | loady/library.py | clear | def clear(prompt=True, cache=None):
"""Clear loady's cache."""
cache = cache or config.cache()
if prompt:
answer = input(
'Clear library cache files in %s/? (yN) ' % cache)
if not answer.startswith('y'):
return False
shutil.rmtree(cache, ignore_errors=True)
re... | python | def clear(prompt=True, cache=None):
"""Clear loady's cache."""
cache = cache or config.cache()
if prompt:
answer = input(
'Clear library cache files in %s/? (yN) ' % cache)
if not answer.startswith('y'):
return False
shutil.rmtree(cache, ignore_errors=True)
re... | [
"def",
"clear",
"(",
"prompt",
"=",
"True",
",",
"cache",
"=",
"None",
")",
":",
"cache",
"=",
"cache",
"or",
"config",
".",
"cache",
"(",
")",
"if",
"prompt",
":",
"answer",
"=",
"input",
"(",
"'Clear library cache files in %s/? (yN) '",
"%",
"cache",
"... | Clear loady's cache. | [
"Clear",
"loady",
"s",
"cache",
"."
] | 94ffcdb92f15a28f3c85f77bd293a9cb59de4cad | https://github.com/timedata-org/loady/blob/94ffcdb92f15a28f3c85f77bd293a9cb59de4cad/loady/library.py#L10-L19 | train |
timedata-org/loady | loady/library.py | create | def create(gitpath, cache=None):
"""
Create a Library from a git path.
"""
if gitpath.startswith(config.LIBRARY_PREFIX):
path = gitpath[len(config.LIBRARY_PREFIX):]
return Library(*path.split('/'), cache=cache) | python | def create(gitpath, cache=None):
"""
Create a Library from a git path.
"""
if gitpath.startswith(config.LIBRARY_PREFIX):
path = gitpath[len(config.LIBRARY_PREFIX):]
return Library(*path.split('/'), cache=cache) | [
"def",
"create",
"(",
"gitpath",
",",
"cache",
"=",
"None",
")",
":",
"if",
"gitpath",
".",
"startswith",
"(",
"config",
".",
"LIBRARY_PREFIX",
")",
":",
"path",
"=",
"gitpath",
"[",
"len",
"(",
"config",
".",
"LIBRARY_PREFIX",
")",
":",
"]",
"return",... | Create a Library from a git path. | [
"Create",
"a",
"Library",
"from",
"a",
"git",
"path",
"."
] | 94ffcdb92f15a28f3c85f77bd293a9cb59de4cad | https://github.com/timedata-org/loady/blob/94ffcdb92f15a28f3c85f77bd293a9cb59de4cad/loady/library.py#L67-L74 | train |
timedata-org/loady | loady/library.py | Library.load | def load(self):
"""Load the library."""
if not git:
raise EnvironmentError(MISSING_GIT_ERROR)
if os.path.exists(self.path):
if not config.CACHE_DISABLE:
return
shutil.rmtree(self.path, ignore_errors=True)
with files.remove_on_exceptio... | python | def load(self):
"""Load the library."""
if not git:
raise EnvironmentError(MISSING_GIT_ERROR)
if os.path.exists(self.path):
if not config.CACHE_DISABLE:
return
shutil.rmtree(self.path, ignore_errors=True)
with files.remove_on_exceptio... | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"not",
"git",
":",
"raise",
"EnvironmentError",
"(",
"MISSING_GIT_ERROR",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"path",
")",
":",
"if",
"not",
"config",
".",
"CACHE_DISABLE",
":",
"... | Load the library. | [
"Load",
"the",
"library",
"."
] | 94ffcdb92f15a28f3c85f77bd293a9cb59de4cad | https://github.com/timedata-org/loady/blob/94ffcdb92f15a28f3c85f77bd293a9cb59de4cad/loady/library.py#L49-L64 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.check_existens_of_staging_tag_in_remote_repo | def check_existens_of_staging_tag_in_remote_repo():
"""
This method will check, if the given tag exists as a staging tag in the remote repository.
The intention is, that every tag, which should be deployed on a production envirnment,
has to be deployed on a staging environment before.
... | python | def check_existens_of_staging_tag_in_remote_repo():
"""
This method will check, if the given tag exists as a staging tag in the remote repository.
The intention is, that every tag, which should be deployed on a production envirnment,
has to be deployed on a staging environment before.
... | [
"def",
"check_existens_of_staging_tag_in_remote_repo",
"(",
")",
":",
"staging_tag",
"=",
"Git",
".",
"create_git_version_tag",
"(",
"APISettings",
".",
"GIT_STAGING_PRE_TAG",
")",
"command_git",
"=",
"'git ls-remote -t'",
"command_awk",
"=",
"'awk \\'{print $2}\\''",
"comm... | This method will check, if the given tag exists as a staging tag in the remote repository.
The intention is, that every tag, which should be deployed on a production envirnment,
has to be deployed on a staging environment before. | [
"This",
"method",
"will",
"check",
"if",
"the",
"given",
"tag",
"exists",
"as",
"a",
"staging",
"tag",
"in",
"the",
"remote",
"repository",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L40-L63 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.__debug | def __debug(command, dry=False):
"""
This method will be called, if the debug mode
is on.
"""
if dry:
command.append('--dry-run')
Shell.debug(command)
if dry:
call(command)
exit(1) | python | def __debug(command, dry=False):
"""
This method will be called, if the debug mode
is on.
"""
if dry:
command.append('--dry-run')
Shell.debug(command)
if dry:
call(command)
exit(1) | [
"def",
"__debug",
"(",
"command",
",",
"dry",
"=",
"False",
")",
":",
"if",
"dry",
":",
"command",
".",
"append",
"(",
"'--dry-run'",
")",
"Shell",
".",
"debug",
"(",
"command",
")",
"if",
"dry",
":",
"call",
"(",
"command",
")",
"exit",
"(",
"1",
... | This method will be called, if the debug mode
is on. | [
"This",
"method",
"will",
"be",
"called",
"if",
"the",
"debug",
"mode",
"is",
"on",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L67-L78 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.__git_add | def __git_add(args=''):
"""
Add files to staging.
The function call will return 0 if the command success.
"""
command = ['git', 'add', '.']
Shell.msg('Adding files...')
if APISettings.DEBUG:
Git.__debug(command, True)
for key in args:
... | python | def __git_add(args=''):
"""
Add files to staging.
The function call will return 0 if the command success.
"""
command = ['git', 'add', '.']
Shell.msg('Adding files...')
if APISettings.DEBUG:
Git.__debug(command, True)
for key in args:
... | [
"def",
"__git_add",
"(",
"args",
"=",
"''",
")",
":",
"command",
"=",
"[",
"'git'",
",",
"'add'",
",",
"'.'",
"]",
"Shell",
".",
"msg",
"(",
"'Adding files...'",
")",
"if",
"APISettings",
".",
"DEBUG",
":",
"Git",
".",
"__debug",
"(",
"command",
",",... | Add files to staging.
The function call will return 0 if the command success. | [
"Add",
"files",
"to",
"staging",
".",
"The",
"function",
"call",
"will",
"return",
"0",
"if",
"the",
"command",
"success",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L83-L98 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.__git_commit | def __git_commit(git_tag):
"""
Commit files to branch.
The function call will return 0 if the command success.
"""
Shell.msg('Commit changes.')
if APISettings.DEBUG:
Shell.debug('Execute "git commit" in dry mode.')
if not call(['git', 'commit', '-m... | python | def __git_commit(git_tag):
"""
Commit files to branch.
The function call will return 0 if the command success.
"""
Shell.msg('Commit changes.')
if APISettings.DEBUG:
Shell.debug('Execute "git commit" in dry mode.')
if not call(['git', 'commit', '-m... | [
"def",
"__git_commit",
"(",
"git_tag",
")",
":",
"Shell",
".",
"msg",
"(",
"'Commit changes.'",
")",
"if",
"APISettings",
".",
"DEBUG",
":",
"Shell",
".",
"debug",
"(",
"'Execute \"git commit\" in dry mode.'",
")",
"if",
"not",
"call",
"(",
"[",
"'git'",
","... | Commit files to branch.
The function call will return 0 if the command success. | [
"Commit",
"files",
"to",
"branch",
".",
"The",
"function",
"call",
"will",
"return",
"0",
"if",
"the",
"command",
"success",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L117-L131 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.__git_tag | def __git_tag(git_tag):
"""
Create new tag.
The function call will return 0 if the command success.
"""
command = ['git', 'tag', '-a', git_tag, '-m', '\'' + git_tag + '\'']
Shell.msg('Create tag from version ' + git_tag)
if APISettings.DEBUG:
Git.__de... | python | def __git_tag(git_tag):
"""
Create new tag.
The function call will return 0 if the command success.
"""
command = ['git', 'tag', '-a', git_tag, '-m', '\'' + git_tag + '\'']
Shell.msg('Create tag from version ' + git_tag)
if APISettings.DEBUG:
Git.__de... | [
"def",
"__git_tag",
"(",
"git_tag",
")",
":",
"command",
"=",
"[",
"'git'",
",",
"'tag'",
",",
"'-a'",
",",
"git_tag",
",",
"'-m'",
",",
"'\\''",
"+",
"git_tag",
"+",
"'\\''",
"]",
"Shell",
".",
"msg",
"(",
"'Create tag from version '",
"+",
"git_tag",
... | Create new tag.
The function call will return 0 if the command success. | [
"Create",
"new",
"tag",
".",
"The",
"function",
"call",
"will",
"return",
"0",
"if",
"the",
"command",
"success",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L135-L148 | train |
rhazdon/django-sonic-screwdriver | django_sonic_screwdriver/git/git.py | Git.__git_tag_push | def __git_tag_push():
"""
Push all tags.
The function call will return 0 if the command success.
"""
command = ['git', 'push', 'origin', '--tags']
Shell.msg('Pushing tags...')
if APISettings.DEBUG:
Git.__debug(command, True)
if not call(comma... | python | def __git_tag_push():
"""
Push all tags.
The function call will return 0 if the command success.
"""
command = ['git', 'push', 'origin', '--tags']
Shell.msg('Pushing tags...')
if APISettings.DEBUG:
Git.__debug(command, True)
if not call(comma... | [
"def",
"__git_tag_push",
"(",
")",
":",
"command",
"=",
"[",
"'git'",
",",
"'push'",
",",
"'origin'",
",",
"'--tags'",
"]",
"Shell",
".",
"msg",
"(",
"'Pushing tags...'",
")",
"if",
"APISettings",
".",
"DEBUG",
":",
"Git",
".",
"__debug",
"(",
"command",... | Push all tags.
The function call will return 0 if the command success. | [
"Push",
"all",
"tags",
".",
"The",
"function",
"call",
"will",
"return",
"0",
"if",
"the",
"command",
"success",
"."
] | 89e885e8c1322fc5c3e0f79b03a55acdc6e63972 | https://github.com/rhazdon/django-sonic-screwdriver/blob/89e885e8c1322fc5c3e0f79b03a55acdc6e63972/django_sonic_screwdriver/git/git.py#L169-L182 | train |
YuriyGuts/pygoose | pygoose/kg/jobs.py | split_into_batches | def split_into_batches(input_list, batch_size, batch_storage_dir, checkpoint=False):
"""
Break the input data into smaller batches, optionally saving each one to disk.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
batch_size: The maximum number of ... | python | def split_into_batches(input_list, batch_size, batch_storage_dir, checkpoint=False):
"""
Break the input data into smaller batches, optionally saving each one to disk.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
batch_size: The maximum number of ... | [
"def",
"split_into_batches",
"(",
"input_list",
",",
"batch_size",
",",
"batch_storage_dir",
",",
"checkpoint",
"=",
"False",
")",
":",
"if",
"checkpoint",
"and",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"batch_storage_dir",
")",
":",
"os",
".",
"mkdir"... | Break the input data into smaller batches, optionally saving each one to disk.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
batch_size: The maximum number of input items in each batch.
batch_storage_dir: The directory to save the checkpoints to.
... | [
"Break",
"the",
"input",
"data",
"into",
"smaller",
"batches",
"optionally",
"saving",
"each",
"one",
"to",
"disk",
"."
] | 4d9b8827c6d6c4b79949d1cd653393498c0bb3c2 | https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/jobs.py#L16-L48 | train |
YuriyGuts/pygoose | pygoose/kg/jobs.py | map_batch_parallel | def map_batch_parallel(input_list, batch_size, item_mapper=None, batch_mapper=None, flatten=True, n_jobs=-1, **kwargs):
"""
Split the data into batches and process each batch in its own thread.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
item_map... | python | def map_batch_parallel(input_list, batch_size, item_mapper=None, batch_mapper=None, flatten=True, n_jobs=-1, **kwargs):
"""
Split the data into batches and process each batch in its own thread.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
item_map... | [
"def",
"map_batch_parallel",
"(",
"input_list",
",",
"batch_size",
",",
"item_mapper",
"=",
"None",
",",
"batch_mapper",
"=",
"None",
",",
"flatten",
"=",
"True",
",",
"n_jobs",
"=",
"-",
"1",
",",
"**",
"kwargs",
")",
":",
"if",
"item_mapper",
"is",
"No... | Split the data into batches and process each batch in its own thread.
Args:
input_list: An input object that has a list-like interface (indexing and slicing).
item_mapper: (optional) A function to apply to each item in the batch.
batch_mapper: (optional) A function to apply to each batch. E... | [
"Split",
"the",
"data",
"into",
"batches",
"and",
"process",
"each",
"batch",
"in",
"its",
"own",
"thread",
"."
] | 4d9b8827c6d6c4b79949d1cd653393498c0bb3c2 | https://github.com/YuriyGuts/pygoose/blob/4d9b8827c6d6c4b79949d1cd653393498c0bb3c2/pygoose/kg/jobs.py#L110-L153 | train |
anayjoshi/platypus | platypus/cfg/ast_to_cfg.py | get_cfg | def get_cfg(ast_func):
"""
Traverses the AST and returns the corresponding CFG
:param ast_func: The AST representation of function
:type ast_func: ast.Function
:returns: The CFG representation of the function
:rtype: cfg.Function
"""
cfg_func = cfg.Function()
for ast_var in ast_fun... | python | def get_cfg(ast_func):
"""
Traverses the AST and returns the corresponding CFG
:param ast_func: The AST representation of function
:type ast_func: ast.Function
:returns: The CFG representation of the function
:rtype: cfg.Function
"""
cfg_func = cfg.Function()
for ast_var in ast_fun... | [
"def",
"get_cfg",
"(",
"ast_func",
")",
":",
"cfg_func",
"=",
"cfg",
".",
"Function",
"(",
")",
"for",
"ast_var",
"in",
"ast_func",
".",
"input_variable_list",
":",
"cfg_var",
"=",
"cfg_func",
".",
"get_variable",
"(",
"ast_var",
".",
"name",
")",
"cfg_fun... | Traverses the AST and returns the corresponding CFG
:param ast_func: The AST representation of function
:type ast_func: ast.Function
:returns: The CFG representation of the function
:rtype: cfg.Function | [
"Traverses",
"the",
"AST",
"and",
"returns",
"the",
"corresponding",
"CFG"
] | 71712f58c99651efbd2e6dfd75a9b1228d42e9ef | https://github.com/anayjoshi/platypus/blob/71712f58c99651efbd2e6dfd75a9b1228d42e9ef/platypus/cfg/ast_to_cfg.py#L4-L28 | train |
Erotemic/utool | utool/util_dev.py | overrideable_partial | def overrideable_partial(func, *args, **default_kwargs):
""" like partial, but given kwargs can be overrideden at calltime """
import functools
@functools.wraps(func)
def partial_wrapper(*given_args, **given_kwargs):
kwargs = default_kwargs.copy()
kwargs.update(given_kwargs)
retu... | python | def overrideable_partial(func, *args, **default_kwargs):
""" like partial, but given kwargs can be overrideden at calltime """
import functools
@functools.wraps(func)
def partial_wrapper(*given_args, **given_kwargs):
kwargs = default_kwargs.copy()
kwargs.update(given_kwargs)
retu... | [
"def",
"overrideable_partial",
"(",
"func",
",",
"*",
"args",
",",
"**",
"default_kwargs",
")",
":",
"import",
"functools",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"partial_wrapper",
"(",
"*",
"given_args",
",",
"**",
"given_kwargs",
")",
... | like partial, but given kwargs can be overrideden at calltime | [
"like",
"partial",
"but",
"given",
"kwargs",
"can",
"be",
"overrideden",
"at",
"calltime"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L40-L48 | train |
Erotemic/utool | utool/util_dev.py | get_nonconflicting_string | def get_nonconflicting_string(base_fmtstr, conflict_set, offset=0):
"""
gets a new string that wont conflict with something that already exists
Args:
base_fmtstr (str):
conflict_set (set):
CommandLine:
python -m utool.util_dev --test-get_nonconflicting_string
Example:
... | python | def get_nonconflicting_string(base_fmtstr, conflict_set, offset=0):
"""
gets a new string that wont conflict with something that already exists
Args:
base_fmtstr (str):
conflict_set (set):
CommandLine:
python -m utool.util_dev --test-get_nonconflicting_string
Example:
... | [
"def",
"get_nonconflicting_string",
"(",
"base_fmtstr",
",",
"conflict_set",
",",
"offset",
"=",
"0",
")",
":",
"conflict_set_",
"=",
"set",
"(",
"conflict_set",
")",
"for",
"count",
"in",
"it",
".",
"count",
"(",
"offset",
")",
":",
"base_str",
"=",
"base... | gets a new string that wont conflict with something that already exists
Args:
base_fmtstr (str):
conflict_set (set):
CommandLine:
python -m utool.util_dev --test-get_nonconflicting_string
Example:
>>> # ENABLE_DOCTEST
>>> from utool.util_dev import * # NOQA
... | [
"gets",
"a",
"new",
"string",
"that",
"wont",
"conflict",
"with",
"something",
"that",
"already",
"exists"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L147-L175 | train |
Erotemic/utool | utool/util_dev.py | get_nonconflicting_path_old | def get_nonconflicting_path_old(base_fmtstr, dpath, offset=0):
r"""
base_fmtstr must have a %d in it
"""
import utool as ut
from os.path import basename
pattern = '*'
dname_list = ut.glob(dpath, pattern, recursive=False,
with_files=True, with_dirs=True)
co... | python | def get_nonconflicting_path_old(base_fmtstr, dpath, offset=0):
r"""
base_fmtstr must have a %d in it
"""
import utool as ut
from os.path import basename
pattern = '*'
dname_list = ut.glob(dpath, pattern, recursive=False,
with_files=True, with_dirs=True)
co... | [
"def",
"get_nonconflicting_path_old",
"(",
"base_fmtstr",
",",
"dpath",
",",
"offset",
"=",
"0",
")",
":",
"r",
"import",
"utool",
"as",
"ut",
"from",
"os",
".",
"path",
"import",
"basename",
"pattern",
"=",
"'*'",
"dname_list",
"=",
"ut",
".",
"glob",
"... | r"""
base_fmtstr must have a %d in it | [
"r",
"base_fmtstr",
"must",
"have",
"a",
"%d",
"in",
"it"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L178-L193 | train |
Erotemic/utool | utool/util_dev.py | are_you_sure | def are_you_sure(msg=''):
r"""
Prompts user to accept or checks command line for -y
Args:
msg (str):
Returns:
bool: accept or not
"""
print(msg)
from utool import util_arg
from utool import util_str
override = util_arg.get_argflag(('--yes', '--y', '-y'))
if over... | python | def are_you_sure(msg=''):
r"""
Prompts user to accept or checks command line for -y
Args:
msg (str):
Returns:
bool: accept or not
"""
print(msg)
from utool import util_arg
from utool import util_str
override = util_arg.get_argflag(('--yes', '--y', '-y'))
if over... | [
"def",
"are_you_sure",
"(",
"msg",
"=",
"''",
")",
":",
"r",
"print",
"(",
"msg",
")",
"from",
"utool",
"import",
"util_arg",
"from",
"utool",
"import",
"util_str",
"override",
"=",
"util_arg",
".",
"get_argflag",
"(",
"(",
"'--yes'",
",",
"'--y'",
",",
... | r"""
Prompts user to accept or checks command line for -y
Args:
msg (str):
Returns:
bool: accept or not | [
"r",
"Prompts",
"user",
"to",
"accept",
"or",
"checks",
"command",
"line",
"for",
"-",
"y"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1170-L1190 | train |
Erotemic/utool | utool/util_dev.py | grace_period | def grace_period(msg='', seconds=10):
"""
Gives user a window to stop a process before it happens
"""
import time
print(msg)
override = util_arg.get_argflag(('--yes', '--y', '-y'))
print('starting grace period')
if override:
print('ending based on command line flag')
retu... | python | def grace_period(msg='', seconds=10):
"""
Gives user a window to stop a process before it happens
"""
import time
print(msg)
override = util_arg.get_argflag(('--yes', '--y', '-y'))
print('starting grace period')
if override:
print('ending based on command line flag')
retu... | [
"def",
"grace_period",
"(",
"msg",
"=",
"''",
",",
"seconds",
"=",
"10",
")",
":",
"import",
"time",
"print",
"(",
"msg",
")",
"override",
"=",
"util_arg",
".",
"get_argflag",
"(",
"(",
"'--yes'",
",",
"'--y'",
",",
"'-y'",
")",
")",
"print",
"(",
... | Gives user a window to stop a process before it happens | [
"Gives",
"user",
"a",
"window",
"to",
"stop",
"a",
"process",
"before",
"it",
"happens"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1193-L1209 | train |
Erotemic/utool | utool/util_dev.py | delayed_retry_gen | def delayed_retry_gen(delay_schedule=[.1, 1, 10], msg=None, timeout=None, raise_=True):
""" template code for a infinte retry loop """
import utool as ut
import time
if not ut.isiterable(delay_schedule):
delay_schedule = [delay_schedule]
tt = ut.tic()
# First attempt is immediate
yi... | python | def delayed_retry_gen(delay_schedule=[.1, 1, 10], msg=None, timeout=None, raise_=True):
""" template code for a infinte retry loop """
import utool as ut
import time
if not ut.isiterable(delay_schedule):
delay_schedule = [delay_schedule]
tt = ut.tic()
# First attempt is immediate
yi... | [
"def",
"delayed_retry_gen",
"(",
"delay_schedule",
"=",
"[",
".1",
",",
"1",
",",
"10",
"]",
",",
"msg",
"=",
"None",
",",
"timeout",
"=",
"None",
",",
"raise_",
"=",
"True",
")",
":",
"import",
"utool",
"as",
"ut",
"import",
"time",
"if",
"not",
"... | template code for a infinte retry loop | [
"template",
"code",
"for",
"a",
"infinte",
"retry",
"loop"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1212-L1233 | train |
Erotemic/utool | utool/util_dev.py | get_stats_str | def get_stats_str(list_=None, newlines=False, keys=None, exclude_keys=[], lbl=None,
precision=None, axis=0, stat_dict=None, use_nan=False,
align=False, use_median=False, **kwargs):
"""
Returns the string version of get_stats
DEPRICATE in favor of ut.repr3(ut.get_stats(..... | python | def get_stats_str(list_=None, newlines=False, keys=None, exclude_keys=[], lbl=None,
precision=None, axis=0, stat_dict=None, use_nan=False,
align=False, use_median=False, **kwargs):
"""
Returns the string version of get_stats
DEPRICATE in favor of ut.repr3(ut.get_stats(..... | [
"def",
"get_stats_str",
"(",
"list_",
"=",
"None",
",",
"newlines",
"=",
"False",
",",
"keys",
"=",
"None",
",",
"exclude_keys",
"=",
"[",
"]",
",",
"lbl",
"=",
"None",
",",
"precision",
"=",
"None",
",",
"axis",
"=",
"0",
",",
"stat_dict",
"=",
"N... | Returns the string version of get_stats
DEPRICATE in favor of ut.repr3(ut.get_stats(...))
if keys is not None then it only displays chosen keys
excluded keys are always removed
CommandLine:
python -m utool.util_dev --test-get_stats_str
Example:
>>> # ENABLE_DOCTEST
>>> f... | [
"Returns",
"the",
"string",
"version",
"of",
"get_stats"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1430-L1520 | train |
Erotemic/utool | utool/util_dev.py | make_call_graph | def make_call_graph(func, *args, **kwargs):
""" profile with pycallgraph
Example:
pycallgraph graphviz -- ./mypythonscript.py
References:
http://pycallgraph.slowchop.com/en/master/
"""
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
with Py... | python | def make_call_graph(func, *args, **kwargs):
""" profile with pycallgraph
Example:
pycallgraph graphviz -- ./mypythonscript.py
References:
http://pycallgraph.slowchop.com/en/master/
"""
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
with Py... | [
"def",
"make_call_graph",
"(",
"func",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"from",
"pycallgraph",
"import",
"PyCallGraph",
"from",
"pycallgraph",
".",
"output",
"import",
"GraphvizOutput",
"with",
"PyCallGraph",
"(",
"output",
"=",
"GraphvizOutput",... | profile with pycallgraph
Example:
pycallgraph graphviz -- ./mypythonscript.py
References:
http://pycallgraph.slowchop.com/en/master/ | [
"profile",
"with",
"pycallgraph"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1549-L1561 | train |
Erotemic/utool | utool/util_dev.py | _memory_profile | def _memory_profile(with_gc=False):
"""
Helper for memory debugging. Mostly just a namespace where I experiment with
guppy and heapy.
References:
http://stackoverflow.com/questions/2629680/deciding-between-subprocess-multiprocessing-and-thread-in-python
Reset Numpy Memory::
%reset ... | python | def _memory_profile(with_gc=False):
"""
Helper for memory debugging. Mostly just a namespace where I experiment with
guppy and heapy.
References:
http://stackoverflow.com/questions/2629680/deciding-between-subprocess-multiprocessing-and-thread-in-python
Reset Numpy Memory::
%reset ... | [
"def",
"_memory_profile",
"(",
"with_gc",
"=",
"False",
")",
":",
"import",
"utool",
"as",
"ut",
"if",
"with_gc",
":",
"garbage_collect",
"(",
")",
"import",
"guppy",
"hp",
"=",
"guppy",
".",
"hpy",
"(",
")",
"print",
"(",
"'[hpy] Waiting for heap output...'... | Helper for memory debugging. Mostly just a namespace where I experiment with
guppy and heapy.
References:
http://stackoverflow.com/questions/2629680/deciding-between-subprocess-multiprocessing-and-thread-in-python
Reset Numpy Memory::
%reset out
%reset array | [
"Helper",
"for",
"memory",
"debugging",
".",
"Mostly",
"just",
"a",
"namespace",
"where",
"I",
"experiment",
"with",
"guppy",
"and",
"heapy",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1586-L1607 | train |
Erotemic/utool | utool/util_dev.py | make_object_graph | def make_object_graph(obj, fpath='sample_graph.png'):
""" memoryprofile with objgraph
Examples:
#import objgraph
#objgraph.show_most_common_types()
#objgraph.show_growth()
#memtrack.report()
#memtrack.report()
#objgraph.show_growth()
#import gc
#g... | python | def make_object_graph(obj, fpath='sample_graph.png'):
""" memoryprofile with objgraph
Examples:
#import objgraph
#objgraph.show_most_common_types()
#objgraph.show_growth()
#memtrack.report()
#memtrack.report()
#objgraph.show_growth()
#import gc
#g... | [
"def",
"make_object_graph",
"(",
"obj",
",",
"fpath",
"=",
"'sample_graph.png'",
")",
":",
"import",
"objgraph",
"objgraph",
".",
"show_most_common_types",
"(",
")",
"objgraph",
".",
"show_refs",
"(",
"[",
"obj",
"]",
",",
"filename",
"=",
"'ref_graph.png'",
"... | memoryprofile with objgraph
Examples:
#import objgraph
#objgraph.show_most_common_types()
#objgraph.show_growth()
#memtrack.report()
#memtrack.report()
#objgraph.show_growth()
#import gc
#gc.collect()
#memtrack.report()
#y = 0
... | [
"memoryprofile",
"with",
"objgraph"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L1612-L1640 | train |
Erotemic/utool | utool/util_dev.py | inverable_unique_two_lists | def inverable_unique_two_lists(item1_list, item2_list):
"""
item1_list = aid1_list
item2_list = aid2_list
"""
import utool as ut
unique_list1, inverse1 = np.unique(item1_list, return_inverse=True)
unique_list2, inverse2 = np.unique(item2_list, return_inverse=True)
flat_stacked, cumsum =... | python | def inverable_unique_two_lists(item1_list, item2_list):
"""
item1_list = aid1_list
item2_list = aid2_list
"""
import utool as ut
unique_list1, inverse1 = np.unique(item1_list, return_inverse=True)
unique_list2, inverse2 = np.unique(item2_list, return_inverse=True)
flat_stacked, cumsum =... | [
"def",
"inverable_unique_two_lists",
"(",
"item1_list",
",",
"item2_list",
")",
":",
"import",
"utool",
"as",
"ut",
"unique_list1",
",",
"inverse1",
"=",
"np",
".",
"unique",
"(",
"item1_list",
",",
"return_inverse",
"=",
"True",
")",
"unique_list2",
",",
"inv... | item1_list = aid1_list
item2_list = aid2_list | [
"item1_list",
"=",
"aid1_list",
"item2_list",
"=",
"aid2_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2151-L2163 | train |
Erotemic/utool | utool/util_dev.py | uninvert_unique_two_lists | def uninvert_unique_two_lists(flat_list, reconstruct_tup):
"""
flat_list = thumb_list
"""
import utool as ut
(inverse3, cumsum, inverse2, inverse1) = reconstruct_tup
flat_stacked_ = ut.take(flat_list, inverse3)
unique_list1_, unique_list2_ = ut.unflatten2(flat_stacked_, cumsum)
res_list1... | python | def uninvert_unique_two_lists(flat_list, reconstruct_tup):
"""
flat_list = thumb_list
"""
import utool as ut
(inverse3, cumsum, inverse2, inverse1) = reconstruct_tup
flat_stacked_ = ut.take(flat_list, inverse3)
unique_list1_, unique_list2_ = ut.unflatten2(flat_stacked_, cumsum)
res_list1... | [
"def",
"uninvert_unique_two_lists",
"(",
"flat_list",
",",
"reconstruct_tup",
")",
":",
"import",
"utool",
"as",
"ut",
"(",
"inverse3",
",",
"cumsum",
",",
"inverse2",
",",
"inverse1",
")",
"=",
"reconstruct_tup",
"flat_stacked_",
"=",
"ut",
".",
"take",
"(",
... | flat_list = thumb_list | [
"flat_list",
"=",
"thumb_list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2166-L2176 | train |
Erotemic/utool | utool/util_dev.py | search_module | def search_module(mod, pat, ignore_case=True, recursive=False, _seen=None):
r"""
Searches module functions, classes, and constants for members matching a
pattern.
Args:
mod (module): live python module
pat (str): regular expression
Returns:
list: found_list
CommandLine... | python | def search_module(mod, pat, ignore_case=True, recursive=False, _seen=None):
r"""
Searches module functions, classes, and constants for members matching a
pattern.
Args:
mod (module): live python module
pat (str): regular expression
Returns:
list: found_list
CommandLine... | [
"def",
"search_module",
"(",
"mod",
",",
"pat",
",",
"ignore_case",
"=",
"True",
",",
"recursive",
"=",
"False",
",",
"_seen",
"=",
"None",
")",
":",
"r",
"if",
"_seen",
"is",
"not",
"None",
"and",
"mod",
"in",
"_seen",
":",
"return",
"[",
"]",
"im... | r"""
Searches module functions, classes, and constants for members matching a
pattern.
Args:
mod (module): live python module
pat (str): regular expression
Returns:
list: found_list
CommandLine:
python -m utool.util_dev --exec-search_module --mod=utool --pat=module... | [
"r",
"Searches",
"module",
"functions",
"classes",
"and",
"constants",
"for",
"members",
"matching",
"a",
"pattern",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2268-L2325 | train |
Erotemic/utool | utool/util_dev.py | instancelist | def instancelist(obj_list, check=False, shared_attrs=None):
"""
Executes methods and attribute calls on a list of objects of the same type
Bundles a list of object of the same type into a single object.
The new object contains the same functions as each original object
but applies them to each elem... | python | def instancelist(obj_list, check=False, shared_attrs=None):
"""
Executes methods and attribute calls on a list of objects of the same type
Bundles a list of object of the same type into a single object.
The new object contains the same functions as each original object
but applies them to each elem... | [
"def",
"instancelist",
"(",
"obj_list",
",",
"check",
"=",
"False",
",",
"shared_attrs",
"=",
"None",
")",
":",
"class",
"InstanceList_",
"(",
"object",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"obj_list",
",",
"shared_attrs",
"=",
"None",
")",
":"... | Executes methods and attribute calls on a list of objects of the same type
Bundles a list of object of the same type into a single object.
The new object contains the same functions as each original object
but applies them to each element of the list independantly when called.
CommandLine:
pyt... | [
"Executes",
"methods",
"and",
"attribute",
"calls",
"on",
"a",
"list",
"of",
"objects",
"of",
"the",
"same",
"type"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2570-L2672 | train |
Erotemic/utool | utool/util_dev.py | _heappush_max | def _heappush_max(heap, item):
""" why is this not in heapq """
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap) - 1) | python | def _heappush_max(heap, item):
""" why is this not in heapq """
heap.append(item)
heapq._siftdown_max(heap, 0, len(heap) - 1) | [
"def",
"_heappush_max",
"(",
"heap",
",",
"item",
")",
":",
"heap",
".",
"append",
"(",
"item",
")",
"heapq",
".",
"_siftdown_max",
"(",
"heap",
",",
"0",
",",
"len",
"(",
"heap",
")",
"-",
"1",
")"
] | why is this not in heapq | [
"why",
"is",
"this",
"not",
"in",
"heapq"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L3235-L3238 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.take_column | def take_column(self, keys, *extra_keys):
""" Takes a subset of columns """
import utool as ut
keys = ut.ensure_iterable(keys) + list(extra_keys)
key_to_list = ut.dict_subset(self._key_to_list, keys)
newself = self.__class__(key_to_list, self._meta.copy())
return newself | python | def take_column(self, keys, *extra_keys):
""" Takes a subset of columns """
import utool as ut
keys = ut.ensure_iterable(keys) + list(extra_keys)
key_to_list = ut.dict_subset(self._key_to_list, keys)
newself = self.__class__(key_to_list, self._meta.copy())
return newself | [
"def",
"take_column",
"(",
"self",
",",
"keys",
",",
"*",
"extra_keys",
")",
":",
"import",
"utool",
"as",
"ut",
"keys",
"=",
"ut",
".",
"ensure_iterable",
"(",
"keys",
")",
"+",
"list",
"(",
"extra_keys",
")",
"key_to_list",
"=",
"ut",
".",
"dict_subs... | Takes a subset of columns | [
"Takes",
"a",
"subset",
"of",
"columns"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2830-L2836 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.take | def take(self, idxs):
""" Takes a subset of rows """
import utool as ut
if False:
key_to_list = ut.odict([
(key, ut.take(val, idxs))
for key, val in six.iteritems(self._key_to_list)
])
else:
import numpy as np
... | python | def take(self, idxs):
""" Takes a subset of rows """
import utool as ut
if False:
key_to_list = ut.odict([
(key, ut.take(val, idxs))
for key, val in six.iteritems(self._key_to_list)
])
else:
import numpy as np
... | [
"def",
"take",
"(",
"self",
",",
"idxs",
")",
":",
"import",
"utool",
"as",
"ut",
"if",
"False",
":",
"key_to_list",
"=",
"ut",
".",
"odict",
"(",
"[",
"(",
"key",
",",
"ut",
".",
"take",
"(",
"val",
",",
"idxs",
")",
")",
"for",
"key",
",",
... | Takes a subset of rows | [
"Takes",
"a",
"subset",
"of",
"rows"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2838-L2855 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.remove | def remove(self, idxs):
""" Returns a copy with idxs removed """
import utool as ut
keep_idxs = ut.index_complement(idxs, len(self))
return self.take(keep_idxs) | python | def remove(self, idxs):
""" Returns a copy with idxs removed """
import utool as ut
keep_idxs = ut.index_complement(idxs, len(self))
return self.take(keep_idxs) | [
"def",
"remove",
"(",
"self",
",",
"idxs",
")",
":",
"import",
"utool",
"as",
"ut",
"keep_idxs",
"=",
"ut",
".",
"index_complement",
"(",
"idxs",
",",
"len",
"(",
"self",
")",
")",
"return",
"self",
".",
"take",
"(",
"keep_idxs",
")"
] | Returns a copy with idxs removed | [
"Returns",
"a",
"copy",
"with",
"idxs",
"removed"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2857-L2861 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.group_items | def group_items(self, labels):
""" group as dict """
import utool as ut
unique_labels, groups = self.group(labels)
label_to_group = ut.odict(zip(unique_labels, groups))
return label_to_group | python | def group_items(self, labels):
""" group as dict """
import utool as ut
unique_labels, groups = self.group(labels)
label_to_group = ut.odict(zip(unique_labels, groups))
return label_to_group | [
"def",
"group_items",
"(",
"self",
",",
"labels",
")",
":",
"import",
"utool",
"as",
"ut",
"unique_labels",
",",
"groups",
"=",
"self",
".",
"group",
"(",
"labels",
")",
"label_to_group",
"=",
"ut",
".",
"odict",
"(",
"zip",
"(",
"unique_labels",
",",
... | group as dict | [
"group",
"as",
"dict"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2880-L2885 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.group | def group(self, labels):
""" group as list """
unique_labels, groupxs = self.group_indicies(labels)
groups = [self.take(idxs) for idxs in groupxs]
return unique_labels, groups | python | def group(self, labels):
""" group as list """
unique_labels, groupxs = self.group_indicies(labels)
groups = [self.take(idxs) for idxs in groupxs]
return unique_labels, groups | [
"def",
"group",
"(",
"self",
",",
"labels",
")",
":",
"unique_labels",
",",
"groupxs",
"=",
"self",
".",
"group_indicies",
"(",
"labels",
")",
"groups",
"=",
"[",
"self",
".",
"take",
"(",
"idxs",
")",
"for",
"idxs",
"in",
"groupxs",
"]",
"return",
"... | group as list | [
"group",
"as",
"list"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2887-L2891 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.cast_column | def cast_column(self, keys, func):
""" like map column but applies values inplace """
import utool as ut
for key in ut.ensure_iterable(keys):
self[key] = [func(v) for v in self[key]] | python | def cast_column(self, keys, func):
""" like map column but applies values inplace """
import utool as ut
for key in ut.ensure_iterable(keys):
self[key] = [func(v) for v in self[key]] | [
"def",
"cast_column",
"(",
"self",
",",
"keys",
",",
"func",
")",
":",
"import",
"utool",
"as",
"ut",
"for",
"key",
"in",
"ut",
".",
"ensure_iterable",
"(",
"keys",
")",
":",
"self",
"[",
"key",
"]",
"=",
"[",
"func",
"(",
"v",
")",
"for",
"v",
... | like map column but applies values inplace | [
"like",
"map",
"column",
"but",
"applies",
"values",
"inplace"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2919-L2923 | train |
Erotemic/utool | utool/util_dev.py | ColumnLists.merge_rows | def merge_rows(self, key, merge_scalars=True):
"""
Uses key as a unique index an merges all duplicates rows. Use
cast_column to modify types of columns before merging to affect
behavior of duplicate rectification.
Args:
key: row to merge on
merge_scalars... | python | def merge_rows(self, key, merge_scalars=True):
"""
Uses key as a unique index an merges all duplicates rows. Use
cast_column to modify types of columns before merging to affect
behavior of duplicate rectification.
Args:
key: row to merge on
merge_scalars... | [
"def",
"merge_rows",
"(",
"self",
",",
"key",
",",
"merge_scalars",
"=",
"True",
")",
":",
"import",
"utool",
"as",
"ut",
"unique_labels",
",",
"groupxs",
"=",
"self",
".",
"group_indicies",
"(",
"key",
")",
"single_xs",
"=",
"[",
"xs",
"for",
"xs",
"i... | Uses key as a unique index an merges all duplicates rows. Use
cast_column to modify types of columns before merging to affect
behavior of duplicate rectification.
Args:
key: row to merge on
merge_scalars: if True, scalar values become lists
Example:
... | [
"Uses",
"key",
"as",
"a",
"unique",
"index",
"an",
"merges",
"all",
"duplicates",
"rows",
".",
"Use",
"cast_column",
"to",
"modify",
"types",
"of",
"columns",
"before",
"merging",
"to",
"affect",
"behavior",
"of",
"duplicate",
"rectification",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L2934-L3024 | train |
Erotemic/utool | utool/util_dev.py | PriorityQueue.peek | def peek(self):
"""
Peek at the next item in the queue
"""
# Ammortized O(1)
_heap = self._heap
_dict = self._dict
val, key = _heap[0]
# Remove items marked for lazy deletion as they are encountered
while key not in _dict or _dict[key] != val:
... | python | def peek(self):
"""
Peek at the next item in the queue
"""
# Ammortized O(1)
_heap = self._heap
_dict = self._dict
val, key = _heap[0]
# Remove items marked for lazy deletion as they are encountered
while key not in _dict or _dict[key] != val:
... | [
"def",
"peek",
"(",
"self",
")",
":",
"_heap",
"=",
"self",
".",
"_heap",
"_dict",
"=",
"self",
".",
"_dict",
"val",
",",
"key",
"=",
"_heap",
"[",
"0",
"]",
"while",
"key",
"not",
"in",
"_dict",
"or",
"_dict",
"[",
"key",
"]",
"!=",
"val",
":"... | Peek at the next item in the queue | [
"Peek",
"at",
"the",
"next",
"item",
"in",
"the",
"queue"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L3363-L3375 | train |
Erotemic/utool | utool/util_dev.py | PriorityQueue.peek_many | def peek_many(self, n):
"""
Actually this can be quite inefficient
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> items = list(zip(range(256), range(256)))
>>> n = 32
>>> ut.shuffle(items)
>>> self = ut.PriorityQ... | python | def peek_many(self, n):
"""
Actually this can be quite inefficient
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> items = list(zip(range(256), range(256)))
>>> n = 32
>>> ut.shuffle(items)
>>> self = ut.PriorityQ... | [
"def",
"peek_many",
"(",
"self",
",",
"n",
")",
":",
"if",
"n",
"==",
"0",
":",
"return",
"[",
"]",
"elif",
"n",
"==",
"1",
":",
"return",
"[",
"self",
".",
"peek",
"(",
")",
"]",
"else",
":",
"items",
"=",
"list",
"(",
"self",
".",
"pop_many... | Actually this can be quite inefficient
Example:
>>> # DISABLE_DOCTEST
>>> import utool as ut
>>> items = list(zip(range(256), range(256)))
>>> n = 32
>>> ut.shuffle(items)
>>> self = ut.PriorityQueue(items, ascending=False)
>>>... | [
"Actually",
"this",
"can",
"be",
"quite",
"inefficient"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L3377-L3397 | train |
Erotemic/utool | utool/util_dev.py | PriorityQueue.pop | def pop(self, key=util_const.NoParam, default=util_const.NoParam):
"""
Pop the next item off the queue
"""
# Dictionary pop if key is specified
if key is not util_const.NoParam:
if default is util_const.NoParam:
return (key, self._dict.pop(key))
... | python | def pop(self, key=util_const.NoParam, default=util_const.NoParam):
"""
Pop the next item off the queue
"""
# Dictionary pop if key is specified
if key is not util_const.NoParam:
if default is util_const.NoParam:
return (key, self._dict.pop(key))
... | [
"def",
"pop",
"(",
"self",
",",
"key",
"=",
"util_const",
".",
"NoParam",
",",
"default",
"=",
"util_const",
".",
"NoParam",
")",
":",
"if",
"key",
"is",
"not",
"util_const",
".",
"NoParam",
":",
"if",
"default",
"is",
"util_const",
".",
"NoParam",
":"... | Pop the next item off the queue | [
"Pop",
"the",
"next",
"item",
"off",
"the",
"queue"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_dev.py#L3405-L3430 | train |
Erotemic/utool | utool/_internal/util_importer.py | __execute_fromimport | def __execute_fromimport(module, modname, import_tuples, verbose=False):
""" Module From Imports """
if verbose:
print('[UTIL_IMPORT] EXECUTING %d FROM IMPORT TUPLES' % (len(import_tuples),))
from_imports = __get_from_imports(import_tuples)
for name, fromlist in from_imports:
full_modnam... | python | def __execute_fromimport(module, modname, import_tuples, verbose=False):
""" Module From Imports """
if verbose:
print('[UTIL_IMPORT] EXECUTING %d FROM IMPORT TUPLES' % (len(import_tuples),))
from_imports = __get_from_imports(import_tuples)
for name, fromlist in from_imports:
full_modnam... | [
"def",
"__execute_fromimport",
"(",
"module",
",",
"modname",
",",
"import_tuples",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"verbose",
":",
"print",
"(",
"'[UTIL_IMPORT] EXECUTING %d FROM IMPORT TUPLES'",
"%",
"(",
"len",
"(",
"import_tuples",
")",
",",
")... | Module From Imports | [
"Module",
"From",
"Imports"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L34-L44 | train |
Erotemic/utool | utool/_internal/util_importer.py | _initstr | def _initstr(modname, imports, from_imports, inject_execstr, withheader=True):
""" Calls the other string makers """
header = _make_module_header() if withheader else ''
import_str = _make_imports_str(imports, modname)
fromimport_str = _make_fromimport_str(from_imports, modname)
initstr ... | python | def _initstr(modname, imports, from_imports, inject_execstr, withheader=True):
""" Calls the other string makers """
header = _make_module_header() if withheader else ''
import_str = _make_imports_str(imports, modname)
fromimport_str = _make_fromimport_str(from_imports, modname)
initstr ... | [
"def",
"_initstr",
"(",
"modname",
",",
"imports",
",",
"from_imports",
",",
"inject_execstr",
",",
"withheader",
"=",
"True",
")",
":",
"header",
"=",
"_make_module_header",
"(",
")",
"if",
"withheader",
"else",
"''",
"import_str",
"=",
"_make_imports_str",
"... | Calls the other string makers | [
"Calls",
"the",
"other",
"string",
"makers"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L152-L163 | train |
Erotemic/utool | utool/_internal/util_importer.py | _inject_execstr | def _inject_execstr(modname, import_tuples):
""" Injection and Reload String Defs """
if modname == 'utool':
# Special case import of the util_inject module
injecter = 'util_inject'
injecter_import = ''
else:
# Normal case implicit import of util_inject
injecter_impor... | python | def _inject_execstr(modname, import_tuples):
""" Injection and Reload String Defs """
if modname == 'utool':
# Special case import of the util_inject module
injecter = 'util_inject'
injecter_import = ''
else:
# Normal case implicit import of util_inject
injecter_impor... | [
"def",
"_inject_execstr",
"(",
"modname",
",",
"import_tuples",
")",
":",
"if",
"modname",
"==",
"'utool'",
":",
"injecter",
"=",
"'util_inject'",
"injecter_import",
"=",
"''",
"else",
":",
"injecter_import",
"=",
"'import utool'",
"injecter",
"=",
"'utool'",
"i... | Injection and Reload String Defs | [
"Injection",
"and",
"Reload",
"String",
"Defs"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L196-L288 | train |
Erotemic/utool | utool/_internal/util_importer.py | dynamic_import | def dynamic_import(modname, import_tuples, developing=True, ignore_froms=[],
dump=False, ignore_startswith=[], ignore_endswith=[],
ignore_list=[], check_not_imported=True, return_initstr=False,
verbose=False):
"""
MAIN ENTRY POINT
Dynamically import ... | python | def dynamic_import(modname, import_tuples, developing=True, ignore_froms=[],
dump=False, ignore_startswith=[], ignore_endswith=[],
ignore_list=[], check_not_imported=True, return_initstr=False,
verbose=False):
"""
MAIN ENTRY POINT
Dynamically import ... | [
"def",
"dynamic_import",
"(",
"modname",
",",
"import_tuples",
",",
"developing",
"=",
"True",
",",
"ignore_froms",
"=",
"[",
"]",
",",
"dump",
"=",
"False",
",",
"ignore_startswith",
"=",
"[",
"]",
",",
"ignore_endswith",
"=",
"[",
"]",
",",
"ignore_list"... | MAIN ENTRY POINT
Dynamically import listed util libraries and their attributes.
Create reload_subs function.
Using __import__ like this is typically not considered good style However,
it is better than import * and this will generate the good file text that
can be used when the module is 'frozen"
... | [
"MAIN",
"ENTRY",
"POINT"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L294-L407 | train |
Erotemic/utool | utool/_internal/util_importer.py | make_initstr | def make_initstr(modname, import_tuples, verbose=False):
"""
Just creates the string representation. Does no importing.
"""
imports = [tup[0] for tup in import_tuples]
from_imports = __get_from_imports(import_tuples)
inject_execstr = _inject_execstr(modname, import_tuples)
return _initstr(mo... | python | def make_initstr(modname, import_tuples, verbose=False):
"""
Just creates the string representation. Does no importing.
"""
imports = [tup[0] for tup in import_tuples]
from_imports = __get_from_imports(import_tuples)
inject_execstr = _inject_execstr(modname, import_tuples)
return _initstr(mo... | [
"def",
"make_initstr",
"(",
"modname",
",",
"import_tuples",
",",
"verbose",
"=",
"False",
")",
":",
"imports",
"=",
"[",
"tup",
"[",
"0",
"]",
"for",
"tup",
"in",
"import_tuples",
"]",
"from_imports",
"=",
"__get_from_imports",
"(",
"import_tuples",
")",
... | Just creates the string representation. Does no importing. | [
"Just",
"creates",
"the",
"string",
"representation",
".",
"Does",
"no",
"importing",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L410-L417 | train |
Erotemic/utool | utool/_internal/util_importer.py | make_import_tuples | def make_import_tuples(module_path, exclude_modnames=[]):
""" Infer the import_tuples from a module_path """
from utool import util_path
kwargs = dict(private=False, full=False)
module_list = util_path.ls_modulefiles(module_path, noext=True, **kwargs)
package_list = util_path.ls_moduledirs(module_p... | python | def make_import_tuples(module_path, exclude_modnames=[]):
""" Infer the import_tuples from a module_path """
from utool import util_path
kwargs = dict(private=False, full=False)
module_list = util_path.ls_modulefiles(module_path, noext=True, **kwargs)
package_list = util_path.ls_moduledirs(module_p... | [
"def",
"make_import_tuples",
"(",
"module_path",
",",
"exclude_modnames",
"=",
"[",
"]",
")",
":",
"from",
"utool",
"import",
"util_path",
"kwargs",
"=",
"dict",
"(",
"private",
"=",
"False",
",",
"full",
"=",
"False",
")",
"module_list",
"=",
"util_path",
... | Infer the import_tuples from a module_path | [
"Infer",
"the",
"import_tuples",
"from",
"a",
"module_path"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/util_importer.py#L420-L432 | train |
Erotemic/utool | utool/_internal/meta_util_cplat.py | get_resource_dir | def get_resource_dir():
"""
Returns a directory which should be writable for any application
"""
#resource_prefix = '~'
if WIN32:
dpath_ = '~/AppData/Roaming'
elif LINUX:
dpath_ = '~/.config'
elif DARWIN:
dpath_ = '~/Library/Application Support'
else:
rai... | python | def get_resource_dir():
"""
Returns a directory which should be writable for any application
"""
#resource_prefix = '~'
if WIN32:
dpath_ = '~/AppData/Roaming'
elif LINUX:
dpath_ = '~/.config'
elif DARWIN:
dpath_ = '~/Library/Application Support'
else:
rai... | [
"def",
"get_resource_dir",
"(",
")",
":",
"if",
"WIN32",
":",
"dpath_",
"=",
"'~/AppData/Roaming'",
"elif",
"LINUX",
":",
"dpath_",
"=",
"'~/.config'",
"elif",
"DARWIN",
":",
"dpath_",
"=",
"'~/Library/Application Support'",
"else",
":",
"raise",
"AssertionError",... | Returns a directory which should be writable for any application | [
"Returns",
"a",
"directory",
"which",
"should",
"be",
"writable",
"for",
"any",
"application"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/_internal/meta_util_cplat.py#L16-L30 | train |
Erotemic/utool | utool/util_io.py | load_data | def load_data(fpath, **kwargs):
""" More generic interface to load data """
ext = splitext(fpath)[1]
if ext in ['.pickle', '.cPkl', '.pkl']:
return load_cPkl(fpath, **kwargs)
elif ext in ['.json']:
return load_json(fpath, **kwargs)
elif ext in ['.hdf5']:
return load_hdf5(fpat... | python | def load_data(fpath, **kwargs):
""" More generic interface to load data """
ext = splitext(fpath)[1]
if ext in ['.pickle', '.cPkl', '.pkl']:
return load_cPkl(fpath, **kwargs)
elif ext in ['.json']:
return load_json(fpath, **kwargs)
elif ext in ['.hdf5']:
return load_hdf5(fpat... | [
"def",
"load_data",
"(",
"fpath",
",",
"**",
"kwargs",
")",
":",
"ext",
"=",
"splitext",
"(",
"fpath",
")",
"[",
"1",
"]",
"if",
"ext",
"in",
"[",
"'.pickle'",
",",
"'.cPkl'",
",",
"'.pkl'",
"]",
":",
"return",
"load_cPkl",
"(",
"fpath",
",",
"**",... | More generic interface to load data | [
"More",
"generic",
"interface",
"to",
"load",
"data"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L32-L46 | train |
Erotemic/utool | utool/util_io.py | save_data | def save_data(fpath, data, **kwargs):
""" More generic interface to write data """
ext = splitext(fpath)[1]
if ext in ['.pickle', '.cPkl', '.pkl']:
return save_cPkl(fpath, data, **kwargs)
elif ext in ['.json']:
return save_json(fpath, data, **kwargs)
elif ext in ['.hdf5']:
re... | python | def save_data(fpath, data, **kwargs):
""" More generic interface to write data """
ext = splitext(fpath)[1]
if ext in ['.pickle', '.cPkl', '.pkl']:
return save_cPkl(fpath, data, **kwargs)
elif ext in ['.json']:
return save_json(fpath, data, **kwargs)
elif ext in ['.hdf5']:
re... | [
"def",
"save_data",
"(",
"fpath",
",",
"data",
",",
"**",
"kwargs",
")",
":",
"ext",
"=",
"splitext",
"(",
"fpath",
")",
"[",
"1",
"]",
"if",
"ext",
"in",
"[",
"'.pickle'",
",",
"'.cPkl'",
",",
"'.pkl'",
"]",
":",
"return",
"save_cPkl",
"(",
"fpath... | More generic interface to write data | [
"More",
"generic",
"interface",
"to",
"write",
"data"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L49-L63 | train |
Erotemic/utool | utool/util_io.py | write_to | def write_to(fpath, to_write, aslines=False, verbose=None,
onlyifdiff=False, mode='w', n=None):
""" Writes text to a file. Automatically encodes text as utf8.
Args:
fpath (str): file path
to_write (str): text to write (must be unicode text)
aslines (bool): if True to_write ... | python | def write_to(fpath, to_write, aslines=False, verbose=None,
onlyifdiff=False, mode='w', n=None):
""" Writes text to a file. Automatically encodes text as utf8.
Args:
fpath (str): file path
to_write (str): text to write (must be unicode text)
aslines (bool): if True to_write ... | [
"def",
"write_to",
"(",
"fpath",
",",
"to_write",
",",
"aslines",
"=",
"False",
",",
"verbose",
"=",
"None",
",",
"onlyifdiff",
"=",
"False",
",",
"mode",
"=",
"'w'",
",",
"n",
"=",
"None",
")",
":",
"if",
"onlyifdiff",
":",
"import",
"utool",
"as",
... | Writes text to a file. Automatically encodes text as utf8.
Args:
fpath (str): file path
to_write (str): text to write (must be unicode text)
aslines (bool): if True to_write is assumed to be a list of lines
verbose (bool): verbosity flag
onlyifdiff (bool): only writes if nee... | [
"Writes",
"text",
"to",
"a",
"file",
".",
"Automatically",
"encodes",
"text",
"as",
"utf8",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L82-L161 | train |
Erotemic/utool | utool/util_io.py | read_from | def read_from(fpath, verbose=None, aslines=False, strict=True, n=None, errors='replace'):
r""" Reads text from a file. Automatically returns utf8.
Args:
fpath (str): file path
aslines (bool): if True returns list of lines
verbose (bool): verbosity flag
Returns:
str: text fr... | python | def read_from(fpath, verbose=None, aslines=False, strict=True, n=None, errors='replace'):
r""" Reads text from a file. Automatically returns utf8.
Args:
fpath (str): file path
aslines (bool): if True returns list of lines
verbose (bool): verbosity flag
Returns:
str: text fr... | [
"def",
"read_from",
"(",
"fpath",
",",
"verbose",
"=",
"None",
",",
"aslines",
"=",
"False",
",",
"strict",
"=",
"True",
",",
"n",
"=",
"None",
",",
"errors",
"=",
"'replace'",
")",
":",
"r",
"if",
"n",
"is",
"None",
":",
"n",
"=",
"__READ_TAIL_N__... | r""" Reads text from a file. Automatically returns utf8.
Args:
fpath (str): file path
aslines (bool): if True returns list of lines
verbose (bool): verbosity flag
Returns:
str: text from fpath (this is unicode)
Ignore:
x = b'''/whaleshark_003_fors\xc3\xb8g.wmv" />\... | [
"r",
"Reads",
"text",
"from",
"a",
"file",
".",
"Automatically",
"returns",
"utf8",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L164-L216 | train |
Erotemic/utool | utool/util_io.py | save_cPkl | def save_cPkl(fpath, data, verbose=None, n=None):
""" Saves data to a pickled file with optional verbosity """
verbose = _rectify_verb_write(verbose)
if verbose:
print('[util_io] * save_cPkl(%r, data)' % (util_path.tail(fpath, n=n),))
with open(fpath, 'wb') as file_:
# Use protocol 2 to ... | python | def save_cPkl(fpath, data, verbose=None, n=None):
""" Saves data to a pickled file with optional verbosity """
verbose = _rectify_verb_write(verbose)
if verbose:
print('[util_io] * save_cPkl(%r, data)' % (util_path.tail(fpath, n=n),))
with open(fpath, 'wb') as file_:
# Use protocol 2 to ... | [
"def",
"save_cPkl",
"(",
"fpath",
",",
"data",
",",
"verbose",
"=",
"None",
",",
"n",
"=",
"None",
")",
":",
"verbose",
"=",
"_rectify_verb_write",
"(",
"verbose",
")",
"if",
"verbose",
":",
"print",
"(",
"'[util_io] * save_cPkl(%r, data)'",
"%",
"(",
"uti... | Saves data to a pickled file with optional verbosity | [
"Saves",
"data",
"to",
"a",
"pickled",
"file",
"with",
"optional",
"verbosity"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L249-L256 | train |
Erotemic/utool | utool/util_io.py | load_cPkl | def load_cPkl(fpath, verbose=None, n=None):
"""
Loads a pickled file with optional verbosity.
Aims for compatibility between python2 and python3.
TestPickleExtentsSimple:
>>> def makedata_simple():
>>> data = np.empty((500, 2 ** 20), dtype=np.uint8) + 1
>>> return data
... | python | def load_cPkl(fpath, verbose=None, n=None):
"""
Loads a pickled file with optional verbosity.
Aims for compatibility between python2 and python3.
TestPickleExtentsSimple:
>>> def makedata_simple():
>>> data = np.empty((500, 2 ** 20), dtype=np.uint8) + 1
>>> return data
... | [
"def",
"load_cPkl",
"(",
"fpath",
",",
"verbose",
"=",
"None",
",",
"n",
"=",
"None",
")",
":",
"verbose",
"=",
"_rectify_verb_read",
"(",
"verbose",
")",
"if",
"verbose",
":",
"print",
"(",
"'[util_io] * load_cPkl(%r)'",
"%",
"(",
"util_path",
".",
"tail"... | Loads a pickled file with optional verbosity.
Aims for compatibility between python2 and python3.
TestPickleExtentsSimple:
>>> def makedata_simple():
>>> data = np.empty((500, 2 ** 20), dtype=np.uint8) + 1
>>> return data
>>> memtrack = ut.MemoryTracker()
>>> # ... | [
"Loads",
"a",
"pickled",
"file",
"with",
"optional",
"verbosity",
".",
"Aims",
"for",
"compatibility",
"between",
"python2",
"and",
"python3",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L259-L354 | train |
Erotemic/utool | utool/util_io.py | save_hdf5 | def save_hdf5(fpath, data, verbose=None, compression='lzf'):
r"""
Restricted save of data using hdf5. Can only save ndarrays and dicts of
ndarrays.
Args:
fpath (str):
data (ndarray):
compression (str):
DEFLATE/GZIP - standard
LZF - fast
SHUFF... | python | def save_hdf5(fpath, data, verbose=None, compression='lzf'):
r"""
Restricted save of data using hdf5. Can only save ndarrays and dicts of
ndarrays.
Args:
fpath (str):
data (ndarray):
compression (str):
DEFLATE/GZIP - standard
LZF - fast
SHUFF... | [
"def",
"save_hdf5",
"(",
"fpath",
",",
"data",
",",
"verbose",
"=",
"None",
",",
"compression",
"=",
"'lzf'",
")",
":",
"r",
"import",
"h5py",
"verbose",
"=",
"_rectify_verb_write",
"(",
"verbose",
")",
"if",
"verbose",
":",
"print",
"(",
"'[util_io] * sav... | r"""
Restricted save of data using hdf5. Can only save ndarrays and dicts of
ndarrays.
Args:
fpath (str):
data (ndarray):
compression (str):
DEFLATE/GZIP - standard
LZF - fast
SHUFFLE - compression ratio
FLETCHER32 - error detection
... | [
"r",
"Restricted",
"save",
"of",
"data",
"using",
"hdf5",
".",
"Can",
"only",
"save",
"ndarrays",
"and",
"dicts",
"of",
"ndarrays",
"."
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L398-L612 | train |
Erotemic/utool | utool/util_io.py | save_pytables | def save_pytables(fpath, data, verbose=False):
"""
sudo pip install numexpr
sudo pip install tables
References:
https://pytables.github.io/cookbook/py2exe_howto.html
https://gist.github.com/andrewgiessel/7515520
http://stackoverflow.com/questions/8843062/python-how-to-store-a-nu... | python | def save_pytables(fpath, data, verbose=False):
"""
sudo pip install numexpr
sudo pip install tables
References:
https://pytables.github.io/cookbook/py2exe_howto.html
https://gist.github.com/andrewgiessel/7515520
http://stackoverflow.com/questions/8843062/python-how-to-store-a-nu... | [
"def",
"save_pytables",
"(",
"fpath",
",",
"data",
",",
"verbose",
"=",
"False",
")",
":",
"import",
"tables",
"verbose",
"=",
"_rectify_verb_write",
"(",
"verbose",
")",
"if",
"verbose",
":",
"print",
"(",
"'[util_io] * save_pytables(%r, data)'",
"%",
"(",
"u... | sudo pip install numexpr
sudo pip install tables
References:
https://pytables.github.io/cookbook/py2exe_howto.html
https://gist.github.com/andrewgiessel/7515520
http://stackoverflow.com/questions/8843062/python-how-to-store-a-numpy-multidimensional-array-in-pytables
http://pytab... | [
"sudo",
"pip",
"install",
"numexpr",
"sudo",
"pip",
"install",
"tables"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_io.py#L648-L693 | train |
Erotemic/utool | utool/util_web.py | start_simple_webserver | def start_simple_webserver(domain=None, port=5832):
r"""
simple webserver that echos its arguments
Args:
domain (None): (default = None)
port (int): (default = 5832)
CommandLine:
python -m utool.util_web --exec-start_simple_webserver:0
python -m utool.util_web --exec-st... | python | def start_simple_webserver(domain=None, port=5832):
r"""
simple webserver that echos its arguments
Args:
domain (None): (default = None)
port (int): (default = 5832)
CommandLine:
python -m utool.util_web --exec-start_simple_webserver:0
python -m utool.util_web --exec-st... | [
"def",
"start_simple_webserver",
"(",
"domain",
"=",
"None",
",",
"port",
"=",
"5832",
")",
":",
"r",
"import",
"tornado",
".",
"ioloop",
"import",
"tornado",
".",
"web",
"import",
"tornado",
".",
"httpserver",
"import",
"tornado",
".",
"wsgi",
"import",
"... | r"""
simple webserver that echos its arguments
Args:
domain (None): (default = None)
port (int): (default = 5832)
CommandLine:
python -m utool.util_web --exec-start_simple_webserver:0
python -m utool.util_web --exec-start_simple_webserver:1
Example:
>>> # DISAB... | [
"r",
"simple",
"webserver",
"that",
"echos",
"its",
"arguments"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_web.py#L66-L110 | train |
Erotemic/utool | utool/util_web.py | render_html | def render_html(html_str):
"""
makes a temporary html rendering
"""
import utool as ut
from os.path import abspath
import webbrowser
try:
html_str = html_str.decode('utf8')
except Exception:
pass
html_dpath = ut.ensure_app_resource_dir('utool', 'temp_html')
fpat... | python | def render_html(html_str):
"""
makes a temporary html rendering
"""
import utool as ut
from os.path import abspath
import webbrowser
try:
html_str = html_str.decode('utf8')
except Exception:
pass
html_dpath = ut.ensure_app_resource_dir('utool', 'temp_html')
fpat... | [
"def",
"render_html",
"(",
"html_str",
")",
":",
"import",
"utool",
"as",
"ut",
"from",
"os",
".",
"path",
"import",
"abspath",
"import",
"webbrowser",
"try",
":",
"html_str",
"=",
"html_str",
".",
"decode",
"(",
"'utf8'",
")",
"except",
"Exception",
":",
... | makes a temporary html rendering | [
"makes",
"a",
"temporary",
"html",
"rendering"
] | 3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a | https://github.com/Erotemic/utool/blob/3b27e1f4e6e6fb23cd8744af7b7195b57d99e03a/utool/util_web.py#L113-L130 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.