repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
sixty-north/asq | asq/queryables.py | Queryable.last_or_default | def last_or_default(self, default, predicate=None):
'''The last element (optionally satisfying a predicate) or a default.
If the predicate is omitted or is None this query returns the last
element in the sequence; otherwise, it returns the last element in
the sequence for which the pred... | python | def last_or_default(self, default, predicate=None):
'''The last element (optionally satisfying a predicate) or a default.
If the predicate is omitted or is None this query returns the last
element in the sequence; otherwise, it returns the last element in
the sequence for which the pred... | [
"def",
"last_or_default",
"(",
"self",
",",
"default",
",",
"predicate",
"=",
"None",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call last_or_default() on a \"",
"\"closed Queryable.\"",
")",
"return",
"self",
... | The last element (optionally satisfying a predicate) or a default.
If the predicate is omitted or is None this query returns the last
element in the sequence; otherwise, it returns the last element in
the sequence for which the predicate evaluates to True. If there is no
such element th... | [
"The",
"last",
"element",
"(",
"optionally",
"satisfying",
"a",
"predicate",
")",
"or",
"a",
"default",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L1828-L1861 |
sixty-north/asq | asq/queryables.py | Queryable.aggregate | def aggregate(self, reducer, seed=default, result_selector=identity):
'''Apply a function over a sequence to produce a single result.
Apply a binary function cumulatively to the elements of the source
sequence so as to reduce the iterable to a single value.
Note: This method uses immed... | python | def aggregate(self, reducer, seed=default, result_selector=identity):
'''Apply a function over a sequence to produce a single result.
Apply a binary function cumulatively to the elements of the source
sequence so as to reduce the iterable to a single value.
Note: This method uses immed... | [
"def",
"aggregate",
"(",
"self",
",",
"reducer",
",",
"seed",
"=",
"default",
",",
"result_selector",
"=",
"identity",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call aggregate() on a \"",
"\"closed Queryable.... | Apply a function over a sequence to produce a single result.
Apply a binary function cumulatively to the elements of the source
sequence so as to reduce the iterable to a single value.
Note: This method uses immediate execution.
Args:
reducer: A binary function the first p... | [
"Apply",
"a",
"function",
"over",
"a",
"sequence",
"to",
"produce",
"a",
"single",
"result",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L1904-L1951 |
sixty-north/asq | asq/queryables.py | Queryable.zip | def zip(self, second_iterable, result_selector=lambda x, y: (x, y)):
'''Elementwise combination of two sequences.
The source sequence and the second iterable are merged element-by-
element using a function to combine them into the single corresponding
element of the result sequence. The... | python | def zip(self, second_iterable, result_selector=lambda x, y: (x, y)):
'''Elementwise combination of two sequences.
The source sequence and the second iterable are merged element-by-
element using a function to combine them into the single corresponding
element of the result sequence. The... | [
"def",
"zip",
"(",
"self",
",",
"second_iterable",
",",
"result_selector",
"=",
"lambda",
"x",
",",
"y",
":",
"(",
"x",
",",
"y",
")",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call zip() on a closed ... | Elementwise combination of two sequences.
The source sequence and the second iterable are merged element-by-
element using a function to combine them into the single corresponding
element of the result sequence. The length of the result sequence is
equal to the length of the shorter of ... | [
"Elementwise",
"combination",
"of",
"two",
"sequences",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L1953-L1993 |
sixty-north/asq | asq/queryables.py | Queryable.to_list | def to_list(self):
'''Convert the source sequence to a list.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_list() on a closed Queryable.")
# Maybe use with closable(self) construct to achieve this.
if ... | python | def to_list(self):
'''Convert the source sequence to a list.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_list() on a closed Queryable.")
# Maybe use with closable(self) construct to achieve this.
if ... | [
"def",
"to_list",
"(",
"self",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_list() on a closed Queryable.\"",
")",
"# Maybe use with closable(self) construct to achieve this.",
"if",
"isinstance",
"(",
"self",
"... | Convert the source sequence to a list.
Note: This method uses immediate execution. | [
"Convert",
"the",
"source",
"sequence",
"to",
"a",
"list",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L1995-L2009 |
sixty-north/asq | asq/queryables.py | Queryable.to_tuple | def to_tuple(self):
'''Convert the source sequence to a tuple.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_tuple() on a closed Queryable.")
if isinstance(self._iterable, tuple):
return self._iter... | python | def to_tuple(self):
'''Convert the source sequence to a tuple.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_tuple() on a closed Queryable.")
if isinstance(self._iterable, tuple):
return self._iter... | [
"def",
"to_tuple",
"(",
"self",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_tuple() on a closed Queryable.\"",
")",
"if",
"isinstance",
"(",
"self",
".",
"_iterable",
",",
"tuple",
")",
":",
"return",... | Convert the source sequence to a tuple.
Note: This method uses immediate execution. | [
"Convert",
"the",
"source",
"sequence",
"to",
"a",
"tuple",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2011-L2024 |
sixty-north/asq | asq/queryables.py | Queryable.to_set | def to_set(self):
'''Convert the source sequence to a set.
Note: This method uses immediate execution.
Raises:
ValueError: If duplicate keys are in the projected source sequence.
ValueError: If the Queryable is closed().
'''
if self.closed():
... | python | def to_set(self):
'''Convert the source sequence to a set.
Note: This method uses immediate execution.
Raises:
ValueError: If duplicate keys are in the projected source sequence.
ValueError: If the Queryable is closed().
'''
if self.closed():
... | [
"def",
"to_set",
"(",
"self",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_set() on a closed Queryable.\"",
")",
"if",
"isinstance",
"(",
"self",
".",
"_iterable",
",",
"set",
")",
":",
"return",
"se... | Convert the source sequence to a set.
Note: This method uses immediate execution.
Raises:
ValueError: If duplicate keys are in the projected source sequence.
ValueError: If the Queryable is closed(). | [
"Convert",
"the",
"source",
"sequence",
"to",
"a",
"set",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2026-L2048 |
sixty-north/asq | asq/queryables.py | Queryable.to_lookup | def to_lookup(self, key_selector=identity, value_selector=identity):
'''Returns a Lookup object, using the provided selector to generate a
key for each item.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_lookup... | python | def to_lookup(self, key_selector=identity, value_selector=identity):
'''Returns a Lookup object, using the provided selector to generate a
key for each item.
Note: This method uses immediate execution.
'''
if self.closed():
raise ValueError("Attempt to call to_lookup... | [
"def",
"to_lookup",
"(",
"self",
",",
"key_selector",
"=",
"identity",
",",
"value_selector",
"=",
"identity",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_lookup() on a closed Queryable.\"",
")",
"if",
... | Returns a Lookup object, using the provided selector to generate a
key for each item.
Note: This method uses immediate execution. | [
"Returns",
"a",
"Lookup",
"object",
"using",
"the",
"provided",
"selector",
"to",
"generate",
"a",
"key",
"for",
"each",
"item",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2050-L2071 |
sixty-north/asq | asq/queryables.py | Queryable.to_dictionary | def to_dictionary(self, key_selector=identity, value_selector=identity):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key is the item itself.
value_selector: A unary callable... | python | def to_dictionary(self, key_selector=identity, value_selector=identity):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key is the item itself.
value_selector: A unary callable... | [
"def",
"to_dictionary",
"(",
"self",
",",
"key_selector",
"=",
"identity",
",",
"value_selector",
"=",
"identity",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_dictionary() on a closed Queryable.\"",
")",
... | Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key is the item itself.
value_selector: A unary callable to extract a value from each item.
By default the value is the item... | [
"Build",
"a",
"dictionary",
"from",
"the",
"source",
"sequence",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2073-L2104 |
sixty-north/asq | asq/queryables.py | Queryable.to_str | def to_str(self, separator=''):
'''Build a string from the source sequence.
The elements of the query result will each coerced to a string and then
the resulting strings concatenated to return a single string. This
allows the natural processing of character sequences as strings. An
... | python | def to_str(self, separator=''):
'''Build a string from the source sequence.
The elements of the query result will each coerced to a string and then
the resulting strings concatenated to return a single string. This
allows the natural processing of character sequences as strings. An
... | [
"def",
"to_str",
"(",
"self",
",",
"separator",
"=",
"''",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_str() on a closed Queryable.\"",
")",
"return",
"str",
"(",
"separator",
")",
".",
"join",
"(",... | Build a string from the source sequence.
The elements of the query result will each coerced to a string and then
the resulting strings concatenated to return a single string. This
allows the natural processing of character sequences as strings. An
optional separator which will be insert... | [
"Build",
"a",
"string",
"from",
"the",
"source",
"sequence",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2106-L2133 |
sixty-north/asq | asq/queryables.py | Queryable.sequence_equal | def sequence_equal(self, second_iterable, equality_comparer=operator.eq):
'''
Determine whether two sequences are equal by elementwise comparison.
Sequence equality is defined as the two sequences being equal length
and corresponding elements being equal as determined by the equality
... | python | def sequence_equal(self, second_iterable, equality_comparer=operator.eq):
'''
Determine whether two sequences are equal by elementwise comparison.
Sequence equality is defined as the two sequences being equal length
and corresponding elements being equal as determined by the equality
... | [
"def",
"sequence_equal",
"(",
"self",
",",
"second_iterable",
",",
"equality_comparer",
"=",
"operator",
".",
"eq",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call to_tuple() on a closed Queryable.\"",
")",
"if"... | Determine whether two sequences are equal by elementwise comparison.
Sequence equality is defined as the two sequences being equal length
and corresponding elements being equal as determined by the equality
comparer.
Note: This method uses immediate execution.
Args:
... | [
"Determine",
"whether",
"two",
"sequences",
"are",
"equal",
"by",
"elementwise",
"comparison",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2135-L2189 |
sixty-north/asq | asq/queryables.py | Queryable.log | def log(self, logger=None, label=None, eager=False):
'''
Log query result consumption details to a logger.
Args:
logger: Any object which supports a debug() method which accepts a
str, such as a Python standard library logger object from the
logging m... | python | def log(self, logger=None, label=None, eager=False):
'''
Log query result consumption details to a logger.
Args:
logger: Any object which supports a debug() method which accepts a
str, such as a Python standard library logger object from the
logging m... | [
"def",
"log",
"(",
"self",
",",
"logger",
"=",
"None",
",",
"label",
"=",
"None",
",",
"eager",
"=",
"False",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call log() on a closed Queryable.\"",
")",
"if",
... | Log query result consumption details to a logger.
Args:
logger: Any object which supports a debug() method which accepts a
str, such as a Python standard library logger object from the
logging module. If logger is not provided or is None, this
method... | [
"Log",
"query",
"result",
"consumption",
"details",
"to",
"a",
"logger",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2213-L2254 |
sixty-north/asq | asq/queryables.py | Queryable.scan | def scan(self, func=operator.add):
'''
An inclusive prefix sum which returns the cumulative application of the
supplied function up to an including the current element.
Args:
func: An optional binary function which is commutative - that is,
the order of the... | python | def scan(self, func=operator.add):
'''
An inclusive prefix sum which returns the cumulative application of the
supplied function up to an including the current element.
Args:
func: An optional binary function which is commutative - that is,
the order of the... | [
"def",
"scan",
"(",
"self",
",",
"func",
"=",
"operator",
".",
"add",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call scan() on a \"",
"\"closed Queryable.\"",
")",
"if",
"not",
"is_callable",
"(",
"func",... | An inclusive prefix sum which returns the cumulative application of the
supplied function up to an including the current element.
Args:
func: An optional binary function which is commutative - that is,
the order of the arguments is unimportant. Defaults to a
... | [
"An",
"inclusive",
"prefix",
"sum",
"which",
"returns",
"the",
"cumulative",
"application",
"of",
"the",
"supplied",
"function",
"up",
"to",
"an",
"including",
"the",
"current",
"element",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2295-L2321 |
sixty-north/asq | asq/queryables.py | Queryable.pre_scan | def pre_scan(self, func=operator.add, seed=0):
'''
An exclusive prefix sum which returns the cumulative application of the
supplied function up to but excluding the current element.
Args:
func: An optional binary function which is commutative - that is,
the... | python | def pre_scan(self, func=operator.add, seed=0):
'''
An exclusive prefix sum which returns the cumulative application of the
supplied function up to but excluding the current element.
Args:
func: An optional binary function which is commutative - that is,
the... | [
"def",
"pre_scan",
"(",
"self",
",",
"func",
"=",
"operator",
".",
"add",
",",
"seed",
"=",
"0",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call pre_scan() on a \"",
"\"closed Queryable.\"",
")",
"if",
"... | An exclusive prefix sum which returns the cumulative application of the
supplied function up to but excluding the current element.
Args:
func: An optional binary function which is commutative - that is,
the order of the arguments is unimportant. Defaults to a
... | [
"An",
"exclusive",
"prefix",
"sum",
"which",
"returns",
"the",
"cumulative",
"application",
"of",
"the",
"supplied",
"function",
"up",
"to",
"but",
"excluding",
"the",
"current",
"element",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2337-L2366 |
sixty-north/asq | asq/queryables.py | OrderedQueryable.then_by | def then_by(self, key_selector=identity):
'''Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary func... | python | def then_by(self, key_selector=identity):
'''Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary func... | [
"def",
"then_by",
"(",
"self",
",",
"key_selector",
"=",
"identity",
")",
":",
"if",
"self",
".",
"closed",
"(",
")",
":",
"raise",
"ValueError",
"(",
"\"Attempt to call then_by() on a \"",
"\"closed OrderedQueryable.\"",
")",
"if",
"not",
"is_callable",
"(",
"k... | Introduce subsequent ordering to the sequence with an optional key.
The returned sequence will be sorted in ascending order by the
selected key.
Note: This method uses deferred execution.
Args:
key_selector: A unary function the only positional argument to
... | [
"Introduce",
"subsequent",
"ordering",
"to",
"the",
"sequence",
"with",
"an",
"optional",
"key",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2526-L2556 |
sixty-north/asq | asq/queryables.py | Lookup.to_dictionary | def to_dictionary(
self,
key_selector=lambda item: item.key,
value_selector=list):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key of the Grouping.
... | python | def to_dictionary(
self,
key_selector=lambda item: item.key,
value_selector=list):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key of the Grouping.
... | [
"def",
"to_dictionary",
"(",
"self",
",",
"key_selector",
"=",
"lambda",
"item",
":",
"item",
".",
"key",
",",
"value_selector",
"=",
"list",
")",
":",
"return",
"super",
"(",
"Lookup",
",",
"self",
")",
".",
"to_dictionary",
"(",
"key_selector",
",",
"v... | Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item.
By default the key of the Grouping.
value_selector: A unary callable to extract a value from each item.
By default the value is the list of... | [
"Build",
"a",
"dictionary",
"from",
"the",
"source",
"sequence",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2739-L2759 |
sixty-north/asq | asq/queryables.py | Grouping.to_dictionary | def to_dictionary(
self,
key_selector=None,
value_selector=None):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item or None.
If None, the default key selector produces a si... | python | def to_dictionary(
self,
key_selector=None,
value_selector=None):
"""Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item or None.
If None, the default key selector produces a si... | [
"def",
"to_dictionary",
"(",
"self",
",",
"key_selector",
"=",
"None",
",",
"value_selector",
"=",
"None",
")",
":",
"if",
"key_selector",
"is",
"None",
":",
"key_selector",
"=",
"lambda",
"_",
":",
"self",
".",
"key",
"if",
"value_selector",
"is",
"None",... | Build a dictionary from the source sequence.
Args:
key_selector: A unary callable to extract a key from each item or None.
If None, the default key selector produces a single dictionary key, which
if the key of this Grouping.
value_selector: A unary call... | [
"Build",
"a",
"dictionary",
"from",
"the",
"source",
"sequence",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/queryables.py#L2818-L2846 |
sixty-north/asq | asq/initiators.py | integers | def integers(start, count):
'''Generates in sequence the integral numbers within a range.
Note: This method uses deferred execution.
Args:
start: The first integer in the sequence.
count: The number of sequential integers to generate.
Returns:
A Queryable over the sp... | python | def integers(start, count):
'''Generates in sequence the integral numbers within a range.
Note: This method uses deferred execution.
Args:
start: The first integer in the sequence.
count: The number of sequential integers to generate.
Returns:
A Queryable over the sp... | [
"def",
"integers",
"(",
"start",
",",
"count",
")",
":",
"if",
"count",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"integers() count cannot be negative\"",
")",
"return",
"query",
"(",
"irange",
"(",
"start",
",",
"start",
"+",
"count",
")",
")"
] | Generates in sequence the integral numbers within a range.
Note: This method uses deferred execution.
Args:
start: The first integer in the sequence.
count: The number of sequential integers to generate.
Returns:
A Queryable over the specified range of integers.
Ra... | [
"Generates",
"in",
"sequence",
"the",
"integral",
"numbers",
"within",
"a",
"range",
".",
"Note",
":",
"This",
"method",
"uses",
"deferred",
"execution",
".",
"Args",
":",
"start",
":",
"The",
"first",
"integer",
"in",
"the",
"sequence",
".",
"count",
":",... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/initiators.py#L34-L51 |
sixty-north/asq | asq/initiators.py | repeat | def repeat(element, count):
'''Generate a sequence with one repeated value.
Note: This method uses deferred execution.
Args:
element: The value to be repeated.
count: The number of times to repeat the value.
Raises:
ValueError: If the count is negative.
'''
... | python | def repeat(element, count):
'''Generate a sequence with one repeated value.
Note: This method uses deferred execution.
Args:
element: The value to be repeated.
count: The number of times to repeat the value.
Raises:
ValueError: If the count is negative.
'''
... | [
"def",
"repeat",
"(",
"element",
",",
"count",
")",
":",
"if",
"count",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"repeat() count cannot be negative\"",
")",
"return",
"query",
"(",
"itertools",
".",
"repeat",
"(",
"element",
",",
"count",
")",
")"
] | Generate a sequence with one repeated value.
Note: This method uses deferred execution.
Args:
element: The value to be repeated.
count: The number of times to repeat the value.
Raises:
ValueError: If the count is negative. | [
"Generate",
"a",
"sequence",
"with",
"one",
"repeated",
"value",
".",
"Note",
":",
"This",
"method",
"uses",
"deferred",
"execution",
".",
"Args",
":",
"element",
":",
"The",
"value",
"to",
"be",
"repeated",
".",
"count",
":",
"The",
"number",
"of",
"tim... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/initiators.py#L54-L68 |
sixty-north/asq | asq/parallel_queryable.py | geometric_partitions | def geometric_partitions(iterable, floor=1, ceiling=32768):
'''
Partition an iterable into chunks. Returns an iterator over partitions.
'''
partition_size = floor
run_length = multiprocessing.cpu_count()
run_count = 0
try:
while True:
#print("partition_size ="... | python | def geometric_partitions(iterable, floor=1, ceiling=32768):
'''
Partition an iterable into chunks. Returns an iterator over partitions.
'''
partition_size = floor
run_length = multiprocessing.cpu_count()
run_count = 0
try:
while True:
#print("partition_size ="... | [
"def",
"geometric_partitions",
"(",
"iterable",
",",
"floor",
"=",
"1",
",",
"ceiling",
"=",
"32768",
")",
":",
"partition_size",
"=",
"floor",
"run_length",
"=",
"multiprocessing",
".",
"cpu_count",
"(",
")",
"run_count",
"=",
"0",
"try",
":",
"while",
"T... | Partition an iterable into chunks. Returns an iterator over partitions. | [
"Partition",
"an",
"iterable",
"into",
"chunks",
".",
"Returns",
"an",
"iterator",
"over",
"partitions",
"."
] | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L268-L303 |
sixty-north/asq | asq/parallel_queryable.py | ParallelQueryable.select | def select(self, selector):
'''Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector... | python | def select(self, selector):
'''Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector... | [
"def",
"select",
"(",
"self",
",",
"selector",
")",
":",
"return",
"self",
".",
"_create",
"(",
"self",
".",
"_pool",
".",
"imap_unordered",
"(",
"selector",
",",
"iter",
"(",
"self",
")",
",",
"self",
".",
"_chunksize",
")",
")"
] | Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector: A unary function mapping a value in th... | [
"Transforms",
"each",
"element",
"of",
"a",
"sequence",
"into",
"a",
"new",
"form",
".",
"Each",
"element",
"is",
"transformed",
"through",
"a",
"selector",
"function",
"to",
"produce",
"a",
"value",
"for",
"each",
"value",
"in",
"the",
"source",
"sequence",... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L51-L75 |
sixty-north/asq | asq/parallel_queryable.py | ParallelQueryable.select_with_index | def select_with_index(self, selector):
'''Transforms each element of a sequence into a new form, incorporating
the index of the element.
Each element is transformed through a selector function which accepts
the element value and its zero-based index in the source sequence. The
... | python | def select_with_index(self, selector):
'''Transforms each element of a sequence into a new form, incorporating
the index of the element.
Each element is transformed through a selector function which accepts
the element value and its zero-based index in the source sequence. The
... | [
"def",
"select_with_index",
"(",
"self",
",",
"selector",
")",
":",
"return",
"self",
".",
"_create",
"(",
"self",
".",
"_pool",
".",
"imap_unordered",
"(",
"star",
",",
"zip",
"(",
"itertools",
".",
"repeat",
"(",
"selector",
")",
",",
"enumerate",
"(",... | Transforms each element of a sequence into a new form, incorporating
the index of the element.
Each element is transformed through a selector function which accepts
the element value and its zero-based index in the source sequence. The
generated sequence is lazily evaluated.
... | [
"Transforms",
"each",
"element",
"of",
"a",
"sequence",
"into",
"a",
"new",
"form",
"incorporating",
"the",
"index",
"of",
"the",
"element",
".",
"Each",
"element",
"is",
"transformed",
"through",
"a",
"selector",
"function",
"which",
"accepts",
"the",
"elemen... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L77-L106 |
sixty-north/asq | asq/parallel_queryable.py | ParallelQueryable.select_many | def select_many(self, projector, selector=identity):
'''Projects each element of a sequence to an intermediate new sequence,
flattens the resulting sequence into one sequence and optionally
transforms the flattened sequence using a selector function.
Args:
projector: A... | python | def select_many(self, projector, selector=identity):
'''Projects each element of a sequence to an intermediate new sequence,
flattens the resulting sequence into one sequence and optionally
transforms the flattened sequence using a selector function.
Args:
projector: A... | [
"def",
"select_many",
"(",
"self",
",",
"projector",
",",
"selector",
"=",
"identity",
")",
":",
"sequences",
"=",
"(",
"self",
".",
"_create",
"(",
"item",
")",
".",
"select",
"(",
"projector",
")",
"for",
"item",
"in",
"iter",
"(",
"self",
")",
")"... | Projects each element of a sequence to an intermediate new sequence,
flattens the resulting sequence into one sequence and optionally
transforms the flattened sequence using a selector function.
Args:
projector: A unary function mapping each element of the source
... | [
"Projects",
"each",
"element",
"of",
"a",
"sequence",
"to",
"an",
"intermediate",
"new",
"sequence",
"flattens",
"the",
"resulting",
"sequence",
"into",
"one",
"sequence",
"and",
"optionally",
"transforms",
"the",
"flattened",
"sequence",
"using",
"a",
"selector",... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L108-L150 |
sixty-north/asq | asq/parallel_queryable.py | OrderedParallelQueryable.select | def select(self, selector):
'''Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector... | python | def select(self, selector):
'''Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector... | [
"def",
"select",
"(",
"self",
",",
"selector",
")",
":",
"return",
"self",
".",
"create",
"(",
"self",
".",
"_pool",
".",
"imap",
"(",
"selector",
",",
"iter",
"(",
"self",
")",
",",
"self",
".",
"_chunksize",
")",
")"
] | Transforms each element of a sequence into a new form.
Each element is transformed through a selector function to produce a
value for each value in the source sequence. The generated sequence is
lazily evaluated.
Args:
selector: A unary function mapping a value in th... | [
"Transforms",
"each",
"element",
"of",
"a",
"sequence",
"into",
"a",
"new",
"form",
".",
"Each",
"element",
"is",
"transformed",
"through",
"a",
"selector",
"function",
"to",
"produce",
"a",
"value",
"for",
"each",
"value",
"in",
"the",
"source",
"sequence",... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/parallel_queryable.py#L210-L233 |
sixty-north/asq | asq/selectors.py | make_selector | def make_selector(value):
'''Create a selector callable from the supplied value.
Args:
value: If is a callable, then returned unchanged. If a string is used
then create an attribute selector. If in an integer is used then
create a key selector.
Returns:
A ... | python | def make_selector(value):
'''Create a selector callable from the supplied value.
Args:
value: If is a callable, then returned unchanged. If a string is used
then create an attribute selector. If in an integer is used then
create a key selector.
Returns:
A ... | [
"def",
"make_selector",
"(",
"value",
")",
":",
"if",
"is_callable",
"(",
"value",
")",
":",
"return",
"value",
"if",
"is_string",
"(",
"value",
")",
":",
"return",
"a_",
"(",
"value",
")",
"raise",
"ValueError",
"(",
"\"Unable to create callable selector from... | Create a selector callable from the supplied value.
Args:
value: If is a callable, then returned unchanged. If a string is used
then create an attribute selector. If in an integer is used then
create a key selector.
Returns:
A callable selector based on the sup... | [
"Create",
"a",
"selector",
"callable",
"from",
"the",
"supplied",
"value",
".",
"Args",
":",
"value",
":",
"If",
"is",
"a",
"callable",
"then",
"returned",
"unchanged",
".",
"If",
"a",
"string",
"is",
"used",
"then",
"create",
"an",
"attribute",
"selector"... | train | https://github.com/sixty-north/asq/blob/db0c4cbcf2118435136d4b63c62a12711441088e/asq/selectors.py#L89-L107 |
leonardt/hwtypes | hwtypes/bit_vector.py | BitVector.adc | def adc(self, other : 'BitVector', carry : Bit) -> tp.Tuple['BitVector', Bit]:
"""
add with carry
returns a two element tuple of the form (result, carry)
"""
T = type(self)
other = _coerce(T, other)
carry = _coerce(T.unsized_t[1], carry)
a = self.zext(1... | python | def adc(self, other : 'BitVector', carry : Bit) -> tp.Tuple['BitVector', Bit]:
"""
add with carry
returns a two element tuple of the form (result, carry)
"""
T = type(self)
other = _coerce(T, other)
carry = _coerce(T.unsized_t[1], carry)
a = self.zext(1... | [
"def",
"adc",
"(",
"self",
",",
"other",
":",
"'BitVector'",
",",
"carry",
":",
"Bit",
")",
"->",
"tp",
".",
"Tuple",
"[",
"'BitVector'",
",",
"Bit",
"]",
":",
"T",
"=",
"type",
"(",
"self",
")",
"other",
"=",
"_coerce",
"(",
"T",
",",
"other",
... | add with carry
returns a two element tuple of the form (result, carry) | [
"add",
"with",
"carry"
] | train | https://github.com/leonardt/hwtypes/blob/65439bb5e1d8f9afa7852c00a8378b622a9f986e/hwtypes/bit_vector.py#L273-L289 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/types.py | ExpandPath.convert | def convert(self, value, *args, **kwargs): # pylint: disable=arguments-differ
"""Take a path with $HOME variables and resolve it to full path."""
value = os.path.expanduser(value)
return super(ExpandPath, self).convert(value, *args, **kwargs) | python | def convert(self, value, *args, **kwargs): # pylint: disable=arguments-differ
"""Take a path with $HOME variables and resolve it to full path."""
value = os.path.expanduser(value)
return super(ExpandPath, self).convert(value, *args, **kwargs) | [
"def",
"convert",
"(",
"self",
",",
"value",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# pylint: disable=arguments-differ",
"value",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"value",
")",
"return",
"super",
"(",
"ExpandPath",
",",
"sel... | Take a path with $HOME variables and resolve it to full path. | [
"Take",
"a",
"path",
"with",
"$HOME",
"variables",
"and",
"resolve",
"it",
"to",
"full",
"path",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/types.py#L13-L16 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/table.py | make_table | def make_table(headers=None, rows=None):
"""Make a table from headers and rows."""
if callable(headers):
headers = headers()
if callable(rows):
rows = rows()
assert isinstance(headers, list)
assert isinstance(rows, list)
assert all(len(row) == len(headers) for row in rows)
p... | python | def make_table(headers=None, rows=None):
"""Make a table from headers and rows."""
if callable(headers):
headers = headers()
if callable(rows):
rows = rows()
assert isinstance(headers, list)
assert isinstance(rows, list)
assert all(len(row) == len(headers) for row in rows)
p... | [
"def",
"make_table",
"(",
"headers",
"=",
"None",
",",
"rows",
"=",
"None",
")",
":",
"if",
"callable",
"(",
"headers",
")",
":",
"headers",
"=",
"headers",
"(",
")",
"if",
"callable",
"(",
"rows",
")",
":",
"rows",
"=",
"rows",
"(",
")",
"assert",... | Make a table from headers and rows. | [
"Make",
"a",
"table",
"from",
"headers",
"and",
"rows",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/table.py#L17-L62 |
venmo/slouch | slouch/__init__.py | _dual_decorator | def _dual_decorator(func):
"""This is a decorator that converts a paramaterized decorator for
no-param use.
source: http://stackoverflow.com/questions/3888158
"""
@functools.wraps(func)
def inner(*args, **kwargs):
if ((len(args) == 1 and not kwargs and callable(args[0])
an... | python | def _dual_decorator(func):
"""This is a decorator that converts a paramaterized decorator for
no-param use.
source: http://stackoverflow.com/questions/3888158
"""
@functools.wraps(func)
def inner(*args, **kwargs):
if ((len(args) == 1 and not kwargs and callable(args[0])
an... | [
"def",
"_dual_decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"inner",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"(",
"(",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"not",
"kwargs",
... | This is a decorator that converts a paramaterized decorator for
no-param use.
source: http://stackoverflow.com/questions/3888158 | [
"This",
"is",
"a",
"decorator",
"that",
"converts",
"a",
"paramaterized",
"decorator",
"for",
"no",
"-",
"param",
"use",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L20-L36 |
venmo/slouch | slouch/__init__.py | help | def help(opts, bot, _):
"""Usage: help [<command>]
With no arguments, print the form of all supported commands.
With an argument, print a detailed explanation of a command.
"""
command = opts['<command>']
if command is None:
return bot.help_text()
if command not in bot.commands:
... | python | def help(opts, bot, _):
"""Usage: help [<command>]
With no arguments, print the form of all supported commands.
With an argument, print a detailed explanation of a command.
"""
command = opts['<command>']
if command is None:
return bot.help_text()
if command not in bot.commands:
... | [
"def",
"help",
"(",
"opts",
",",
"bot",
",",
"_",
")",
":",
"command",
"=",
"opts",
"[",
"'<command>'",
"]",
"if",
"command",
"is",
"None",
":",
"return",
"bot",
".",
"help_text",
"(",
")",
"if",
"command",
"not",
"in",
"bot",
".",
"commands",
":",... | Usage: help [<command>]
With no arguments, print the form of all supported commands.
With an argument, print a detailed explanation of a command. | [
"Usage",
":",
"help",
"[",
"<command",
">",
"]"
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L39-L52 |
venmo/slouch | slouch/__init__.py | Bot.command | def command(cls, name=None):
"""
A decorator to convert a function to a command.
A command's docstring must be a docopt usage string.
See docopt.org for what it supports.
Commands receive three arguments:
* opts: a dictionary output by docopt
* bot: the Bot... | python | def command(cls, name=None):
"""
A decorator to convert a function to a command.
A command's docstring must be a docopt usage string.
See docopt.org for what it supports.
Commands receive three arguments:
* opts: a dictionary output by docopt
* bot: the Bot... | [
"def",
"command",
"(",
"cls",
",",
"name",
"=",
"None",
")",
":",
"# adapted from https://github.com/docopt/docopt/blob/master/examples/interactive_example.py",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"_cmd... | A decorator to convert a function to a command.
A command's docstring must be a docopt usage string.
See docopt.org for what it supports.
Commands receive three arguments:
* opts: a dictionary output by docopt
* bot: the Bot instance handling the command (eg for storing st... | [
"A",
"decorator",
"to",
"convert",
"a",
"function",
"to",
"a",
"command",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L83-L129 |
venmo/slouch | slouch/__init__.py | Bot.help_text | def help_text(cls):
"""Return a slack-formatted list of commands with their usage."""
docs = [cmd_func.__doc__ for cmd_func in cls.commands.values()]
# Don't want to include 'usage: ' or explanation.
usage_lines = [doc.partition('\n')[0] for doc in docs]
terse_lines = [line[len(... | python | def help_text(cls):
"""Return a slack-formatted list of commands with their usage."""
docs = [cmd_func.__doc__ for cmd_func in cls.commands.values()]
# Don't want to include 'usage: ' or explanation.
usage_lines = [doc.partition('\n')[0] for doc in docs]
terse_lines = [line[len(... | [
"def",
"help_text",
"(",
"cls",
")",
":",
"docs",
"=",
"[",
"cmd_func",
".",
"__doc__",
"for",
"cmd_func",
"in",
"cls",
".",
"commands",
".",
"values",
"(",
")",
"]",
"# Don't want to include 'usage: ' or explanation.",
"usage_lines",
"=",
"[",
"doc",
".",
"... | Return a slack-formatted list of commands with their usage. | [
"Return",
"a",
"slack",
"-",
"formatted",
"list",
"of",
"commands",
"with",
"their",
"usage",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L132-L140 |
venmo/slouch | slouch/__init__.py | Bot.run_forever | def run_forever(self):
"""Run the bot, blocking forever."""
res = self.slack.rtm.start()
self.log.info("current channels: %s",
','.join(c['name'] for c in res.body['channels']
if c['is_member']))
self.id = res.body['self']['id']
... | python | def run_forever(self):
"""Run the bot, blocking forever."""
res = self.slack.rtm.start()
self.log.info("current channels: %s",
','.join(c['name'] for c in res.body['channels']
if c['is_member']))
self.id = res.body['self']['id']
... | [
"def",
"run_forever",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"slack",
".",
"rtm",
".",
"start",
"(",
")",
"self",
".",
"log",
".",
"info",
"(",
"\"current channels: %s\"",
",",
"','",
".",
"join",
"(",
"c",
"[",
"'name'",
"]",
"for",
"c",
... | Run the bot, blocking forever. | [
"Run",
"the",
"bot",
"blocking",
"forever",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L199-L216 |
venmo/slouch | slouch/__init__.py | Bot._bot_identifier | def _bot_identifier(self, message):
"""Return the identifier used to address this bot in this message.
If one is not found, return None.
:param message: a message dict from the slack api.
"""
text = message['text']
formatters = [
lambda identifier: "%s " % ... | python | def _bot_identifier(self, message):
"""Return the identifier used to address this bot in this message.
If one is not found, return None.
:param message: a message dict from the slack api.
"""
text = message['text']
formatters = [
lambda identifier: "%s " % ... | [
"def",
"_bot_identifier",
"(",
"self",
",",
"message",
")",
":",
"text",
"=",
"message",
"[",
"'text'",
"]",
"formatters",
"=",
"[",
"lambda",
"identifier",
":",
"\"%s \"",
"%",
"identifier",
",",
"lambda",
"identifier",
":",
"\"%s:\"",
"%",
"identifier",
... | Return the identifier used to address this bot in this message.
If one is not found, return None.
:param message: a message dict from the slack api. | [
"Return",
"the",
"identifier",
"used",
"to",
"address",
"this",
"bot",
"in",
"this",
"message",
".",
"If",
"one",
"is",
"not",
"found",
"return",
"None",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L218-L238 |
venmo/slouch | slouch/__init__.py | Bot._handle_command_response | def _handle_command_response(self, res, event):
"""Either send a message (choosing between rtm and postMessage) or ignore the response.
:param event: a slacker event dict
:param res: a string, a dict, or None.
See the command docstring for what these represent.
"""
re... | python | def _handle_command_response(self, res, event):
"""Either send a message (choosing between rtm and postMessage) or ignore the response.
:param event: a slacker event dict
:param res: a string, a dict, or None.
See the command docstring for what these represent.
"""
re... | [
"def",
"_handle_command_response",
"(",
"self",
",",
"res",
",",
"event",
")",
":",
"response_handler",
"=",
"None",
"if",
"isinstance",
"(",
"res",
",",
"basestring",
")",
":",
"response_handler",
"=",
"functools",
".",
"partial",
"(",
"self",
".",
"_send_r... | Either send a message (choosing between rtm and postMessage) or ignore the response.
:param event: a slacker event dict
:param res: a string, a dict, or None.
See the command docstring for what these represent. | [
"Either",
"send",
"a",
"message",
"(",
"choosing",
"between",
"rtm",
"and",
"postMessage",
")",
"or",
"ignore",
"the",
"response",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L240-L256 |
venmo/slouch | slouch/__init__.py | Bot._handle_long_response | def _handle_long_response(self, res):
"""Splits messages that are too long into multiple events
:param res: a slack response string or dict
"""
is_rtm_message = isinstance(res, basestring)
is_api_message = isinstance(res, dict)
if is_rtm_message:
text = res
... | python | def _handle_long_response(self, res):
"""Splits messages that are too long into multiple events
:param res: a slack response string or dict
"""
is_rtm_message = isinstance(res, basestring)
is_api_message = isinstance(res, dict)
if is_rtm_message:
text = res
... | [
"def",
"_handle_long_response",
"(",
"self",
",",
"res",
")",
":",
"is_rtm_message",
"=",
"isinstance",
"(",
"res",
",",
"basestring",
")",
"is_api_message",
"=",
"isinstance",
"(",
"res",
",",
"dict",
")",
"if",
"is_rtm_message",
":",
"text",
"=",
"res",
... | Splits messages that are too long into multiple events
:param res: a slack response string or dict | [
"Splits",
"messages",
"that",
"are",
"too",
"long",
"into",
"multiple",
"events",
":",
"param",
"res",
":",
"a",
"slack",
"response",
"string",
"or",
"dict"
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L258-L301 |
venmo/slouch | slouch/__init__.py | Bot._send_rtm_message | def _send_rtm_message(self, channel_id, text):
"""Send a Slack message to a channel over RTM.
:param channel_id: a slack channel id.
:param text: a slack message. Serverside formatting is done
in a similar way to normal user message; see
`Slack's docs <https://api.slack.com/... | python | def _send_rtm_message(self, channel_id, text):
"""Send a Slack message to a channel over RTM.
:param channel_id: a slack channel id.
:param text: a slack message. Serverside formatting is done
in a similar way to normal user message; see
`Slack's docs <https://api.slack.com/... | [
"def",
"_send_rtm_message",
"(",
"self",
",",
"channel_id",
",",
"text",
")",
":",
"message",
"=",
"{",
"'id'",
":",
"self",
".",
"_current_message_id",
",",
"'type'",
":",
"'message'",
",",
"'channel'",
":",
"channel_id",
",",
"'text'",
":",
"text",
",",
... | Send a Slack message to a channel over RTM.
:param channel_id: a slack channel id.
:param text: a slack message. Serverside formatting is done
in a similar way to normal user message; see
`Slack's docs <https://api.slack.com/docs/formatting>`__. | [
"Send",
"a",
"Slack",
"message",
"to",
"a",
"channel",
"over",
"RTM",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L303-L319 |
venmo/slouch | slouch/__init__.py | Bot._send_api_message | def _send_api_message(self, message):
"""Send a Slack message via the chat.postMessage api.
:param message: a dict of kwargs to be passed to slacker.
"""
self.slack.chat.post_message(**message)
self.log.debug("sent api message %r", message) | python | def _send_api_message(self, message):
"""Send a Slack message via the chat.postMessage api.
:param message: a dict of kwargs to be passed to slacker.
"""
self.slack.chat.post_message(**message)
self.log.debug("sent api message %r", message) | [
"def",
"_send_api_message",
"(",
"self",
",",
"message",
")",
":",
"self",
".",
"slack",
".",
"chat",
".",
"post_message",
"(",
"*",
"*",
"message",
")",
"self",
".",
"log",
".",
"debug",
"(",
"\"sent api message %r\"",
",",
"message",
")"
] | Send a Slack message via the chat.postMessage api.
:param message: a dict of kwargs to be passed to slacker. | [
"Send",
"a",
"Slack",
"message",
"via",
"the",
"chat",
".",
"postMessage",
"api",
"."
] | train | https://github.com/venmo/slouch/blob/000b03bc220a0d7aa5b06f59caf423e2b63a81d7/slouch/__init__.py#L321-L328 |
marrow/schema | marrow/schema/validate/compound.py | Compound._validators | def _validators(self):
"""Iterate across the complete set of child validators."""
for validator in self.__validators__.values():
yield validator
if self.validators:
for validator in self.validators:
yield validator | python | def _validators(self):
"""Iterate across the complete set of child validators."""
for validator in self.__validators__.values():
yield validator
if self.validators:
for validator in self.validators:
yield validator | [
"def",
"_validators",
"(",
"self",
")",
":",
"for",
"validator",
"in",
"self",
".",
"__validators__",
".",
"values",
"(",
")",
":",
"yield",
"validator",
"if",
"self",
".",
"validators",
":",
"for",
"validator",
"in",
"self",
".",
"validators",
":",
"yie... | Iterate across the complete set of child validators. | [
"Iterate",
"across",
"the",
"complete",
"set",
"of",
"child",
"validators",
"."
] | train | https://github.com/marrow/schema/blob/0c4c3e3b8c79d8bfeb8d7265cfa5b12a2e643152/marrow/schema/validate/compound.py#L24-L32 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | make_user_agent | def make_user_agent(prefix=None):
"""Get a suitable user agent for identifying the CLI process."""
prefix = (prefix or platform.platform(terse=1)).strip().lower()
return "cloudsmith-cli/%(prefix)s cli:%(version)s api:%(api_version)s" % {
"version": get_cli_version(),
"api_version": get_api_v... | python | def make_user_agent(prefix=None):
"""Get a suitable user agent for identifying the CLI process."""
prefix = (prefix or platform.platform(terse=1)).strip().lower()
return "cloudsmith-cli/%(prefix)s cli:%(version)s api:%(api_version)s" % {
"version": get_cli_version(),
"api_version": get_api_v... | [
"def",
"make_user_agent",
"(",
"prefix",
"=",
"None",
")",
":",
"prefix",
"=",
"(",
"prefix",
"or",
"platform",
".",
"platform",
"(",
"terse",
"=",
"1",
")",
")",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
"return",
"\"cloudsmith-cli/%(prefix)s cli:... | Get a suitable user agent for identifying the CLI process. | [
"Get",
"a",
"suitable",
"user",
"agent",
"for",
"identifying",
"the",
"CLI",
"process",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L18-L25 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | pretty_print_list_info | def pretty_print_list_info(num_results, page_info=None, suffix=None):
"""Pretty print list info, with pagination, for user display."""
num_results_fg = "green" if num_results else "red"
num_results_text = click.style(str(num_results), fg=num_results_fg)
if page_info and page_info.is_valid:
page... | python | def pretty_print_list_info(num_results, page_info=None, suffix=None):
"""Pretty print list info, with pagination, for user display."""
num_results_fg = "green" if num_results else "red"
num_results_text = click.style(str(num_results), fg=num_results_fg)
if page_info and page_info.is_valid:
page... | [
"def",
"pretty_print_list_info",
"(",
"num_results",
",",
"page_info",
"=",
"None",
",",
"suffix",
"=",
"None",
")",
":",
"num_results_fg",
"=",
"\"green\"",
"if",
"num_results",
"else",
"\"red\"",
"num_results_text",
"=",
"click",
".",
"style",
"(",
"str",
"(... | Pretty print list info, with pagination, for user display. | [
"Pretty",
"print",
"list",
"info",
"with",
"pagination",
"for",
"user",
"display",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L28-L57 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | pretty_print_table | def pretty_print_table(headers, rows):
"""Pretty print a table from headers and rows."""
table = make_table(headers=headers, rows=rows)
pretty_print_table_instance(table) | python | def pretty_print_table(headers, rows):
"""Pretty print a table from headers and rows."""
table = make_table(headers=headers, rows=rows)
pretty_print_table_instance(table) | [
"def",
"pretty_print_table",
"(",
"headers",
",",
"rows",
")",
":",
"table",
"=",
"make_table",
"(",
"headers",
"=",
"headers",
",",
"rows",
"=",
"rows",
")",
"pretty_print_table_instance",
"(",
"table",
")"
] | Pretty print a table from headers and rows. | [
"Pretty",
"print",
"a",
"table",
"from",
"headers",
"and",
"rows",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L60-L63 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | pretty_print_table_instance | def pretty_print_table_instance(table):
"""Pretty print a table instance."""
assert isinstance(table, Table)
def pretty_print_row(styled, plain):
"""Pretty print a row."""
click.secho(
" | ".join(
v + " " * (table.column_widths[k] - len(plain[k]))
... | python | def pretty_print_table_instance(table):
"""Pretty print a table instance."""
assert isinstance(table, Table)
def pretty_print_row(styled, plain):
"""Pretty print a row."""
click.secho(
" | ".join(
v + " " * (table.column_widths[k] - len(plain[k]))
... | [
"def",
"pretty_print_table_instance",
"(",
"table",
")",
":",
"assert",
"isinstance",
"(",
"table",
",",
"Table",
")",
"def",
"pretty_print_row",
"(",
"styled",
",",
"plain",
")",
":",
"\"\"\"Pretty print a row.\"\"\"",
"click",
".",
"secho",
"(",
"\" | \"",
"."... | Pretty print a table instance. | [
"Pretty",
"print",
"a",
"table",
"instance",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L66-L81 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | print_rate_limit_info | def print_rate_limit_info(opts, rate_info, atexit=False):
"""Tell the user when we're being rate limited."""
if not rate_info:
return
show_info = (
opts.always_show_rate_limit
or atexit
or rate_info.interval > opts.rate_limit_warning
)
if not show_info:
retu... | python | def print_rate_limit_info(opts, rate_info, atexit=False):
"""Tell the user when we're being rate limited."""
if not rate_info:
return
show_info = (
opts.always_show_rate_limit
or atexit
or rate_info.interval > opts.rate_limit_warning
)
if not show_info:
retu... | [
"def",
"print_rate_limit_info",
"(",
"opts",
",",
"rate_info",
",",
"atexit",
"=",
"False",
")",
":",
"if",
"not",
"rate_info",
":",
"return",
"show_info",
"=",
"(",
"opts",
".",
"always_show_rate_limit",
"or",
"atexit",
"or",
"rate_info",
".",
"interval",
"... | Tell the user when we're being rate limited. | [
"Tell",
"the",
"user",
"when",
"we",
"re",
"being",
"rate",
"limited",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L84-L104 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | maybe_print_as_json | def maybe_print_as_json(opts, data, page_info=None):
"""Maybe print data as JSON."""
if opts.output not in ("json", "pretty_json"):
return False
root = {"data": data}
if page_info is not None and page_info.is_valid:
meta = root["meta"] = {}
meta["pagination"] = page_info.as_dic... | python | def maybe_print_as_json(opts, data, page_info=None):
"""Maybe print data as JSON."""
if opts.output not in ("json", "pretty_json"):
return False
root = {"data": data}
if page_info is not None and page_info.is_valid:
meta = root["meta"] = {}
meta["pagination"] = page_info.as_dic... | [
"def",
"maybe_print_as_json",
"(",
"opts",
",",
"data",
",",
"page_info",
"=",
"None",
")",
":",
"if",
"opts",
".",
"output",
"not",
"in",
"(",
"\"json\"",
",",
"\"pretty_json\"",
")",
":",
"return",
"False",
"root",
"=",
"{",
"\"data\"",
":",
"data",
... | Maybe print data as JSON. | [
"Maybe",
"print",
"data",
"as",
"JSON",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L107-L124 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/utils.py | confirm_operation | def confirm_operation(prompt, prefix=None, assume_yes=False, err=False):
"""Prompt the user for confirmation for dangerous actions."""
if assume_yes:
return True
prefix = prefix or click.style(
"Are you %s certain you want to" % (click.style("absolutely", bold=True))
)
prompt = "%(... | python | def confirm_operation(prompt, prefix=None, assume_yes=False, err=False):
"""Prompt the user for confirmation for dangerous actions."""
if assume_yes:
return True
prefix = prefix or click.style(
"Are you %s certain you want to" % (click.style("absolutely", bold=True))
)
prompt = "%(... | [
"def",
"confirm_operation",
"(",
"prompt",
",",
"prefix",
"=",
"None",
",",
"assume_yes",
"=",
"False",
",",
"err",
"=",
"False",
")",
":",
"if",
"assume_yes",
":",
"return",
"True",
"prefix",
"=",
"prefix",
"or",
"click",
".",
"style",
"(",
"\"Are you %... | Prompt the user for confirmation for dangerous actions. | [
"Prompt",
"the",
"user",
"for",
"confirmation",
"for",
"dangerous",
"actions",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/utils.py#L127-L143 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/token.py | validate_login | def validate_login(ctx, param, value):
"""Ensure that login is not blank."""
# pylint: disable=unused-argument
value = value.strip()
if not value:
raise click.BadParameter("The value cannot be blank.", param=param)
return value | python | def validate_login(ctx, param, value):
"""Ensure that login is not blank."""
# pylint: disable=unused-argument
value = value.strip()
if not value:
raise click.BadParameter("The value cannot be blank.", param=param)
return value | [
"def",
"validate_login",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"# pylint: disable=unused-argument",
"value",
"=",
"value",
".",
"strip",
"(",
")",
"if",
"not",
"value",
":",
"raise",
"click",
".",
"BadParameter",
"(",
"\"The value cannot be blank.\""... | Ensure that login is not blank. | [
"Ensure",
"that",
"login",
"is",
"not",
"blank",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/token.py#L22-L28 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/token.py | create_config_files | def create_config_files(ctx, opts, api_key):
"""Create default config files."""
# pylint: disable=unused-argument
config_reader = opts.get_config_reader()
creds_reader = opts.get_creds_reader()
has_config = config_reader.has_default_file()
has_creds = creds_reader.has_default_file()
if has_... | python | def create_config_files(ctx, opts, api_key):
"""Create default config files."""
# pylint: disable=unused-argument
config_reader = opts.get_config_reader()
creds_reader = opts.get_creds_reader()
has_config = config_reader.has_default_file()
has_creds = creds_reader.has_default_file()
if has_... | [
"def",
"create_config_files",
"(",
"ctx",
",",
"opts",
",",
"api_key",
")",
":",
"# pylint: disable=unused-argument",
"config_reader",
"=",
"opts",
".",
"get_config_reader",
"(",
")",
"creds_reader",
"=",
"opts",
".",
"get_creds_reader",
"(",
")",
"has_config",
"=... | Create default config files. | [
"Create",
"default",
"config",
"files",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/token.py#L31-L103 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/token.py | token | def token(ctx, opts, login, password):
"""Retrieve your API authentication token/key."""
click.echo(
"Retrieving API token for %(login)s ... "
% {"login": click.style(login, bold=True)},
nl=False,
)
context_msg = "Failed to retrieve the API token!"
with handle_api_exceptions... | python | def token(ctx, opts, login, password):
"""Retrieve your API authentication token/key."""
click.echo(
"Retrieving API token for %(login)s ... "
% {"login": click.style(login, bold=True)},
nl=False,
)
context_msg = "Failed to retrieve the API token!"
with handle_api_exceptions... | [
"def",
"token",
"(",
"ctx",
",",
"opts",
",",
"login",
",",
"password",
")",
":",
"click",
".",
"echo",
"(",
"\"Retrieving API token for %(login)s ... \"",
"%",
"{",
"\"login\"",
":",
"click",
".",
"style",
"(",
"login",
",",
"bold",
"=",
"True",
")",
"}... | Retrieve your API authentication token/key. | [
"Retrieve",
"your",
"API",
"authentication",
"token",
"/",
"key",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/token.py#L120-L167 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/status.py | status | def status(ctx, opts, owner_repo_package):
"""
Get the synchronisation status for a package.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'y... | python | def status(ctx, opts, owner_repo_package):
"""
Get the synchronisation status for a package.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'y... | [
"def",
"status",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_package",
")",
":",
"owner",
",",
"repo",
",",
"slug",
"=",
"owner_repo_package",
"click",
".",
"echo",
"(",
"\"Getting status of %(package)s in %(owner)s/%(repo)s ... \"",
"%",
"{",
"\"owner\"",
":",
"cli... | Get the synchronisation status for a package.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
package itself. All separated by a slash.
Example: 'your-org/awesome-repo/better-pkg'. | [
"Get",
"the",
"synchronisation",
"status",
"for",
"a",
"package",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/status.py#L25-L79 |
marrow/schema | marrow/schema/declarative.py | Container._process_arguments | def _process_arguments(self, args, kw):
"""Map positional to keyword arguments, identify invalid assignments, and return the result.
This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of
effort to ensure raised exceptions are as Python-like as possible.
"""... | python | def _process_arguments(self, args, kw):
"""Map positional to keyword arguments, identify invalid assignments, and return the result.
This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of
effort to ensure raised exceptions are as Python-like as possible.
"""... | [
"def",
"_process_arguments",
"(",
"self",
",",
"args",
",",
"kw",
")",
":",
"# Ensure we were not passed too many arguments.",
"if",
"len",
"(",
"args",
")",
">",
"len",
"(",
"self",
".",
"__attributes__",
")",
":",
"raise",
"TypeError",
"(",
"'{0} takes no more... | Map positional to keyword arguments, identify invalid assignments, and return the result.
This is likely generic enough to be useful as a standalone utility function, and goes to a fair amount of
effort to ensure raised exceptions are as Python-like as possible. | [
"Map",
"positional",
"to",
"keyword",
"arguments",
"identify",
"invalid",
"assignments",
"and",
"return",
"the",
"result",
".",
"This",
"is",
"likely",
"generic",
"enough",
"to",
"be",
"useful",
"as",
"a",
"standalone",
"utility",
"function",
"and",
"goes",
"t... | train | https://github.com/marrow/schema/blob/0c4c3e3b8c79d8bfeb8d7265cfa5b12a2e643152/marrow/schema/declarative.py#L51-L104 |
kalefranz/auxlib | auxlib/deprecation.py | import_and_wrap_deprecated | def import_and_wrap_deprecated(module_name, module_dict, warn_import=True):
"""
Usage:
import_and_wrap_deprecated('conda.common.connection', locals())
# looks for conda.common.connection.__all__
"""
if warn_import:
deprecated_import(module_name)
from importlib import import_... | python | def import_and_wrap_deprecated(module_name, module_dict, warn_import=True):
"""
Usage:
import_and_wrap_deprecated('conda.common.connection', locals())
# looks for conda.common.connection.__all__
"""
if warn_import:
deprecated_import(module_name)
from importlib import import_... | [
"def",
"import_and_wrap_deprecated",
"(",
"module_name",
",",
"module_dict",
",",
"warn_import",
"=",
"True",
")",
":",
"if",
"warn_import",
":",
"deprecated_import",
"(",
"module_name",
")",
"from",
"importlib",
"import",
"import_module",
"module",
"=",
"import_mod... | Usage:
import_and_wrap_deprecated('conda.common.connection', locals())
# looks for conda.common.connection.__all__ | [
"Usage",
":",
"import_and_wrap_deprecated",
"(",
"conda",
".",
"common",
".",
"connection",
"locals",
"()",
")",
"#",
"looks",
"for",
"conda",
".",
"common",
".",
"connection",
".",
"__all__"
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/deprecation.py#L39-L51 |
kalefranz/auxlib | auxlib/deprecation.py | deprecate_module_with_proxy | def deprecate_module_with_proxy(module_name, module_dict, deprecated_attributes=None):
"""
Usage:
deprecate_module_with_proxy(__name__, locals()) # at bottom of module
"""
def _ModuleProxy(module, depr):
"""Return a wrapped object that warns about deprecated accesses"""
# http:/... | python | def deprecate_module_with_proxy(module_name, module_dict, deprecated_attributes=None):
"""
Usage:
deprecate_module_with_proxy(__name__, locals()) # at bottom of module
"""
def _ModuleProxy(module, depr):
"""Return a wrapped object that warns about deprecated accesses"""
# http:/... | [
"def",
"deprecate_module_with_proxy",
"(",
"module_name",
",",
"module_dict",
",",
"deprecated_attributes",
"=",
"None",
")",
":",
"def",
"_ModuleProxy",
"(",
"module",
",",
"depr",
")",
":",
"\"\"\"Return a wrapped object that warns about deprecated accesses\"\"\"",
"# htt... | Usage:
deprecate_module_with_proxy(__name__, locals()) # at bottom of module | [
"Usage",
":",
"deprecate_module_with_proxy",
"(",
"__name__",
"locals",
"()",
")",
"#",
"at",
"bottom",
"of",
"module"
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/deprecation.py#L54-L85 |
marrow/schema | marrow/schema/transform/type.py | Boolean.native | def native(self, value, context=None):
"""Convert a foreign value to a native boolean."""
value = super().native(value, context)
if self.none and (value is None):
return None
try:
value = value.lower()
except AttributeError:
return bool(value)
if value in self.truthy:
return True
... | python | def native(self, value, context=None):
"""Convert a foreign value to a native boolean."""
value = super().native(value, context)
if self.none and (value is None):
return None
try:
value = value.lower()
except AttributeError:
return bool(value)
if value in self.truthy:
return True
... | [
"def",
"native",
"(",
"self",
",",
"value",
",",
"context",
"=",
"None",
")",
":",
"value",
"=",
"super",
"(",
")",
".",
"native",
"(",
"value",
",",
"context",
")",
"if",
"self",
".",
"none",
"and",
"(",
"value",
"is",
"None",
")",
":",
"return"... | Convert a foreign value to a native boolean. | [
"Convert",
"a",
"foreign",
"value",
"to",
"a",
"native",
"boolean",
"."
] | train | https://github.com/marrow/schema/blob/0c4c3e3b8c79d8bfeb8d7265cfa5b12a2e643152/marrow/schema/transform/type.py#L22-L41 |
marrow/schema | marrow/schema/transform/type.py | Boolean.foreign | def foreign(self, value, context=None):
"""Convert a native value to a textual boolean."""
if self.none and value is None:
return ''
try:
value = self.native(value, context)
except Concern:
# The value might not be in the lists; bool() evaluate it instead.
value = bool(value.strip() if self.st... | python | def foreign(self, value, context=None):
"""Convert a native value to a textual boolean."""
if self.none and value is None:
return ''
try:
value = self.native(value, context)
except Concern:
# The value might not be in the lists; bool() evaluate it instead.
value = bool(value.strip() if self.st... | [
"def",
"foreign",
"(",
"self",
",",
"value",
",",
"context",
"=",
"None",
")",
":",
"if",
"self",
".",
"none",
"and",
"value",
"is",
"None",
":",
"return",
"''",
"try",
":",
"value",
"=",
"self",
".",
"native",
"(",
"value",
",",
"context",
")",
... | Convert a native value to a textual boolean. | [
"Convert",
"a",
"native",
"value",
"to",
"a",
"textual",
"boolean",
"."
] | train | https://github.com/marrow/schema/blob/0c4c3e3b8c79d8bfeb8d7265cfa5b12a2e643152/marrow/schema/transform/type.py#L43-L58 |
cloudsmith-io/cloudsmith-cli | setup.py | get_root_path | def get_root_path():
"""Get the root path for the application."""
root_path = __file__
return os.path.dirname(os.path.realpath(root_path)) | python | def get_root_path():
"""Get the root path for the application."""
root_path = __file__
return os.path.dirname(os.path.realpath(root_path)) | [
"def",
"get_root_path",
"(",
")",
":",
"root_path",
"=",
"__file__",
"return",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"realpath",
"(",
"root_path",
")",
")"
] | Get the root path for the application. | [
"Get",
"the",
"root",
"path",
"for",
"the",
"application",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/setup.py#L10-L13 |
cloudsmith-io/cloudsmith-cli | setup.py | read | def read(path, root_path=None):
"""Read the specific file into a string in its entirety."""
try:
root_path = root_path or get_root_path()
real_path = os.path.realpath(os.path.join(root_path, path))
with open(real_path) as fp:
return fp.read().strip()
except IOError:
... | python | def read(path, root_path=None):
"""Read the specific file into a string in its entirety."""
try:
root_path = root_path or get_root_path()
real_path = os.path.realpath(os.path.join(root_path, path))
with open(real_path) as fp:
return fp.read().strip()
except IOError:
... | [
"def",
"read",
"(",
"path",
",",
"root_path",
"=",
"None",
")",
":",
"try",
":",
"root_path",
"=",
"root_path",
"or",
"get_root_path",
"(",
")",
"real_path",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"root_pat... | Read the specific file into a string in its entirety. | [
"Read",
"the",
"specific",
"file",
"into",
"a",
"string",
"in",
"its",
"entirety",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/setup.py#L16-L24 |
cloudsmith-io/cloudsmith-cli | setup.py | get_long_description | def get_long_description():
"""Grok the readme, turn it into whine (rst)."""
root_path = get_root_path()
readme_path = os.path.join(root_path, "README.md")
try:
import pypandoc
return pypandoc.convert(readme_path, "rst").strip()
except ImportError:
return "Cloudsmith CLI" | python | def get_long_description():
"""Grok the readme, turn it into whine (rst)."""
root_path = get_root_path()
readme_path = os.path.join(root_path, "README.md")
try:
import pypandoc
return pypandoc.convert(readme_path, "rst").strip()
except ImportError:
return "Cloudsmith CLI" | [
"def",
"get_long_description",
"(",
")",
":",
"root_path",
"=",
"get_root_path",
"(",
")",
"readme_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"root_path",
",",
"\"README.md\"",
")",
"try",
":",
"import",
"pypandoc",
"return",
"pypandoc",
".",
"convert"... | Grok the readme, turn it into whine (rst). | [
"Grok",
"the",
"readme",
"turn",
"it",
"into",
"whine",
"(",
"rst",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/setup.py#L27-L37 |
skulumani/kinematics | kinematics/sphere.py | rand | def rand(n, **kwargs):
"""Random vector from the n-Sphere
This function will return a random vector which is an element of the n-Sphere.
The n-Sphere is defined as a vector in R^n+1 with a norm of one.
Basically, we'll find a random vector in R^n+1 and normalize it.
This uses the method of Marsa... | python | def rand(n, **kwargs):
"""Random vector from the n-Sphere
This function will return a random vector which is an element of the n-Sphere.
The n-Sphere is defined as a vector in R^n+1 with a norm of one.
Basically, we'll find a random vector in R^n+1 and normalize it.
This uses the method of Marsa... | [
"def",
"rand",
"(",
"n",
",",
"*",
"*",
"kwargs",
")",
":",
"rvec",
"=",
"np",
".",
"random",
".",
"randn",
"(",
"3",
")",
"rvec",
"=",
"rvec",
"/",
"np",
".",
"linalg",
".",
"norm",
"(",
"rvec",
")",
"return",
"rvec"
] | Random vector from the n-Sphere
This function will return a random vector which is an element of the n-Sphere.
The n-Sphere is defined as a vector in R^n+1 with a norm of one.
Basically, we'll find a random vector in R^n+1 and normalize it.
This uses the method of Marsaglia 1972.
Parameters
... | [
"Random",
"vector",
"from",
"the",
"n",
"-",
"Sphere"
] | train | https://github.com/skulumani/kinematics/blob/e8cb45efb40539982025ed0f85d6561f9f10fef0/kinematics/sphere.py#L13-L34 |
skulumani/kinematics | kinematics/sphere.py | tan_rand | def tan_rand(q, seed=9):
"""Find a random vector in the tangent space of the n sphere
This function will find a random orthogonal vector to q.
Parameters
----------
q
(n+1,) array which is in the n-sphere
Returns
-------
qd
(n+1,) array which is orthogonal to n-sphere ... | python | def tan_rand(q, seed=9):
"""Find a random vector in the tangent space of the n sphere
This function will find a random orthogonal vector to q.
Parameters
----------
q
(n+1,) array which is in the n-sphere
Returns
-------
qd
(n+1,) array which is orthogonal to n-sphere ... | [
"def",
"tan_rand",
"(",
"q",
",",
"seed",
"=",
"9",
")",
":",
"# probably need a check in case we get a parallel vector",
"rs",
"=",
"np",
".",
"random",
".",
"RandomState",
"(",
"seed",
")",
"rvec",
"=",
"rs",
".",
"rand",
"(",
"q",
".",
"shape",
"[",
"... | Find a random vector in the tangent space of the n sphere
This function will find a random orthogonal vector to q.
Parameters
----------
q
(n+1,) array which is in the n-sphere
Returns
-------
qd
(n+1,) array which is orthogonal to n-sphere and also random | [
"Find",
"a",
"random",
"vector",
"in",
"the",
"tangent",
"space",
"of",
"the",
"n",
"sphere"
] | train | https://github.com/skulumani/kinematics/blob/e8cb45efb40539982025ed0f85d6561f9f10fef0/kinematics/sphere.py#L36-L64 |
skulumani/kinematics | kinematics/sphere.py | perturb_vec | def perturb_vec(q, cone_half_angle=2):
r"""Perturb a vector randomly
qp = perturb_vec(q, cone_half_angle=2)
Parameters
----------
q : (n,) numpy array
Vector to perturb
cone_half_angle : float
Maximum angle to perturb the vector in degrees
Returns
-------
perturbed... | python | def perturb_vec(q, cone_half_angle=2):
r"""Perturb a vector randomly
qp = perturb_vec(q, cone_half_angle=2)
Parameters
----------
q : (n,) numpy array
Vector to perturb
cone_half_angle : float
Maximum angle to perturb the vector in degrees
Returns
-------
perturbed... | [
"def",
"perturb_vec",
"(",
"q",
",",
"cone_half_angle",
"=",
"2",
")",
":",
"rand_vec",
"=",
"tan_rand",
"(",
"q",
")",
"cross_vector",
"=",
"attitude",
".",
"unit_vector",
"(",
"np",
".",
"cross",
"(",
"q",
",",
"rand_vec",
")",
")",
"s",
"=",
"np",... | r"""Perturb a vector randomly
qp = perturb_vec(q, cone_half_angle=2)
Parameters
----------
q : (n,) numpy array
Vector to perturb
cone_half_angle : float
Maximum angle to perturb the vector in degrees
Returns
-------
perturbed : (n,) numpy array
Perturbed numpy... | [
"r",
"Perturb",
"a",
"vector",
"randomly"
] | train | https://github.com/skulumani/kinematics/blob/e8cb45efb40539982025ed0f85d6561f9f10fef0/kinematics/sphere.py#L66-L109 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | common_package_action_options | def common_package_action_options(f):
"""Add common options for package actions."""
@click.option(
"-s",
"--skip-errors",
default=False,
is_flag=True,
help="Skip/ignore errors when copying packages.",
)
@click.option(
"-W",
"--no-wait-for-sync",
... | python | def common_package_action_options(f):
"""Add common options for package actions."""
@click.option(
"-s",
"--skip-errors",
default=False,
is_flag=True,
help="Skip/ignore errors when copying packages.",
)
@click.option(
"-W",
"--no-wait-for-sync",
... | [
"def",
"common_package_action_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"-s\"",
",",
"\"--skip-errors\"",
",",
"default",
"=",
"False",
",",
"is_flag",
"=",
"True",
",",
"help",
"=",
"\"Skip/ignore errors when copying packages.\"",
",",
"... | Add common options for package actions. | [
"Add",
"common",
"options",
"for",
"package",
"actions",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L13-L52 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | common_cli_config_options | def common_cli_config_options(f):
"""Add common CLI config options to commands."""
@click.option(
"-C",
"--config-file",
envvar="CLOUDSMITH_CONFIG_FILE",
type=click.Path(dir_okay=True, exists=True, writable=False, resolve_path=True),
help="The path to your config.ini fil... | python | def common_cli_config_options(f):
"""Add common CLI config options to commands."""
@click.option(
"-C",
"--config-file",
envvar="CLOUDSMITH_CONFIG_FILE",
type=click.Path(dir_okay=True, exists=True, writable=False, resolve_path=True),
help="The path to your config.ini fil... | [
"def",
"common_cli_config_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"-C\"",
",",
"\"--config-file\"",
",",
"envvar",
"=",
"\"CLOUDSMITH_CONFIG_FILE\"",
",",
"type",
"=",
"click",
".",
"Path",
"(",
"dir_okay",
"=",
"True",
",",
"exists... | Add common CLI config options to commands. | [
"Add",
"common",
"CLI",
"config",
"options",
"to",
"commands",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L55-L91 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | common_cli_output_options | def common_cli_output_options(f):
"""Add common CLI output options to commands."""
@click.option(
"-d",
"--debug",
default=False,
is_flag=True,
help="Produce debug output during processing.",
)
@click.option(
"-F",
"--output-format",
defau... | python | def common_cli_output_options(f):
"""Add common CLI output options to commands."""
@click.option(
"-d",
"--debug",
default=False,
is_flag=True,
help="Produce debug output during processing.",
)
@click.option(
"-F",
"--output-format",
defau... | [
"def",
"common_cli_output_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"-d\"",
",",
"\"--debug\"",
",",
"default",
"=",
"False",
",",
"is_flag",
"=",
"True",
",",
"help",
"=",
"\"Produce debug output during processing.\"",
",",
")",
"@",
... | Add common CLI output options to commands. | [
"Add",
"common",
"CLI",
"output",
"options",
"to",
"commands",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L94-L130 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | common_cli_list_options | def common_cli_list_options(f):
"""Add common list options to commands."""
@click.option(
"-p",
"--page",
default=1,
type=int,
help="The page to view for lists, where 1 is the first page",
callback=validators.validate_page,
)
@click.option(
"-l",
... | python | def common_cli_list_options(f):
"""Add common list options to commands."""
@click.option(
"-p",
"--page",
default=1,
type=int,
help="The page to view for lists, where 1 is the first page",
callback=validators.validate_page,
)
@click.option(
"-l",
... | [
"def",
"common_cli_list_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"-p\"",
",",
"\"--page\"",
",",
"default",
"=",
"1",
",",
"type",
"=",
"int",
",",
"help",
"=",
"\"The page to view for lists, where 1 is the first page\"",
",",
"callback"... | Add common list options to commands. | [
"Add",
"common",
"list",
"options",
"to",
"commands",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L133-L160 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | common_api_auth_options | def common_api_auth_options(f):
"""Add common API authentication options to commands."""
@click.option(
"-k",
"--api-key",
hide_input=True,
envvar="CLOUDSMITH_API_KEY",
help="The API key for authenticating with the API.",
)
@click.pass_context
@functools.wrap... | python | def common_api_auth_options(f):
"""Add common API authentication options to commands."""
@click.option(
"-k",
"--api-key",
hide_input=True,
envvar="CLOUDSMITH_API_KEY",
help="The API key for authenticating with the API.",
)
@click.pass_context
@functools.wrap... | [
"def",
"common_api_auth_options",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"-k\"",
",",
"\"--api-key\"",
",",
"hide_input",
"=",
"True",
",",
"envvar",
"=",
"\"CLOUDSMITH_API_KEY\"",
",",
"help",
"=",
"\"The API key for authenticating with the API.\""... | Add common API authentication options to commands. | [
"Add",
"common",
"API",
"authentication",
"options",
"to",
"commands",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L163-L182 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/decorators.py | initialise_api | def initialise_api(f):
"""Initialise the Cloudsmith API for use."""
@click.option(
"--api-host", envvar="CLOUDSMITH_API_HOST", help="The API host to connect to."
)
@click.option(
"--api-proxy",
envvar="CLOUDSMITH_API_PROXY",
help="The API proxy to connect through.",
... | python | def initialise_api(f):
"""Initialise the Cloudsmith API for use."""
@click.option(
"--api-host", envvar="CLOUDSMITH_API_HOST", help="The API host to connect to."
)
@click.option(
"--api-proxy",
envvar="CLOUDSMITH_API_PROXY",
help="The API proxy to connect through.",
... | [
"def",
"initialise_api",
"(",
"f",
")",
":",
"@",
"click",
".",
"option",
"(",
"\"--api-host\"",
",",
"envvar",
"=",
"\"CLOUDSMITH_API_HOST\"",
",",
"help",
"=",
"\"The API host to connect to.\"",
")",
"@",
"click",
".",
"option",
"(",
"\"--api-proxy\"",
",",
... | Initialise the Cloudsmith API for use. | [
"Initialise",
"the",
"Cloudsmith",
"API",
"for",
"use",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/decorators.py#L185-L279 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | list_entitlements | def list_entitlements(owner, repo, page, page_size, show_tokens):
"""Get a list of entitlements on a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_list_with_http_info(
owner=owner,
repo=repo,
... | python | def list_entitlements(owner, repo, page, page_size, show_tokens):
"""Get a list of entitlements on a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_list_with_http_info(
owner=owner,
repo=repo,
... | [
"def",
"list_entitlements",
"(",
"owner",
",",
"repo",
",",
"page",
",",
"page_size",
",",
"show_tokens",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"with",
"catch_raise_api_exception",
"(",
")",
":",
"data",
",",
"_",
",",
"headers",
"=",
... | Get a list of entitlements on a repository. | [
"Get",
"a",
"list",
"of",
"entitlements",
"on",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L18-L34 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | create_entitlement | def create_entitlement(owner, repo, name, token, show_tokens):
"""Create an entitlement in a repository."""
client = get_entitlements_api()
data = {}
if name is not None:
data["name"] = name
if token is not None:
data["token"] = token
with catch_raise_api_exception():
... | python | def create_entitlement(owner, repo, name, token, show_tokens):
"""Create an entitlement in a repository."""
client = get_entitlements_api()
data = {}
if name is not None:
data["name"] = name
if token is not None:
data["token"] = token
with catch_raise_api_exception():
... | [
"def",
"create_entitlement",
"(",
"owner",
",",
"repo",
",",
"name",
",",
"token",
",",
"show_tokens",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"data",
"=",
"{",
"}",
"if",
"name",
"is",
"not",
"None",
":",
"data",
"[",
"\"name\"",
"]... | Create an entitlement in a repository. | [
"Create",
"an",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L37-L54 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | delete_entitlement | def delete_entitlement(owner, repo, identifier):
"""Delete an entitlement from a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
_, _, headers = client.entitlements_delete_with_http_info(
owner=owner, repo=repo, identifier=identifier
)
ratel... | python | def delete_entitlement(owner, repo, identifier):
"""Delete an entitlement from a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
_, _, headers = client.entitlements_delete_with_http_info(
owner=owner, repo=repo, identifier=identifier
)
ratel... | [
"def",
"delete_entitlement",
"(",
"owner",
",",
"repo",
",",
"identifier",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"with",
"catch_raise_api_exception",
"(",
")",
":",
"_",
",",
"_",
",",
"headers",
"=",
"client",
".",
"entitlements_delete_wi... | Delete an entitlement from a repository. | [
"Delete",
"an",
"entitlement",
"from",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L57-L66 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | update_entitlement | def update_entitlement(owner, repo, identifier, name, token, show_tokens):
"""Update an entitlement in a repository."""
client = get_entitlements_api()
data = {}
if name is not None:
data["name"] = name
if token is not None:
data["token"] = token
with catch_raise_api_exception... | python | def update_entitlement(owner, repo, identifier, name, token, show_tokens):
"""Update an entitlement in a repository."""
client = get_entitlements_api()
data = {}
if name is not None:
data["name"] = name
if token is not None:
data["token"] = token
with catch_raise_api_exception... | [
"def",
"update_entitlement",
"(",
"owner",
",",
"repo",
",",
"identifier",
",",
"name",
",",
"token",
",",
"show_tokens",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"data",
"=",
"{",
"}",
"if",
"name",
"is",
"not",
"None",
":",
"data",
... | Update an entitlement in a repository. | [
"Update",
"an",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L69-L90 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | refresh_entitlement | def refresh_entitlement(owner, repo, identifier, show_tokens):
"""Refresh an entitlement in a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_refresh_with_http_info(
owner=owner, repo=repo, identifier=identifier, sh... | python | def refresh_entitlement(owner, repo, identifier, show_tokens):
"""Refresh an entitlement in a repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_refresh_with_http_info(
owner=owner, repo=repo, identifier=identifier, sh... | [
"def",
"refresh_entitlement",
"(",
"owner",
",",
"repo",
",",
"identifier",
",",
"show_tokens",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"with",
"catch_raise_api_exception",
"(",
")",
":",
"data",
",",
"_",
",",
"headers",
"=",
"client",
".... | Refresh an entitlement in a repository. | [
"Refresh",
"an",
"entitlement",
"in",
"a",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L93-L103 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/entitlements.py | sync_entitlements | def sync_entitlements(owner, repo, source, show_tokens):
"""Sync entitlements from another repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_sync_with_http_info(
owner=owner, repo=repo, data={"source": source}, show_t... | python | def sync_entitlements(owner, repo, source, show_tokens):
"""Sync entitlements from another repository."""
client = get_entitlements_api()
with catch_raise_api_exception():
data, _, headers = client.entitlements_sync_with_http_info(
owner=owner, repo=repo, data={"source": source}, show_t... | [
"def",
"sync_entitlements",
"(",
"owner",
",",
"repo",
",",
"source",
",",
"show_tokens",
")",
":",
"client",
"=",
"get_entitlements_api",
"(",
")",
"with",
"catch_raise_api_exception",
"(",
")",
":",
"data",
",",
"_",
",",
"headers",
"=",
"client",
".",
"... | Sync entitlements from another repository. | [
"Sync",
"entitlements",
"from",
"another",
"repository",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/entitlements.py#L106-L118 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/init.py | initialise_api | def initialise_api(
debug=False,
host=None,
key=None,
proxy=None,
user_agent=None,
headers=None,
rate_limit=True,
rate_limit_callback=None,
error_retry_max=None,
error_retry_backoff=None,
error_retry_codes=None,
):
"""Initialise the API."""
config = cloudsmith_api.Con... | python | def initialise_api(
debug=False,
host=None,
key=None,
proxy=None,
user_agent=None,
headers=None,
rate_limit=True,
rate_limit_callback=None,
error_retry_max=None,
error_retry_backoff=None,
error_retry_codes=None,
):
"""Initialise the API."""
config = cloudsmith_api.Con... | [
"def",
"initialise_api",
"(",
"debug",
"=",
"False",
",",
"host",
"=",
"None",
",",
"key",
"=",
"None",
",",
"proxy",
"=",
"None",
",",
"user_agent",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"rate_limit",
"=",
"True",
",",
"rate_limit_callback",
... | Initialise the API. | [
"Initialise",
"the",
"API",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/init.py#L13-L47 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/init.py | get_api_client | def get_api_client(cls):
"""Get an API client (with configuration)."""
config = cloudsmith_api.Configuration()
client = cls()
client.config = config
client.api_client.rest_client = RestClient()
user_agent = getattr(config, "user_agent", None)
if user_agent:
client.api_client.user_ag... | python | def get_api_client(cls):
"""Get an API client (with configuration)."""
config = cloudsmith_api.Configuration()
client = cls()
client.config = config
client.api_client.rest_client = RestClient()
user_agent = getattr(config, "user_agent", None)
if user_agent:
client.api_client.user_ag... | [
"def",
"get_api_client",
"(",
"cls",
")",
":",
"config",
"=",
"cloudsmith_api",
".",
"Configuration",
"(",
")",
"client",
"=",
"cls",
"(",
")",
"client",
".",
"config",
"=",
"config",
"client",
".",
"api_client",
".",
"rest_client",
"=",
"RestClient",
"(",... | Get an API client (with configuration). | [
"Get",
"an",
"API",
"client",
"(",
"with",
"configuration",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/init.py#L50-L66 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/init.py | set_api_key | def set_api_key(config, key):
"""Configure a new API key."""
if not key and "X-Api-Key" in config.api_key:
del config.api_key["X-Api-Key"]
else:
config.api_key["X-Api-Key"] = key | python | def set_api_key(config, key):
"""Configure a new API key."""
if not key and "X-Api-Key" in config.api_key:
del config.api_key["X-Api-Key"]
else:
config.api_key["X-Api-Key"] = key | [
"def",
"set_api_key",
"(",
"config",
",",
"key",
")",
":",
"if",
"not",
"key",
"and",
"\"X-Api-Key\"",
"in",
"config",
".",
"api_key",
":",
"del",
"config",
".",
"api_key",
"[",
"\"X-Api-Key\"",
"]",
"else",
":",
"config",
".",
"api_key",
"[",
"\"X-Api-K... | Configure a new API key. | [
"Configure",
"a",
"new",
"API",
"key",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/init.py#L69-L74 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/files.py | validate_request_file_upload | def validate_request_file_upload(owner, repo, filepath, md5_checksum=None):
"""Validate parameters for requesting a file upload."""
client = get_files_api()
md5_checksum = md5_checksum or calculate_file_md5(filepath)
with catch_raise_api_exception():
_, _, headers = client.files_validate_with_h... | python | def validate_request_file_upload(owner, repo, filepath, md5_checksum=None):
"""Validate parameters for requesting a file upload."""
client = get_files_api()
md5_checksum = md5_checksum or calculate_file_md5(filepath)
with catch_raise_api_exception():
_, _, headers = client.files_validate_with_h... | [
"def",
"validate_request_file_upload",
"(",
"owner",
",",
"repo",
",",
"filepath",
",",
"md5_checksum",
"=",
"None",
")",
":",
"client",
"=",
"get_files_api",
"(",
")",
"md5_checksum",
"=",
"md5_checksum",
"or",
"calculate_file_md5",
"(",
"filepath",
")",
"with"... | Validate parameters for requesting a file upload. | [
"Validate",
"parameters",
"for",
"requesting",
"a",
"file",
"upload",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/files.py#L25-L38 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/files.py | request_file_upload | def request_file_upload(owner, repo, filepath, md5_checksum=None):
"""Request a new package file upload (for creating packages)."""
client = get_files_api()
md5_checksum = md5_checksum or calculate_file_md5(filepath)
with catch_raise_api_exception():
data, _, headers = client.files_create_with_... | python | def request_file_upload(owner, repo, filepath, md5_checksum=None):
"""Request a new package file upload (for creating packages)."""
client = get_files_api()
md5_checksum = md5_checksum or calculate_file_md5(filepath)
with catch_raise_api_exception():
data, _, headers = client.files_create_with_... | [
"def",
"request_file_upload",
"(",
"owner",
",",
"repo",
",",
"filepath",
",",
"md5_checksum",
"=",
"None",
")",
":",
"client",
"=",
"get_files_api",
"(",
")",
"md5_checksum",
"=",
"md5_checksum",
"or",
"calculate_file_md5",
"(",
"filepath",
")",
"with",
"catc... | Request a new package file upload (for creating packages). | [
"Request",
"a",
"new",
"package",
"file",
"upload",
"(",
"for",
"creating",
"packages",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/files.py#L41-L56 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/api/files.py | upload_file | def upload_file(upload_url, upload_fields, filepath, callback=None):
"""Upload a pre-signed file to Cloudsmith."""
upload_fields = list(six.iteritems(upload_fields))
upload_fields.append(
("file", (os.path.basename(filepath), click.open_file(filepath, "rb")))
)
encoder = MultipartEncoder(upl... | python | def upload_file(upload_url, upload_fields, filepath, callback=None):
"""Upload a pre-signed file to Cloudsmith."""
upload_fields = list(six.iteritems(upload_fields))
upload_fields.append(
("file", (os.path.basename(filepath), click.open_file(filepath, "rb")))
)
encoder = MultipartEncoder(upl... | [
"def",
"upload_file",
"(",
"upload_url",
",",
"upload_fields",
",",
"filepath",
",",
"callback",
"=",
"None",
")",
":",
"upload_fields",
"=",
"list",
"(",
"six",
".",
"iteritems",
"(",
"upload_fields",
")",
")",
"upload_fields",
".",
"append",
"(",
"(",
"\... | Upload a pre-signed file to Cloudsmith. | [
"Upload",
"a",
"pre",
"-",
"signed",
"file",
"to",
"Cloudsmith",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/api/files.py#L59-L87 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/exceptions.py | handle_api_exceptions | def handle_api_exceptions(
ctx, opts, context_msg=None, nl=False, exit_on_error=True, reraise_on_error=False
):
"""Context manager that handles API exceptions."""
# flake8: ignore=C901
# Use stderr for messages if the output is something else (e.g. # JSON)
use_stderr = opts.output != "pretty"
... | python | def handle_api_exceptions(
ctx, opts, context_msg=None, nl=False, exit_on_error=True, reraise_on_error=False
):
"""Context manager that handles API exceptions."""
# flake8: ignore=C901
# Use stderr for messages if the output is something else (e.g. # JSON)
use_stderr = opts.output != "pretty"
... | [
"def",
"handle_api_exceptions",
"(",
"ctx",
",",
"opts",
",",
"context_msg",
"=",
"None",
",",
"nl",
"=",
"False",
",",
"exit_on_error",
"=",
"True",
",",
"reraise_on_error",
"=",
"False",
")",
":",
"# flake8: ignore=C901",
"# Use stderr for messages if the output i... | Context manager that handles API exceptions. | [
"Context",
"manager",
"that",
"handles",
"API",
"exceptions",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/exceptions.py#L16-L89 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/exceptions.py | get_details | def get_details(exc):
"""Get the details from the exception."""
detail = None
fields = collections.OrderedDict()
if exc.detail:
detail = exc.detail
if exc.fields:
for k, v in six.iteritems(exc.fields):
try:
field_detail = v["detail"]
except (... | python | def get_details(exc):
"""Get the details from the exception."""
detail = None
fields = collections.OrderedDict()
if exc.detail:
detail = exc.detail
if exc.fields:
for k, v in six.iteritems(exc.fields):
try:
field_detail = v["detail"]
except (... | [
"def",
"get_details",
"(",
"exc",
")",
":",
"detail",
"=",
"None",
"fields",
"=",
"collections",
".",
"OrderedDict",
"(",
")",
"if",
"exc",
".",
"detail",
":",
"detail",
"=",
"exc",
".",
"detail",
"if",
"exc",
".",
"fields",
":",
"for",
"k",
",",
"... | Get the details from the exception. | [
"Get",
"the",
"details",
"from",
"the",
"exception",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/exceptions.py#L92-L119 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/exceptions.py | get_error_hint | def get_error_hint(ctx, opts, exc):
"""Get a hint to show to the user (if any)."""
module = sys.modules[__name__]
get_specific_error_hint = getattr(module, "get_%s_error_hint" % exc.status, None)
if get_specific_error_hint:
return get_specific_error_hint(ctx, opts, exc)
return None | python | def get_error_hint(ctx, opts, exc):
"""Get a hint to show to the user (if any)."""
module = sys.modules[__name__]
get_specific_error_hint = getattr(module, "get_%s_error_hint" % exc.status, None)
if get_specific_error_hint:
return get_specific_error_hint(ctx, opts, exc)
return None | [
"def",
"get_error_hint",
"(",
"ctx",
",",
"opts",
",",
"exc",
")",
":",
"module",
"=",
"sys",
".",
"modules",
"[",
"__name__",
"]",
"get_specific_error_hint",
"=",
"getattr",
"(",
"module",
",",
"\"get_%s_error_hint\"",
"%",
"exc",
".",
"status",
",",
"Non... | Get a hint to show to the user (if any). | [
"Get",
"a",
"hint",
"to",
"show",
"to",
"the",
"user",
"(",
"if",
"any",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/exceptions.py#L122-L128 |
kalefranz/auxlib | auxlib/configuration.py | make_env_key | def make_env_key(app_name, key):
"""Creates an environment key-equivalent for the given key"""
key = key.replace('-', '_').replace(' ', '_')
return str("_".join((x.upper() for x in (app_name, key)))) | python | def make_env_key(app_name, key):
"""Creates an environment key-equivalent for the given key"""
key = key.replace('-', '_').replace(' ', '_')
return str("_".join((x.upper() for x in (app_name, key)))) | [
"def",
"make_env_key",
"(",
"app_name",
",",
"key",
")",
":",
"key",
"=",
"key",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
".",
"replace",
"(",
"' '",
",",
"'_'",
")",
"return",
"str",
"(",
"\"_\"",
".",
"join",
"(",
"(",
"x",
".",
"upper",
... | Creates an environment key-equivalent for the given key | [
"Creates",
"an",
"environment",
"key",
"-",
"equivalent",
"for",
"the",
"given",
"key"
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/configuration.py#L45-L48 |
kalefranz/auxlib | auxlib/configuration.py | Configuration.set_env | def set_env(self, key, value):
"""Sets environment variables by prepending the app_name to `key`. Also registers the
environment variable with the instance object preventing an otherwise-required call to
`reload()`.
"""
os.environ[make_env_key(self.appname, key)] = str(value) # ... | python | def set_env(self, key, value):
"""Sets environment variables by prepending the app_name to `key`. Also registers the
environment variable with the instance object preventing an otherwise-required call to
`reload()`.
"""
os.environ[make_env_key(self.appname, key)] = str(value) # ... | [
"def",
"set_env",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"os",
".",
"environ",
"[",
"make_env_key",
"(",
"self",
".",
"appname",
",",
"key",
")",
"]",
"=",
"str",
"(",
"value",
")",
"# must coerce to string",
"self",
".",
"_registered_env_keys"... | Sets environment variables by prepending the app_name to `key`. Also registers the
environment variable with the instance object preventing an otherwise-required call to
`reload()`. | [
"Sets",
"environment",
"variables",
"by",
"prepending",
"the",
"app_name",
"to",
"key",
".",
"Also",
"registers",
"the",
"environment",
"variable",
"with",
"the",
"instance",
"object",
"preventing",
"an",
"otherwise",
"-",
"required",
"call",
"to",
"reload",
"()... | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/configuration.py#L137-L144 |
kalefranz/auxlib | auxlib/configuration.py | Configuration.unset_env | def unset_env(self, key):
"""Removes an environment variable using the prepended app_name convention with `key`."""
os.environ.pop(make_env_key(self.appname, key), None)
self._registered_env_keys.discard(key)
self._clear_memoization() | python | def unset_env(self, key):
"""Removes an environment variable using the prepended app_name convention with `key`."""
os.environ.pop(make_env_key(self.appname, key), None)
self._registered_env_keys.discard(key)
self._clear_memoization() | [
"def",
"unset_env",
"(",
"self",
",",
"key",
")",
":",
"os",
".",
"environ",
".",
"pop",
"(",
"make_env_key",
"(",
"self",
".",
"appname",
",",
"key",
")",
",",
"None",
")",
"self",
".",
"_registered_env_keys",
".",
"discard",
"(",
"key",
")",
"self"... | Removes an environment variable using the prepended app_name convention with `key`. | [
"Removes",
"an",
"environment",
"variable",
"using",
"the",
"prepended",
"app_name",
"convention",
"with",
"key",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/configuration.py#L146-L150 |
kalefranz/auxlib | auxlib/configuration.py | Configuration._reload | def _reload(self, force=False):
"""Reloads the configuration from the file and environment variables. Useful if using
`os.environ` instead of this class' `set_env` method, or if the underlying configuration
file is changed externally.
"""
self._config_map = dict()
self._r... | python | def _reload(self, force=False):
"""Reloads the configuration from the file and environment variables. Useful if using
`os.environ` instead of this class' `set_env` method, or if the underlying configuration
file is changed externally.
"""
self._config_map = dict()
self._r... | [
"def",
"_reload",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"self",
".",
"_config_map",
"=",
"dict",
"(",
")",
"self",
".",
"_registered_env_keys",
"=",
"set",
"(",
")",
"self",
".",
"__reload_sources",
"(",
"force",
")",
"self",
".",
"__load_... | Reloads the configuration from the file and environment variables. Useful if using
`os.environ` instead of this class' `set_env` method, or if the underlying configuration
file is changed externally. | [
"Reloads",
"the",
"configuration",
"from",
"the",
"file",
"and",
"environment",
"variables",
".",
"Useful",
"if",
"using",
"os",
".",
"environ",
"instead",
"of",
"this",
"class",
"set_env",
"method",
"or",
"if",
"the",
"underlying",
"configuration",
"file",
"i... | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/configuration.py#L152-L162 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/cli/commands/move.py | move | def move(
ctx,
opts,
owner_repo_package,
destination,
skip_errors,
wait_interval,
no_wait_for_sync,
sync_attempts,
yes,
):
"""
Move (promote) a package to another repo.
This requires appropriate permissions for both the source
repository/package and the destination r... | python | def move(
ctx,
opts,
owner_repo_package,
destination,
skip_errors,
wait_interval,
no_wait_for_sync,
sync_attempts,
yes,
):
"""
Move (promote) a package to another repo.
This requires appropriate permissions for both the source
repository/package and the destination r... | [
"def",
"move",
"(",
"ctx",
",",
"opts",
",",
"owner_repo_package",
",",
"destination",
",",
"skip_errors",
",",
"wait_interval",
",",
"no_wait_for_sync",
",",
"sync_attempts",
",",
"yes",
",",
")",
":",
"owner",
",",
"source",
",",
"slug",
"=",
"owner_repo_p... | Move (promote) a package to another repo.
This requires appropriate permissions for both the source
repository/package and the destination repository.
- OWNER/REPO/PACKAGE: Specify the OWNER namespace (i.e. user or org), the
REPO name where the package is stored, and the PACKAGE name (slug) of the
... | [
"Move",
"(",
"promote",
")",
"a",
"package",
"to",
"another",
"repo",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/cli/commands/move.py#L35-L106 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/rest.py | create_requests_session | def create_requests_session(
retries=None,
backoff_factor=None,
status_forcelist=None,
pools_size=4,
maxsize=4,
ssl_verify=None,
ssl_cert=None,
proxy=None,
session=None,
):
"""Create a requests session that retries some errors."""
# pylint: disable=too-many-branches
confi... | python | def create_requests_session(
retries=None,
backoff_factor=None,
status_forcelist=None,
pools_size=4,
maxsize=4,
ssl_verify=None,
ssl_cert=None,
proxy=None,
session=None,
):
"""Create a requests session that retries some errors."""
# pylint: disable=too-many-branches
confi... | [
"def",
"create_requests_session",
"(",
"retries",
"=",
"None",
",",
"backoff_factor",
"=",
"None",
",",
"status_forcelist",
"=",
"None",
",",
"pools_size",
"=",
"4",
",",
"maxsize",
"=",
"4",
",",
"ssl_verify",
"=",
"None",
",",
"ssl_cert",
"=",
"None",
",... | Create a requests session that retries some errors. | [
"Create",
"a",
"requests",
"session",
"that",
"retries",
"some",
"errors",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/rest.py#L21-L92 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/rest.py | RestResponse.data | def data(self):
"""
Get the content for the response (lazily decoded).
"""
if self._data is None:
self._data = self.response.content.decode("utf-8")
return self._data | python | def data(self):
"""
Get the content for the response (lazily decoded).
"""
if self._data is None:
self._data = self.response.content.decode("utf-8")
return self._data | [
"def",
"data",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"self",
".",
"_data",
"=",
"self",
".",
"response",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
"return",
"self",
".",
"_data"
] | Get the content for the response (lazily decoded). | [
"Get",
"the",
"content",
"for",
"the",
"response",
"(",
"lazily",
"decoded",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/rest.py#L106-L112 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/rest.py | RestResponse.getheader | def getheader(self, name, default=None):
"""
Return a given response header.
"""
return self.response.headers.get(name, default) | python | def getheader(self, name, default=None):
"""
Return a given response header.
"""
return self.response.headers.get(name, default) | [
"def",
"getheader",
"(",
"self",
",",
"name",
",",
"default",
"=",
"None",
")",
":",
"return",
"self",
".",
"response",
".",
"headers",
".",
"get",
"(",
"name",
",",
"default",
")"
] | Return a given response header. | [
"Return",
"a",
"given",
"response",
"header",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/rest.py#L120-L124 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/rest.py | RestClient.request | def request(
self,
method,
url,
query_params=None,
headers=None,
body=None,
post_params=None,
_preload_content=True,
_request_timeout=None,
):
"""
:param method: http request method
:param url: http request url
:... | python | def request(
self,
method,
url,
query_params=None,
headers=None,
body=None,
post_params=None,
_preload_content=True,
_request_timeout=None,
):
"""
:param method: http request method
:param url: http request url
:... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"query_params",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"body",
"=",
"None",
",",
"post_params",
"=",
"None",
",",
"_preload_content",
"=",
"True",
",",
"_request_timeout",
"=",
"None"... | :param method: http request method
:param url: http request url
:param query_params: query parameters in the url
:param headers: http request headers
:param body: request json body, for `application/json`
:param post_params: request post parameters,
`a... | [
":",
"param",
"method",
":",
"http",
"request",
"method",
":",
"param",
"url",
":",
"http",
"request",
"url",
":",
"param",
"query_params",
":",
"query",
"parameters",
"in",
"the",
"url",
":",
"param",
"headers",
":",
"http",
"request",
"headers",
":",
"... | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/rest.py#L134-L215 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/utils.py | get_root_path | def get_root_path():
"""Get the root directory for the application."""
return os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir)) | python | def get_root_path():
"""Get the root directory for the application."""
return os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir)) | [
"def",
"get_root_path",
"(",
")",
":",
"return",
"os",
".",
"path",
".",
"realpath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"os",
".",
"pardir",
")",
")"
] | Get the root directory for the application. | [
"Get",
"the",
"root",
"directory",
"for",
"the",
"application",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/utils.py#L21-L23 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/utils.py | read_file | def read_file(*path):
"""Read the specific file into a string in its entirety."""
real_path = os.path.realpath(os.path.join(*path))
with click.open_file(real_path, "r") as fp:
return fp.read() | python | def read_file(*path):
"""Read the specific file into a string in its entirety."""
real_path = os.path.realpath(os.path.join(*path))
with click.open_file(real_path, "r") as fp:
return fp.read() | [
"def",
"read_file",
"(",
"*",
"path",
")",
":",
"real_path",
"=",
"os",
".",
"path",
".",
"realpath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"*",
"path",
")",
")",
"with",
"click",
".",
"open_file",
"(",
"real_path",
",",
"\"r\"",
")",
"as",
"... | Read the specific file into a string in its entirety. | [
"Read",
"the",
"specific",
"file",
"into",
"a",
"string",
"in",
"its",
"entirety",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/utils.py#L31-L35 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/utils.py | calculate_file_md5 | def calculate_file_md5(filepath, blocksize=2 ** 20):
"""Calculate an MD5 hash for a file."""
checksum = hashlib.md5()
with click.open_file(filepath, "rb") as f:
def update_chunk():
"""Add chunk to checksum."""
buf = f.read(blocksize)
if buf:
chec... | python | def calculate_file_md5(filepath, blocksize=2 ** 20):
"""Calculate an MD5 hash for a file."""
checksum = hashlib.md5()
with click.open_file(filepath, "rb") as f:
def update_chunk():
"""Add chunk to checksum."""
buf = f.read(blocksize)
if buf:
chec... | [
"def",
"calculate_file_md5",
"(",
"filepath",
",",
"blocksize",
"=",
"2",
"**",
"20",
")",
":",
"checksum",
"=",
"hashlib",
".",
"md5",
"(",
")",
"with",
"click",
".",
"open_file",
"(",
"filepath",
",",
"\"rb\"",
")",
"as",
"f",
":",
"def",
"update_chu... | Calculate an MD5 hash for a file. | [
"Calculate",
"an",
"MD5",
"hash",
"for",
"a",
"file",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/utils.py#L38-L54 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/utils.py | get_page_kwargs | def get_page_kwargs(**kwargs):
"""Construct page and page size kwargs (if present)."""
page_kwargs = {}
page = kwargs.get("page")
if page is not None and page > 0:
page_kwargs["page"] = page
page_size = kwargs.get("page_size")
if page_size is not None and page_size > 0:
page_kw... | python | def get_page_kwargs(**kwargs):
"""Construct page and page size kwargs (if present)."""
page_kwargs = {}
page = kwargs.get("page")
if page is not None and page > 0:
page_kwargs["page"] = page
page_size = kwargs.get("page_size")
if page_size is not None and page_size > 0:
page_kw... | [
"def",
"get_page_kwargs",
"(",
"*",
"*",
"kwargs",
")",
":",
"page_kwargs",
"=",
"{",
"}",
"page",
"=",
"kwargs",
".",
"get",
"(",
"\"page\"",
")",
"if",
"page",
"is",
"not",
"None",
"and",
"page",
">",
"0",
":",
"page_kwargs",
"[",
"\"page\"",
"]",
... | Construct page and page size kwargs (if present). | [
"Construct",
"page",
"and",
"page",
"size",
"kwargs",
"(",
"if",
"present",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/utils.py#L63-L75 |
cloudsmith-io/cloudsmith-cli | cloudsmith_cli/core/utils.py | get_query_kwargs | def get_query_kwargs(**kwargs):
"""Construct page and page size kwargs (if present)."""
query_kwargs = {}
query = kwargs.pop("query")
if query:
query_kwargs["query"] = query
return query_kwargs | python | def get_query_kwargs(**kwargs):
"""Construct page and page size kwargs (if present)."""
query_kwargs = {}
query = kwargs.pop("query")
if query:
query_kwargs["query"] = query
return query_kwargs | [
"def",
"get_query_kwargs",
"(",
"*",
"*",
"kwargs",
")",
":",
"query_kwargs",
"=",
"{",
"}",
"query",
"=",
"kwargs",
".",
"pop",
"(",
"\"query\"",
")",
"if",
"query",
":",
"query_kwargs",
"[",
"\"query\"",
"]",
"=",
"query",
"return",
"query_kwargs"
] | Construct page and page size kwargs (if present). | [
"Construct",
"page",
"and",
"page",
"size",
"kwargs",
"(",
"if",
"present",
")",
"."
] | train | https://github.com/cloudsmith-io/cloudsmith-cli/blob/5bc245ca5d0bfa85380be48e7c206b4c86cc6c8e/cloudsmith_cli/core/utils.py#L78-L86 |
kalefranz/auxlib | auxlib/packaging.py | _get_version_from_git_tag | def _get_version_from_git_tag(path):
"""Return a PEP440-compliant version derived from the git status.
If that fails for any reason, return the changeset hash.
"""
m = GIT_DESCRIBE_REGEX.match(_git_describe_tags(path) or '')
if m is None:
return None
version, post_commit, hash = m.groups... | python | def _get_version_from_git_tag(path):
"""Return a PEP440-compliant version derived from the git status.
If that fails for any reason, return the changeset hash.
"""
m = GIT_DESCRIBE_REGEX.match(_git_describe_tags(path) or '')
if m is None:
return None
version, post_commit, hash = m.groups... | [
"def",
"_get_version_from_git_tag",
"(",
"path",
")",
":",
"m",
"=",
"GIT_DESCRIBE_REGEX",
".",
"match",
"(",
"_git_describe_tags",
"(",
"path",
")",
"or",
"''",
")",
"if",
"m",
"is",
"None",
":",
"return",
"None",
"version",
",",
"post_commit",
",",
"hash... | Return a PEP440-compliant version derived from the git status.
If that fails for any reason, return the changeset hash. | [
"Return",
"a",
"PEP440",
"-",
"compliant",
"version",
"derived",
"from",
"the",
"git",
"status",
".",
"If",
"that",
"fails",
"for",
"any",
"reason",
"return",
"the",
"changeset",
"hash",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/packaging.py#L142-L150 |
kalefranz/auxlib | auxlib/packaging.py | get_version | def get_version(dunder_file):
"""Returns a version string for the current package, derived
either from git or from a .version file.
This function is expected to run in two contexts. In a development
context, where .git/ exists, the version is pulled from git tags.
Using the BuildPyCommand and SDist... | python | def get_version(dunder_file):
"""Returns a version string for the current package, derived
either from git or from a .version file.
This function is expected to run in two contexts. In a development
context, where .git/ exists, the version is pulled from git tags.
Using the BuildPyCommand and SDist... | [
"def",
"get_version",
"(",
"dunder_file",
")",
":",
"path",
"=",
"abspath",
"(",
"expanduser",
"(",
"dirname",
"(",
"dunder_file",
")",
")",
")",
"try",
":",
"return",
"_get_version_from_version_file",
"(",
"path",
")",
"or",
"_get_version_from_git_tag",
"(",
... | Returns a version string for the current package, derived
either from git or from a .version file.
This function is expected to run in two contexts. In a development
context, where .git/ exists, the version is pulled from git tags.
Using the BuildPyCommand and SDistCommand classes for cmdclass in
s... | [
"Returns",
"a",
"version",
"string",
"for",
"the",
"current",
"package",
"derived",
"either",
"from",
"git",
"or",
"from",
"a",
".",
"version",
"file",
"."
] | train | https://github.com/kalefranz/auxlib/blob/6ff2d6b57d128d0b9ed8f01ad83572e938da064f/auxlib/packaging.py#L153-L174 |
visualfabriq/bquery | bquery/benchmarks/bench_groupby.py | ctime | def ctime(message=None):
"Counts the time spent in some context"
global t_elapsed
t_elapsed = 0.0
print('\n')
t = time.time()
yield
if message:
print(message + ": ", end='')
t_elapsed = time.time() - t
print(round(t_elapsed, 4), "sec") | python | def ctime(message=None):
"Counts the time spent in some context"
global t_elapsed
t_elapsed = 0.0
print('\n')
t = time.time()
yield
if message:
print(message + ": ", end='')
t_elapsed = time.time() - t
print(round(t_elapsed, 4), "sec") | [
"def",
"ctime",
"(",
"message",
"=",
"None",
")",
":",
"global",
"t_elapsed",
"t_elapsed",
"=",
"0.0",
"print",
"(",
"'\\n'",
")",
"t",
"=",
"time",
".",
"time",
"(",
")",
"yield",
"if",
"message",
":",
"print",
"(",
"message",
"+",
"\": \"",
",",
... | Counts the time spent in some context | [
"Counts",
"the",
"time",
"spent",
"in",
"some",
"context"
] | train | https://github.com/visualfabriq/bquery/blob/3702e974696e22876944a3339affad2f29e1ee06/bquery/benchmarks/bench_groupby.py#L29-L39 |
skulumani/kinematics | kinematics/attitude.py | rot1 | def rot1(angle, form='c'):
"""Euler rotation about first axis
This computes the rotation matrix associated with a rotation about the first
axis. It will output matrices assuming column or row format vectors.
For example, to transform a vector from reference frame b to reference frame a:
Column V... | python | def rot1(angle, form='c'):
"""Euler rotation about first axis
This computes the rotation matrix associated with a rotation about the first
axis. It will output matrices assuming column or row format vectors.
For example, to transform a vector from reference frame b to reference frame a:
Column V... | [
"def",
"rot1",
"(",
"angle",
",",
"form",
"=",
"'c'",
")",
":",
"cos_a",
"=",
"np",
".",
"cos",
"(",
"angle",
")",
"sin_a",
"=",
"np",
".",
"sin",
"(",
"angle",
")",
"rot_mat",
"=",
"np",
".",
"identity",
"(",
"3",
")",
"if",
"form",
"==",
"'... | Euler rotation about first axis
This computes the rotation matrix associated with a rotation about the first
axis. It will output matrices assuming column or row format vectors.
For example, to transform a vector from reference frame b to reference frame a:
Column Vectors : a = rot1(angle, 'c').dot(... | [
"Euler",
"rotation",
"about",
"first",
"axis"
] | train | https://github.com/skulumani/kinematics/blob/e8cb45efb40539982025ed0f85d6561f9f10fef0/kinematics/attitude.py#L45-L88 |
skulumani/kinematics | kinematics/attitude.py | dcm2body313 | def dcm2body313(dcm):
"""Convert DCM to body Euler 3-1-3 angles
"""
theta = np.zeros(3)
theta[0] = np.arctan2(dcm[2, 0], dcm[2, 1])
theta[1] = np.arccos(dcm[2, 2])
theta[2] = np.arctan2(dcm[0, 2], -dcm[1, 2])
return theta | python | def dcm2body313(dcm):
"""Convert DCM to body Euler 3-1-3 angles
"""
theta = np.zeros(3)
theta[0] = np.arctan2(dcm[2, 0], dcm[2, 1])
theta[1] = np.arccos(dcm[2, 2])
theta[2] = np.arctan2(dcm[0, 2], -dcm[1, 2])
return theta | [
"def",
"dcm2body313",
"(",
"dcm",
")",
":",
"theta",
"=",
"np",
".",
"zeros",
"(",
"3",
")",
"theta",
"[",
"0",
"]",
"=",
"np",
".",
"arctan2",
"(",
"dcm",
"[",
"2",
",",
"0",
"]",
",",
"dcm",
"[",
"2",
",",
"1",
"]",
")",
"theta",
"[",
"... | Convert DCM to body Euler 3-1-3 angles | [
"Convert",
"DCM",
"to",
"body",
"Euler",
"3",
"-",
"1",
"-",
"3",
"angles"
] | train | https://github.com/skulumani/kinematics/blob/e8cb45efb40539982025ed0f85d6561f9f10fef0/kinematics/attitude.py#L180-L190 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.