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 listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/mongo/preprocess_data.py | get_collection_documents_generator | def get_collection_documents_generator(client, database_name, collection_name, spec, latest_n, sort_key):
"""
This is a python generator that yields tweets stored in a mongodb collection.
Tweet "created_at" field is assumed to have been stored in the format supported by MongoDB.
Inputs: - client: A py... | python | def get_collection_documents_generator(client, database_name, collection_name, spec, latest_n, sort_key):
"""
This is a python generator that yields tweets stored in a mongodb collection.
Tweet "created_at" field is assumed to have been stored in the format supported by MongoDB.
Inputs: - client: A py... | [
"def",
"get_collection_documents_generator",
"(",
"client",
",",
"database_name",
",",
"collection_name",
",",
"spec",
",",
"latest_n",
",",
"sort_key",
")",
":",
"mongo_database",
"=",
"client",
"[",
"database_name",
"]",
"collection",
"=",
"mongo_database",
"[",
... | This is a python generator that yields tweets stored in a mongodb collection.
Tweet "created_at" field is assumed to have been stored in the format supported by MongoDB.
Inputs: - client: A pymongo MongoClient object.
- database_name: The name of a Mongo database as a string.
- collect... | [
"This",
"is",
"a",
"python",
"generator",
"that",
"yields",
"tweets",
"stored",
"in",
"a",
"mongodb",
"collection",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/mongo/preprocess_data.py#L117-L146 | train | 57,600 |
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/mongo/preprocess_data.py | extract_connected_components | def extract_connected_components(graph, connectivity_type, node_to_id):
"""
Extract the largest connected component from a graph.
Inputs: - graph: An adjacency matrix in scipy sparse matrix format.
- connectivity_type: A string that can be either: "strong" or "weak".
- node_to_id... | python | def extract_connected_components(graph, connectivity_type, node_to_id):
"""
Extract the largest connected component from a graph.
Inputs: - graph: An adjacency matrix in scipy sparse matrix format.
- connectivity_type: A string that can be either: "strong" or "weak".
- node_to_id... | [
"def",
"extract_connected_components",
"(",
"graph",
",",
"connectivity_type",
",",
"node_to_id",
")",
":",
"# Get a networkx graph.",
"nx_graph",
"=",
"nx",
".",
"from_scipy_sparse_matrix",
"(",
"graph",
",",
"create_using",
"=",
"nx",
".",
"DiGraph",
"(",
")",
"... | Extract the largest connected component from a graph.
Inputs: - graph: An adjacency matrix in scipy sparse matrix format.
- connectivity_type: A string that can be either: "strong" or "weak".
- node_to_id: A map from graph node id to Twitter id, in python dictionary format.
Outputs:... | [
"Extract",
"the",
"largest",
"connected",
"component",
"from",
"a",
"graph",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/mongo/preprocess_data.py#L768-L808 | train | 57,601 |
agrc/agrc.python | agrc/messaging.py | Emailer.sendEmail | def sendEmail(self, subject, body, toAddress=False):
"""
sends an email using the agrcpythonemailer@gmail.com account
"""
if not toAddress:
toAddress = self.toAddress
toAddress = toAddress.split(';')
message = MIMEText(body)
message['Subject'] = subj... | python | def sendEmail(self, subject, body, toAddress=False):
"""
sends an email using the agrcpythonemailer@gmail.com account
"""
if not toAddress:
toAddress = self.toAddress
toAddress = toAddress.split(';')
message = MIMEText(body)
message['Subject'] = subj... | [
"def",
"sendEmail",
"(",
"self",
",",
"subject",
",",
"body",
",",
"toAddress",
"=",
"False",
")",
":",
"if",
"not",
"toAddress",
":",
"toAddress",
"=",
"self",
".",
"toAddress",
"toAddress",
"=",
"toAddress",
".",
"split",
"(",
"';'",
")",
"message",
... | sends an email using the agrcpythonemailer@gmail.com account | [
"sends",
"an",
"email",
"using",
"the",
"agrcpythonemailer"
] | be427e919bd4cdd6f19524b7f7fe18882429c25b | https://github.com/agrc/agrc.python/blob/be427e919bd4cdd6f19524b7f7fe18882429c25b/agrc/messaging.py#L25-L49 | train | 57,602 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode._get_completions | def _get_completions(self):
"""Return a list of possible completions for the string ending at the point.
Also set begidx and endidx in the process."""
completions = []
self.begidx = self.l_buffer.point
self.endidx = self.l_buffer.point
buf=self.l_buffer.line_buffer
... | python | def _get_completions(self):
"""Return a list of possible completions for the string ending at the point.
Also set begidx and endidx in the process."""
completions = []
self.begidx = self.l_buffer.point
self.endidx = self.l_buffer.point
buf=self.l_buffer.line_buffer
... | [
"def",
"_get_completions",
"(",
"self",
")",
":",
"completions",
"=",
"[",
"]",
"self",
".",
"begidx",
"=",
"self",
".",
"l_buffer",
".",
"point",
"self",
".",
"endidx",
"=",
"self",
".",
"l_buffer",
".",
"point",
"buf",
"=",
"self",
".",
"l_buffer",
... | Return a list of possible completions for the string ending at the point.
Also set begidx and endidx in the process. | [
"Return",
"a",
"list",
"of",
"possible",
"completions",
"for",
"the",
"string",
"ending",
"at",
"the",
"point",
".",
"Also",
"set",
"begidx",
"and",
"endidx",
"in",
"the",
"process",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L179-L228 | train | 57,603 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.complete | def complete(self, e): # (TAB)
u"""Attempt to perform completion on the text before point. The
actual completion performed is application-specific. The default is
filename completion."""
completions = self._get_completions()
if completions:
cprefix = commonprefi... | python | def complete(self, e): # (TAB)
u"""Attempt to perform completion on the text before point. The
actual completion performed is application-specific. The default is
filename completion."""
completions = self._get_completions()
if completions:
cprefix = commonprefi... | [
"def",
"complete",
"(",
"self",
",",
"e",
")",
":",
"# (TAB)\r",
"completions",
"=",
"self",
".",
"_get_completions",
"(",
")",
"if",
"completions",
":",
"cprefix",
"=",
"commonprefix",
"(",
"completions",
")",
"if",
"len",
"(",
"cprefix",
")",
">",
"0",... | u"""Attempt to perform completion on the text before point. The
actual completion performed is application-specific. The default is
filename completion. | [
"u",
"Attempt",
"to",
"perform",
"completion",
"on",
"the",
"text",
"before",
"point",
".",
"The",
"actual",
"completion",
"performed",
"is",
"application",
"-",
"specific",
".",
"The",
"default",
"is",
"filename",
"completion",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L251-L270 | train | 57,604 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.possible_completions | def possible_completions(self, e): # (M-?)
u"""List the possible completions of the text before point. """
completions = self._get_completions()
self._display_completions(completions)
self.finalize() | python | def possible_completions(self, e): # (M-?)
u"""List the possible completions of the text before point. """
completions = self._get_completions()
self._display_completions(completions)
self.finalize() | [
"def",
"possible_completions",
"(",
"self",
",",
"e",
")",
":",
"# (M-?)\r",
"completions",
"=",
"self",
".",
"_get_completions",
"(",
")",
"self",
".",
"_display_completions",
"(",
"completions",
")",
"self",
".",
"finalize",
"(",
")"
] | u"""List the possible completions of the text before point. | [
"u",
"List",
"the",
"possible",
"completions",
"of",
"the",
"text",
"before",
"point",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L272-L276 | train | 57,605 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.insert_completions | def insert_completions(self, e): # (M-*)
u"""Insert all completions of the text before point that would have
been generated by possible-completions."""
completions = self._get_completions()
b = self.begidx
e = self.endidx
for comp in completions:
rep = ... | python | def insert_completions(self, e): # (M-*)
u"""Insert all completions of the text before point that would have
been generated by possible-completions."""
completions = self._get_completions()
b = self.begidx
e = self.endidx
for comp in completions:
rep = ... | [
"def",
"insert_completions",
"(",
"self",
",",
"e",
")",
":",
"# (M-*)\r",
"completions",
"=",
"self",
".",
"_get_completions",
"(",
")",
"b",
"=",
"self",
".",
"begidx",
"e",
"=",
"self",
".",
"endidx",
"for",
"comp",
"in",
"completions",
":",
"rep",
... | u"""Insert all completions of the text before point that would have
been generated by possible-completions. | [
"u",
"Insert",
"all",
"completions",
"of",
"the",
"text",
"before",
"point",
"that",
"would",
"have",
"been",
"generated",
"by",
"possible",
"-",
"completions",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L278-L291 | train | 57,606 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.insert_text | def insert_text(self, string):
u"""Insert text into the command line."""
self.l_buffer.insert_text(string, self.argument_reset)
self.finalize() | python | def insert_text(self, string):
u"""Insert text into the command line."""
self.l_buffer.insert_text(string, self.argument_reset)
self.finalize() | [
"def",
"insert_text",
"(",
"self",
",",
"string",
")",
":",
"self",
".",
"l_buffer",
".",
"insert_text",
"(",
"string",
",",
"self",
".",
"argument_reset",
")",
"self",
".",
"finalize",
"(",
")"
] | u"""Insert text into the command line. | [
"u",
"Insert",
"text",
"into",
"the",
"command",
"line",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L308-L311 | train | 57,607 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.delete_char | def delete_char(self, e): # (C-d)
u"""Delete the character at point. If point is at the beginning of
the line, there are no characters in the line, and the last
character typed was not bound to delete-char, then return EOF."""
self.l_buffer.delete_char(self.argument_reset)
s... | python | def delete_char(self, e): # (C-d)
u"""Delete the character at point. If point is at the beginning of
the line, there are no characters in the line, and the last
character typed was not bound to delete-char, then return EOF."""
self.l_buffer.delete_char(self.argument_reset)
s... | [
"def",
"delete_char",
"(",
"self",
",",
"e",
")",
":",
"# (C-d)\r",
"self",
".",
"l_buffer",
".",
"delete_char",
"(",
"self",
".",
"argument_reset",
")",
"self",
".",
"finalize",
"(",
")"
] | u"""Delete the character at point. If point is at the beginning of
the line, there are no characters in the line, and the last
character typed was not bound to delete-char, then return EOF. | [
"u",
"Delete",
"the",
"character",
"at",
"point",
".",
"If",
"point",
"is",
"at",
"the",
"beginning",
"of",
"the",
"line",
"there",
"are",
"no",
"characters",
"in",
"the",
"line",
"and",
"the",
"last",
"character",
"typed",
"was",
"not",
"bound",
"to",
... | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L443-L448 | train | 57,608 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.self_insert | def self_insert(self, e): # (a, b, A, 1, !, ...)
u"""Insert yourself. """
if e.char and ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys.
self.insert_text(e.char)
self.finalize() | python | def self_insert(self, e): # (a, b, A, 1, !, ...)
u"""Insert yourself. """
if e.char and ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys.
self.insert_text(e.char)
self.finalize() | [
"def",
"self_insert",
"(",
"self",
",",
"e",
")",
":",
"# (a, b, A, 1, !, ...)\r",
"if",
"e",
".",
"char",
"and",
"ord",
"(",
"e",
".",
"char",
")",
"!=",
"0",
":",
"#don't insert null character in buffer, can happen with dead keys.\r",
"self",
".",
"insert_text",... | u"""Insert yourself. | [
"u",
"Insert",
"yourself",
"."
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L473-L477 | train | 57,609 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.paste | def paste(self,e):
u"""Paste windows clipboard.
Assume single line strip other lines and end of line markers and trailing spaces""" #(Control-v)
if self.enable_win32_clipboard:
txt=clipboard.get_clipboard_text_and_convert(False)
txt=txt.split("\n")[0].strip("... | python | def paste(self,e):
u"""Paste windows clipboard.
Assume single line strip other lines and end of line markers and trailing spaces""" #(Control-v)
if self.enable_win32_clipboard:
txt=clipboard.get_clipboard_text_and_convert(False)
txt=txt.split("\n")[0].strip("... | [
"def",
"paste",
"(",
"self",
",",
"e",
")",
":",
"#(Control-v)\r",
"if",
"self",
".",
"enable_win32_clipboard",
":",
"txt",
"=",
"clipboard",
".",
"get_clipboard_text_and_convert",
"(",
"False",
")",
"txt",
"=",
"txt",
".",
"split",
"(",
"\"\\n\"",
")",
"[... | u"""Paste windows clipboard.
Assume single line strip other lines and end of line markers and trailing spaces | [
"u",
"Paste",
"windows",
"clipboard",
".",
"Assume",
"single",
"line",
"strip",
"other",
"lines",
"and",
"end",
"of",
"line",
"markers",
"and",
"trailing",
"spaces"
] | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L482-L490 | train | 57,610 |
SeattleTestbed/seash | pyreadline/modes/basemode.py | BaseMode.dump_functions | def dump_functions(self, e): # ()
u"""Print all of the functions and their key bindings to the Readline
output stream. If a numeric argument is supplied, the output is
formatted in such a way that it can be made part of an inputrc
file. This command is unbound by default."""
... | python | def dump_functions(self, e): # ()
u"""Print all of the functions and their key bindings to the Readline
output stream. If a numeric argument is supplied, the output is
formatted in such a way that it can be made part of an inputrc
file. This command is unbound by default."""
... | [
"def",
"dump_functions",
"(",
"self",
",",
"e",
")",
":",
"# ()\r",
"print",
"txt",
"=",
"\"\\n\"",
".",
"join",
"(",
"self",
".",
"rl_settings_to_string",
"(",
")",
")",
"print",
"txt",
"self",
".",
"_print_prompt",
"(",
")",
"self",
".",
"finalize",
... | u"""Print all of the functions and their key bindings to the Readline
output stream. If a numeric argument is supplied, the output is
formatted in such a way that it can be made part of an inputrc
file. This command is unbound by default. | [
"u",
"Print",
"all",
"of",
"the",
"functions",
"and",
"their",
"key",
"bindings",
"to",
"the",
"Readline",
"output",
"stream",
".",
"If",
"a",
"numeric",
"argument",
"is",
"supplied",
"the",
"output",
"is",
"formatted",
"in",
"such",
"a",
"way",
"that",
... | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/pyreadline/modes/basemode.py#L540-L549 | train | 57,611 |
kmedian/ctmc | ctmc/ctmc_class.py | Ctmc.fit | def fit(self, X, y=None):
"""Calls the ctmc.ctmc function
Parameters
----------
X : list of lists
(see ctmc function 'data')
y
not used, present for API consistence purpose.
"""
self.transmat, self.genmat, self.transcount, self.statetime ... | python | def fit(self, X, y=None):
"""Calls the ctmc.ctmc function
Parameters
----------
X : list of lists
(see ctmc function 'data')
y
not used, present for API consistence purpose.
"""
self.transmat, self.genmat, self.transcount, self.statetime ... | [
"def",
"fit",
"(",
"self",
",",
"X",
",",
"y",
"=",
"None",
")",
":",
"self",
".",
"transmat",
",",
"self",
".",
"genmat",
",",
"self",
".",
"transcount",
",",
"self",
".",
"statetime",
"=",
"ctmc",
"(",
"X",
",",
"self",
".",
"numstates",
",",
... | Calls the ctmc.ctmc function
Parameters
----------
X : list of lists
(see ctmc function 'data')
y
not used, present for API consistence purpose. | [
"Calls",
"the",
"ctmc",
".",
"ctmc",
"function"
] | e30747f797ce777fd2aaa1b7ee5a77e91d7db5e4 | https://github.com/kmedian/ctmc/blob/e30747f797ce777fd2aaa1b7ee5a77e91d7db5e4/ctmc/ctmc_class.py#L17-L30 | train | 57,612 |
timothydmorton/orbitutils | orbitutils/populations.py | TripleOrbitPopulation.RV_1 | def RV_1(self):
"""Instantaneous RV of star 1 with respect to system center-of-mass
"""
return self.orbpop_long.RV * (self.orbpop_long.M2 / (self.orbpop_long.M1 + self.orbpop_long.M2)) | python | def RV_1(self):
"""Instantaneous RV of star 1 with respect to system center-of-mass
"""
return self.orbpop_long.RV * (self.orbpop_long.M2 / (self.orbpop_long.M1 + self.orbpop_long.M2)) | [
"def",
"RV_1",
"(",
"self",
")",
":",
"return",
"self",
".",
"orbpop_long",
".",
"RV",
"*",
"(",
"self",
".",
"orbpop_long",
".",
"M2",
"/",
"(",
"self",
".",
"orbpop_long",
".",
"M1",
"+",
"self",
".",
"orbpop_long",
".",
"M2",
")",
")"
] | Instantaneous RV of star 1 with respect to system center-of-mass | [
"Instantaneous",
"RV",
"of",
"star",
"1",
"with",
"respect",
"to",
"system",
"center",
"-",
"of",
"-",
"mass"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L92-L95 | train | 57,613 |
timothydmorton/orbitutils | orbitutils/populations.py | TripleOrbitPopulation.RV_2 | def RV_2(self):
"""Instantaneous RV of star 2 with respect to system center-of-mass
"""
return -self.orbpop_long.RV * (self.orbpop_long.M1 /
(self.orbpop_long.M1 + self.orbpop_long.M2)) +\
self.orbpop_short.RV_com1 | python | def RV_2(self):
"""Instantaneous RV of star 2 with respect to system center-of-mass
"""
return -self.orbpop_long.RV * (self.orbpop_long.M1 /
(self.orbpop_long.M1 + self.orbpop_long.M2)) +\
self.orbpop_short.RV_com1 | [
"def",
"RV_2",
"(",
"self",
")",
":",
"return",
"-",
"self",
".",
"orbpop_long",
".",
"RV",
"*",
"(",
"self",
".",
"orbpop_long",
".",
"M1",
"/",
"(",
"self",
".",
"orbpop_long",
".",
"M1",
"+",
"self",
".",
"orbpop_long",
".",
"M2",
")",
")",
"+... | Instantaneous RV of star 2 with respect to system center-of-mass | [
"Instantaneous",
"RV",
"of",
"star",
"2",
"with",
"respect",
"to",
"system",
"center",
"-",
"of",
"-",
"mass"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L98-L103 | train | 57,614 |
timothydmorton/orbitutils | orbitutils/populations.py | TripleOrbitPopulation.RV_3 | def RV_3(self):
"""Instantaneous RV of star 3 with respect to system center-of-mass
"""
return -self.orbpop_long.RV * (self.orbpop_long.M1 / (self.orbpop_long.M1 + self.orbpop_long.M2)) +\
self.orbpop_short.RV_com2 | python | def RV_3(self):
"""Instantaneous RV of star 3 with respect to system center-of-mass
"""
return -self.orbpop_long.RV * (self.orbpop_long.M1 / (self.orbpop_long.M1 + self.orbpop_long.M2)) +\
self.orbpop_short.RV_com2 | [
"def",
"RV_3",
"(",
"self",
")",
":",
"return",
"-",
"self",
".",
"orbpop_long",
".",
"RV",
"*",
"(",
"self",
".",
"orbpop_long",
".",
"M1",
"/",
"(",
"self",
".",
"orbpop_long",
".",
"M1",
"+",
"self",
".",
"orbpop_long",
".",
"M2",
")",
")",
"+... | Instantaneous RV of star 3 with respect to system center-of-mass | [
"Instantaneous",
"RV",
"of",
"star",
"3",
"with",
"respect",
"to",
"system",
"center",
"-",
"of",
"-",
"mass"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L106-L110 | train | 57,615 |
timothydmorton/orbitutils | orbitutils/populations.py | TripleOrbitPopulation.save_hdf | def save_hdf(self,filename,path=''):
"""Save to .h5 file.
"""
self.orbpop_long.save_hdf(filename,'{}/long'.format(path))
self.orbpop_short.save_hdf(filename,'{}/short'.format(path)) | python | def save_hdf(self,filename,path=''):
"""Save to .h5 file.
"""
self.orbpop_long.save_hdf(filename,'{}/long'.format(path))
self.orbpop_short.save_hdf(filename,'{}/short'.format(path)) | [
"def",
"save_hdf",
"(",
"self",
",",
"filename",
",",
"path",
"=",
"''",
")",
":",
"self",
".",
"orbpop_long",
".",
"save_hdf",
"(",
"filename",
",",
"'{}/long'",
".",
"format",
"(",
"path",
")",
")",
"self",
".",
"orbpop_short",
".",
"save_hdf",
"(",
... | Save to .h5 file. | [
"Save",
"to",
".",
"h5",
"file",
"."
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L140-L144 | train | 57,616 |
timothydmorton/orbitutils | orbitutils/populations.py | OrbitPopulation.Rsky | def Rsky(self):
"""Projected sky separation of stars
"""
return np.sqrt(self.position.x**2 + self.position.y**2) | python | def Rsky(self):
"""Projected sky separation of stars
"""
return np.sqrt(self.position.x**2 + self.position.y**2) | [
"def",
"Rsky",
"(",
"self",
")",
":",
"return",
"np",
".",
"sqrt",
"(",
"self",
".",
"position",
".",
"x",
"**",
"2",
"+",
"self",
".",
"position",
".",
"y",
"**",
"2",
")"
] | Projected sky separation of stars | [
"Projected",
"sky",
"separation",
"of",
"stars"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L281-L284 | train | 57,617 |
timothydmorton/orbitutils | orbitutils/populations.py | OrbitPopulation.RV_com1 | def RV_com1(self):
"""RVs of star 1 relative to center-of-mass
"""
return self.RV * (self.M2 / (self.M1 + self.M2)) | python | def RV_com1(self):
"""RVs of star 1 relative to center-of-mass
"""
return self.RV * (self.M2 / (self.M1 + self.M2)) | [
"def",
"RV_com1",
"(",
"self",
")",
":",
"return",
"self",
".",
"RV",
"*",
"(",
"self",
".",
"M2",
"/",
"(",
"self",
".",
"M1",
"+",
"self",
".",
"M2",
")",
")"
] | RVs of star 1 relative to center-of-mass | [
"RVs",
"of",
"star",
"1",
"relative",
"to",
"center",
"-",
"of",
"-",
"mass"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L293-L296 | train | 57,618 |
timothydmorton/orbitutils | orbitutils/populations.py | OrbitPopulation.RV_com2 | def RV_com2(self):
"""RVs of star 2 relative to center-of-mass
"""
return -self.RV * (self.M1 / (self.M1 + self.M2)) | python | def RV_com2(self):
"""RVs of star 2 relative to center-of-mass
"""
return -self.RV * (self.M1 / (self.M1 + self.M2)) | [
"def",
"RV_com2",
"(",
"self",
")",
":",
"return",
"-",
"self",
".",
"RV",
"*",
"(",
"self",
".",
"M1",
"/",
"(",
"self",
".",
"M1",
"+",
"self",
".",
"M2",
")",
")"
] | RVs of star 2 relative to center-of-mass | [
"RVs",
"of",
"star",
"2",
"relative",
"to",
"center",
"-",
"of",
"-",
"mass"
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L299-L302 | train | 57,619 |
timothydmorton/orbitutils | orbitutils/populations.py | OrbitPopulation.save_hdf | def save_hdf(self,filename,path=''):
"""Saves all relevant data to .h5 file; so state can be restored.
"""
self.dataframe.to_hdf(filename,'{}/df'.format(path)) | python | def save_hdf(self,filename,path=''):
"""Saves all relevant data to .h5 file; so state can be restored.
"""
self.dataframe.to_hdf(filename,'{}/df'.format(path)) | [
"def",
"save_hdf",
"(",
"self",
",",
"filename",
",",
"path",
"=",
"''",
")",
":",
"self",
".",
"dataframe",
".",
"to_hdf",
"(",
"filename",
",",
"'{}/df'",
".",
"format",
"(",
"path",
")",
")"
] | Saves all relevant data to .h5 file; so state can be restored. | [
"Saves",
"all",
"relevant",
"data",
"to",
".",
"h5",
"file",
";",
"so",
"state",
"can",
"be",
"restored",
"."
] | 949c6b901e519458d80b8d7427916c0698e4013e | https://github.com/timothydmorton/orbitutils/blob/949c6b901e519458d80b8d7427916c0698e4013e/orbitutils/populations.py#L387-L390 | train | 57,620 |
clinicedc/edc-permissions | edc_permissions/pii_updater.py | PiiUpdater.add_pii_permissions | def add_pii_permissions(self, group, view_only=None):
"""Adds PII model permissions.
"""
pii_model_names = [m.split(".")[1] for m in self.pii_models]
if view_only:
permissions = Permission.objects.filter(
(Q(codename__startswith="view") | Q(codename__startswit... | python | def add_pii_permissions(self, group, view_only=None):
"""Adds PII model permissions.
"""
pii_model_names = [m.split(".")[1] for m in self.pii_models]
if view_only:
permissions = Permission.objects.filter(
(Q(codename__startswith="view") | Q(codename__startswit... | [
"def",
"add_pii_permissions",
"(",
"self",
",",
"group",
",",
"view_only",
"=",
"None",
")",
":",
"pii_model_names",
"=",
"[",
"m",
".",
"split",
"(",
"\".\"",
")",
"[",
"1",
"]",
"for",
"m",
"in",
"self",
".",
"pii_models",
"]",
"if",
"view_only",
"... | Adds PII model permissions. | [
"Adds",
"PII",
"model",
"permissions",
"."
] | d1aee39a8ddaf4b7741d9306139ddd03625d4e1a | https://github.com/clinicedc/edc-permissions/blob/d1aee39a8ddaf4b7741d9306139ddd03625d4e1a/edc_permissions/pii_updater.py#L39-L77 | train | 57,621 |
helixyte/everest | everest/attributes.py | get_attribute_cardinality | def get_attribute_cardinality(attribute):
"""
Returns the cardinality of the given resource attribute.
:returns: One of the constants defined in
:class:`evererst.constants.CARDINALITY_CONSTANTS`.
:raises ValueError: If the given attribute is not a relation attribute
(i.e., if it is a termin... | python | def get_attribute_cardinality(attribute):
"""
Returns the cardinality of the given resource attribute.
:returns: One of the constants defined in
:class:`evererst.constants.CARDINALITY_CONSTANTS`.
:raises ValueError: If the given attribute is not a relation attribute
(i.e., if it is a termin... | [
"def",
"get_attribute_cardinality",
"(",
"attribute",
")",
":",
"if",
"attribute",
".",
"kind",
"==",
"RESOURCE_ATTRIBUTE_KINDS",
".",
"MEMBER",
":",
"card",
"=",
"CARDINALITY_CONSTANTS",
".",
"ONE",
"elif",
"attribute",
".",
"kind",
"==",
"RESOURCE_ATTRIBUTE_KINDS"... | Returns the cardinality of the given resource attribute.
:returns: One of the constants defined in
:class:`evererst.constants.CARDINALITY_CONSTANTS`.
:raises ValueError: If the given attribute is not a relation attribute
(i.e., if it is a terminal attribute). | [
"Returns",
"the",
"cardinality",
"of",
"the",
"given",
"resource",
"attribute",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/attributes.py#L41-L57 | train | 57,622 |
wdbm/scalar | scalar/__init__.py | setup | def setup(path_config="~/.config/scalar/config.yaml", configuration_name=None):
"""
Load a configuration from a default or specified configuration file, accessing a default or
specified configuration name.
"""
global config
global client
global token
global room
# config file
pat... | python | def setup(path_config="~/.config/scalar/config.yaml", configuration_name=None):
"""
Load a configuration from a default or specified configuration file, accessing a default or
specified configuration name.
"""
global config
global client
global token
global room
# config file
pat... | [
"def",
"setup",
"(",
"path_config",
"=",
"\"~/.config/scalar/config.yaml\"",
",",
"configuration_name",
"=",
"None",
")",
":",
"global",
"config",
"global",
"client",
"global",
"token",
"global",
"room",
"# config file",
"path_config",
"=",
"Path",
"(",
"path_config... | Load a configuration from a default or specified configuration file, accessing a default or
specified configuration name. | [
"Load",
"a",
"configuration",
"from",
"a",
"default",
"or",
"specified",
"configuration",
"file",
"accessing",
"a",
"default",
"or",
"specified",
"configuration",
"name",
"."
] | c4d70e778a6151b95aad721ca2d3a8bfa38126da | https://github.com/wdbm/scalar/blob/c4d70e778a6151b95aad721ca2d3a8bfa38126da/scalar/__init__.py#L71-L101 | train | 57,623 |
ViiSiX/FlaskRedislite | flask_redislite.py | worker_wrapper | def worker_wrapper(worker_instance, pid_path):
"""
A wrapper to start RQ worker as a new process.
:param worker_instance: RQ's worker instance
:param pid_path: A file to check if the worker
is running or not
"""
def exit_handler(*args):
"""
Remove pid file on exit
... | python | def worker_wrapper(worker_instance, pid_path):
"""
A wrapper to start RQ worker as a new process.
:param worker_instance: RQ's worker instance
:param pid_path: A file to check if the worker
is running or not
"""
def exit_handler(*args):
"""
Remove pid file on exit
... | [
"def",
"worker_wrapper",
"(",
"worker_instance",
",",
"pid_path",
")",
":",
"def",
"exit_handler",
"(",
"*",
"args",
")",
":",
"\"\"\"\n Remove pid file on exit\n \"\"\"",
"if",
"len",
"(",
"args",
")",
">",
"0",
":",
"print",
"(",
"\"Exit py signal ... | A wrapper to start RQ worker as a new process.
:param worker_instance: RQ's worker instance
:param pid_path: A file to check if the worker
is running or not | [
"A",
"wrapper",
"to",
"start",
"RQ",
"worker",
"as",
"a",
"new",
"process",
"."
] | 01bc9fbbeb415aac621c7a9cc091a666e728e651 | https://github.com/ViiSiX/FlaskRedislite/blob/01bc9fbbeb415aac621c7a9cc091a666e728e651/flask_redislite.py#L29-L52 | train | 57,624 |
ViiSiX/FlaskRedislite | flask_redislite.py | FlaskRedis.collection | def collection(self):
"""Return the redis-collection instance."""
if not self.include_collections:
return None
ctx = stack.top
if ctx is not None:
if not hasattr(ctx, 'redislite_collection'):
ctx.redislite_collection = Collection(redis=self.connect... | python | def collection(self):
"""Return the redis-collection instance."""
if not self.include_collections:
return None
ctx = stack.top
if ctx is not None:
if not hasattr(ctx, 'redislite_collection'):
ctx.redislite_collection = Collection(redis=self.connect... | [
"def",
"collection",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"include_collections",
":",
"return",
"None",
"ctx",
"=",
"stack",
".",
"top",
"if",
"ctx",
"is",
"not",
"None",
":",
"if",
"not",
"hasattr",
"(",
"ctx",
",",
"'redislite_collection'",... | Return the redis-collection instance. | [
"Return",
"the",
"redis",
"-",
"collection",
"instance",
"."
] | 01bc9fbbeb415aac621c7a9cc091a666e728e651 | https://github.com/ViiSiX/FlaskRedislite/blob/01bc9fbbeb415aac621c7a9cc091a666e728e651/flask_redislite.py#L150-L158 | train | 57,625 |
ViiSiX/FlaskRedislite | flask_redislite.py | FlaskRedis.queue | def queue(self):
"""The queue property. Return rq.Queue instance."""
if not self.include_rq:
return None
ctx = stack.top
if ctx is not None:
if not hasattr(ctx, 'redislite_queue'):
ctx.redislite_queue = {}
for queue_name in self.qu... | python | def queue(self):
"""The queue property. Return rq.Queue instance."""
if not self.include_rq:
return None
ctx = stack.top
if ctx is not None:
if not hasattr(ctx, 'redislite_queue'):
ctx.redislite_queue = {}
for queue_name in self.qu... | [
"def",
"queue",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"include_rq",
":",
"return",
"None",
"ctx",
"=",
"stack",
".",
"top",
"if",
"ctx",
"is",
"not",
"None",
":",
"if",
"not",
"hasattr",
"(",
"ctx",
",",
"'redislite_queue'",
")",
":",
"c... | The queue property. Return rq.Queue instance. | [
"The",
"queue",
"property",
".",
"Return",
"rq",
".",
"Queue",
"instance",
"."
] | 01bc9fbbeb415aac621c7a9cc091a666e728e651 | https://github.com/ViiSiX/FlaskRedislite/blob/01bc9fbbeb415aac621c7a9cc091a666e728e651/flask_redislite.py#L161-L174 | train | 57,626 |
ViiSiX/FlaskRedislite | flask_redislite.py | FlaskRedis.start_worker | def start_worker(self):
"""Trigger new process as a RQ worker."""
if not self.include_rq:
return None
worker = Worker(queues=self.queues,
connection=self.connection)
worker_pid_path = current_app.config.get(
"{}_WORKER_PID".format(self.con... | python | def start_worker(self):
"""Trigger new process as a RQ worker."""
if not self.include_rq:
return None
worker = Worker(queues=self.queues,
connection=self.connection)
worker_pid_path = current_app.config.get(
"{}_WORKER_PID".format(self.con... | [
"def",
"start_worker",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"include_rq",
":",
"return",
"None",
"worker",
"=",
"Worker",
"(",
"queues",
"=",
"self",
".",
"queues",
",",
"connection",
"=",
"self",
".",
"connection",
")",
"worker_pid_path",
"=... | Trigger new process as a RQ worker. | [
"Trigger",
"new",
"process",
"as",
"a",
"RQ",
"worker",
"."
] | 01bc9fbbeb415aac621c7a9cc091a666e728e651 | https://github.com/ViiSiX/FlaskRedislite/blob/01bc9fbbeb415aac621c7a9cc091a666e728e651/flask_redislite.py#L176-L208 | train | 57,627 |
liminspace/dju-image | dju_image/image.py | image_save_buffer_fix | def image_save_buffer_fix(maxblock=1048576):
"""
Contextmanager that change MAXBLOCK in ImageFile.
"""
before = ImageFile.MAXBLOCK
ImageFile.MAXBLOCK = maxblock
try:
yield
finally:
ImageFile.MAXBLOCK = before | python | def image_save_buffer_fix(maxblock=1048576):
"""
Contextmanager that change MAXBLOCK in ImageFile.
"""
before = ImageFile.MAXBLOCK
ImageFile.MAXBLOCK = maxblock
try:
yield
finally:
ImageFile.MAXBLOCK = before | [
"def",
"image_save_buffer_fix",
"(",
"maxblock",
"=",
"1048576",
")",
":",
"before",
"=",
"ImageFile",
".",
"MAXBLOCK",
"ImageFile",
".",
"MAXBLOCK",
"=",
"maxblock",
"try",
":",
"yield",
"finally",
":",
"ImageFile",
".",
"MAXBLOCK",
"=",
"before"
] | Contextmanager that change MAXBLOCK in ImageFile. | [
"Contextmanager",
"that",
"change",
"MAXBLOCK",
"in",
"ImageFile",
"."
] | b06eb3be2069cd6cb52cf1e26c2c761883142d4e | https://github.com/liminspace/dju-image/blob/b06eb3be2069cd6cb52cf1e26c2c761883142d4e/dju_image/image.py#L62-L71 | train | 57,628 |
ponty/confduino | confduino/examples/upgrademany.py | upgrade_many | def upgrade_many(upgrade=True, create_examples_all=True):
"""upgrade many libs.
source: http://arduino.cc/playground/Main/LibraryList
you can set your arduino path if it is not default
os.environ['ARDUINO_HOME'] = '/home/...'
"""
urls = set()
def inst(url):
print('upgrading %s' %... | python | def upgrade_many(upgrade=True, create_examples_all=True):
"""upgrade many libs.
source: http://arduino.cc/playground/Main/LibraryList
you can set your arduino path if it is not default
os.environ['ARDUINO_HOME'] = '/home/...'
"""
urls = set()
def inst(url):
print('upgrading %s' %... | [
"def",
"upgrade_many",
"(",
"upgrade",
"=",
"True",
",",
"create_examples_all",
"=",
"True",
")",
":",
"urls",
"=",
"set",
"(",
")",
"def",
"inst",
"(",
"url",
")",
":",
"print",
"(",
"'upgrading %s'",
"%",
"url",
")",
"assert",
"url",
"not",
"in",
"... | upgrade many libs.
source: http://arduino.cc/playground/Main/LibraryList
you can set your arduino path if it is not default
os.environ['ARDUINO_HOME'] = '/home/...' | [
"upgrade",
"many",
"libs",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/examples/upgrademany.py#L7-L180 | train | 57,629 |
erikvw/django-collect-offline-files | django_collect_offline_files/confirmation.py | Confirmation.confirm | def confirm(self, batch_id=None, filename=None):
"""Flags the batch as confirmed by updating
confirmation_datetime on the history model for this batch.
"""
if batch_id or filename:
export_history = self.history_model.objects.using(self.using).filter(
Q(batch_i... | python | def confirm(self, batch_id=None, filename=None):
"""Flags the batch as confirmed by updating
confirmation_datetime on the history model for this batch.
"""
if batch_id or filename:
export_history = self.history_model.objects.using(self.using).filter(
Q(batch_i... | [
"def",
"confirm",
"(",
"self",
",",
"batch_id",
"=",
"None",
",",
"filename",
"=",
"None",
")",
":",
"if",
"batch_id",
"or",
"filename",
":",
"export_history",
"=",
"self",
".",
"history_model",
".",
"objects",
".",
"using",
"(",
"self",
".",
"using",
... | Flags the batch as confirmed by updating
confirmation_datetime on the history model for this batch. | [
"Flags",
"the",
"batch",
"as",
"confirmed",
"by",
"updating",
"confirmation_datetime",
"on",
"the",
"history",
"model",
"for",
"this",
"batch",
"."
] | 78f61c823ea3926eb88206b019b5dca3c36017da | https://github.com/erikvw/django-collect-offline-files/blob/78f61c823ea3926eb88206b019b5dca3c36017da/django_collect_offline_files/confirmation.py#L24-L48 | train | 57,630 |
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/clean_text.py | clean_single_word | def clean_single_word(word, lemmatizing="wordnet"):
"""
Performs stemming or lemmatizing on a single word.
If we are to search for a word in a clean bag-of-words, we need to search it after the same kind of preprocessing.
Inputs: - word: A string containing the source word.
- lemmatizing: ... | python | def clean_single_word(word, lemmatizing="wordnet"):
"""
Performs stemming or lemmatizing on a single word.
If we are to search for a word in a clean bag-of-words, we need to search it after the same kind of preprocessing.
Inputs: - word: A string containing the source word.
- lemmatizing: ... | [
"def",
"clean_single_word",
"(",
"word",
",",
"lemmatizing",
"=",
"\"wordnet\"",
")",
":",
"if",
"lemmatizing",
"==",
"\"porter\"",
":",
"porter",
"=",
"PorterStemmer",
"(",
")",
"lemma",
"=",
"porter",
".",
"stem",
"(",
"word",
")",
"elif",
"lemmatizing",
... | Performs stemming or lemmatizing on a single word.
If we are to search for a word in a clean bag-of-words, we need to search it after the same kind of preprocessing.
Inputs: - word: A string containing the source word.
- lemmatizing: A string containing one of the following: "porter", "snowball" o... | [
"Performs",
"stemming",
"or",
"lemmatizing",
"on",
"a",
"single",
"word",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/clean_text.py#L72-L96 | train | 57,631 |
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/clean_text.py | clean_document | def clean_document(document,
sent_tokenize, _treebank_word_tokenize,
tagger,
lemmatizer,
lemmatize,
stopset,
first_cap_re, all_cap_re,
digits_punctuation_whitespace_re,
... | python | def clean_document(document,
sent_tokenize, _treebank_word_tokenize,
tagger,
lemmatizer,
lemmatize,
stopset,
first_cap_re, all_cap_re,
digits_punctuation_whitespace_re,
... | [
"def",
"clean_document",
"(",
"document",
",",
"sent_tokenize",
",",
"_treebank_word_tokenize",
",",
"tagger",
",",
"lemmatizer",
",",
"lemmatize",
",",
"stopset",
",",
"first_cap_re",
",",
"all_cap_re",
",",
"digits_punctuation_whitespace_re",
",",
"pos_set",
")",
... | Extracts a clean bag-of-words from a document.
Inputs: - document: A string containing some text.
Output: - lemma_list: A python list of lemmas or stems.
- lemma_to_keywordbag: A python dictionary that maps stems/lemmas to original topic keywords. | [
"Extracts",
"a",
"clean",
"bag",
"-",
"of",
"-",
"words",
"from",
"a",
"document",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/clean_text.py#L99-L199 | train | 57,632 |
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/clean_text.py | clean_corpus_serial | def clean_corpus_serial(corpus, lemmatizing="wordnet"):
"""
Extracts a bag-of-words from each document in a corpus serially.
Inputs: - corpus: A python list of python strings. Each string is a document.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
... | python | def clean_corpus_serial(corpus, lemmatizing="wordnet"):
"""
Extracts a bag-of-words from each document in a corpus serially.
Inputs: - corpus: A python list of python strings. Each string is a document.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
... | [
"def",
"clean_corpus_serial",
"(",
"corpus",
",",
"lemmatizing",
"=",
"\"wordnet\"",
")",
":",
"list_of_bags_of_words",
"=",
"list",
"(",
")",
"append_bag_of_words",
"=",
"list_of_bags_of_words",
".",
"append",
"lemma_to_keywordbag_total",
"=",
"defaultdict",
"(",
"la... | Extracts a bag-of-words from each document in a corpus serially.
Inputs: - corpus: A python list of python strings. Each string is a document.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
Output: - list_of_bags_of_words: A list of python dictionaries ... | [
"Extracts",
"a",
"bag",
"-",
"of",
"-",
"words",
"from",
"each",
"document",
"in",
"a",
"corpus",
"serially",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/clean_text.py#L252-L276 | train | 57,633 |
MKLab-ITI/reveal-user-annotation | reveal_user_annotation/text/clean_text.py | extract_bag_of_words_from_corpus_parallel | def extract_bag_of_words_from_corpus_parallel(corpus, lemmatizing="wordnet"):
"""
This extracts one bag-of-words from a list of strings. The documents are mapped to parallel processes.
Inputs: - corpus: A list of strings.
- lemmatizing: A string containing one of the following: "porter", "snowb... | python | def extract_bag_of_words_from_corpus_parallel(corpus, lemmatizing="wordnet"):
"""
This extracts one bag-of-words from a list of strings. The documents are mapped to parallel processes.
Inputs: - corpus: A list of strings.
- lemmatizing: A string containing one of the following: "porter", "snowb... | [
"def",
"extract_bag_of_words_from_corpus_parallel",
"(",
"corpus",
",",
"lemmatizing",
"=",
"\"wordnet\"",
")",
":",
"####################################################################################################################",
"# Map and reduce document cleaning.",
"###############... | This extracts one bag-of-words from a list of strings. The documents are mapped to parallel processes.
Inputs: - corpus: A list of strings.
- lemmatizing: A string containing one of the following: "porter", "snowball" or "wordnet".
Output: - bag_of_words: This is a bag-of-words in python dictionar... | [
"This",
"extracts",
"one",
"bag",
"-",
"of",
"-",
"words",
"from",
"a",
"list",
"of",
"strings",
".",
"The",
"documents",
"are",
"mapped",
"to",
"parallel",
"processes",
"."
] | ed019c031857b091e5601f53ba3f01a499a0e3ef | https://github.com/MKLab-ITI/reveal-user-annotation/blob/ed019c031857b091e5601f53ba3f01a499a0e3ef/reveal_user_annotation/text/clean_text.py#L279-L311 | train | 57,634 |
AtomHash/evernode | evernode/decorators/middleware.py | middleware | def middleware(func):
""" Executes routes.py route middleware """
@wraps(func)
def parse(*args, **kwargs):
""" get middleware from route, execute middleware in order """
middleware = copy.deepcopy(kwargs['middleware'])
kwargs.pop('middleware')
if request.method == "OPT... | python | def middleware(func):
""" Executes routes.py route middleware """
@wraps(func)
def parse(*args, **kwargs):
""" get middleware from route, execute middleware in order """
middleware = copy.deepcopy(kwargs['middleware'])
kwargs.pop('middleware')
if request.method == "OPT... | [
"def",
"middleware",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"parse",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\" get middleware from route, execute middleware in order \"\"\"",
"middleware",
"=",
"copy",
".",
"deepcopy",
... | Executes routes.py route middleware | [
"Executes",
"routes",
".",
"py",
"route",
"middleware"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/decorators/middleware.py#L8-L25 | train | 57,635 |
foobarbecue/afterflight | afterflight/progressbarupload/templatetags/progress_bar.py | progress_bar_media | def progress_bar_media():
"""
progress_bar_media simple tag
return rendered script tag for javascript used by progress_bar
"""
if PROGRESSBARUPLOAD_INCLUDE_JQUERY:
js = ["http://code.jquery.com/jquery-1.8.3.min.js",]
else:
js = []
js.append("js/progress_bar.js")
... | python | def progress_bar_media():
"""
progress_bar_media simple tag
return rendered script tag for javascript used by progress_bar
"""
if PROGRESSBARUPLOAD_INCLUDE_JQUERY:
js = ["http://code.jquery.com/jquery-1.8.3.min.js",]
else:
js = []
js.append("js/progress_bar.js")
... | [
"def",
"progress_bar_media",
"(",
")",
":",
"if",
"PROGRESSBARUPLOAD_INCLUDE_JQUERY",
":",
"js",
"=",
"[",
"\"http://code.jquery.com/jquery-1.8.3.min.js\"",
",",
"]",
"else",
":",
"js",
"=",
"[",
"]",
"js",
".",
"append",
"(",
"\"js/progress_bar.js\"",
")",
"m",
... | progress_bar_media simple tag
return rendered script tag for javascript used by progress_bar | [
"progress_bar_media",
"simple",
"tag"
] | 7085f719593f88999dce93f35caec5f15d2991b6 | https://github.com/foobarbecue/afterflight/blob/7085f719593f88999dce93f35caec5f15d2991b6/afterflight/progressbarupload/templatetags/progress_bar.py#L31-L44 | train | 57,636 |
Eyepea/systemDream | src/systemdream/journal/helpers.py | send | def send(MESSAGE, SOCKET, MESSAGE_ID=None,
CODE_FILE=None, CODE_LINE=None, CODE_FUNC=None,
**kwargs):
r"""Send a message to the journal.
>>> journal.send('Hello world')
>>> journal.send('Hello, again, world', FIELD2='Greetings!')
>>> journal.send('Binary message', BINARY=b'\xde\xad\xb... | python | def send(MESSAGE, SOCKET, MESSAGE_ID=None,
CODE_FILE=None, CODE_LINE=None, CODE_FUNC=None,
**kwargs):
r"""Send a message to the journal.
>>> journal.send('Hello world')
>>> journal.send('Hello, again, world', FIELD2='Greetings!')
>>> journal.send('Binary message', BINARY=b'\xde\xad\xb... | [
"def",
"send",
"(",
"MESSAGE",
",",
"SOCKET",
",",
"MESSAGE_ID",
"=",
"None",
",",
"CODE_FILE",
"=",
"None",
",",
"CODE_LINE",
"=",
"None",
",",
"CODE_FUNC",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"args",
"=",
"[",
"'MESSAGE='",
"+",
"MESSAG... | r"""Send a message to the journal.
>>> journal.send('Hello world')
>>> journal.send('Hello, again, world', FIELD2='Greetings!')
>>> journal.send('Binary message', BINARY=b'\xde\xad\xbe\xef')
Value of the MESSAGE argument will be used for the MESSAGE=
field. MESSAGE must be a string and will be sen... | [
"r",
"Send",
"a",
"message",
"to",
"the",
"journal",
"."
] | 018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8 | https://github.com/Eyepea/systemDream/blob/018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8/src/systemdream/journal/helpers.py#L13-L61 | train | 57,637 |
AtomHash/evernode | evernode/models/base_model.py | BaseModel.exists | def exists(self):
""" Checks if item already exists in database """
self_object = self.query.filter_by(id=self.id).first()
if self_object is None:
return False
return True | python | def exists(self):
""" Checks if item already exists in database """
self_object = self.query.filter_by(id=self.id).first()
if self_object is None:
return False
return True | [
"def",
"exists",
"(",
"self",
")",
":",
"self_object",
"=",
"self",
".",
"query",
".",
"filter_by",
"(",
"id",
"=",
"self",
".",
"id",
")",
".",
"first",
"(",
")",
"if",
"self_object",
"is",
"None",
":",
"return",
"False",
"return",
"True"
] | Checks if item already exists in database | [
"Checks",
"if",
"item",
"already",
"exists",
"in",
"database"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/models/base_model.py#L27-L32 | train | 57,638 |
AtomHash/evernode | evernode/models/base_model.py | BaseModel.delete | def delete(self):
""" Easy delete for db models """
try:
if self.exists() is False:
return None
self.db.session.delete(self)
self.db.session.commit()
except (Exception, BaseException) as error:
# fail silently
r... | python | def delete(self):
""" Easy delete for db models """
try:
if self.exists() is False:
return None
self.db.session.delete(self)
self.db.session.commit()
except (Exception, BaseException) as error:
# fail silently
r... | [
"def",
"delete",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"exists",
"(",
")",
"is",
"False",
":",
"return",
"None",
"self",
".",
"db",
".",
"session",
".",
"delete",
"(",
"self",
")",
"self",
".",
"db",
".",
"session",
".",
"commit",... | Easy delete for db models | [
"Easy",
"delete",
"for",
"db",
"models"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/models/base_model.py#L39-L48 | train | 57,639 |
zsiciarz/pygcvs | pygcvs/parser.py | GcvsParser.row_to_dict | def row_to_dict(self, row):
"""
Converts a raw GCVS record to a dictionary of star data.
"""
constellation = self.parse_constellation(row[0])
name = self.parse_name(row[1])
ra, dec = self.parse_coordinates(row[2])
variable_type = row[3].strip()
max_magnitu... | python | def row_to_dict(self, row):
"""
Converts a raw GCVS record to a dictionary of star data.
"""
constellation = self.parse_constellation(row[0])
name = self.parse_name(row[1])
ra, dec = self.parse_coordinates(row[2])
variable_type = row[3].strip()
max_magnitu... | [
"def",
"row_to_dict",
"(",
"self",
",",
"row",
")",
":",
"constellation",
"=",
"self",
".",
"parse_constellation",
"(",
"row",
"[",
"0",
"]",
")",
"name",
"=",
"self",
".",
"parse_name",
"(",
"row",
"[",
"1",
"]",
")",
"ra",
",",
"dec",
"=",
"self"... | Converts a raw GCVS record to a dictionary of star data. | [
"Converts",
"a",
"raw",
"GCVS",
"record",
"to",
"a",
"dictionary",
"of",
"star",
"data",
"."
] | ed5522ab9cf9237592a6af7a0bc8cad079afeb67 | https://github.com/zsiciarz/pygcvs/blob/ed5522ab9cf9237592a6af7a0bc8cad079afeb67/pygcvs/parser.py#L139-L164 | train | 57,640 |
zsiciarz/pygcvs | pygcvs/parser.py | GcvsParser.parse_magnitude | def parse_magnitude(self, magnitude_str):
"""
Converts magnitude field to a float value, or ``None`` if GCVS does
not list the magnitude.
Returns a tuple (magnitude, symbol), where symbol can be either an
empty string or a single character - one of '<', '>', '('.
"""
... | python | def parse_magnitude(self, magnitude_str):
"""
Converts magnitude field to a float value, or ``None`` if GCVS does
not list the magnitude.
Returns a tuple (magnitude, symbol), where symbol can be either an
empty string or a single character - one of '<', '>', '('.
"""
... | [
"def",
"parse_magnitude",
"(",
"self",
",",
"magnitude_str",
")",
":",
"symbol",
"=",
"magnitude_str",
"[",
"0",
"]",
".",
"strip",
"(",
")",
"magnitude",
"=",
"magnitude_str",
"[",
"1",
":",
"6",
"]",
".",
"strip",
"(",
")",
"return",
"float",
"(",
... | Converts magnitude field to a float value, or ``None`` if GCVS does
not list the magnitude.
Returns a tuple (magnitude, symbol), where symbol can be either an
empty string or a single character - one of '<', '>', '('. | [
"Converts",
"magnitude",
"field",
"to",
"a",
"float",
"value",
"or",
"None",
"if",
"GCVS",
"does",
"not",
"list",
"the",
"magnitude",
"."
] | ed5522ab9cf9237592a6af7a0bc8cad079afeb67 | https://github.com/zsiciarz/pygcvs/blob/ed5522ab9cf9237592a6af7a0bc8cad079afeb67/pygcvs/parser.py#L190-L200 | train | 57,641 |
zsiciarz/pygcvs | pygcvs/parser.py | GcvsParser.parse_period | def parse_period(self, period_str):
"""
Converts period field to a float value or ``None`` if there is
no period in GCVS record.
"""
period = period_str.translate(TRANSLATION_MAP)[3:14].strip()
return float(period) if period else None | python | def parse_period(self, period_str):
"""
Converts period field to a float value or ``None`` if there is
no period in GCVS record.
"""
period = period_str.translate(TRANSLATION_MAP)[3:14].strip()
return float(period) if period else None | [
"def",
"parse_period",
"(",
"self",
",",
"period_str",
")",
":",
"period",
"=",
"period_str",
".",
"translate",
"(",
"TRANSLATION_MAP",
")",
"[",
"3",
":",
"14",
"]",
".",
"strip",
"(",
")",
"return",
"float",
"(",
"period",
")",
"if",
"period",
"else"... | Converts period field to a float value or ``None`` if there is
no period in GCVS record. | [
"Converts",
"period",
"field",
"to",
"a",
"float",
"value",
"or",
"None",
"if",
"there",
"is",
"no",
"period",
"in",
"GCVS",
"record",
"."
] | ed5522ab9cf9237592a6af7a0bc8cad079afeb67 | https://github.com/zsiciarz/pygcvs/blob/ed5522ab9cf9237592a6af7a0bc8cad079afeb67/pygcvs/parser.py#L210-L216 | train | 57,642 |
ponty/confduino | confduino/hwpackinstall.py | find_hwpack_dir | def find_hwpack_dir(root):
"""search for hwpack dir under root."""
root = path(root)
log.debug('files in dir: %s', root)
for x in root.walkfiles():
log.debug(' %s', x)
hwpack_dir = None
for h in (root.walkfiles('boards.txt')):
assert not hwpack_dir
hwpack_dir = h.parent... | python | def find_hwpack_dir(root):
"""search for hwpack dir under root."""
root = path(root)
log.debug('files in dir: %s', root)
for x in root.walkfiles():
log.debug(' %s', x)
hwpack_dir = None
for h in (root.walkfiles('boards.txt')):
assert not hwpack_dir
hwpack_dir = h.parent... | [
"def",
"find_hwpack_dir",
"(",
"root",
")",
":",
"root",
"=",
"path",
"(",
"root",
")",
"log",
".",
"debug",
"(",
"'files in dir: %s'",
",",
"root",
")",
"for",
"x",
"in",
"root",
".",
"walkfiles",
"(",
")",
":",
"log",
".",
"debug",
"(",
"' %s'",
... | search for hwpack dir under root. | [
"search",
"for",
"hwpack",
"dir",
"under",
"root",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/hwpackinstall.py#L11-L25 | train | 57,643 |
ponty/confduino | confduino/hwpackinstall.py | install_hwpack | def install_hwpack(url, replace_existing=False):
"""install hwpackrary from web or local files system.
:param url: web address or file path
:param replace_existing: bool
:rtype: None
"""
d = tmpdir(tmpdir())
f = download(url)
Archive(f).extractall(d)
clean_dir(d)
src_dhwpack =... | python | def install_hwpack(url, replace_existing=False):
"""install hwpackrary from web or local files system.
:param url: web address or file path
:param replace_existing: bool
:rtype: None
"""
d = tmpdir(tmpdir())
f = download(url)
Archive(f).extractall(d)
clean_dir(d)
src_dhwpack =... | [
"def",
"install_hwpack",
"(",
"url",
",",
"replace_existing",
"=",
"False",
")",
":",
"d",
"=",
"tmpdir",
"(",
"tmpdir",
"(",
")",
")",
"f",
"=",
"download",
"(",
"url",
")",
"Archive",
"(",
"f",
")",
".",
"extractall",
"(",
"d",
")",
"clean_dir",
... | install hwpackrary from web or local files system.
:param url: web address or file path
:param replace_existing: bool
:rtype: None | [
"install",
"hwpackrary",
"from",
"web",
"or",
"local",
"files",
"system",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/hwpackinstall.py#L29-L61 | train | 57,644 |
rackerlabs/python-lunrclient | lunrclient/lunr.py | LunrVolume.create | def create(self, volume_id, vtype, size, affinity):
"""
create a volume
"""
volume_id = volume_id or str(uuid.uuid4())
params = {'volume_type_name': vtype,
'size': size,
'affinity': affinity}
return self.http_put('/volumes/%s' % volume_... | python | def create(self, volume_id, vtype, size, affinity):
"""
create a volume
"""
volume_id = volume_id or str(uuid.uuid4())
params = {'volume_type_name': vtype,
'size': size,
'affinity': affinity}
return self.http_put('/volumes/%s' % volume_... | [
"def",
"create",
"(",
"self",
",",
"volume_id",
",",
"vtype",
",",
"size",
",",
"affinity",
")",
":",
"volume_id",
"=",
"volume_id",
"or",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"params",
"=",
"{",
"'volume_type_name'",
":",
"vtype",
",",
"... | create a volume | [
"create",
"a",
"volume"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr.py#L47-L56 | train | 57,645 |
rackerlabs/python-lunrclient | lunrclient/lunr.py | LunrVolume.restore | def restore(self, volume_id, **kwargs):
"""
restore a volume from a backup
"""
# These arguments are required
self.required('create', kwargs, ['backup', 'size'])
# Optional Arguments
volume_id = volume_id or str(uuid.uuid4())
kwargs['volume_type_name'] = k... | python | def restore(self, volume_id, **kwargs):
"""
restore a volume from a backup
"""
# These arguments are required
self.required('create', kwargs, ['backup', 'size'])
# Optional Arguments
volume_id = volume_id or str(uuid.uuid4())
kwargs['volume_type_name'] = k... | [
"def",
"restore",
"(",
"self",
",",
"volume_id",
",",
"*",
"*",
"kwargs",
")",
":",
"# These arguments are required",
"self",
".",
"required",
"(",
"'create'",
",",
"kwargs",
",",
"[",
"'backup'",
",",
"'size'",
"]",
")",
"# Optional Arguments",
"volume_id",
... | restore a volume from a backup | [
"restore",
"a",
"volume",
"from",
"a",
"backup"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr.py#L58-L70 | train | 57,646 |
rackerlabs/python-lunrclient | lunrclient/lunr.py | LunrBackup.create | def create(self, volume_id, backup_id):
"""
create a backup
"""
backup_id = backup_id or str(uuid.uuid4())
return self.http_put('/backups/%s' % backup_id,
params={'volume': volume_id}) | python | def create(self, volume_id, backup_id):
"""
create a backup
"""
backup_id = backup_id or str(uuid.uuid4())
return self.http_put('/backups/%s' % backup_id,
params={'volume': volume_id}) | [
"def",
"create",
"(",
"self",
",",
"volume_id",
",",
"backup_id",
")",
":",
"backup_id",
"=",
"backup_id",
"or",
"str",
"(",
"uuid",
".",
"uuid4",
"(",
")",
")",
"return",
"self",
".",
"http_put",
"(",
"'/backups/%s'",
"%",
"backup_id",
",",
"params",
... | create a backup | [
"create",
"a",
"backup"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr.py#L102-L108 | train | 57,647 |
rackerlabs/python-lunrclient | lunrclient/lunr.py | LunrExport.delete | def delete(self, volume_id, force=False):
"""
delete an export
"""
return self.http_delete('/volumes/%s/export'
% volume_id, params={'force': force}) | python | def delete(self, volume_id, force=False):
"""
delete an export
"""
return self.http_delete('/volumes/%s/export'
% volume_id, params={'force': force}) | [
"def",
"delete",
"(",
"self",
",",
"volume_id",
",",
"force",
"=",
"False",
")",
":",
"return",
"self",
".",
"http_delete",
"(",
"'/volumes/%s/export'",
"%",
"volume_id",
",",
"params",
"=",
"{",
"'force'",
":",
"force",
"}",
")"
] | delete an export | [
"delete",
"an",
"export"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr.py#L215-L220 | train | 57,648 |
rackerlabs/python-lunrclient | lunrclient/lunr.py | LunrExport.update | def update(self, volume_id, **kwargs):
"""
update an export
"""
# These arguments are allowed
self.allowed('update', kwargs,
['status', 'instance_id',
'mountpoint', 'ip', 'initiator', 'session_ip',
'session_initiato... | python | def update(self, volume_id, **kwargs):
"""
update an export
"""
# These arguments are allowed
self.allowed('update', kwargs,
['status', 'instance_id',
'mountpoint', 'ip', 'initiator', 'session_ip',
'session_initiato... | [
"def",
"update",
"(",
"self",
",",
"volume_id",
",",
"*",
"*",
"kwargs",
")",
":",
"# These arguments are allowed",
"self",
".",
"allowed",
"(",
"'update'",
",",
"kwargs",
",",
"[",
"'status'",
",",
"'instance_id'",
",",
"'mountpoint'",
",",
"'ip'",
",",
"... | update an export | [
"update",
"an",
"export"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/lunr.py#L222-L233 | train | 57,649 |
hsdp/python-dropsonde | build.py | proto_refactor | def proto_refactor(proto_filename, namespace, namespace_path):
"""This method refactors a Protobuf file to import from a namespace
that will map to the desired python package structure. It also ensures
that the syntax is set to "proto2", since protoc complains without it.
Args:
proto_filename (... | python | def proto_refactor(proto_filename, namespace, namespace_path):
"""This method refactors a Protobuf file to import from a namespace
that will map to the desired python package structure. It also ensures
that the syntax is set to "proto2", since protoc complains without it.
Args:
proto_filename (... | [
"def",
"proto_refactor",
"(",
"proto_filename",
",",
"namespace",
",",
"namespace_path",
")",
":",
"with",
"open",
"(",
"proto_filename",
")",
"as",
"f",
":",
"data",
"=",
"f",
".",
"read",
"(",
")",
"if",
"not",
"re",
".",
"search",
"(",
"'syntax = \"pr... | This method refactors a Protobuf file to import from a namespace
that will map to the desired python package structure. It also ensures
that the syntax is set to "proto2", since protoc complains without it.
Args:
proto_filename (str): the protobuf filename to be refactored
namespace (str): ... | [
"This",
"method",
"refactors",
"a",
"Protobuf",
"file",
"to",
"import",
"from",
"a",
"namespace",
"that",
"will",
"map",
"to",
"the",
"desired",
"python",
"package",
"structure",
".",
"It",
"also",
"ensures",
"that",
"the",
"syntax",
"is",
"set",
"to",
"pr... | e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07 | https://github.com/hsdp/python-dropsonde/blob/e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07/build.py#L12-L30 | train | 57,650 |
hsdp/python-dropsonde | build.py | proto_refactor_files | def proto_refactor_files(dest_dir, namespace, namespace_path):
"""This method runs the refactoring on all the Protobuf files in the
Dropsonde repo.
Args:
dest_dir (str): directory where the Protobuf files lives.
namespace (str): the desired package name (i.e. "dropsonde.py2")
namesp... | python | def proto_refactor_files(dest_dir, namespace, namespace_path):
"""This method runs the refactoring on all the Protobuf files in the
Dropsonde repo.
Args:
dest_dir (str): directory where the Protobuf files lives.
namespace (str): the desired package name (i.e. "dropsonde.py2")
namesp... | [
"def",
"proto_refactor_files",
"(",
"dest_dir",
",",
"namespace",
",",
"namespace_path",
")",
":",
"for",
"dn",
",",
"dns",
",",
"fns",
"in",
"os",
".",
"walk",
"(",
"dest_dir",
")",
":",
"for",
"fn",
"in",
"fns",
":",
"fn",
"=",
"os",
".",
"path",
... | This method runs the refactoring on all the Protobuf files in the
Dropsonde repo.
Args:
dest_dir (str): directory where the Protobuf files lives.
namespace (str): the desired package name (i.e. "dropsonde.py2")
namespace_path (str): the desired path corresponding to the package
... | [
"This",
"method",
"runs",
"the",
"refactoring",
"on",
"all",
"the",
"Protobuf",
"files",
"in",
"the",
"Dropsonde",
"repo",
"."
] | e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07 | https://github.com/hsdp/python-dropsonde/blob/e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07/build.py#L33-L49 | train | 57,651 |
hsdp/python-dropsonde | build.py | clone_source_dir | def clone_source_dir(source_dir, dest_dir):
"""Copies the source Protobuf files into a build directory.
Args:
source_dir (str): source directory of the Protobuf files
dest_dir (str): destination directory of the Protobuf files
"""
if os.path.isdir(dest_dir):
print('removing', de... | python | def clone_source_dir(source_dir, dest_dir):
"""Copies the source Protobuf files into a build directory.
Args:
source_dir (str): source directory of the Protobuf files
dest_dir (str): destination directory of the Protobuf files
"""
if os.path.isdir(dest_dir):
print('removing', de... | [
"def",
"clone_source_dir",
"(",
"source_dir",
",",
"dest_dir",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"dest_dir",
")",
":",
"print",
"(",
"'removing'",
",",
"dest_dir",
")",
"shutil",
".",
"rmtree",
"(",
"dest_dir",
")",
"shutil",
".",
"... | Copies the source Protobuf files into a build directory.
Args:
source_dir (str): source directory of the Protobuf files
dest_dir (str): destination directory of the Protobuf files | [
"Copies",
"the",
"source",
"Protobuf",
"files",
"into",
"a",
"build",
"directory",
"."
] | e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07 | https://github.com/hsdp/python-dropsonde/blob/e72680a3139cbb5ee4910ce1bbc2ccbaa227fb07/build.py#L52-L62 | train | 57,652 |
openspending/ckanext-budgets | ckanext/budgets/plugin.py | BudgetDataPackagePlugin.are_budget_data_package_fields_filled_in | def are_budget_data_package_fields_filled_in(self, resource):
"""
Check if the budget data package fields are all filled in because
if not then this can't be a budget data package
"""
fields = ['country', 'currency', 'year', 'status']
return all([self.in_resource(f, resou... | python | def are_budget_data_package_fields_filled_in(self, resource):
"""
Check if the budget data package fields are all filled in because
if not then this can't be a budget data package
"""
fields = ['country', 'currency', 'year', 'status']
return all([self.in_resource(f, resou... | [
"def",
"are_budget_data_package_fields_filled_in",
"(",
"self",
",",
"resource",
")",
":",
"fields",
"=",
"[",
"'country'",
",",
"'currency'",
",",
"'year'",
",",
"'status'",
"]",
"return",
"all",
"(",
"[",
"self",
".",
"in_resource",
"(",
"f",
",",
"resourc... | Check if the budget data package fields are all filled in because
if not then this can't be a budget data package | [
"Check",
"if",
"the",
"budget",
"data",
"package",
"fields",
"are",
"all",
"filled",
"in",
"because",
"if",
"not",
"then",
"this",
"can",
"t",
"be",
"a",
"budget",
"data",
"package"
] | 07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc | https://github.com/openspending/ckanext-budgets/blob/07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc/ckanext/budgets/plugin.py#L228-L234 | train | 57,653 |
openspending/ckanext-budgets | ckanext/budgets/plugin.py | BudgetDataPackagePlugin.generate_budget_data_package | def generate_budget_data_package(self, resource):
"""
Try to grab a budget data package schema from the resource.
The schema only allows fields which are defined in the budget
data package specification. If a field is found that is not in
the specification this will return a NotA... | python | def generate_budget_data_package(self, resource):
"""
Try to grab a budget data package schema from the resource.
The schema only allows fields which are defined in the budget
data package specification. If a field is found that is not in
the specification this will return a NotA... | [
"def",
"generate_budget_data_package",
"(",
"self",
",",
"resource",
")",
":",
"# Return if the budget data package fields have not been filled in",
"if",
"not",
"self",
".",
"are_budget_data_package_fields_filled_in",
"(",
"resource",
")",
":",
"return",
"try",
":",
"resou... | Try to grab a budget data package schema from the resource.
The schema only allows fields which are defined in the budget
data package specification. If a field is found that is not in
the specification this will return a NotABudgetDataPackageException
and in that case we can just return... | [
"Try",
"to",
"grab",
"a",
"budget",
"data",
"package",
"schema",
"from",
"the",
"resource",
".",
"The",
"schema",
"only",
"allows",
"fields",
"which",
"are",
"defined",
"in",
"the",
"budget",
"data",
"package",
"specification",
".",
"If",
"a",
"field",
"is... | 07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc | https://github.com/openspending/ckanext-budgets/blob/07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc/ckanext/budgets/plugin.py#L236-L261 | train | 57,654 |
openspending/ckanext-budgets | ckanext/budgets/plugin.py | BudgetDataPackagePlugin.before_update | def before_update(self, context, current, resource):
"""
If the resource has changed we try to generate a budget data
package, but if it hasn't then we don't do anything
"""
# Return if the budget data package fields have not been filled in
if not self.are_budget_data_pa... | python | def before_update(self, context, current, resource):
"""
If the resource has changed we try to generate a budget data
package, but if it hasn't then we don't do anything
"""
# Return if the budget data package fields have not been filled in
if not self.are_budget_data_pa... | [
"def",
"before_update",
"(",
"self",
",",
"context",
",",
"current",
",",
"resource",
")",
":",
"# Return if the budget data package fields have not been filled in",
"if",
"not",
"self",
".",
"are_budget_data_package_fields_filled_in",
"(",
"resource",
")",
":",
"return",... | If the resource has changed we try to generate a budget data
package, but if it hasn't then we don't do anything | [
"If",
"the",
"resource",
"has",
"changed",
"we",
"try",
"to",
"generate",
"a",
"budget",
"data",
"package",
"but",
"if",
"it",
"hasn",
"t",
"then",
"we",
"don",
"t",
"do",
"anything"
] | 07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc | https://github.com/openspending/ckanext-budgets/blob/07dde5a4fdec6b36ceb812b70f0c31cdecb40cfc/ckanext/budgets/plugin.py#L287-L307 | train | 57,655 |
SeattleTestbed/seash | modules/uploaddir/__init__.py | upload_directory_contents | def upload_directory_contents(input_dict, environment_dict):
"""This function serves to upload every file in a user-supplied
source directory to all of the vessels in the current target group.
It essentially calls seash's `upload` function repeatedly, each
time with a file name taken from the source directory... | python | def upload_directory_contents(input_dict, environment_dict):
"""This function serves to upload every file in a user-supplied
source directory to all of the vessels in the current target group.
It essentially calls seash's `upload` function repeatedly, each
time with a file name taken from the source directory... | [
"def",
"upload_directory_contents",
"(",
"input_dict",
",",
"environment_dict",
")",
":",
"# Check user input and seash state:",
"# 1, Make sure there is an active user key.",
"if",
"environment_dict",
"[",
"\"currentkeyname\"",
"]",
"is",
"None",
":",
"raise",
"seash_exception... | This function serves to upload every file in a user-supplied
source directory to all of the vessels in the current target group.
It essentially calls seash's `upload` function repeatedly, each
time with a file name taken from the source directory.
A note on the input_dict argument:
`input_dict` contains ou... | [
"This",
"function",
"serves",
"to",
"upload",
"every",
"file",
"in",
"a",
"user",
"-",
"supplied",
"source",
"directory",
"to",
"all",
"of",
"the",
"vessels",
"in",
"the",
"current",
"target",
"group",
".",
"It",
"essentially",
"calls",
"seash",
"s",
"uplo... | 40f9d2285662ff8b61e0468b4196acee089b273b | https://github.com/SeattleTestbed/seash/blob/40f9d2285662ff8b61e0468b4196acee089b273b/modules/uploaddir/__init__.py#L26-L95 | train | 57,656 |
AtomHash/evernode | evernode/classes/translator.py | Translator.__load_file | def __load_file(self, key_list) -> str:
""" Load a translator file """
file = str(key_list[0]) + self.extension
key_list.pop(0)
file_path = os.path.join(self.path, file)
if os.path.exists(file_path):
return Json.from_file(file_path)
else:
r... | python | def __load_file(self, key_list) -> str:
""" Load a translator file """
file = str(key_list[0]) + self.extension
key_list.pop(0)
file_path = os.path.join(self.path, file)
if os.path.exists(file_path):
return Json.from_file(file_path)
else:
r... | [
"def",
"__load_file",
"(",
"self",
",",
"key_list",
")",
"->",
"str",
":",
"file",
"=",
"str",
"(",
"key_list",
"[",
"0",
"]",
")",
"+",
"self",
".",
"extension",
"key_list",
".",
"pop",
"(",
"0",
")",
"file_path",
"=",
"os",
".",
"path",
".",
"j... | Load a translator file | [
"Load",
"a",
"translator",
"file"
] | b2fb91555fb937a3f3eba41db56dee26f9b034be | https://github.com/AtomHash/evernode/blob/b2fb91555fb937a3f3eba41db56dee26f9b034be/evernode/classes/translator.py#L71-L79 | train | 57,657 |
ponty/confduino | confduino/progremove.py | remove_programmer | def remove_programmer(programmer_id):
"""remove programmer.
:param programmer_id: programmer id (e.g. 'avrisp')
:rtype: None
"""
log.debug('remove %s', programmer_id)
lines = programmers_txt().lines()
lines = filter(
lambda x: not x.strip().startswith(programmer_id + '.'), lines)
... | python | def remove_programmer(programmer_id):
"""remove programmer.
:param programmer_id: programmer id (e.g. 'avrisp')
:rtype: None
"""
log.debug('remove %s', programmer_id)
lines = programmers_txt().lines()
lines = filter(
lambda x: not x.strip().startswith(programmer_id + '.'), lines)
... | [
"def",
"remove_programmer",
"(",
"programmer_id",
")",
":",
"log",
".",
"debug",
"(",
"'remove %s'",
",",
"programmer_id",
")",
"lines",
"=",
"programmers_txt",
"(",
")",
".",
"lines",
"(",
")",
"lines",
"=",
"filter",
"(",
"lambda",
"x",
":",
"not",
"x"... | remove programmer.
:param programmer_id: programmer id (e.g. 'avrisp')
:rtype: None | [
"remove",
"programmer",
"."
] | f4c261e5e84997f145a8bdd001f471db74c9054b | https://github.com/ponty/confduino/blob/f4c261e5e84997f145a8bdd001f471db74c9054b/confduino/progremove.py#L9-L21 | train | 57,658 |
helixyte/everest | everest/repositories/memory/session.py | MemorySession.load | def load(self, entity_class, entity):
"""
Load the given repository entity into the session and return a
clone. If it was already loaded before, look up the loaded entity
and return it.
All entities referenced by the loaded entity will also be loaded
(and cloned) recursi... | python | def load(self, entity_class, entity):
"""
Load the given repository entity into the session and return a
clone. If it was already loaded before, look up the loaded entity
and return it.
All entities referenced by the loaded entity will also be loaded
(and cloned) recursi... | [
"def",
"load",
"(",
"self",
",",
"entity_class",
",",
"entity",
")",
":",
"if",
"self",
".",
"__needs_flushing",
":",
"self",
".",
"flush",
"(",
")",
"if",
"entity",
".",
"id",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Can not load entity without an... | Load the given repository entity into the session and return a
clone. If it was already loaded before, look up the loaded entity
and return it.
All entities referenced by the loaded entity will also be loaded
(and cloned) recursively.
:raises ValueError: When an attempt is made... | [
"Load",
"the",
"given",
"repository",
"entity",
"into",
"the",
"session",
"and",
"return",
"a",
"clone",
".",
"If",
"it",
"was",
"already",
"loaded",
"before",
"look",
"up",
"the",
"loaded",
"entity",
"and",
"return",
"it",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/repositories/memory/session.py#L127-L152 | train | 57,659 |
corydodt/Codado | doc/sample/ondie.py | AppMourner.onStart | def onStart(self, event):
"""
Display the environment of a started container
"""
c = event.container
print '+' * 5, 'started:', c
kv = lambda s: s.split('=', 1)
env = {k: v for (k, v) in (kv(s) for s in c.attrs['Config']['Env'])}
print env | python | def onStart(self, event):
"""
Display the environment of a started container
"""
c = event.container
print '+' * 5, 'started:', c
kv = lambda s: s.split('=', 1)
env = {k: v for (k, v) in (kv(s) for s in c.attrs['Config']['Env'])}
print env | [
"def",
"onStart",
"(",
"self",
",",
"event",
")",
":",
"c",
"=",
"event",
".",
"container",
"print",
"'+'",
"*",
"5",
",",
"'started:'",
",",
"c",
"kv",
"=",
"lambda",
"s",
":",
"s",
".",
"split",
"(",
"'='",
",",
"1",
")",
"env",
"=",
"{",
"... | Display the environment of a started container | [
"Display",
"the",
"environment",
"of",
"a",
"started",
"container"
] | 487d51ec6132c05aa88e2f128012c95ccbf6928e | https://github.com/corydodt/Codado/blob/487d51ec6132c05aa88e2f128012c95ccbf6928e/doc/sample/ondie.py#L28-L36 | train | 57,660 |
RI-imaging/qpformat | qpformat/file_formats/__init__.py | SeriesFolder._identifier_data | def _identifier_data(self):
"""Return a unique identifier for the folder data"""
# Use only file names
data = [ff.name for ff in self.files]
data.sort()
# also use the folder name
data.append(self.path.name)
# add meta data
data += self._identifier_meta()
... | python | def _identifier_data(self):
"""Return a unique identifier for the folder data"""
# Use only file names
data = [ff.name for ff in self.files]
data.sort()
# also use the folder name
data.append(self.path.name)
# add meta data
data += self._identifier_meta()
... | [
"def",
"_identifier_data",
"(",
"self",
")",
":",
"# Use only file names",
"data",
"=",
"[",
"ff",
".",
"name",
"for",
"ff",
"in",
"self",
".",
"files",
"]",
"data",
".",
"sort",
"(",
")",
"# also use the folder name",
"data",
".",
"append",
"(",
"self",
... | Return a unique identifier for the folder data | [
"Return",
"a",
"unique",
"identifier",
"for",
"the",
"folder",
"data"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/file_formats/__init__.py#L80-L89 | train | 57,661 |
RI-imaging/qpformat | qpformat/file_formats/__init__.py | SeriesFolder._search_files | def _search_files(path):
"""Search a folder for data files
.. versionchanged:: 0.6.0
`path` is not searched recursively anymore
"""
path = pathlib.Path(path)
fifo = []
for fp in path.glob("*"):
if fp.is_dir():
continue
... | python | def _search_files(path):
"""Search a folder for data files
.. versionchanged:: 0.6.0
`path` is not searched recursively anymore
"""
path = pathlib.Path(path)
fifo = []
for fp in path.glob("*"):
if fp.is_dir():
continue
... | [
"def",
"_search_files",
"(",
"path",
")",
":",
"path",
"=",
"pathlib",
".",
"Path",
"(",
"path",
")",
"fifo",
"=",
"[",
"]",
"for",
"fp",
"in",
"path",
".",
"glob",
"(",
"\"*\"",
")",
":",
"if",
"fp",
".",
"is_dir",
"(",
")",
":",
"continue",
"... | Search a folder for data files
.. versionchanged:: 0.6.0
`path` is not searched recursively anymore | [
"Search",
"a",
"folder",
"for",
"data",
"files"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/file_formats/__init__.py#L93-L131 | train | 57,662 |
RI-imaging/qpformat | qpformat/file_formats/__init__.py | SeriesFolder.get_identifier | def get_identifier(self, idx):
"""Return an identifier for the data at index `idx`
.. versionchanged:: 0.4.2
indexing starts at 1 instead of 0
"""
name = self._get_cropped_file_names()[idx]
return "{}:{}:{}".format(self.identifier, name, idx + 1) | python | def get_identifier(self, idx):
"""Return an identifier for the data at index `idx`
.. versionchanged:: 0.4.2
indexing starts at 1 instead of 0
"""
name = self._get_cropped_file_names()[idx]
return "{}:{}:{}".format(self.identifier, name, idx + 1) | [
"def",
"get_identifier",
"(",
"self",
",",
"idx",
")",
":",
"name",
"=",
"self",
".",
"_get_cropped_file_names",
"(",
")",
"[",
"idx",
"]",
"return",
"\"{}:{}:{}\"",
".",
"format",
"(",
"self",
".",
"identifier",
",",
"name",
",",
"idx",
"+",
"1",
")"
... | Return an identifier for the data at index `idx`
.. versionchanged:: 0.4.2
indexing starts at 1 instead of 0 | [
"Return",
"an",
"identifier",
"for",
"the",
"data",
"at",
"index",
"idx"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/file_formats/__init__.py#L148-L155 | train | 57,663 |
RI-imaging/qpformat | qpformat/file_formats/__init__.py | SeriesFolder.verify | def verify(path):
"""Verify folder file format
The folder file format is only valid when
there is only one file format present.
"""
valid = True
fifo = SeriesFolder._search_files(path)
# dataset size
if len(fifo) == 0:
valid = False
# ... | python | def verify(path):
"""Verify folder file format
The folder file format is only valid when
there is only one file format present.
"""
valid = True
fifo = SeriesFolder._search_files(path)
# dataset size
if len(fifo) == 0:
valid = False
# ... | [
"def",
"verify",
"(",
"path",
")",
":",
"valid",
"=",
"True",
"fifo",
"=",
"SeriesFolder",
".",
"_search_files",
"(",
"path",
")",
"# dataset size",
"if",
"len",
"(",
"fifo",
")",
"==",
"0",
":",
"valid",
"=",
"False",
"# number of different file formats",
... | Verify folder file format
The folder file format is only valid when
there is only one file format present. | [
"Verify",
"folder",
"file",
"format"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/file_formats/__init__.py#L176-L191 | train | 57,664 |
RI-imaging/qpformat | examples/convert_txt2npy.py | load_file | def load_file(path):
'''Load a txt data file'''
path = pathlib.Path(path)
data = path.open().readlines()
# remove comments and empty lines
data = [l for l in data if len(l.strip()) and not l.startswith("#")]
# determine data shape
n = len(data)
m = len(data[0].strip().split())
res = ... | python | def load_file(path):
'''Load a txt data file'''
path = pathlib.Path(path)
data = path.open().readlines()
# remove comments and empty lines
data = [l for l in data if len(l.strip()) and not l.startswith("#")]
# determine data shape
n = len(data)
m = len(data[0].strip().split())
res = ... | [
"def",
"load_file",
"(",
"path",
")",
":",
"path",
"=",
"pathlib",
".",
"Path",
"(",
"path",
")",
"data",
"=",
"path",
".",
"open",
"(",
")",
".",
"readlines",
"(",
")",
"# remove comments and empty lines",
"data",
"=",
"[",
"l",
"for",
"l",
"in",
"d... | Load a txt data file | [
"Load",
"a",
"txt",
"data",
"file"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/examples/convert_txt2npy.py#L27-L41 | train | 57,665 |
Eyepea/systemDream | src/systemdream/journal/handler.py | JournalHandler.emit | def emit(self, record):
"""Write record as journal event.
MESSAGE is taken from the message provided by the
user, and PRIORITY, LOGGER, THREAD_NAME,
CODE_{FILE,LINE,FUNC} fields are appended
automatically. In addition, record.MESSAGE_ID will be
used if present.
"... | python | def emit(self, record):
"""Write record as journal event.
MESSAGE is taken from the message provided by the
user, and PRIORITY, LOGGER, THREAD_NAME,
CODE_{FILE,LINE,FUNC} fields are appended
automatically. In addition, record.MESSAGE_ID will be
used if present.
"... | [
"def",
"emit",
"(",
"self",
",",
"record",
")",
":",
"if",
"record",
".",
"args",
"and",
"isinstance",
"(",
"record",
".",
"args",
",",
"collections",
".",
"Mapping",
")",
":",
"extra",
"=",
"dict",
"(",
"self",
".",
"_extra",
",",
"*",
"*",
"recor... | Write record as journal event.
MESSAGE is taken from the message provided by the
user, and PRIORITY, LOGGER, THREAD_NAME,
CODE_{FILE,LINE,FUNC} fields are appended
automatically. In addition, record.MESSAGE_ID will be
used if present. | [
"Write",
"record",
"as",
"journal",
"event",
"."
] | 018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8 | https://github.com/Eyepea/systemDream/blob/018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8/src/systemdream/journal/handler.py#L109-L137 | train | 57,666 |
Eyepea/systemDream | src/systemdream/journal/handler.py | JournalHandler.mapPriority | def mapPriority(levelno):
"""Map logging levels to journald priorities.
Since Python log level numbers are "sparse", we have
to map numbers in between the standard levels too.
"""
if levelno <= _logging.DEBUG:
return LOG_DEBUG
elif levelno <= _logging.INFO:
... | python | def mapPriority(levelno):
"""Map logging levels to journald priorities.
Since Python log level numbers are "sparse", we have
to map numbers in between the standard levels too.
"""
if levelno <= _logging.DEBUG:
return LOG_DEBUG
elif levelno <= _logging.INFO:
... | [
"def",
"mapPriority",
"(",
"levelno",
")",
":",
"if",
"levelno",
"<=",
"_logging",
".",
"DEBUG",
":",
"return",
"LOG_DEBUG",
"elif",
"levelno",
"<=",
"_logging",
".",
"INFO",
":",
"return",
"LOG_INFO",
"elif",
"levelno",
"<=",
"_logging",
".",
"WARNING",
"... | Map logging levels to journald priorities.
Since Python log level numbers are "sparse", we have
to map numbers in between the standard levels too. | [
"Map",
"logging",
"levels",
"to",
"journald",
"priorities",
"."
] | 018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8 | https://github.com/Eyepea/systemDream/blob/018fa5e9ff0f4fdc62fa85b235725d0f8b24f1a8/src/systemdream/journal/handler.py#L140-L157 | train | 57,667 |
rackerlabs/python-lunrclient | lunrclient/subcommand.py | SubCommand.get_args | def get_args(self, func):
"""
Get the arguments of a method and return it as a dictionary with the
supplied defaults, method arguments with no default are assigned None
"""
def reverse(iterable):
if iterable:
iterable = list(iterable)
w... | python | def get_args(self, func):
"""
Get the arguments of a method and return it as a dictionary with the
supplied defaults, method arguments with no default are assigned None
"""
def reverse(iterable):
if iterable:
iterable = list(iterable)
w... | [
"def",
"get_args",
"(",
"self",
",",
"func",
")",
":",
"def",
"reverse",
"(",
"iterable",
")",
":",
"if",
"iterable",
":",
"iterable",
"=",
"list",
"(",
"iterable",
")",
"while",
"len",
"(",
"iterable",
")",
":",
"yield",
"iterable",
".",
"pop",
"(",... | Get the arguments of a method and return it as a dictionary with the
supplied defaults, method arguments with no default are assigned None | [
"Get",
"the",
"arguments",
"of",
"a",
"method",
"and",
"return",
"it",
"as",
"a",
"dictionary",
"with",
"the",
"supplied",
"defaults",
"method",
"arguments",
"with",
"no",
"default",
"are",
"assigned",
"None"
] | f26a450a422600f492480bfa42cbee50a5c7016f | https://github.com/rackerlabs/python-lunrclient/blob/f26a450a422600f492480bfa42cbee50a5c7016f/lunrclient/subcommand.py#L253-L274 | train | 57,668 |
RI-imaging/qpformat | qpformat/core.py | guess_format | def guess_format(path):
"""Determine the file format of a folder or a file"""
for fmt in formats:
if fmt.verify(path):
return fmt.__name__
else:
msg = "Undefined file format: '{}'".format(path)
raise UnknownFileFormatError(msg) | python | def guess_format(path):
"""Determine the file format of a folder or a file"""
for fmt in formats:
if fmt.verify(path):
return fmt.__name__
else:
msg = "Undefined file format: '{}'".format(path)
raise UnknownFileFormatError(msg) | [
"def",
"guess_format",
"(",
"path",
")",
":",
"for",
"fmt",
"in",
"formats",
":",
"if",
"fmt",
".",
"verify",
"(",
"path",
")",
":",
"return",
"fmt",
".",
"__name__",
"else",
":",
"msg",
"=",
"\"Undefined file format: '{}'\"",
".",
"format",
"(",
"path",... | Determine the file format of a folder or a file | [
"Determine",
"the",
"file",
"format",
"of",
"a",
"folder",
"or",
"a",
"file"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/core.py#L10-L17 | train | 57,669 |
RI-imaging/qpformat | qpformat/core.py | load_data | def load_data(path, fmt=None, bg_data=None, bg_fmt=None,
meta_data={}, holo_kw={}, as_type="float32"):
"""Load experimental data
Parameters
----------
path: str
Path to experimental data file or folder
fmt: str
The file format to use (see `file_formats.formats`).
... | python | def load_data(path, fmt=None, bg_data=None, bg_fmt=None,
meta_data={}, holo_kw={}, as_type="float32"):
"""Load experimental data
Parameters
----------
path: str
Path to experimental data file or folder
fmt: str
The file format to use (see `file_formats.formats`).
... | [
"def",
"load_data",
"(",
"path",
",",
"fmt",
"=",
"None",
",",
"bg_data",
"=",
"None",
",",
"bg_fmt",
"=",
"None",
",",
"meta_data",
"=",
"{",
"}",
",",
"holo_kw",
"=",
"{",
"}",
",",
"as_type",
"=",
"\"float32\"",
")",
":",
"path",
"=",
"pathlib",... | Load experimental data
Parameters
----------
path: str
Path to experimental data file or folder
fmt: str
The file format to use (see `file_formats.formats`).
If set to `None`, the file format is guessed.
bg_data: str
Path to background data file or `qpimage.QPImage`
... | [
"Load",
"experimental",
"data"
] | 364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb | https://github.com/RI-imaging/qpformat/blob/364e29d7d9e8b9f1d7a4a25c753d1baf9d73d5eb/qpformat/core.py#L20-L90 | train | 57,670 |
kxz/littlebrother | littlebrother/humanize.py | duration | def duration(seconds):
"""Return a string of the form "1 hr 2 min 3 sec" representing the
given number of seconds."""
if seconds < 1:
return 'less than 1 sec'
seconds = int(round(seconds))
components = []
for magnitude, label in ((3600, 'hr'), (60, 'min'), (1, 'sec')):
if seconds... | python | def duration(seconds):
"""Return a string of the form "1 hr 2 min 3 sec" representing the
given number of seconds."""
if seconds < 1:
return 'less than 1 sec'
seconds = int(round(seconds))
components = []
for magnitude, label in ((3600, 'hr'), (60, 'min'), (1, 'sec')):
if seconds... | [
"def",
"duration",
"(",
"seconds",
")",
":",
"if",
"seconds",
"<",
"1",
":",
"return",
"'less than 1 sec'",
"seconds",
"=",
"int",
"(",
"round",
"(",
"seconds",
")",
")",
"components",
"=",
"[",
"]",
"for",
"magnitude",
",",
"label",
"in",
"(",
"(",
... | Return a string of the form "1 hr 2 min 3 sec" representing the
given number of seconds. | [
"Return",
"a",
"string",
"of",
"the",
"form",
"1",
"hr",
"2",
"min",
"3",
"sec",
"representing",
"the",
"given",
"number",
"of",
"seconds",
"."
] | af9ec9af5c0de9a74796bb7e16a6b836286e8b9f | https://github.com/kxz/littlebrother/blob/af9ec9af5c0de9a74796bb7e16a6b836286e8b9f/littlebrother/humanize.py#L4-L15 | train | 57,671 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._get_shortcut_prefix | def _get_shortcut_prefix(self, user_agent, standart_prefix):
"""
Returns the shortcut prefix of browser.
:param user_agent: The user agent of browser.
:type user_agent: str
:param standart_prefix: The default prefix.
:type standart_prefix: str
:return: The shortc... | python | def _get_shortcut_prefix(self, user_agent, standart_prefix):
"""
Returns the shortcut prefix of browser.
:param user_agent: The user agent of browser.
:type user_agent: str
:param standart_prefix: The default prefix.
:type standart_prefix: str
:return: The shortc... | [
"def",
"_get_shortcut_prefix",
"(",
"self",
",",
"user_agent",
",",
"standart_prefix",
")",
":",
"# pylint: disable=no-self-use",
"if",
"user_agent",
"is",
"not",
"None",
":",
"user_agent",
"=",
"user_agent",
".",
"lower",
"(",
")",
"opera",
"=",
"'opera'",
"in"... | Returns the shortcut prefix of browser.
:param user_agent: The user agent of browser.
:type user_agent: str
:param standart_prefix: The default prefix.
:type standart_prefix: str
:return: The shortcut prefix of browser.
:rtype: str | [
"Returns",
"the",
"shortcut",
"prefix",
"of",
"browser",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L442-L486 | train | 57,672 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._get_role_description | def _get_role_description(self, role):
"""
Returns the description of role.
:param role: The role.
:type role: str
:return: The description of role.
:rtype: str
"""
parameter = 'role-' + role.lower()
if self.configure.has_parameter(parameter):
... | python | def _get_role_description(self, role):
"""
Returns the description of role.
:param role: The role.
:type role: str
:return: The description of role.
:rtype: str
"""
parameter = 'role-' + role.lower()
if self.configure.has_parameter(parameter):
... | [
"def",
"_get_role_description",
"(",
"self",
",",
"role",
")",
":",
"parameter",
"=",
"'role-'",
"+",
"role",
".",
"lower",
"(",
")",
"if",
"self",
".",
"configure",
".",
"has_parameter",
"(",
"parameter",
")",
":",
"return",
"self",
".",
"configure",
".... | Returns the description of role.
:param role: The role.
:type role: str
:return: The description of role.
:rtype: str | [
"Returns",
"the",
"description",
"of",
"role",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L488-L501 | train | 57,673 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._get_language_description | def _get_language_description(self, language_code):
"""
Returns the description of language.
:param language_code: The BCP 47 code language.
:type language_code: str
:return: The description of language.
:rtype: str
"""
language = language_code.lower()
... | python | def _get_language_description(self, language_code):
"""
Returns the description of language.
:param language_code: The BCP 47 code language.
:type language_code: str
:return: The description of language.
:rtype: str
"""
language = language_code.lower()
... | [
"def",
"_get_language_description",
"(",
"self",
",",
"language_code",
")",
":",
"language",
"=",
"language_code",
".",
"lower",
"(",
")",
"parameter",
"=",
"'language-'",
"+",
"language",
"if",
"self",
".",
"configure",
".",
"has_parameter",
"(",
"parameter",
... | Returns the description of language.
:param language_code: The BCP 47 code language.
:type language_code: str
:return: The description of language.
:rtype: str | [
"Returns",
"the",
"description",
"of",
"language",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L503-L522 | train | 57,674 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._get_description | def _get_description(self, element):
"""
Returns the description of element.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:return: The description of element.
:rtype: str
"""
description = None
if e... | python | def _get_description(self, element):
"""
Returns the description of element.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:return: The description of element.
:rtype: str
"""
description = None
if e... | [
"def",
"_get_description",
"(",
"self",
",",
"element",
")",
":",
"description",
"=",
"None",
"if",
"element",
".",
"has_attribute",
"(",
"'title'",
")",
":",
"description",
"=",
"element",
".",
"get_attribute",
"(",
"'title'",
")",
"elif",
"element",
".",
... | Returns the description of element.
:param element: The element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:return: The description of element.
:rtype: str | [
"Returns",
"the",
"description",
"of",
"element",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L524-L580 | train | 57,675 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._generate_list_shortcuts | def _generate_list_shortcuts(self):
"""
Generate the list of shortcuts of page.
"""
id_container_shortcuts_before = (
AccessibleDisplayImplementation.ID_CONTAINER_SHORTCUTS_BEFORE
)
id_container_shortcuts_after = (
AccessibleDisplayImplementation.... | python | def _generate_list_shortcuts(self):
"""
Generate the list of shortcuts of page.
"""
id_container_shortcuts_before = (
AccessibleDisplayImplementation.ID_CONTAINER_SHORTCUTS_BEFORE
)
id_container_shortcuts_after = (
AccessibleDisplayImplementation.... | [
"def",
"_generate_list_shortcuts",
"(",
"self",
")",
":",
"id_container_shortcuts_before",
"=",
"(",
"AccessibleDisplayImplementation",
".",
"ID_CONTAINER_SHORTCUTS_BEFORE",
")",
"id_container_shortcuts_after",
"=",
"(",
"AccessibleDisplayImplementation",
".",
"ID_CONTAINER_SHORT... | Generate the list of shortcuts of page. | [
"Generate",
"the",
"list",
"of",
"shortcuts",
"of",
"page",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L582-L664 | train | 57,676 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._insert | def _insert(self, element, new_element, before):
"""
Insert a element before or after other element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param new_element: The element that be inserted.
:type new_element... | python | def _insert(self, element, new_element, before):
"""
Insert a element before or after other element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param new_element: The element that be inserted.
:type new_element... | [
"def",
"_insert",
"(",
"self",
",",
"element",
",",
"new_element",
",",
"before",
")",
":",
"tag_name",
"=",
"element",
".",
"get_tag_name",
"(",
")",
"append_tags",
"=",
"[",
"'BODY'",
",",
"'A'",
",",
"'FIGCAPTION'",
",",
"'LI'",
",",
"'DT'",
",",
"'... | Insert a element before or after other element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param new_element: The element that be inserted.
:type new_element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param bef... | [
"Insert",
"a",
"element",
"before",
"or",
"after",
"other",
"element",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L666-L718 | train | 57,677 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._force_read_simple | def _force_read_simple(self, element, text_before, text_after, data_of):
"""
Force the screen reader display an information of element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param text_before: The text content to ... | python | def _force_read_simple(self, element, text_before, text_after, data_of):
"""
Force the screen reader display an information of element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param text_before: The text content to ... | [
"def",
"_force_read_simple",
"(",
"self",
",",
"element",
",",
"text_before",
",",
"text_after",
",",
"data_of",
")",
":",
"self",
".",
"id_generator",
".",
"generate_id",
"(",
"element",
")",
"identifier",
"=",
"element",
".",
"get_attribute",
"(",
"'id'",
... | Force the screen reader display an information of element.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param text_before: The text content to show before the element.
:type text_before: str
:param text_after: The text c... | [
"Force",
"the",
"screen",
"reader",
"display",
"an",
"information",
"of",
"element",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L720-L779 | train | 57,678 |
hatemile/hatemile-for-python | hatemile/implementation/display.py | AccessibleDisplayImplementation._force_read | def _force_read(
self,
element,
value,
text_prefix_before,
text_suffix_before,
text_prefix_after,
text_suffix_after,
data_of
):
"""
Force the screen reader display an information of element with prefixes
or suffixes.
:p... | python | def _force_read(
self,
element,
value,
text_prefix_before,
text_suffix_before,
text_prefix_after,
text_suffix_after,
data_of
):
"""
Force the screen reader display an information of element with prefixes
or suffixes.
:p... | [
"def",
"_force_read",
"(",
"self",
",",
"element",
",",
"value",
",",
"text_prefix_before",
",",
"text_suffix_before",
",",
"text_prefix_after",
",",
"text_suffix_after",
",",
"data_of",
")",
":",
"if",
"(",
"text_prefix_before",
")",
"or",
"(",
"text_suffix_befor... | Force the screen reader display an information of element with prefixes
or suffixes.
:param element: The reference element.
:type element: hatemile.util.html.htmldomelement.HTMLDOMElement
:param value: The value to be show.
:type value: str
:param text_prefix_before: The... | [
"Force",
"the",
"screen",
"reader",
"display",
"an",
"information",
"of",
"element",
"with",
"prefixes",
"or",
"suffixes",
"."
] | 1e914f9aa09f6f8d78282af131311546ecba9fb8 | https://github.com/hatemile/hatemile-for-python/blob/1e914f9aa09f6f8d78282af131311546ecba9fb8/hatemile/implementation/display.py#L781-L824 | train | 57,679 |
anlutro/diay.py | diay/__init__.py | provider | def provider(func=None, *, singleton=False, injector=None):
"""
Decorator to mark a function as a provider.
Args:
singleton (bool): The returned value should be a singleton or shared
instance. If False (the default) the provider function will be
invoked again for every time ... | python | def provider(func=None, *, singleton=False, injector=None):
"""
Decorator to mark a function as a provider.
Args:
singleton (bool): The returned value should be a singleton or shared
instance. If False (the default) the provider function will be
invoked again for every time ... | [
"def",
"provider",
"(",
"func",
"=",
"None",
",",
"*",
",",
"singleton",
"=",
"False",
",",
"injector",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"wrapped",
"=",
"_wrap_provider_func",
"(",
"func",
",",
"{",
"'singleton'",
":",
... | Decorator to mark a function as a provider.
Args:
singleton (bool): The returned value should be a singleton or shared
instance. If False (the default) the provider function will be
invoked again for every time it's needed for injection.
injector (Injector): If provided, the... | [
"Decorator",
"to",
"mark",
"a",
"function",
"as",
"a",
"provider",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L21-L45 | train | 57,680 |
anlutro/diay.py | diay/__init__.py | inject | def inject(*args, **kwargs):
"""
Mark a class or function for injection, meaning that a DI container knows
that it should inject dependencies into it.
Normally you won't need this as the injector will inject the required
arguments anyway, but it can be used to inject properties into a class
wit... | python | def inject(*args, **kwargs):
"""
Mark a class or function for injection, meaning that a DI container knows
that it should inject dependencies into it.
Normally you won't need this as the injector will inject the required
arguments anyway, but it can be used to inject properties into a class
wit... | [
"def",
"inject",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"wrapper",
"(",
"obj",
")",
":",
"if",
"inspect",
".",
"isclass",
"(",
"obj",
")",
"or",
"callable",
"(",
"obj",
")",
":",
"_inject_object",
"(",
"obj",
",",
"*",
"args"... | Mark a class or function for injection, meaning that a DI container knows
that it should inject dependencies into it.
Normally you won't need this as the injector will inject the required
arguments anyway, but it can be used to inject properties into a class
without having to specify it in the construc... | [
"Mark",
"a",
"class",
"or",
"function",
"for",
"injection",
"meaning",
"that",
"a",
"DI",
"container",
"knows",
"that",
"it",
"should",
"inject",
"dependencies",
"into",
"it",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L55-L75 | train | 57,681 |
anlutro/diay.py | diay/__init__.py | Injector.register_plugin | def register_plugin(self, plugin: Plugin):
"""
Register a plugin.
"""
if isinstance(plugin, Plugin):
lazy = False
elif issubclass(plugin, Plugin):
lazy = True
else:
msg = 'plugin %r must be an object/class of type Plugin' % plugin
... | python | def register_plugin(self, plugin: Plugin):
"""
Register a plugin.
"""
if isinstance(plugin, Plugin):
lazy = False
elif issubclass(plugin, Plugin):
lazy = True
else:
msg = 'plugin %r must be an object/class of type Plugin' % plugin
... | [
"def",
"register_plugin",
"(",
"self",
",",
"plugin",
":",
"Plugin",
")",
":",
"if",
"isinstance",
"(",
"plugin",
",",
"Plugin",
")",
":",
"lazy",
"=",
"False",
"elif",
"issubclass",
"(",
"plugin",
",",
"Plugin",
")",
":",
"lazy",
"=",
"True",
"else",
... | Register a plugin. | [
"Register",
"a",
"plugin",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L93-L112 | train | 57,682 |
anlutro/diay.py | diay/__init__.py | Injector.register_provider | def register_provider(self, func):
"""
Register a provider function.
"""
if 'provides' not in getattr(func, '__di__', {}):
raise DiayException('function %r is not a provider' % func)
self.factories[func.__di__['provides']] = func | python | def register_provider(self, func):
"""
Register a provider function.
"""
if 'provides' not in getattr(func, '__di__', {}):
raise DiayException('function %r is not a provider' % func)
self.factories[func.__di__['provides']] = func | [
"def",
"register_provider",
"(",
"self",
",",
"func",
")",
":",
"if",
"'provides'",
"not",
"in",
"getattr",
"(",
"func",
",",
"'__di__'",
",",
"{",
"}",
")",
":",
"raise",
"DiayException",
"(",
"'function %r is not a provider'",
"%",
"func",
")",
"self",
"... | Register a provider function. | [
"Register",
"a",
"provider",
"function",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L114-L121 | train | 57,683 |
anlutro/diay.py | diay/__init__.py | Injector.register_lazy_provider_method | def register_lazy_provider_method(self, cls, method):
"""
Register a class method lazily as a provider.
"""
if 'provides' not in getattr(method, '__di__', {}):
raise DiayException('method %r is not a provider' % method)
@functools.wraps(method)
def wrapper(*a... | python | def register_lazy_provider_method(self, cls, method):
"""
Register a class method lazily as a provider.
"""
if 'provides' not in getattr(method, '__di__', {}):
raise DiayException('method %r is not a provider' % method)
@functools.wraps(method)
def wrapper(*a... | [
"def",
"register_lazy_provider_method",
"(",
"self",
",",
"cls",
",",
"method",
")",
":",
"if",
"'provides'",
"not",
"in",
"getattr",
"(",
"method",
",",
"'__di__'",
",",
"{",
"}",
")",
":",
"raise",
"DiayException",
"(",
"'method %r is not a provider'",
"%",
... | Register a class method lazily as a provider. | [
"Register",
"a",
"class",
"method",
"lazily",
"as",
"a",
"provider",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L123-L134 | train | 57,684 |
anlutro/diay.py | diay/__init__.py | Injector.set_factory | def set_factory(self, thing: type, value, overwrite=False):
"""
Set the factory for something.
"""
if thing in self.factories and not overwrite:
raise DiayException('factory for %r already exists' % thing)
self.factories[thing] = value | python | def set_factory(self, thing: type, value, overwrite=False):
"""
Set the factory for something.
"""
if thing in self.factories and not overwrite:
raise DiayException('factory for %r already exists' % thing)
self.factories[thing] = value | [
"def",
"set_factory",
"(",
"self",
",",
"thing",
":",
"type",
",",
"value",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"thing",
"in",
"self",
".",
"factories",
"and",
"not",
"overwrite",
":",
"raise",
"DiayException",
"(",
"'factory for %r already exist... | Set the factory for something. | [
"Set",
"the",
"factory",
"for",
"something",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L136-L142 | train | 57,685 |
anlutro/diay.py | diay/__init__.py | Injector.set_instance | def set_instance(self, thing: type, value, overwrite=False):
"""
Set an instance of a thing.
"""
if thing in self.instances and not overwrite:
raise DiayException('instance for %r already exists' % thing)
self.instances[thing] = value | python | def set_instance(self, thing: type, value, overwrite=False):
"""
Set an instance of a thing.
"""
if thing in self.instances and not overwrite:
raise DiayException('instance for %r already exists' % thing)
self.instances[thing] = value | [
"def",
"set_instance",
"(",
"self",
",",
"thing",
":",
"type",
",",
"value",
",",
"overwrite",
"=",
"False",
")",
":",
"if",
"thing",
"in",
"self",
".",
"instances",
"and",
"not",
"overwrite",
":",
"raise",
"DiayException",
"(",
"'instance for %r already exi... | Set an instance of a thing. | [
"Set",
"an",
"instance",
"of",
"a",
"thing",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L144-L150 | train | 57,686 |
anlutro/diay.py | diay/__init__.py | Injector.get | def get(self, thing: type):
"""
Get an instance of some type.
"""
if thing in self.instances:
return self.instances[thing]
if thing in self.factories:
fact = self.factories[thing]
ret = self.get(fact)
if hasattr(fact, '__di__') and... | python | def get(self, thing: type):
"""
Get an instance of some type.
"""
if thing in self.instances:
return self.instances[thing]
if thing in self.factories:
fact = self.factories[thing]
ret = self.get(fact)
if hasattr(fact, '__di__') and... | [
"def",
"get",
"(",
"self",
",",
"thing",
":",
"type",
")",
":",
"if",
"thing",
"in",
"self",
".",
"instances",
":",
"return",
"self",
".",
"instances",
"[",
"thing",
"]",
"if",
"thing",
"in",
"self",
".",
"factories",
":",
"fact",
"=",
"self",
".",... | Get an instance of some type. | [
"Get",
"an",
"instance",
"of",
"some",
"type",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L152-L171 | train | 57,687 |
anlutro/diay.py | diay/__init__.py | Injector.call | def call(self, func, *args, **kwargs):
"""
Call a function, resolving any type-hinted arguments.
"""
guessed_kwargs = self._guess_kwargs(func)
for key, val in guessed_kwargs.items():
kwargs.setdefault(key, val)
try:
return func(*args, **kwargs)
... | python | def call(self, func, *args, **kwargs):
"""
Call a function, resolving any type-hinted arguments.
"""
guessed_kwargs = self._guess_kwargs(func)
for key, val in guessed_kwargs.items():
kwargs.setdefault(key, val)
try:
return func(*args, **kwargs)
... | [
"def",
"call",
"(",
"self",
",",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"guessed_kwargs",
"=",
"self",
".",
"_guess_kwargs",
"(",
"func",
")",
"for",
"key",
",",
"val",
"in",
"guessed_kwargs",
".",
"items",
"(",
")",
":",
"kwa... | Call a function, resolving any type-hinted arguments. | [
"Call",
"a",
"function",
"resolving",
"any",
"type",
"-",
"hinted",
"arguments",
"."
] | 78cfd2b53c8dca3dbac468d620eaa0bb7af08275 | https://github.com/anlutro/diay.py/blob/78cfd2b53c8dca3dbac468d620eaa0bb7af08275/diay/__init__.py#L173-L187 | train | 57,688 |
dariusbakunas/rawdisk | rawdisk/ui/cli/cli_mode.py | CliShell.do_load | def do_load(self, filename):
"""Load disk image for analysis"""
try:
self.__session.load(filename)
except IOError as e:
self.logger.error(e.strerror) | python | def do_load(self, filename):
"""Load disk image for analysis"""
try:
self.__session.load(filename)
except IOError as e:
self.logger.error(e.strerror) | [
"def",
"do_load",
"(",
"self",
",",
"filename",
")",
":",
"try",
":",
"self",
".",
"__session",
".",
"load",
"(",
"filename",
")",
"except",
"IOError",
"as",
"e",
":",
"self",
".",
"logger",
".",
"error",
"(",
"e",
".",
"strerror",
")"
] | Load disk image for analysis | [
"Load",
"disk",
"image",
"for",
"analysis"
] | 1dc9d0b377fe5da3c406ccec4abc238c54167403 | https://github.com/dariusbakunas/rawdisk/blob/1dc9d0b377fe5da3c406ccec4abc238c54167403/rawdisk/ui/cli/cli_mode.py#L69-L74 | train | 57,689 |
dariusbakunas/rawdisk | rawdisk/ui/cli/cli_mode.py | CliShell.do_session | def do_session(self, args):
"""Print current session information"""
filename = 'Not specified' if self.__session.filename is None \
else self.__session.filename
print('{0: <30}: {1}'.format('Filename', filename)) | python | def do_session(self, args):
"""Print current session information"""
filename = 'Not specified' if self.__session.filename is None \
else self.__session.filename
print('{0: <30}: {1}'.format('Filename', filename)) | [
"def",
"do_session",
"(",
"self",
",",
"args",
")",
":",
"filename",
"=",
"'Not specified'",
"if",
"self",
".",
"__session",
".",
"filename",
"is",
"None",
"else",
"self",
".",
"__session",
".",
"filename",
"print",
"(",
"'{0: <30}: {1}'",
".",
"format",
"... | Print current session information | [
"Print",
"current",
"session",
"information"
] | 1dc9d0b377fe5da3c406ccec4abc238c54167403 | https://github.com/dariusbakunas/rawdisk/blob/1dc9d0b377fe5da3c406ccec4abc238c54167403/rawdisk/ui/cli/cli_mode.py#L76-L81 | train | 57,690 |
thomasw/querylist | querylist/list.py | QueryList._convert_iterable | def _convert_iterable(self, iterable):
"""Converts elements returned by an iterable into instances of
self._wrapper
"""
# Return original if _wrapper isn't callable
if not callable(self._wrapper):
return iterable
return [self._wrapper(x) for x in iterable] | python | def _convert_iterable(self, iterable):
"""Converts elements returned by an iterable into instances of
self._wrapper
"""
# Return original if _wrapper isn't callable
if not callable(self._wrapper):
return iterable
return [self._wrapper(x) for x in iterable] | [
"def",
"_convert_iterable",
"(",
"self",
",",
"iterable",
")",
":",
"# Return original if _wrapper isn't callable",
"if",
"not",
"callable",
"(",
"self",
".",
"_wrapper",
")",
":",
"return",
"iterable",
"return",
"[",
"self",
".",
"_wrapper",
"(",
"x",
")",
"f... | Converts elements returned by an iterable into instances of
self._wrapper | [
"Converts",
"elements",
"returned",
"by",
"an",
"iterable",
"into",
"instances",
"of",
"self",
".",
"_wrapper"
] | 4304023ef3330238ef3abccaa530ee97011fba2d | https://github.com/thomasw/querylist/blob/4304023ef3330238ef3abccaa530ee97011fba2d/querylist/list.py#L59-L68 | train | 57,691 |
thomasw/querylist | querylist/list.py | QueryList.get | def get(self, **kwargs):
"""Returns the first object encountered that matches the specified
lookup parameters.
>>> site_list.get(id=1)
{'url': 'http://site1.tld/', 'published': False, 'id': 1}
>>> site_list.get(published=True, id__lt=3)
{'url': 'http://site1.tld/', 'publ... | python | def get(self, **kwargs):
"""Returns the first object encountered that matches the specified
lookup parameters.
>>> site_list.get(id=1)
{'url': 'http://site1.tld/', 'published': False, 'id': 1}
>>> site_list.get(published=True, id__lt=3)
{'url': 'http://site1.tld/', 'publ... | [
"def",
"get",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"x",
"in",
"self",
":",
"if",
"self",
".",
"_check_element",
"(",
"kwargs",
",",
"x",
")",
":",
"return",
"x",
"kv_str",
"=",
"self",
".",
"_stringify_kwargs",
"(",
"kwargs",
")",... | Returns the first object encountered that matches the specified
lookup parameters.
>>> site_list.get(id=1)
{'url': 'http://site1.tld/', 'published': False, 'id': 1}
>>> site_list.get(published=True, id__lt=3)
{'url': 'http://site1.tld/', 'published': True, 'id': 2}
>>> s... | [
"Returns",
"the",
"first",
"object",
"encountered",
"that",
"matches",
"the",
"specified",
"lookup",
"parameters",
"."
] | 4304023ef3330238ef3abccaa530ee97011fba2d | https://github.com/thomasw/querylist/blob/4304023ef3330238ef3abccaa530ee97011fba2d/querylist/list.py#L81-L113 | train | 57,692 |
dnif/fnExchange | fnexchange/cli.py | runserver | def runserver(ctx, conf, port, foreground):
"""Run the fnExchange server"""
config = read_config(conf)
debug = config['conf'].get('debug', False)
click.echo('Debug mode {0}.'.format('on' if debug else 'off'))
port = port or config['conf']['server']['port']
app_settings = {
'debug': de... | python | def runserver(ctx, conf, port, foreground):
"""Run the fnExchange server"""
config = read_config(conf)
debug = config['conf'].get('debug', False)
click.echo('Debug mode {0}.'.format('on' if debug else 'off'))
port = port or config['conf']['server']['port']
app_settings = {
'debug': de... | [
"def",
"runserver",
"(",
"ctx",
",",
"conf",
",",
"port",
",",
"foreground",
")",
":",
"config",
"=",
"read_config",
"(",
"conf",
")",
"debug",
"=",
"config",
"[",
"'conf'",
"]",
".",
"get",
"(",
"'debug'",
",",
"False",
")",
"click",
".",
"echo",
... | Run the fnExchange server | [
"Run",
"the",
"fnExchange",
"server"
] | d75431b37da3193447b919b4be2e0104266156f1 | https://github.com/dnif/fnExchange/blob/d75431b37da3193447b919b4be2e0104266156f1/fnexchange/cli.py#L99-L120 | train | 57,693 |
helixyte/everest | everest/repositories/utils.py | as_repository | def as_repository(resource):
"""
Adapts the given registered resource to its configured repository.
:return: object implementing
:class:`everest.repositories.interfaces.IRepository`.
"""
reg = get_current_registry()
if IInterface in provided_by(resource):
resource = reg.getUtility... | python | def as_repository(resource):
"""
Adapts the given registered resource to its configured repository.
:return: object implementing
:class:`everest.repositories.interfaces.IRepository`.
"""
reg = get_current_registry()
if IInterface in provided_by(resource):
resource = reg.getUtility... | [
"def",
"as_repository",
"(",
"resource",
")",
":",
"reg",
"=",
"get_current_registry",
"(",
")",
"if",
"IInterface",
"in",
"provided_by",
"(",
"resource",
")",
":",
"resource",
"=",
"reg",
".",
"getUtility",
"(",
"resource",
",",
"name",
"=",
"'collection-cl... | Adapts the given registered resource to its configured repository.
:return: object implementing
:class:`everest.repositories.interfaces.IRepository`. | [
"Adapts",
"the",
"given",
"registered",
"resource",
"to",
"its",
"configured",
"repository",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/repositories/utils.py#L78-L88 | train | 57,694 |
helixyte/everest | everest/repositories/utils.py | commit_veto | def commit_veto(request, response): # unused request arg pylint: disable=W0613
"""
Strict commit veto to use with the transaction manager.
Unlike the default commit veto supplied with the transaction manager,
this will veto all commits for HTTP status codes other than 2xx unless
a commit is explici... | python | def commit_veto(request, response): # unused request arg pylint: disable=W0613
"""
Strict commit veto to use with the transaction manager.
Unlike the default commit veto supplied with the transaction manager,
this will veto all commits for HTTP status codes other than 2xx unless
a commit is explici... | [
"def",
"commit_veto",
"(",
"request",
",",
"response",
")",
":",
"# unused request arg pylint: disable=W0613",
"tm_header",
"=",
"response",
".",
"headers",
".",
"get",
"(",
"'x-tm'",
")",
"if",
"not",
"tm_header",
"is",
"None",
":",
"result",
"=",
"tm_header",
... | Strict commit veto to use with the transaction manager.
Unlike the default commit veto supplied with the transaction manager,
this will veto all commits for HTTP status codes other than 2xx unless
a commit is explicitly requested by setting the "x-tm" response header to
"commit". As with the default co... | [
"Strict",
"commit",
"veto",
"to",
"use",
"with",
"the",
"transaction",
"manager",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/repositories/utils.py#L91-L107 | train | 57,695 |
helixyte/everest | everest/repositories/utils.py | GlobalObjectManager.set | def set(cls, key, obj):
"""
Sets the given object as global object for the given key.
"""
with cls._lock:
if not cls._globs.get(key) is None:
raise ValueError('Duplicate key "%s".' % key)
cls._globs[key] = obj
return cls._globs[key] | python | def set(cls, key, obj):
"""
Sets the given object as global object for the given key.
"""
with cls._lock:
if not cls._globs.get(key) is None:
raise ValueError('Duplicate key "%s".' % key)
cls._globs[key] = obj
return cls._globs[key] | [
"def",
"set",
"(",
"cls",
",",
"key",
",",
"obj",
")",
":",
"with",
"cls",
".",
"_lock",
":",
"if",
"not",
"cls",
".",
"_globs",
".",
"get",
"(",
"key",
")",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'Duplicate key \"%s\".'",
"%",
"key",
")",... | Sets the given object as global object for the given key. | [
"Sets",
"the",
"given",
"object",
"as",
"global",
"object",
"for",
"the",
"given",
"key",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/repositories/utils.py#L30-L38 | train | 57,696 |
helixyte/everest | everest/representers/utils.py | as_representer | def as_representer(resource, content_type):
"""
Adapts the given resource and content type to a representer.
:param resource: resource to adapt.
:param str content_type: content (MIME) type to obtain a representer for.
"""
reg = get_current_registry()
rpr_reg = reg.queryUtility(IRepresenter... | python | def as_representer(resource, content_type):
"""
Adapts the given resource and content type to a representer.
:param resource: resource to adapt.
:param str content_type: content (MIME) type to obtain a representer for.
"""
reg = get_current_registry()
rpr_reg = reg.queryUtility(IRepresenter... | [
"def",
"as_representer",
"(",
"resource",
",",
"content_type",
")",
":",
"reg",
"=",
"get_current_registry",
"(",
")",
"rpr_reg",
"=",
"reg",
".",
"queryUtility",
"(",
"IRepresenterRegistry",
")",
"return",
"rpr_reg",
".",
"create",
"(",
"type",
"(",
"resource... | Adapts the given resource and content type to a representer.
:param resource: resource to adapt.
:param str content_type: content (MIME) type to obtain a representer for. | [
"Adapts",
"the",
"given",
"resource",
"and",
"content",
"type",
"to",
"a",
"representer",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/representers/utils.py#L29-L38 | train | 57,697 |
helixyte/everest | everest/representers/utils.py | data_element_tree_to_string | def data_element_tree_to_string(data_element):
"""
Creates a string representation of the given data element tree.
"""
# FIXME: rewrite this as a visitor to use the data element tree traverser.
def __dump(data_el, stream, offset):
name = data_el.__class__.__name__
stream.write("%s%s"... | python | def data_element_tree_to_string(data_element):
"""
Creates a string representation of the given data element tree.
"""
# FIXME: rewrite this as a visitor to use the data element tree traverser.
def __dump(data_el, stream, offset):
name = data_el.__class__.__name__
stream.write("%s%s"... | [
"def",
"data_element_tree_to_string",
"(",
"data_element",
")",
":",
"# FIXME: rewrite this as a visitor to use the data element tree traverser.",
"def",
"__dump",
"(",
"data_el",
",",
"stream",
",",
"offset",
")",
":",
"name",
"=",
"data_el",
".",
"__class__",
".",
"__... | Creates a string representation of the given data element tree. | [
"Creates",
"a",
"string",
"representation",
"of",
"the",
"given",
"data",
"element",
"tree",
"."
] | 70c9b93c3061db5cb62428349d18b8fb8566411b | https://github.com/helixyte/everest/blob/70c9b93c3061db5cb62428349d18b8fb8566411b/everest/representers/utils.py#L53-L98 | train | 57,698 |
pbrisk/timewave | timewave/consumers.py | ConsumerConsumer.initialize_path | def initialize_path(self, path_num=None):
"""
make the consumer_state ready for the next MC path
:param int path_num:
"""
for c in self.consumers:
c.initialize_path(path_num)
self.state = [c.state for c in self.consumers] | python | def initialize_path(self, path_num=None):
"""
make the consumer_state ready for the next MC path
:param int path_num:
"""
for c in self.consumers:
c.initialize_path(path_num)
self.state = [c.state for c in self.consumers] | [
"def",
"initialize_path",
"(",
"self",
",",
"path_num",
"=",
"None",
")",
":",
"for",
"c",
"in",
"self",
".",
"consumers",
":",
"c",
".",
"initialize_path",
"(",
"path_num",
")",
"self",
".",
"state",
"=",
"[",
"c",
".",
"state",
"for",
"c",
"in",
... | make the consumer_state ready for the next MC path
:param int path_num: | [
"make",
"the",
"consumer_state",
"ready",
"for",
"the",
"next",
"MC",
"path"
] | cf641391d1607a424042724c8b990d43ee270ef6 | https://github.com/pbrisk/timewave/blob/cf641391d1607a424042724c8b990d43ee270ef6/timewave/consumers.py#L148-L156 | train | 57,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.