repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pmelchior/proxmin | proxmin/operators.py | prox_unity_plus | def prox_unity_plus(X, step, axis=0):
"""Non-negative projection onto sum=1 along an axis
"""
return prox_unity(prox_plus(X, step), step, axis=axis) | python | def prox_unity_plus(X, step, axis=0):
"""Non-negative projection onto sum=1 along an axis
"""
return prox_unity(prox_plus(X, step), step, axis=axis) | [
"def",
"prox_unity_plus",
"(",
"X",
",",
"step",
",",
"axis",
"=",
"0",
")",
":",
"return",
"prox_unity",
"(",
"prox_plus",
"(",
"X",
",",
"step",
")",
",",
"step",
",",
"axis",
"=",
"axis",
")"
] | Non-negative projection onto sum=1 along an axis | [
"Non",
"-",
"negative",
"projection",
"onto",
"sum",
"=",
"1",
"along",
"an",
"axis"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L39-L42 | train |
pmelchior/proxmin | proxmin/operators.py | prox_min | def prox_min(X, step, thresh=0):
"""Projection onto numbers above `thresh`
"""
thresh_ = _step_gamma(step, thresh)
below = X - thresh_ < 0
X[below] = thresh_
return X | python | def prox_min(X, step, thresh=0):
"""Projection onto numbers above `thresh`
"""
thresh_ = _step_gamma(step, thresh)
below = X - thresh_ < 0
X[below] = thresh_
return X | [
"def",
"prox_min",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"0",
")",
":",
"thresh_",
"=",
"_step_gamma",
"(",
"step",
",",
"thresh",
")",
"below",
"=",
"X",
"-",
"thresh_",
"<",
"0",
"X",
"[",
"below",
"]",
"=",
"thresh_",
"return",
"X"
] | Projection onto numbers above `thresh` | [
"Projection",
"onto",
"numbers",
"above",
"thresh"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L44-L50 | train |
pmelchior/proxmin | proxmin/operators.py | prox_max | def prox_max(X, step, thresh=0):
"""Projection onto numbers below `thresh`
"""
thresh_ = _step_gamma(step, thresh)
above = X - thresh_ > 0
X[above] = thresh_
return X | python | def prox_max(X, step, thresh=0):
"""Projection onto numbers below `thresh`
"""
thresh_ = _step_gamma(step, thresh)
above = X - thresh_ > 0
X[above] = thresh_
return X | [
"def",
"prox_max",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"0",
")",
":",
"thresh_",
"=",
"_step_gamma",
"(",
"step",
",",
"thresh",
")",
"above",
"=",
"X",
"-",
"thresh_",
">",
"0",
"X",
"[",
"above",
"]",
"=",
"thresh_",
"return",
"X"
] | Projection onto numbers below `thresh` | [
"Projection",
"onto",
"numbers",
"below",
"thresh"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L52-L58 | train |
pmelchior/proxmin | proxmin/operators.py | prox_components | def prox_components(X, step, prox=None, axis=0):
"""Split X along axis and apply prox to each chunk.
prox can be a list.
"""
K = X.shape[axis]
if not hasattr(prox_list, '__iter__'):
prox = [prox] * K
assert len(prox_list) == K
if axis == 0:
Pk = [prox_list[k](X[k], step) f... | python | def prox_components(X, step, prox=None, axis=0):
"""Split X along axis and apply prox to each chunk.
prox can be a list.
"""
K = X.shape[axis]
if not hasattr(prox_list, '__iter__'):
prox = [prox] * K
assert len(prox_list) == K
if axis == 0:
Pk = [prox_list[k](X[k], step) f... | [
"def",
"prox_components",
"(",
"X",
",",
"step",
",",
"prox",
"=",
"None",
",",
"axis",
"=",
"0",
")",
":",
"K",
"=",
"X",
".",
"shape",
"[",
"axis",
"]",
"if",
"not",
"hasattr",
"(",
"prox_list",
",",
"'__iter__'",
")",
":",
"prox",
"=",
"[",
... | Split X along axis and apply prox to each chunk.
prox can be a list. | [
"Split",
"X",
"along",
"axis",
"and",
"apply",
"prox",
"to",
"each",
"chunk",
"."
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L60-L75 | train |
pmelchior/proxmin | proxmin/operators.py | prox_hard_plus | def prox_hard_plus(X, step, thresh=0):
"""Hard thresholding with projection onto non-negative numbers
"""
return prox_plus(prox_hard(X, step, thresh=thresh), step) | python | def prox_hard_plus(X, step, thresh=0):
"""Hard thresholding with projection onto non-negative numbers
"""
return prox_plus(prox_hard(X, step, thresh=thresh), step) | [
"def",
"prox_hard_plus",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"0",
")",
":",
"return",
"prox_plus",
"(",
"prox_hard",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"thresh",
")",
",",
"step",
")"
] | Hard thresholding with projection onto non-negative numbers | [
"Hard",
"thresholding",
"with",
"projection",
"onto",
"non",
"-",
"negative",
"numbers"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L91-L94 | train |
pmelchior/proxmin | proxmin/operators.py | prox_soft | def prox_soft(X, step, thresh=0):
"""Soft thresholding proximal operator
"""
thresh_ = _step_gamma(step, thresh)
return np.sign(X)*prox_plus(np.abs(X) - thresh_, step) | python | def prox_soft(X, step, thresh=0):
"""Soft thresholding proximal operator
"""
thresh_ = _step_gamma(step, thresh)
return np.sign(X)*prox_plus(np.abs(X) - thresh_, step) | [
"def",
"prox_soft",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"0",
")",
":",
"thresh_",
"=",
"_step_gamma",
"(",
"step",
",",
"thresh",
")",
"return",
"np",
".",
"sign",
"(",
"X",
")",
"*",
"prox_plus",
"(",
"np",
".",
"abs",
"(",
"X",
")",
"-... | Soft thresholding proximal operator | [
"Soft",
"thresholding",
"proximal",
"operator"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L96-L100 | train |
pmelchior/proxmin | proxmin/operators.py | prox_soft_plus | def prox_soft_plus(X, step, thresh=0):
"""Soft thresholding with projection onto non-negative numbers
"""
return prox_plus(prox_soft(X, step, thresh=thresh), step) | python | def prox_soft_plus(X, step, thresh=0):
"""Soft thresholding with projection onto non-negative numbers
"""
return prox_plus(prox_soft(X, step, thresh=thresh), step) | [
"def",
"prox_soft_plus",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"0",
")",
":",
"return",
"prox_plus",
"(",
"prox_soft",
"(",
"X",
",",
"step",
",",
"thresh",
"=",
"thresh",
")",
",",
"step",
")"
] | Soft thresholding with projection onto non-negative numbers | [
"Soft",
"thresholding",
"with",
"projection",
"onto",
"non",
"-",
"negative",
"numbers"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L102-L105 | train |
pmelchior/proxmin | proxmin/operators.py | prox_max_entropy | def prox_max_entropy(X, step, gamma=1):
"""Proximal operator for maximum entropy regularization.
g(x) = gamma \sum_i x_i ln(x_i)
has the analytical solution of gamma W(1/gamma exp((X-gamma)/gamma)), where
W is the Lambert W function.
"""
from scipy.special import lambertw
gamma_ = _step_ga... | python | def prox_max_entropy(X, step, gamma=1):
"""Proximal operator for maximum entropy regularization.
g(x) = gamma \sum_i x_i ln(x_i)
has the analytical solution of gamma W(1/gamma exp((X-gamma)/gamma)), where
W is the Lambert W function.
"""
from scipy.special import lambertw
gamma_ = _step_ga... | [
"def",
"prox_max_entropy",
"(",
"X",
",",
"step",
",",
"gamma",
"=",
"1",
")",
":",
"from",
"scipy",
".",
"special",
"import",
"lambertw",
"gamma_",
"=",
"_step_gamma",
"(",
"step",
",",
"gamma",
")",
"above",
"=",
"X",
">",
"0",
"X",
"[",
"above",
... | Proximal operator for maximum entropy regularization.
g(x) = gamma \sum_i x_i ln(x_i)
has the analytical solution of gamma W(1/gamma exp((X-gamma)/gamma)), where
W is the Lambert W function. | [
"Proximal",
"operator",
"for",
"maximum",
"entropy",
"regularization",
"."
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L107-L120 | train |
pmelchior/proxmin | proxmin/operators.py | get_gradient_y | def get_gradient_y(shape, py):
"""Calculate the gradient in the y direction to the line at py
The y gradient operator is a block matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
import scipy.s... | python | def get_gradient_y(shape, py):
"""Calculate the gradient in the y direction to the line at py
The y gradient operator is a block matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
import scipy.s... | [
"def",
"get_gradient_y",
"(",
"shape",
",",
"py",
")",
":",
"import",
"scipy",
".",
"sparse",
"height",
",",
"width",
"=",
"shape",
"rows",
"=",
"[",
"]",
"empty",
"=",
"scipy",
".",
"sparse",
".",
"dia_matrix",
"(",
"(",
"width",
",",
"width",
")",
... | Calculate the gradient in the y direction to the line at py
The y gradient operator is a block matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros. | [
"Calculate",
"the",
"gradient",
"in",
"the",
"y",
"direction",
"to",
"the",
"line",
"at",
"py"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L159-L186 | train |
pmelchior/proxmin | proxmin/operators.py | get_gradient_x | def get_gradient_x(shape, px):
"""Calculate the gradient in the x direction to the line at px
The y gradient operator is a block diagonal matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
impor... | python | def get_gradient_x(shape, px):
"""Calculate the gradient in the x direction to the line at px
The y gradient operator is a block diagonal matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
impor... | [
"def",
"get_gradient_x",
"(",
"shape",
",",
"px",
")",
":",
"import",
"scipy",
".",
"sparse",
"height",
",",
"width",
"=",
"shape",
"size",
"=",
"height",
"*",
"width",
"c",
"=",
"-",
"np",
".",
"ones",
"(",
"(",
"width",
",",
")",
")",
"c",
"[",... | Calculate the gradient in the x direction to the line at px
The y gradient operator is a block diagonal matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros. | [
"Calculate",
"the",
"gradient",
"in",
"the",
"x",
"direction",
"to",
"the",
"line",
"at",
"px"
] | 60e49d90c67c46329cc1d3b5c484951dc8bd2c3f | https://github.com/pmelchior/proxmin/blob/60e49d90c67c46329cc1d3b5c484951dc8bd2c3f/proxmin/operators.py#L188-L212 | train |
ValvePython/vpk | vpk/__init__.py | NewVPK.read_dir | def read_dir(self, path):
"""
Reads the given path into the tree
"""
self.tree = {}
self.file_count = 0
self.path = path
for root, _, filelist in os.walk(path):
rel = root[len(path):].lstrip('/\\')
# empty rel, means file is in root dir
... | python | def read_dir(self, path):
"""
Reads the given path into the tree
"""
self.tree = {}
self.file_count = 0
self.path = path
for root, _, filelist in os.walk(path):
rel = root[len(path):].lstrip('/\\')
# empty rel, means file is in root dir
... | [
"def",
"read_dir",
"(",
"self",
",",
"path",
")",
":",
"self",
".",
"tree",
"=",
"{",
"}",
"self",
".",
"file_count",
"=",
"0",
"self",
".",
"path",
"=",
"path",
"for",
"root",
",",
"_",
",",
"filelist",
"in",
"os",
".",
"walk",
"(",
"path",
")... | Reads the given path into the tree | [
"Reads",
"the",
"given",
"path",
"into",
"the",
"tree"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L43-L76 | train |
ValvePython/vpk | vpk/__init__.py | NewVPK.calculate_tree_length | def calculate_tree_length(self):
"""
Walks the tree and calculate the tree length
"""
tree_length = 0
for ext in self.tree:
tree_length += len(ext) + 2
for relpath in self.tree[ext]:
tree_length += len(relpath) + 2
for fi... | python | def calculate_tree_length(self):
"""
Walks the tree and calculate the tree length
"""
tree_length = 0
for ext in self.tree:
tree_length += len(ext) + 2
for relpath in self.tree[ext]:
tree_length += len(relpath) + 2
for fi... | [
"def",
"calculate_tree_length",
"(",
"self",
")",
":",
"tree_length",
"=",
"0",
"for",
"ext",
"in",
"self",
".",
"tree",
":",
"tree_length",
"+=",
"len",
"(",
"ext",
")",
"+",
"2",
"for",
"relpath",
"in",
"self",
".",
"tree",
"[",
"ext",
"]",
":",
... | Walks the tree and calculate the tree length | [
"Walks",
"the",
"tree",
"and",
"calculate",
"the",
"tree",
"length"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L79-L94 | train |
ValvePython/vpk | vpk/__init__.py | NewVPK.save | def save(self, vpk_output_path):
"""
Saves the VPK at the given path
"""
with fopen(vpk_output_path, 'wb') as f:
# write VPK1 header
f.write(struct.pack("3I", self.signature,
self.version,
... | python | def save(self, vpk_output_path):
"""
Saves the VPK at the given path
"""
with fopen(vpk_output_path, 'wb') as f:
# write VPK1 header
f.write(struct.pack("3I", self.signature,
self.version,
... | [
"def",
"save",
"(",
"self",
",",
"vpk_output_path",
")",
":",
"with",
"fopen",
"(",
"vpk_output_path",
",",
"'wb'",
")",
"as",
"f",
":",
"f",
".",
"write",
"(",
"struct",
".",
"pack",
"(",
"\"3I\"",
",",
"self",
".",
"signature",
",",
"self",
".",
... | Saves the VPK at the given path | [
"Saves",
"the",
"VPK",
"at",
"the",
"given",
"path"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L97-L163 | train |
ValvePython/vpk | vpk/__init__.py | VPK.get_file | def get_file(self, path):
"""
Returns VPKFile instance for the given path
"""
metadata = self.get_file_meta(path)
return self.get_vpkfile_instance(path, metadata) | python | def get_file(self, path):
"""
Returns VPKFile instance for the given path
"""
metadata = self.get_file_meta(path)
return self.get_vpkfile_instance(path, metadata) | [
"def",
"get_file",
"(",
"self",
",",
"path",
")",
":",
"metadata",
"=",
"self",
".",
"get_file_meta",
"(",
"path",
")",
"return",
"self",
".",
"get_vpkfile_instance",
"(",
"path",
",",
"metadata",
")"
] | Returns VPKFile instance for the given path | [
"Returns",
"VPKFile",
"instance",
"for",
"the",
"given",
"path"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L251-L256 | train |
ValvePython/vpk | vpk/__init__.py | VPK.get_file_meta | def get_file_meta(self, path):
"""
Returns metadata for given file path
"""
if self.tree is None:
self.read_index()
if path not in self.tree:
raise KeyError("Path doesn't exist")
return self._make_meta_dict(self.tree[path]) | python | def get_file_meta(self, path):
"""
Returns metadata for given file path
"""
if self.tree is None:
self.read_index()
if path not in self.tree:
raise KeyError("Path doesn't exist")
return self._make_meta_dict(self.tree[path]) | [
"def",
"get_file_meta",
"(",
"self",
",",
"path",
")",
":",
"if",
"self",
".",
"tree",
"is",
"None",
":",
"self",
".",
"read_index",
"(",
")",
"if",
"path",
"not",
"in",
"self",
".",
"tree",
":",
"raise",
"KeyError",
"(",
"\"Path doesn't exist\"",
")",... | Returns metadata for given file path | [
"Returns",
"metadata",
"for",
"given",
"file",
"path"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L258-L268 | train |
ValvePython/vpk | vpk/__init__.py | VPK.read_header | def read_header(self):
"""
Reads VPK file header from the file
"""
with fopen(self.vpk_path, 'rb') as f:
(self.signature,
self.version,
self.tree_length
) = struct.unpack("3I", f.read(3*4))
# original format - headerless
... | python | def read_header(self):
"""
Reads VPK file header from the file
"""
with fopen(self.vpk_path, 'rb') as f:
(self.signature,
self.version,
self.tree_length
) = struct.unpack("3I", f.read(3*4))
# original format - headerless
... | [
"def",
"read_header",
"(",
"self",
")",
":",
"with",
"fopen",
"(",
"self",
".",
"vpk_path",
",",
"'rb'",
")",
"as",
"f",
":",
"(",
"self",
".",
"signature",
",",
"self",
".",
"version",
",",
"self",
".",
"tree_length",
")",
"=",
"struct",
".",
"unp... | Reads VPK file header from the file | [
"Reads",
"VPK",
"file",
"header",
"from",
"the",
"file"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L284-L330 | train |
ValvePython/vpk | vpk/__init__.py | VPK.read_index | def read_index(self):
"""
Reads the index and populates the directory tree
"""
if not isinstance(self.tree, dict):
self.tree = dict()
self.tree.clear()
for path, metadata in self.read_index_iter():
self.tree[path] = metadata | python | def read_index(self):
"""
Reads the index and populates the directory tree
"""
if not isinstance(self.tree, dict):
self.tree = dict()
self.tree.clear()
for path, metadata in self.read_index_iter():
self.tree[path] = metadata | [
"def",
"read_index",
"(",
"self",
")",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"tree",
",",
"dict",
")",
":",
"self",
".",
"tree",
"=",
"dict",
"(",
")",
"self",
".",
"tree",
".",
"clear",
"(",
")",
"for",
"path",
",",
"metadata",
"in",... | Reads the index and populates the directory tree | [
"Reads",
"the",
"index",
"and",
"populates",
"the",
"directory",
"tree"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L363-L373 | train |
ValvePython/vpk | vpk/__init__.py | VPK.read_index_iter | def read_index_iter(self):
"""Generator function that reads the file index from the vpk file
yeilds (file_path, metadata)
"""
with fopen(self.vpk_path, 'rb') as f:
f.seek(self.header_length)
while True:
if self.version > 0 and f.tell() > self.tr... | python | def read_index_iter(self):
"""Generator function that reads the file index from the vpk file
yeilds (file_path, metadata)
"""
with fopen(self.vpk_path, 'rb') as f:
f.seek(self.header_length)
while True:
if self.version > 0 and f.tell() > self.tr... | [
"def",
"read_index_iter",
"(",
"self",
")",
":",
"with",
"fopen",
"(",
"self",
".",
"vpk_path",
",",
"'rb'",
")",
"as",
"f",
":",
"f",
".",
"seek",
"(",
"self",
".",
"header_length",
")",
"while",
"True",
":",
"if",
"self",
".",
"version",
">",
"0"... | Generator function that reads the file index from the vpk file
yeilds (file_path, metadata) | [
"Generator",
"function",
"that",
"reads",
"the",
"file",
"index",
"from",
"the",
"vpk",
"file"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L375-L422 | train |
ValvePython/vpk | vpk/__init__.py | VPKFile.save | def save(self, path):
"""
Save the file to the specified path
"""
# remember and restore file position
pos = self.tell()
self.seek(0)
with fopen(path, 'wb') as output:
output.truncate(self.length)
for chunk in iter(lambda: self.read(1024),... | python | def save(self, path):
"""
Save the file to the specified path
"""
# remember and restore file position
pos = self.tell()
self.seek(0)
with fopen(path, 'wb') as output:
output.truncate(self.length)
for chunk in iter(lambda: self.read(1024),... | [
"def",
"save",
"(",
"self",
",",
"path",
")",
":",
"pos",
"=",
"self",
".",
"tell",
"(",
")",
"self",
".",
"seek",
"(",
"0",
")",
"with",
"fopen",
"(",
"path",
",",
"'wb'",
")",
"as",
"output",
":",
"output",
".",
"truncate",
"(",
"self",
".",
... | Save the file to the specified path | [
"Save",
"the",
"file",
"to",
"the",
"specified",
"path"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L454-L467 | train |
ValvePython/vpk | vpk/__init__.py | VPKFile.verify | def verify(self):
"""
Returns True if the file contents match with the CRC32 attribute
note: reset
"""
# remember file pointer
pos = self.tell()
self.seek(0)
checksum = 0
for chunk in iter(lambda: self.read(1024), b''):
checksum = cr... | python | def verify(self):
"""
Returns True if the file contents match with the CRC32 attribute
note: reset
"""
# remember file pointer
pos = self.tell()
self.seek(0)
checksum = 0
for chunk in iter(lambda: self.read(1024), b''):
checksum = cr... | [
"def",
"verify",
"(",
"self",
")",
":",
"pos",
"=",
"self",
".",
"tell",
"(",
")",
"self",
".",
"seek",
"(",
"0",
")",
"checksum",
"=",
"0",
"for",
"chunk",
"in",
"iter",
"(",
"lambda",
":",
"self",
".",
"read",
"(",
"1024",
")",
",",
"b''",
... | Returns True if the file contents match with the CRC32 attribute
note: reset | [
"Returns",
"True",
"if",
"the",
"file",
"contents",
"match",
"with",
"the",
"CRC32",
"attribute"
] | cc522fc7febbf53efa5d58fcd1ad2103dae37ac8 | https://github.com/ValvePython/vpk/blob/cc522fc7febbf53efa5d58fcd1ad2103dae37ac8/vpk/__init__.py#L469-L487 | train |
stephen-bunn/file-config | tasks/__init__.py | publish | def publish(ctx, test=False, force=False, draft=False):
""" Publish the project.
:param bool test: Publishes to PyPi test server (defaults to False)
:param bool force: Skip version check (defaults to False)
:param bool draft: Sample publish (has no effect) (defaults to False)
"""
previous_vers... | python | def publish(ctx, test=False, force=False, draft=False):
""" Publish the project.
:param bool test: Publishes to PyPi test server (defaults to False)
:param bool force: Skip version check (defaults to False)
:param bool draft: Sample publish (has no effect) (defaults to False)
"""
previous_vers... | [
"def",
"publish",
"(",
"ctx",
",",
"test",
"=",
"False",
",",
"force",
"=",
"False",
",",
"draft",
"=",
"False",
")",
":",
"previous_version",
"=",
"get_previous_version",
"(",
"ctx",
")",
"current_version",
"=",
"parver",
".",
"Version",
".",
"parse",
"... | Publish the project.
:param bool test: Publishes to PyPi test server (defaults to False)
:param bool force: Skip version check (defaults to False)
:param bool draft: Sample publish (has no effect) (defaults to False) | [
"Publish",
"the",
"project",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/__init__.py#L76-L169 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | _handle_dumps | def _handle_dumps(self, handler, **kwargs):
""" Dumps caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:return: The dumped string
:rtype: str
"""
return handler.dumps(self.__class__, to_dict(self), **kwargs) | python | def _handle_dumps(self, handler, **kwargs):
""" Dumps caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:return: The dumped string
:rtype: str
"""
return handler.dumps(self.__class__, to_dict(self), **kwargs) | [
"def",
"_handle_dumps",
"(",
"self",
",",
"handler",
",",
"**",
"kwargs",
")",
":",
"return",
"handler",
".",
"dumps",
"(",
"self",
".",
"__class__",
",",
"to_dict",
"(",
"self",
")",
",",
"**",
"kwargs",
")"
] | Dumps caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:return: The dumped string
:rtype: str | [
"Dumps",
"caller",
"used",
"by",
"partial",
"method",
"for",
"dynamic",
"handler",
"assignments",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L48-L56 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | _handle_dump | def _handle_dump(self, handler, file_object, **kwargs):
""" Dump caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:param file file_object: The file object to dump to
:return: The dumped string
:rtype: str
"""
return handler.dump(self._... | python | def _handle_dump(self, handler, file_object, **kwargs):
""" Dump caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:param file file_object: The file object to dump to
:return: The dumped string
:rtype: str
"""
return handler.dump(self._... | [
"def",
"_handle_dump",
"(",
"self",
",",
"handler",
",",
"file_object",
",",
"**",
"kwargs",
")",
":",
"return",
"handler",
".",
"dump",
"(",
"self",
".",
"__class__",
",",
"to_dict",
"(",
"self",
")",
",",
"file_object",
",",
"**",
"kwargs",
")"
] | Dump caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:param file file_object: The file object to dump to
:return: The dumped string
:rtype: str | [
"Dump",
"caller",
"used",
"by",
"partial",
"method",
"for",
"dynamic",
"handler",
"assignments",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L59-L68 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | config | def config(maybe_cls=None, these=None, title=None, description=None):
""" File config class decorator.
Usage is to simply decorate a **class** to make it a
:func:`config <file_config._file_config.config>` class.
>>> import file_config
>>> @file_config.config(
title="My Config Title",
... | python | def config(maybe_cls=None, these=None, title=None, description=None):
""" File config class decorator.
Usage is to simply decorate a **class** to make it a
:func:`config <file_config._file_config.config>` class.
>>> import file_config
>>> @file_config.config(
title="My Config Title",
... | [
"def",
"config",
"(",
"maybe_cls",
"=",
"None",
",",
"these",
"=",
"None",
",",
"title",
"=",
"None",
",",
"description",
"=",
"None",
")",
":",
"def",
"wrap",
"(",
"config_cls",
")",
":",
"setattr",
"(",
"config_cls",
",",
"CONFIG_KEY",
",",
"dict",
... | File config class decorator.
Usage is to simply decorate a **class** to make it a
:func:`config <file_config._file_config.config>` class.
>>> import file_config
>>> @file_config.config(
title="My Config Title",
description="A description about my config"
)
class... | [
"File",
"config",
"class",
"decorator",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L101-L163 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | var | def var(
type=None, # noqa
default=None,
name=None,
title=None,
description=None,
required=True,
examples=None,
encoder=None,
decoder=None,
min=None, # noqa
max=None, # noqa
unique=None,
contains=None,
**kwargs,
):
""" Creates a config variable.
Use th... | python | def var(
type=None, # noqa
default=None,
name=None,
title=None,
description=None,
required=True,
examples=None,
encoder=None,
decoder=None,
min=None, # noqa
max=None, # noqa
unique=None,
contains=None,
**kwargs,
):
""" Creates a config variable.
Use th... | [
"def",
"var",
"(",
"type",
"=",
"None",
",",
"default",
"=",
"None",
",",
"name",
"=",
"None",
",",
"title",
"=",
"None",
",",
"description",
"=",
"None",
",",
"required",
"=",
"True",
",",
"examples",
"=",
"None",
",",
"encoder",
"=",
"None",
",",... | Creates a config variable.
Use this method to create the class variables of your
:func:`config <file_config._file_config.config>` decorated class.
>>> import file_config
>>> @file_config.config
class MyConfig(object):
name = file_config.var(str)
:param type type: The expected ... | [
"Creates",
"a",
"config",
"variable",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L166-L238 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | make_config | def make_config(name, var_dict, title=None, description=None, **kwargs):
""" Creates a config instance from scratch.
Usage is virtually the same as :func:`attr.make_class`.
>>> import file_config
>>> MyConfig = file_config.make_config(
"MyConfig",
{"name": file_config.var(str)}... | python | def make_config(name, var_dict, title=None, description=None, **kwargs):
""" Creates a config instance from scratch.
Usage is virtually the same as :func:`attr.make_class`.
>>> import file_config
>>> MyConfig = file_config.make_config(
"MyConfig",
{"name": file_config.var(str)}... | [
"def",
"make_config",
"(",
"name",
",",
"var_dict",
",",
"title",
"=",
"None",
",",
"description",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"return",
"config",
"(",
"attr",
".",
"make_class",
"(",
"name",
",",
"attrs",
"=",
"{",
"}",
",",
"**",
... | Creates a config instance from scratch.
Usage is virtually the same as :func:`attr.make_class`.
>>> import file_config
>>> MyConfig = file_config.make_config(
"MyConfig",
{"name": file_config.var(str)}
)
:param str name: The name of the config
:param dict var_dict:... | [
"Creates",
"a",
"config",
"instance",
"from",
"scratch",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L241-L265 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | _build | def _build(config_cls, dictionary, validate=False): # noqa
""" Builds an instance of ``config_cls`` using ``dictionary``.
:param type config_cls: The class to use for building
:param dict dictionary: The dictionary to use for building ``config_cls``
:param bool validate: Performs validation before bui... | python | def _build(config_cls, dictionary, validate=False): # noqa
""" Builds an instance of ``config_cls`` using ``dictionary``.
:param type config_cls: The class to use for building
:param dict dictionary: The dictionary to use for building ``config_cls``
:param bool validate: Performs validation before bui... | [
"def",
"_build",
"(",
"config_cls",
",",
"dictionary",
",",
"validate",
"=",
"False",
")",
":",
"if",
"not",
"is_config_type",
"(",
"config_cls",
")",
":",
"raise",
"ValueError",
"(",
"f\"cannot build {config_cls!r} from {dictionary!r}, \"",
"f\"{config_cls!r} is not a ... | Builds an instance of ``config_cls`` using ``dictionary``.
:param type config_cls: The class to use for building
:param dict dictionary: The dictionary to use for building ``config_cls``
:param bool validate: Performs validation before building ``config_cls``,
defaults to False, optional
:retur... | [
"Builds",
"an",
"instance",
"of",
"config_cls",
"using",
"dictionary",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L268-L345 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | _dump | def _dump(config_instance, dict_type=OrderedDict):
""" Dumps an instance from ``instance`` to a dictionary type mapping.
:param object instance: The instance to serialized to a dictionary
:param object dict_type: Some dictionary type, defaults to ``OrderedDict``
:return: Dumped dictionary
:rtype: c... | python | def _dump(config_instance, dict_type=OrderedDict):
""" Dumps an instance from ``instance`` to a dictionary type mapping.
:param object instance: The instance to serialized to a dictionary
:param object dict_type: Some dictionary type, defaults to ``OrderedDict``
:return: Dumped dictionary
:rtype: c... | [
"def",
"_dump",
"(",
"config_instance",
",",
"dict_type",
"=",
"OrderedDict",
")",
":",
"if",
"not",
"is_config",
"(",
"config_instance",
")",
":",
"raise",
"ValueError",
"(",
"f\"cannot dump instance {config_instance!r} to dict, \"",
"\"instance is not a config class\"",
... | Dumps an instance from ``instance`` to a dictionary type mapping.
:param object instance: The instance to serialized to a dictionary
:param object dict_type: Some dictionary type, defaults to ``OrderedDict``
:return: Dumped dictionary
:rtype: collections.OrderedDict (or instance of ``dict_type``) | [
"Dumps",
"an",
"instance",
"from",
"instance",
"to",
"a",
"dictionary",
"type",
"mapping",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L348-L414 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | validate | def validate(instance):
""" Validates a given ``instance``.
:param object instance: The instance to validate
:raises jsonschema.exceptions.ValidationError: On failed validation
"""
jsonschema.validate(
to_dict(instance, dict_type=dict), build_schema(instance.__class__)
) | python | def validate(instance):
""" Validates a given ``instance``.
:param object instance: The instance to validate
:raises jsonschema.exceptions.ValidationError: On failed validation
"""
jsonschema.validate(
to_dict(instance, dict_type=dict), build_schema(instance.__class__)
) | [
"def",
"validate",
"(",
"instance",
")",
":",
"jsonschema",
".",
"validate",
"(",
"to_dict",
"(",
"instance",
",",
"dict_type",
"=",
"dict",
")",
",",
"build_schema",
"(",
"instance",
".",
"__class__",
")",
")"
] | Validates a given ``instance``.
:param object instance: The instance to validate
:raises jsonschema.exceptions.ValidationError: On failed validation | [
"Validates",
"a",
"given",
"instance",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L417-L426 | train |
stephen-bunn/file-config | src/file_config/_file_config.py | from_dict | def from_dict(config_cls, dictionary, validate=False):
""" Loads an instance of ``config_cls`` from a dictionary.
:param type config_cls: The class to build an instance of
:param dict dictionary: The dictionary to load from
:param bool validate: Preforms validation before building ``config_cls``,
... | python | def from_dict(config_cls, dictionary, validate=False):
""" Loads an instance of ``config_cls`` from a dictionary.
:param type config_cls: The class to build an instance of
:param dict dictionary: The dictionary to load from
:param bool validate: Preforms validation before building ``config_cls``,
... | [
"def",
"from_dict",
"(",
"config_cls",
",",
"dictionary",
",",
"validate",
"=",
"False",
")",
":",
"return",
"_build",
"(",
"config_cls",
",",
"dictionary",
",",
"validate",
"=",
"validate",
")"
] | Loads an instance of ``config_cls`` from a dictionary.
:param type config_cls: The class to build an instance of
:param dict dictionary: The dictionary to load from
:param bool validate: Preforms validation before building ``config_cls``,
defaults to False, optional
:return: An instance of ``co... | [
"Loads",
"an",
"instance",
"of",
"config_cls",
"from",
"a",
"dictionary",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/_file_config.py#L429-L440 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.imported | def imported(self):
""" The imported handler module.
:return: The imported handler module.
:rtype: module
"""
if not hasattr(self, "_imported"):
self._imported = self._discover_import()
return self._imported | python | def imported(self):
""" The imported handler module.
:return: The imported handler module.
:rtype: module
"""
if not hasattr(self, "_imported"):
self._imported = self._discover_import()
return self._imported | [
"def",
"imported",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_imported\"",
")",
":",
"self",
".",
"_imported",
"=",
"self",
".",
"_discover_import",
"(",
")",
"return",
"self",
".",
"_imported"
] | The imported handler module.
:return: The imported handler module.
:rtype: module | [
"The",
"imported",
"handler",
"module",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L15-L24 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.handler | def handler(self):
""" The current imported serialization handler module.
:return: The imported handler
:rtype: module
"""
if not hasattr(self, "_handler"):
self._handler = sys.modules[self.imported]
return self._handler | python | def handler(self):
""" The current imported serialization handler module.
:return: The imported handler
:rtype: module
"""
if not hasattr(self, "_handler"):
self._handler = sys.modules[self.imported]
return self._handler | [
"def",
"handler",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_handler\"",
")",
":",
"self",
".",
"_handler",
"=",
"sys",
".",
"modules",
"[",
"self",
".",
"imported",
"]",
"return",
"self",
".",
"_handler"
] | The current imported serialization handler module.
:return: The imported handler
:rtype: module | [
"The",
"current",
"imported",
"serialization",
"handler",
"module",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L27-L36 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.available | def available(self):
""" True if any of the supported modules from ``packages`` is available for use.
:return: True if any modules from ``packages`` exist
:rtype: bool
"""
for module_name in self.packages:
if importlib.util.find_spec(module_name):
re... | python | def available(self):
""" True if any of the supported modules from ``packages`` is available for use.
:return: True if any modules from ``packages`` exist
:rtype: bool
"""
for module_name in self.packages:
if importlib.util.find_spec(module_name):
re... | [
"def",
"available",
"(",
"self",
")",
":",
"for",
"module_name",
"in",
"self",
".",
"packages",
":",
"if",
"importlib",
".",
"util",
".",
"find_spec",
"(",
"module_name",
")",
":",
"return",
"True",
"return",
"False"
] | True if any of the supported modules from ``packages`` is available for use.
:return: True if any modules from ``packages`` exist
:rtype: bool | [
"True",
"if",
"any",
"of",
"the",
"supported",
"modules",
"from",
"packages",
"is",
"available",
"for",
"use",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L69-L79 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler._discover_import | def _discover_import(self, prefer=None):
""" Discovers and imports the best available module from ``packages``.
:raises ModuleNotFoundError: If no module is available
:return: The name of the module to use
:rtype: str
"""
available_packages = self.packages
if is... | python | def _discover_import(self, prefer=None):
""" Discovers and imports the best available module from ``packages``.
:raises ModuleNotFoundError: If no module is available
:return: The name of the module to use
:rtype: str
"""
available_packages = self.packages
if is... | [
"def",
"_discover_import",
"(",
"self",
",",
"prefer",
"=",
"None",
")",
":",
"available_packages",
"=",
"self",
".",
"packages",
"if",
"isinstance",
"(",
"prefer",
",",
"str",
")",
":",
"available_packages",
"=",
"(",
"prefer",
",",
")",
"for",
"module_na... | Discovers and imports the best available module from ``packages``.
:raises ModuleNotFoundError: If no module is available
:return: The name of the module to use
:rtype: str | [
"Discovers",
"and",
"imports",
"the",
"best",
"available",
"module",
"from",
"packages",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L81-L101 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler._prefer_package | def _prefer_package(self, package):
""" Prefer a serializtion handler over other handlers.
:param str package: The name of the package to use
:raises ValueError: When the given package name is not one of the available
supported serializtion packages for this handler
:return:... | python | def _prefer_package(self, package):
""" Prefer a serializtion handler over other handlers.
:param str package: The name of the package to use
:raises ValueError: When the given package name is not one of the available
supported serializtion packages for this handler
:return:... | [
"def",
"_prefer_package",
"(",
"self",
",",
"package",
")",
":",
"if",
"isinstance",
"(",
"package",
",",
"str",
")",
"and",
"package",
"!=",
"self",
".",
"imported",
":",
"if",
"package",
"not",
"in",
"self",
".",
"packages",
":",
"raise",
"ValueError",... | Prefer a serializtion handler over other handlers.
:param str package: The name of the package to use
:raises ValueError: When the given package name is not one of the available
supported serializtion packages for this handler
:return: The name of the serialization handler
:... | [
"Prefer",
"a",
"serializtion",
"handler",
"over",
"other",
"handlers",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L103-L125 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.dumps | def dumps(self, config, instance, prefer=None, **kwargs):
""" An abstract dumps method which dumps an instance into the subclasses format.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param str prefer: The preferred serialization mo... | python | def dumps(self, config, instance, prefer=None, **kwargs):
""" An abstract dumps method which dumps an instance into the subclasses format.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param str prefer: The preferred serialization mo... | [
"def",
"dumps",
"(",
"self",
",",
"config",
",",
"instance",
",",
"prefer",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"dumper",
"=",
"self",
".",
"_prefer_package",
"(",
"prefer",
")",
"dumps_hook_name",
"=",
"f\"on_{dumper}_dumps\"",
"dumps_hook",
"=",
... | An abstract dumps method which dumps an instance into the subclasses format.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param str prefer: The preferred serialization module name
:raises ValueError: If dump handler does not provide... | [
"An",
"abstract",
"dumps",
"method",
"which",
"dumps",
"an",
"instance",
"into",
"the",
"subclasses",
"format",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L127-L155 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.loads | def loads(self, config, content, prefer=None):
""" An abstract loads method which loads an instance from some content.
:param class config: The config class to load into
:param str content: The content to load from
:param str prefer: The preferred serialization module name
:rais... | python | def loads(self, config, content, prefer=None):
""" An abstract loads method which loads an instance from some content.
:param class config: The config class to load into
:param str content: The content to load from
:param str prefer: The preferred serialization module name
:rais... | [
"def",
"loads",
"(",
"self",
",",
"config",
",",
"content",
",",
"prefer",
"=",
"None",
")",
":",
"loader",
"=",
"self",
".",
"_prefer_package",
"(",
"prefer",
")",
"loads_hook_name",
"=",
"f\"on_{loader}_loads\"",
"loads_hook",
"=",
"getattr",
"(",
"self",
... | An abstract loads method which loads an instance from some content.
:param class config: The config class to load into
:param str content: The content to load from
:param str prefer: The preferred serialization module name
:raises ValueError: If load handler does not provided handler me... | [
"An",
"abstract",
"loads",
"method",
"which",
"loads",
"an",
"instance",
"from",
"some",
"content",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L157-L176 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.dump | def dump(self, config, instance, file_object, prefer=None, **kwargs):
""" An abstract method that dumps to a given file object.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param file file_object: The file object to dump to
... | python | def dump(self, config, instance, file_object, prefer=None, **kwargs):
""" An abstract method that dumps to a given file object.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param file file_object: The file object to dump to
... | [
"def",
"dump",
"(",
"self",
",",
"config",
",",
"instance",
",",
"file_object",
",",
"prefer",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"file_object",
".",
"write",
"(",
"self",
".",
"dumps",
"(",
"config",
",",
"instance",
",",
"prefer",
"=",
"pr... | An abstract method that dumps to a given file object.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param file file_object: The file object to dump to
:param str prefer: The preferred serialization module name | [
"An",
"abstract",
"method",
"that",
"dumps",
"to",
"a",
"given",
"file",
"object",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L178-L187 | train |
stephen-bunn/file-config | src/file_config/handlers/_common.py | BaseHandler.load | def load(self, config, file_object, prefer=None):
""" An abstract method that loads from a given file object.
:param class config: The config class to load into
:param file file_object: The file object to load from
:param str prefer: The preferred serialization module name
:retu... | python | def load(self, config, file_object, prefer=None):
""" An abstract method that loads from a given file object.
:param class config: The config class to load into
:param file file_object: The file object to load from
:param str prefer: The preferred serialization module name
:retu... | [
"def",
"load",
"(",
"self",
",",
"config",
",",
"file_object",
",",
"prefer",
"=",
"None",
")",
":",
"return",
"self",
".",
"loads",
"(",
"config",
",",
"file_object",
".",
"read",
"(",
")",
",",
"prefer",
"=",
"prefer",
")"
] | An abstract method that loads from a given file object.
:param class config: The config class to load into
:param file file_object: The file object to load from
:param str prefer: The preferred serialization module name
:returns: A dictionary converted from the content of the given file... | [
"An",
"abstract",
"method",
"that",
"loads",
"from",
"a",
"given",
"file",
"object",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/handlers/_common.py#L189-L199 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_attribute_modifiers | def _build_attribute_modifiers(var, attribute_mapping, ignore=None):
""" Handles adding schema modifiers for a given config var and some mapping.
:param attr._make.Attribute var: The config var to build modifiers for
:param Dict[str, str] attribute_mapping: A mapping of attribute to jsonschema
modi... | python | def _build_attribute_modifiers(var, attribute_mapping, ignore=None):
""" Handles adding schema modifiers for a given config var and some mapping.
:param attr._make.Attribute var: The config var to build modifiers for
:param Dict[str, str] attribute_mapping: A mapping of attribute to jsonschema
modi... | [
"def",
"_build_attribute_modifiers",
"(",
"var",
",",
"attribute_mapping",
",",
"ignore",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"ignore",
",",
"list",
")",
":",
"ignore",
"=",
"[",
"\"type\"",
",",
"\"name\"",
",",
"\"required\"",
",",
"\"... | Handles adding schema modifiers for a given config var and some mapping.
:param attr._make.Attribute var: The config var to build modifiers for
:param Dict[str, str] attribute_mapping: A mapping of attribute to jsonschema
modifiers
:param List[str] ignore: A list of mapping keys to ignore, defaults... | [
"Handles",
"adding",
"schema",
"modifiers",
"for",
"a",
"given",
"config",
"var",
"and",
"some",
"mapping",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L41-L91 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_enum_type | def _build_enum_type(var, property_path=None):
""" Builds schema definitions for enum type values.
:param var: The enum type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict[str, Any]
... | python | def _build_enum_type(var, property_path=None):
""" Builds schema definitions for enum type values.
:param var: The enum type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict[str, Any]
... | [
"def",
"_build_enum_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"entry",
"=",
"var",
".",
"metadata",
"[",
"CONFIG_KEY",
"]",
"enum_values",
"=",
"[",
"member",
".",
"... | Builds schema definitions for enum type values.
:param var: The enum type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"enum",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L110-L137 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_string_type | def _build_string_type(var, property_path=None):
""" Builds schema definitions for string type values.
:param var: The string type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | def _build_string_type(var, property_path=None):
""" Builds schema definitions for string type values.
:param var: The string type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | [
"def",
"_build_string_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"schema",
"=",
"{",
"\"type\"",
":",
"\"string\"",
"}",
"if",
"is_builtin_type",
"(",
"var",
")",
":",
... | Builds schema definitions for string type values.
:param var: The string type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"string",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L157-L186 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_integer_type | def _build_integer_type(var, property_path=None):
""" Builds schema definitions for integer type values.
:param var: The integer type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The b... | python | def _build_integer_type(var, property_path=None):
""" Builds schema definitions for integer type values.
:param var: The integer type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The b... | [
"def",
"_build_integer_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"schema",
"=",
"{",
"\"type\"",
":",
"\"integer\"",
"}",
"if",
"is_builtin_type",
"(",
"var",
")",
":"... | Builds schema definitions for integer type values.
:param var: The integer type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"integer",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L189-L212 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_number_type | def _build_number_type(var, property_path=None):
""" Builds schema definitions for number type values.
:param var: The number type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | def _build_number_type(var, property_path=None):
""" Builds schema definitions for number type values.
:param var: The number type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | [
"def",
"_build_number_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"schema",
"=",
"{",
"\"type\"",
":",
"\"number\"",
"}",
"if",
"is_builtin_type",
"(",
"var",
")",
":",
... | Builds schema definitions for number type values.
:param var: The number type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"number",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L215-L238 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_array_type | def _build_array_type(var, property_path=None):
""" Builds schema definitions for array type values.
:param var: The array type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built s... | python | def _build_array_type(var, property_path=None):
""" Builds schema definitions for array type values.
:param var: The array type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built s... | [
"def",
"_build_array_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"schema",
"=",
"{",
"\"type\"",
":",
"\"array\"",
",",
"\"items\"",
":",
"{",
"\"$id\"",
":",
"f\"#/{'/'... | Builds schema definitions for array type values.
:param var: The array type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"array",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L241-L284 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_object_type | def _build_object_type(var, property_path=None):
""" Builds schema definitions for object type values.
:param var: The object type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | python | def _build_object_type(var, property_path=None):
""" Builds schema definitions for object type values.
:param var: The object type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The buil... | [
"def",
"_build_object_type",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"schema",
"=",
"{",
"\"type\"",
":",
"\"object\"",
"}",
"if",
"is_builtin_type",
"(",
"var",
")",
":",
... | Builds schema definitions for object type values.
:param var: The object type value
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:param property_path: [type], optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"Builds",
"schema",
"definitions",
"for",
"object",
"type",
"values",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L287-L329 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_type | def _build_type(type_, value, property_path=None):
""" Builds the schema definition based on the given type for the given value.
:param type_: The type of the value
:param value: The value to build the schema definition for
:param List[str] property_path: The property path of the current type,
... | python | def _build_type(type_, value, property_path=None):
""" Builds the schema definition based on the given type for the given value.
:param type_: The type of the value
:param value: The value to build the schema definition for
:param List[str] property_path: The property path of the current type,
... | [
"def",
"_build_type",
"(",
"type_",
",",
"value",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"for",
"(",
"type_check",
",",
"builder",
")",
"in",
"(",
"(",
"is_enum_type",
",",
"_build_... | Builds the schema definition based on the given type for the given value.
:param type_: The type of the value
:param value: The value to build the schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema de... | [
"Builds",
"the",
"schema",
"definition",
"based",
"on",
"the",
"given",
"type",
"for",
"the",
"given",
"value",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L332-L362 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_var | def _build_var(var, property_path=None):
""" Builds a schema definition for a given config var.
:param attr._make.Attribute var: The var to generate a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises ValueError: When... | python | def _build_var(var, property_path=None):
""" Builds a schema definition for a given config var.
:param attr._make.Attribute var: The var to generate a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises ValueError: When... | [
"def",
"_build_var",
"(",
"var",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"if",
"not",
"is_config_var",
"(",
"var",
")",
":",
"raise",
"ValueError",
"(",
"f\"var {var!r} is not a config var... | Builds a schema definition for a given config var.
:param attr._make.Attribute var: The var to generate a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises ValueError: When the given ``var`` is not a file_config var
:... | [
"Builds",
"a",
"schema",
"definition",
"for",
"a",
"given",
"config",
"var",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L365-L412 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build_config | def _build_config(config_cls, property_path=None):
""" Builds the schema definition for a given config class.
:param class config_cls: The config class to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises Valu... | python | def _build_config(config_cls, property_path=None):
""" Builds the schema definition for a given config class.
:param class config_cls: The config class to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises Valu... | [
"def",
"_build_config",
"(",
"config_cls",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"if",
"not",
"is_config_type",
"(",
"config_cls",
")",
":",
"raise",
"ValueError",
"(",
"f\"class {config... | Builds the schema definition for a given config class.
:param class config_cls: The config class to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:raises ValueError: When the given ``config_cls`` is not a config decor... | [
"Builds",
"the",
"schema",
"definition",
"for",
"a",
"given",
"config",
"class",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L415-L471 | train |
stephen-bunn/file-config | src/file_config/schema_builder.py | _build | def _build(value, property_path=None):
""" The generic schema definition build method.
:param value: The value to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict... | python | def _build(value, property_path=None):
""" The generic schema definition build method.
:param value: The value to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict... | [
"def",
"_build",
"(",
"value",
",",
"property_path",
"=",
"None",
")",
":",
"if",
"not",
"property_path",
":",
"property_path",
"=",
"[",
"]",
"if",
"is_config_type",
"(",
"value",
")",
":",
"return",
"_build_config",
"(",
"value",
",",
"property_path",
"=... | The generic schema definition build method.
:param value: The value to build a schema definition for
:param List[str] property_path: The property path of the current type,
defaults to None, optional
:return: The built schema definition
:rtype: Dict[str, Any] | [
"The",
"generic",
"schema",
"definition",
"build",
"method",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/schema_builder.py#L474-L498 | train |
stephen-bunn/file-config | src/file_config/utils.py | _get_types | def _get_types(type_):
""" Gathers all types within the ``TYPE_MAPPINGS`` for a specific ``Types`` value.
:param Types type_: The type to retrieve
:return: All types within the ``TYPE_MAPPINGS``
:rtype: list
"""
return list(
itertools.chain.from_iterable(
map(lambda x: TYPE... | python | def _get_types(type_):
""" Gathers all types within the ``TYPE_MAPPINGS`` for a specific ``Types`` value.
:param Types type_: The type to retrieve
:return: All types within the ``TYPE_MAPPINGS``
:rtype: list
"""
return list(
itertools.chain.from_iterable(
map(lambda x: TYPE... | [
"def",
"_get_types",
"(",
"type_",
")",
":",
"return",
"list",
"(",
"itertools",
".",
"chain",
".",
"from_iterable",
"(",
"map",
"(",
"lambda",
"x",
":",
"TYPE_MAPPINGS",
"[",
"x",
"]",
".",
"get",
"(",
"type_",
",",
"[",
"]",
")",
",",
"TYPE_MAPPING... | Gathers all types within the ``TYPE_MAPPINGS`` for a specific ``Types`` value.
:param Types type_: The type to retrieve
:return: All types within the ``TYPE_MAPPINGS``
:rtype: list | [
"Gathers",
"all",
"types",
"within",
"the",
"TYPE_MAPPINGS",
"for",
"a",
"specific",
"Types",
"value",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L69-L81 | train |
stephen-bunn/file-config | src/file_config/utils.py | decode_bytes | def decode_bytes(string):
""" Decodes a given base64 string into bytes.
:param str string: The string to decode
:return: The decoded bytes
:rtype: bytes
"""
if is_string_type(type(string)):
string = bytes(string, "utf-8")
return base64.decodebytes(string) | python | def decode_bytes(string):
""" Decodes a given base64 string into bytes.
:param str string: The string to decode
:return: The decoded bytes
:rtype: bytes
"""
if is_string_type(type(string)):
string = bytes(string, "utf-8")
return base64.decodebytes(string) | [
"def",
"decode_bytes",
"(",
"string",
")",
":",
"if",
"is_string_type",
"(",
"type",
"(",
"string",
")",
")",
":",
"string",
"=",
"bytes",
"(",
"string",
",",
"\"utf-8\"",
")",
"return",
"base64",
".",
"decodebytes",
"(",
"string",
")"
] | Decodes a given base64 string into bytes.
:param str string: The string to decode
:return: The decoded bytes
:rtype: bytes | [
"Decodes",
"a",
"given",
"base64",
"string",
"into",
"bytes",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L95-L105 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_config_var | def is_config_var(var):
""" Checks if the given value is a valid ``file_config.var``.
:param var: The value to check
:return: True if the given value is a var, otherwise False
:rtype: bool
"""
return (
isinstance(var, (attr._make.Attribute, attr._make._CountingAttr))
and hasatt... | python | def is_config_var(var):
""" Checks if the given value is a valid ``file_config.var``.
:param var: The value to check
:return: True if the given value is a var, otherwise False
:rtype: bool
"""
return (
isinstance(var, (attr._make.Attribute, attr._make._CountingAttr))
and hasatt... | [
"def",
"is_config_var",
"(",
"var",
")",
":",
"return",
"(",
"isinstance",
"(",
"var",
",",
"(",
"attr",
".",
"_make",
".",
"Attribute",
",",
"attr",
".",
"_make",
".",
"_CountingAttr",
")",
")",
"and",
"hasattr",
"(",
"var",
",",
"\"metadata\"",
")",
... | Checks if the given value is a valid ``file_config.var``.
:param var: The value to check
:return: True if the given value is a var, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"value",
"is",
"a",
"valid",
"file_config",
".",
"var",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L108-L120 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_config_type | def is_config_type(type_):
""" Checks if the given type is ``file_config.config`` decorated.
:param type_: The type to check
:return: True if the type is config decorated, otherwise False
:rtype: bool
"""
return (
isinstance(type_, type)
and hasattr(type_, "__attrs_attrs__")
... | python | def is_config_type(type_):
""" Checks if the given type is ``file_config.config`` decorated.
:param type_: The type to check
:return: True if the type is config decorated, otherwise False
:rtype: bool
"""
return (
isinstance(type_, type)
and hasattr(type_, "__attrs_attrs__")
... | [
"def",
"is_config_type",
"(",
"type_",
")",
":",
"return",
"(",
"isinstance",
"(",
"type_",
",",
"type",
")",
"and",
"hasattr",
"(",
"type_",
",",
"\"__attrs_attrs__\"",
")",
"and",
"hasattr",
"(",
"type_",
",",
"CONFIG_KEY",
")",
")"
] | Checks if the given type is ``file_config.config`` decorated.
:param type_: The type to check
:return: True if the type is config decorated, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"file_config",
".",
"config",
"decorated",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L123-L135 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_enum_type | def is_enum_type(type_):
""" Checks if the given type is an enum type.
:param type_: The type to check
:return: True if the type is a enum type, otherwise False
:rtype: bool
"""
return isinstance(type_, type) and issubclass(type_, tuple(_get_types(Types.ENUM))) | python | def is_enum_type(type_):
""" Checks if the given type is an enum type.
:param type_: The type to check
:return: True if the type is a enum type, otherwise False
:rtype: bool
"""
return isinstance(type_, type) and issubclass(type_, tuple(_get_types(Types.ENUM))) | [
"def",
"is_enum_type",
"(",
"type_",
")",
":",
"return",
"isinstance",
"(",
"type_",
",",
"type",
")",
"and",
"issubclass",
"(",
"type_",
",",
"tuple",
"(",
"_get_types",
"(",
"Types",
".",
"ENUM",
")",
")",
")"
] | Checks if the given type is an enum type.
:param type_: The type to check
:return: True if the type is a enum type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"an",
"enum",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L175-L183 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_regex_type | def is_regex_type(type_):
""" Checks if the given type is a regex type.
:param type_: The type to check
:return: True if the type is a regex type, otherwise False
:rtype: bool
"""
return (
callable(type_)
and getattr(type_, "__name__", None) == REGEX_TYPE_NAME
and hasat... | python | def is_regex_type(type_):
""" Checks if the given type is a regex type.
:param type_: The type to check
:return: True if the type is a regex type, otherwise False
:rtype: bool
"""
return (
callable(type_)
and getattr(type_, "__name__", None) == REGEX_TYPE_NAME
and hasat... | [
"def",
"is_regex_type",
"(",
"type_",
")",
":",
"return",
"(",
"callable",
"(",
"type_",
")",
"and",
"getattr",
"(",
"type_",
",",
"\"__name__\"",
",",
"None",
")",
"==",
"REGEX_TYPE_NAME",
"and",
"hasattr",
"(",
"type_",
",",
"\"__supertype__\"",
")",
"an... | Checks if the given type is a regex type.
:param type_: The type to check
:return: True if the type is a regex type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"a",
"regex",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L213-L226 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_union_type | def is_union_type(type_):
""" Checks if the given type is a union type.
:param type_: The type to check
:return: True if the type is a union type, otherwise False
:rtype: bool
"""
if is_typing_type(type_) and hasattr(type_, "__origin__"):
# NOTE: union types can only be from typing mod... | python | def is_union_type(type_):
""" Checks if the given type is a union type.
:param type_: The type to check
:return: True if the type is a union type, otherwise False
:rtype: bool
"""
if is_typing_type(type_) and hasattr(type_, "__origin__"):
# NOTE: union types can only be from typing mod... | [
"def",
"is_union_type",
"(",
"type_",
")",
":",
"if",
"is_typing_type",
"(",
"type_",
")",
"and",
"hasattr",
"(",
"type_",
",",
"\"__origin__\"",
")",
":",
"return",
"type_",
".",
"__origin__",
"in",
"_get_types",
"(",
"Types",
".",
"UNION",
")",
"return",... | Checks if the given type is a union type.
:param type_: The type to check
:return: True if the type is a union type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"a",
"union",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L230-L241 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_string_type | def is_string_type(type_):
""" Checks if the given type is a string type.
:param type_: The type to check
:return: True if the type is a string type, otherwise False
:rtype: bool
"""
string_types = _get_types(Types.STRING)
if is_typing_type(type_):
return type_ in string_types or i... | python | def is_string_type(type_):
""" Checks if the given type is a string type.
:param type_: The type to check
:return: True if the type is a string type, otherwise False
:rtype: bool
"""
string_types = _get_types(Types.STRING)
if is_typing_type(type_):
return type_ in string_types or i... | [
"def",
"is_string_type",
"(",
"type_",
")",
":",
"string_types",
"=",
"_get_types",
"(",
"Types",
".",
"STRING",
")",
"if",
"is_typing_type",
"(",
"type_",
")",
":",
"return",
"type_",
"in",
"string_types",
"or",
"is_regex_type",
"(",
"type_",
")",
"return",... | Checks if the given type is a string type.
:param type_: The type to check
:return: True if the type is a string type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"a",
"string",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L281-L292 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_array_type | def is_array_type(type_):
""" Checks if the given type is a array type.
:param type_: The type to check
:return: True if the type is a array type, otherwise False
:rtype: bool
"""
array_types = _get_types(Types.ARRAY)
if is_typing_type(type_):
return type_ in array_types or (
... | python | def is_array_type(type_):
""" Checks if the given type is a array type.
:param type_: The type to check
:return: True if the type is a array type, otherwise False
:rtype: bool
"""
array_types = _get_types(Types.ARRAY)
if is_typing_type(type_):
return type_ in array_types or (
... | [
"def",
"is_array_type",
"(",
"type_",
")",
":",
"array_types",
"=",
"_get_types",
"(",
"Types",
".",
"ARRAY",
")",
"if",
"is_typing_type",
"(",
"type_",
")",
":",
"return",
"type_",
"in",
"array_types",
"or",
"(",
"hasattr",
"(",
"type_",
",",
"\"__origin_... | Checks if the given type is a array type.
:param type_: The type to check
:return: True if the type is a array type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"a",
"array",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L320-L333 | train |
stephen-bunn/file-config | src/file_config/utils.py | is_object_type | def is_object_type(type_):
""" Checks if the given type is a object type.
:param type_: The type to check
:return: True if the type is a object type, otherwise False
:rtype: bool
"""
object_types = _get_types(Types.OBJECT)
if is_typing_type(type_):
return type_ in object_types or (... | python | def is_object_type(type_):
""" Checks if the given type is a object type.
:param type_: The type to check
:return: True if the type is a object type, otherwise False
:rtype: bool
"""
object_types = _get_types(Types.OBJECT)
if is_typing_type(type_):
return type_ in object_types or (... | [
"def",
"is_object_type",
"(",
"type_",
")",
":",
"object_types",
"=",
"_get_types",
"(",
"Types",
".",
"OBJECT",
")",
"if",
"is_typing_type",
"(",
"type_",
")",
":",
"return",
"type_",
"in",
"object_types",
"or",
"(",
"hasattr",
"(",
"type_",
",",
"\"__ori... | Checks if the given type is a object type.
:param type_: The type to check
:return: True if the type is a object type, otherwise False
:rtype: bool | [
"Checks",
"if",
"the",
"given",
"type",
"is",
"a",
"object",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L336-L349 | train |
stephen-bunn/file-config | src/file_config/utils.py | typecast | def typecast(type_, value):
""" Tries to smartly typecast the given value with the given type.
:param type_: The type to try to use for the given value
:param value: The value to try and typecast to the given type
:return: The typecasted value if possible, otherwise just the original value
"""
... | python | def typecast(type_, value):
""" Tries to smartly typecast the given value with the given type.
:param type_: The type to try to use for the given value
:param value: The value to try and typecast to the given type
:return: The typecasted value if possible, otherwise just the original value
"""
... | [
"def",
"typecast",
"(",
"type_",
",",
"value",
")",
":",
"if",
"is_builtin_type",
"(",
"type_",
")",
"or",
"is_collections_type",
"(",
"type_",
")",
"or",
"is_enum_type",
"(",
"type_",
")",
":",
"if",
"is_bytes_type",
"(",
"type_",
")",
":",
"return",
"d... | Tries to smartly typecast the given value with the given type.
:param type_: The type to try to use for the given value
:param value: The value to try and typecast to the given type
:return: The typecasted value if possible, otherwise just the original value | [
"Tries",
"to",
"smartly",
"typecast",
"the",
"given",
"value",
"with",
"the",
"given",
"type",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/utils.py#L352-L397 | train |
stephen-bunn/file-config | tasks/docs.py | clean | def clean(ctx):
""" Clean built docs.
"""
clean_command = f"make clean"
with ctx.cd(ctx.docs.directory.as_posix()):
report.info(ctx, "docs.clean", "cleaning documentation artifacts")
ctx.run(clean_command) | python | def clean(ctx):
""" Clean built docs.
"""
clean_command = f"make clean"
with ctx.cd(ctx.docs.directory.as_posix()):
report.info(ctx, "docs.clean", "cleaning documentation artifacts")
ctx.run(clean_command) | [
"def",
"clean",
"(",
"ctx",
")",
":",
"clean_command",
"=",
"f\"make clean\"",
"with",
"ctx",
".",
"cd",
"(",
"ctx",
".",
"docs",
".",
"directory",
".",
"as_posix",
"(",
")",
")",
":",
"report",
".",
"info",
"(",
"ctx",
",",
"\"docs.clean\"",
",",
"\... | Clean built docs. | [
"Clean",
"built",
"docs",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/docs.py#L14-L21 | train |
stephen-bunn/file-config | tasks/docs.py | build_news | def build_news(ctx, draft=False, yes=False):
""" Build towncrier newsfragments.
"""
report.info(ctx, "docs.build-news", "building changelog from news fragments")
build_command = f"towncrier --version {ctx.metadata['version']}"
if draft:
report.warn(
ctx,
"docs.build-... | python | def build_news(ctx, draft=False, yes=False):
""" Build towncrier newsfragments.
"""
report.info(ctx, "docs.build-news", "building changelog from news fragments")
build_command = f"towncrier --version {ctx.metadata['version']}"
if draft:
report.warn(
ctx,
"docs.build-... | [
"def",
"build_news",
"(",
"ctx",
",",
"draft",
"=",
"False",
",",
"yes",
"=",
"False",
")",
":",
"report",
".",
"info",
"(",
"ctx",
",",
"\"docs.build-news\"",
",",
"\"building changelog from news fragments\"",
")",
"build_command",
"=",
"f\"towncrier --version {c... | Build towncrier newsfragments. | [
"Build",
"towncrier",
"newsfragments",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/docs.py#L25-L43 | train |
stephen-bunn/file-config | tasks/docs.py | build | def build(ctx, output="html"):
""" Build docs.
"""
with ctx.cd(ctx.docs.directory.as_posix()):
build_command = f"make {output}"
report.info(ctx, "docs.build", f"building {output!r} documentation")
ctx.run(build_command) | python | def build(ctx, output="html"):
""" Build docs.
"""
with ctx.cd(ctx.docs.directory.as_posix()):
build_command = f"make {output}"
report.info(ctx, "docs.build", f"building {output!r} documentation")
ctx.run(build_command) | [
"def",
"build",
"(",
"ctx",
",",
"output",
"=",
"\"html\"",
")",
":",
"with",
"ctx",
".",
"cd",
"(",
"ctx",
".",
"docs",
".",
"directory",
".",
"as_posix",
"(",
")",
")",
":",
"build_command",
"=",
"f\"make {output}\"",
"report",
".",
"info",
"(",
"c... | Build docs. | [
"Build",
"docs",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/docs.py#L47-L54 | train |
stephen-bunn/file-config | tasks/docs.py | view | def view(ctx):
""" Build and view docs.
"""
report.info(ctx, "docs.view", f"viewing documentation")
build_path = ctx.docs.directory / "build" / "html" / "index.html"
build_path = pathname2url(build_path.as_posix())
webbrowser.open(f"file:{build_path!s}") | python | def view(ctx):
""" Build and view docs.
"""
report.info(ctx, "docs.view", f"viewing documentation")
build_path = ctx.docs.directory / "build" / "html" / "index.html"
build_path = pathname2url(build_path.as_posix())
webbrowser.open(f"file:{build_path!s}") | [
"def",
"view",
"(",
"ctx",
")",
":",
"report",
".",
"info",
"(",
"ctx",
",",
"\"docs.view\"",
",",
"f\"viewing documentation\"",
")",
"build_path",
"=",
"ctx",
".",
"docs",
".",
"directory",
"/",
"\"build\"",
"/",
"\"html\"",
"/",
"\"index.html\"",
"build_pa... | Build and view docs. | [
"Build",
"and",
"view",
"docs",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/docs.py#L58-L65 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser._encode_var | def _encode_var(cls, var):
""" Encodes a variable to the appropriate string format for ini files.
:param var: The variable to encode
:return: The ini representation of the variable
:rtype: str
"""
if isinstance(var, str):
if any(_ in var for _ in cls.require... | python | def _encode_var(cls, var):
""" Encodes a variable to the appropriate string format for ini files.
:param var: The variable to encode
:return: The ini representation of the variable
:rtype: str
"""
if isinstance(var, str):
if any(_ in var for _ in cls.require... | [
"def",
"_encode_var",
"(",
"cls",
",",
"var",
")",
":",
"if",
"isinstance",
"(",
"var",
",",
"str",
")",
":",
"if",
"any",
"(",
"_",
"in",
"var",
"for",
"_",
"in",
"cls",
".",
"requires_quotes",
")",
":",
"return",
"'\"'",
"+",
"var",
".",
"repla... | Encodes a variable to the appropriate string format for ini files.
:param var: The variable to encode
:return: The ini representation of the variable
:rtype: str | [
"Encodes",
"a",
"variable",
"to",
"the",
"appropriate",
"string",
"format",
"for",
"ini",
"files",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L33-L47 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser._decode_var | def _decode_var(cls, string):
""" Decodes a given string into the appropriate type in Python.
:param str string: The string to decode
:return: The decoded value
"""
str_match = cls.quoted_string_regex.match(string)
if str_match:
return string.strip("'" if st... | python | def _decode_var(cls, string):
""" Decodes a given string into the appropriate type in Python.
:param str string: The string to decode
:return: The decoded value
"""
str_match = cls.quoted_string_regex.match(string)
if str_match:
return string.strip("'" if st... | [
"def",
"_decode_var",
"(",
"cls",
",",
"string",
")",
":",
"str_match",
"=",
"cls",
".",
"quoted_string_regex",
".",
"match",
"(",
"string",
")",
"if",
"str_match",
":",
"return",
"string",
".",
"strip",
"(",
"\"'\"",
"if",
"str_match",
".",
"groups",
"(... | Decodes a given string into the appropriate type in Python.
:param str string: The string to decode
:return: The decoded value | [
"Decodes",
"a",
"given",
"string",
"into",
"the",
"appropriate",
"type",
"in",
"Python",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L50-L78 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser._build_dict | def _build_dict(
cls, parser_dict, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict
):
""" Builds a dictionary of ``dict_type`` given the ``parser._sections`` dict.
:param dict parser_dict: The ``parser._sections`` mapping
:param str delimiter: The delimiter for nested... | python | def _build_dict(
cls, parser_dict, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict
):
""" Builds a dictionary of ``dict_type`` given the ``parser._sections`` dict.
:param dict parser_dict: The ``parser._sections`` mapping
:param str delimiter: The delimiter for nested... | [
"def",
"_build_dict",
"(",
"cls",
",",
"parser_dict",
",",
"delimiter",
"=",
"DEFAULT_DELIMITER",
",",
"dict_type",
"=",
"collections",
".",
"OrderedDict",
")",
":",
"result",
"=",
"dict_type",
"(",
")",
"for",
"(",
"key",
",",
"value",
")",
"in",
"parser_... | Builds a dictionary of ``dict_type`` given the ``parser._sections`` dict.
:param dict parser_dict: The ``parser._sections`` mapping
:param str delimiter: The delimiter for nested dictionaries,
defaults to ":", optional
:param class dict_type: The dictionary type to use for building ... | [
"Builds",
"a",
"dictionary",
"of",
"dict_type",
"given",
"the",
"parser",
".",
"_sections",
"dict",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L81-L117 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser._build_parser | def _build_parser(
cls,
dictionary,
parser,
section_name,
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Populates a parser instance with the content of a dictionary.
:param dict dictionary: The dictionary to use for populating the parser i... | python | def _build_parser(
cls,
dictionary,
parser,
section_name,
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Populates a parser instance with the content of a dictionary.
:param dict dictionary: The dictionary to use for populating the parser i... | [
"def",
"_build_parser",
"(",
"cls",
",",
"dictionary",
",",
"parser",
",",
"section_name",
",",
"delimiter",
"=",
"DEFAULT_DELIMITER",
",",
"empty_sections",
"=",
"False",
",",
")",
":",
"for",
"(",
"key",
",",
"value",
")",
"in",
"dictionary",
".",
"items... | Populates a parser instance with the content of a dictionary.
:param dict dictionary: The dictionary to use for populating the parser instance
:param configparser.ConfigParser parser: The parser instance
:param str section_name: The current section name to add the dictionary keys to
:pa... | [
"Populates",
"a",
"parser",
"instance",
"with",
"the",
"content",
"of",
"a",
"dictionary",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L120-L159 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser.from_dict | def from_dict(
cls,
dictionary,
root_section="root",
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Create an instance of ``INIParser`` from a given dictionary.
:param dict dictionary: The dictionary to create an instance from
:param str ro... | python | def from_dict(
cls,
dictionary,
root_section="root",
delimiter=DEFAULT_DELIMITER,
empty_sections=False,
):
""" Create an instance of ``INIParser`` from a given dictionary.
:param dict dictionary: The dictionary to create an instance from
:param str ro... | [
"def",
"from_dict",
"(",
"cls",
",",
"dictionary",
",",
"root_section",
"=",
"\"root\"",
",",
"delimiter",
"=",
"DEFAULT_DELIMITER",
",",
"empty_sections",
"=",
"False",
",",
")",
":",
"parser",
"=",
"cls",
"(",
")",
"parser",
".",
"add_section",
"(",
"roo... | Create an instance of ``INIParser`` from a given dictionary.
:param dict dictionary: The dictionary to create an instance from
:param str root_section: The root key of the ini content, defaults to "root",
optional
:param str delimiter: The delimiter character to use for nested dicti... | [
"Create",
"an",
"instance",
"of",
"INIParser",
"from",
"a",
"given",
"dictionary",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L162-L190 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser.to_dict | def to_dict(self, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict):
""" Get the dictionary representation of the current parser.
:param str delimiter: The delimiter used for nested dictionaries,
defaults to ":", optional
:param class dict_type: The dictionary type to ... | python | def to_dict(self, delimiter=DEFAULT_DELIMITER, dict_type=collections.OrderedDict):
""" Get the dictionary representation of the current parser.
:param str delimiter: The delimiter used for nested dictionaries,
defaults to ":", optional
:param class dict_type: The dictionary type to ... | [
"def",
"to_dict",
"(",
"self",
",",
"delimiter",
"=",
"DEFAULT_DELIMITER",
",",
"dict_type",
"=",
"collections",
".",
"OrderedDict",
")",
":",
"root_key",
"=",
"self",
".",
"sections",
"(",
")",
"[",
"0",
"]",
"return",
"self",
".",
"_build_dict",
"(",
"... | Get the dictionary representation of the current parser.
:param str delimiter: The delimiter used for nested dictionaries,
defaults to ":", optional
:param class dict_type: The dictionary type to use for building the dictionary
reperesentation, defaults to collections.OrderedDic... | [
"Get",
"the",
"dictionary",
"representation",
"of",
"the",
"current",
"parser",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L205-L219 | train |
stephen-bunn/file-config | src/file_config/contrib/ini_parser.py | INIParser.to_ini | def to_ini(self):
""" Get the ini string of the current parser.
:return: The ini string of the current parser
:rtype: str
"""
fake_io = io.StringIO()
self.write(fake_io)
return fake_io.getvalue() | python | def to_ini(self):
""" Get the ini string of the current parser.
:return: The ini string of the current parser
:rtype: str
"""
fake_io = io.StringIO()
self.write(fake_io)
return fake_io.getvalue() | [
"def",
"to_ini",
"(",
"self",
")",
":",
"fake_io",
"=",
"io",
".",
"StringIO",
"(",
")",
"self",
".",
"write",
"(",
"fake_io",
")",
"return",
"fake_io",
".",
"getvalue",
"(",
")"
] | Get the ini string of the current parser.
:return: The ini string of the current parser
:rtype: str | [
"Get",
"the",
"ini",
"string",
"of",
"the",
"current",
"parser",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/src/file_config/contrib/ini_parser.py#L221-L230 | train |
stephen-bunn/file-config | tasks/package.py | format | def format(ctx):
""" Auto format package source files.
"""
isort_command = f"isort -rc {ctx.package.directory!s}"
black_command = f"black {ctx.package.directory.parent!s}"
report.info(ctx, "package.format", "sorting imports")
ctx.run(isort_command)
report.info(ctx, "package.format", "forma... | python | def format(ctx):
""" Auto format package source files.
"""
isort_command = f"isort -rc {ctx.package.directory!s}"
black_command = f"black {ctx.package.directory.parent!s}"
report.info(ctx, "package.format", "sorting imports")
ctx.run(isort_command)
report.info(ctx, "package.format", "forma... | [
"def",
"format",
"(",
"ctx",
")",
":",
"isort_command",
"=",
"f\"isort -rc {ctx.package.directory!s}\"",
"black_command",
"=",
"f\"black {ctx.package.directory.parent!s}\"",
"report",
".",
"info",
"(",
"ctx",
",",
"\"package.format\"",
",",
"\"sorting imports\"",
")",
"ct... | Auto format package source files. | [
"Auto",
"format",
"package",
"source",
"files",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/package.py#L32-L42 | train |
stephen-bunn/file-config | tasks/package.py | check | def check(ctx):
""" Check built package is valid.
"""
check_command = f"twine check {ctx.directory!s}/dist/*"
report.info(ctx, "package.check", "checking package")
ctx.run(check_command) | python | def check(ctx):
""" Check built package is valid.
"""
check_command = f"twine check {ctx.directory!s}/dist/*"
report.info(ctx, "package.check", "checking package")
ctx.run(check_command) | [
"def",
"check",
"(",
"ctx",
")",
":",
"check_command",
"=",
"f\"twine check {ctx.directory!s}/dist/*\"",
"report",
".",
"info",
"(",
"ctx",
",",
"\"package.check\"",
",",
"\"checking package\"",
")",
"ctx",
".",
"run",
"(",
"check_command",
")"
] | Check built package is valid. | [
"Check",
"built",
"package",
"is",
"valid",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/package.py#L56-L62 | train |
stephen-bunn/file-config | tasks/package.py | licenses | def licenses(
ctx,
summary=False,
from_classifier=False,
with_system=False,
with_authors=False,
with_urls=False,
):
""" List dependency licenses.
"""
licenses_command = "pip-licenses --order=license"
report.info(ctx, "package.licenses", "listing licenses of package dependencies"... | python | def licenses(
ctx,
summary=False,
from_classifier=False,
with_system=False,
with_authors=False,
with_urls=False,
):
""" List dependency licenses.
"""
licenses_command = "pip-licenses --order=license"
report.info(ctx, "package.licenses", "listing licenses of package dependencies"... | [
"def",
"licenses",
"(",
"ctx",
",",
"summary",
"=",
"False",
",",
"from_classifier",
"=",
"False",
",",
"with_system",
"=",
"False",
",",
"with_authors",
"=",
"False",
",",
"with_urls",
"=",
"False",
",",
")",
":",
"licenses_command",
"=",
"\"pip-licenses --... | List dependency licenses. | [
"List",
"dependency",
"licenses",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/package.py#L66-L94 | train |
stephen-bunn/file-config | tasks/package.py | version | def version(ctx, version=None, force=False):
""" Specify a new version for the package.
.. important:: If no version is specified, will take the most recent parsable git
tag and bump the patch number.
:param str version: The new version of the package.
:param bool force: If True, skips version... | python | def version(ctx, version=None, force=False):
""" Specify a new version for the package.
.. important:: If no version is specified, will take the most recent parsable git
tag and bump the patch number.
:param str version: The new version of the package.
:param bool force: If True, skips version... | [
"def",
"version",
"(",
"ctx",
",",
"version",
"=",
"None",
",",
"force",
"=",
"False",
")",
":",
"updates",
"=",
"{",
"ctx",
".",
"directory",
".",
"joinpath",
"(",
"\"setup.cfg\"",
")",
":",
"[",
"(",
"r\"^(version\\s?=\\s?)(.*)\"",
",",
"\"\\\\g<1>{versi... | Specify a new version for the package.
.. important:: If no version is specified, will take the most recent parsable git
tag and bump the patch number.
:param str version: The new version of the package.
:param bool force: If True, skips version check | [
"Specify",
"a",
"new",
"version",
"for",
"the",
"package",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/package.py#L98-L141 | train |
stephen-bunn/file-config | tasks/package.py | stub | def stub(ctx):
""" Generate typing stubs for the package.
"""
report.info(ctx, "package.stub", f"generating typing stubs for package")
ctx.run(
f"stubgen --include-private --no-import "
f"--output {ctx.directory.joinpath('stubs')!s} "
f"--search-path {ctx.directory.joinpath('src... | python | def stub(ctx):
""" Generate typing stubs for the package.
"""
report.info(ctx, "package.stub", f"generating typing stubs for package")
ctx.run(
f"stubgen --include-private --no-import "
f"--output {ctx.directory.joinpath('stubs')!s} "
f"--search-path {ctx.directory.joinpath('src... | [
"def",
"stub",
"(",
"ctx",
")",
":",
"report",
".",
"info",
"(",
"ctx",
",",
"\"package.stub\"",
",",
"f\"generating typing stubs for package\"",
")",
"ctx",
".",
"run",
"(",
"f\"stubgen --include-private --no-import \"",
"f\"--output {ctx.directory.joinpath('stubs')!s} \""... | Generate typing stubs for the package. | [
"Generate",
"typing",
"stubs",
"for",
"the",
"package",
"."
] | 93429360c949985202e1f2b9cd0340731819ba75 | https://github.com/stephen-bunn/file-config/blob/93429360c949985202e1f2b9cd0340731819ba75/tasks/package.py#L145-L155 | train |
tarruda/python-ush | helper.py | s | def s(obj):
"""Helper to normalize linefeeds in strings."""
if isinstance(obj, bytes):
return obj.replace(b'\n', os.linesep.encode())
else:
return obj.replace('\n', os.linesep) | python | def s(obj):
"""Helper to normalize linefeeds in strings."""
if isinstance(obj, bytes):
return obj.replace(b'\n', os.linesep.encode())
else:
return obj.replace('\n', os.linesep) | [
"def",
"s",
"(",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"bytes",
")",
":",
"return",
"obj",
".",
"replace",
"(",
"b'\\n'",
",",
"os",
".",
"linesep",
".",
"encode",
"(",
")",
")",
"else",
":",
"return",
"obj",
".",
"replace",
"(",
... | Helper to normalize linefeeds in strings. | [
"Helper",
"to",
"normalize",
"linefeeds",
"in",
"strings",
"."
] | a339e9e7ebc1b601405b6e0fd84a07514821d579 | https://github.com/tarruda/python-ush/blob/a339e9e7ebc1b601405b6e0fd84a07514821d579/helper.py#L19-L24 | train |
oceanprotocol/oceandb-driver-interface | oceandb_driver_interface/utils.py | parse_config | def parse_config(file_path):
"""Loads the configuration file given as parameter"""
config_parser = configparser.ConfigParser()
config_parser.read(file_path)
plugin_config = {}
options = config_parser.options(CONFIG_OPTION)
for option in options:
try:
plugin_config[option] = c... | python | def parse_config(file_path):
"""Loads the configuration file given as parameter"""
config_parser = configparser.ConfigParser()
config_parser.read(file_path)
plugin_config = {}
options = config_parser.options(CONFIG_OPTION)
for option in options:
try:
plugin_config[option] = c... | [
"def",
"parse_config",
"(",
"file_path",
")",
":",
"config_parser",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"config_parser",
".",
"read",
"(",
"file_path",
")",
"plugin_config",
"=",
"{",
"}",
"options",
"=",
"config_parser",
".",
"options",
"(",
... | Loads the configuration file given as parameter | [
"Loads",
"the",
"configuration",
"file",
"given",
"as",
"parameter"
] | ce70fd202ef3d057d857a23b59f977bb3e2e4402 | https://github.com/oceanprotocol/oceandb-driver-interface/blob/ce70fd202ef3d057d857a23b59f977bb3e2e4402/oceandb_driver_interface/utils.py#L15-L30 | train |
oceanprotocol/oceandb-driver-interface | oceandb_driver_interface/utils.py | start_plugin | def start_plugin(file_path=None):
"""This function initialize the Ocean plugin"""
if os.getenv('CONFIG_PATH'):
file_path = os.getenv('CONFIG_PATH')
else:
file_path = file_path
if file_path is not None:
config = parse_config(file_path)
plugin_instance = load_plugin(config)... | python | def start_plugin(file_path=None):
"""This function initialize the Ocean plugin"""
if os.getenv('CONFIG_PATH'):
file_path = os.getenv('CONFIG_PATH')
else:
file_path = file_path
if file_path is not None:
config = parse_config(file_path)
plugin_instance = load_plugin(config)... | [
"def",
"start_plugin",
"(",
"file_path",
"=",
"None",
")",
":",
"if",
"os",
".",
"getenv",
"(",
"'CONFIG_PATH'",
")",
":",
"file_path",
"=",
"os",
".",
"getenv",
"(",
"'CONFIG_PATH'",
")",
"else",
":",
"file_path",
"=",
"file_path",
"if",
"file_path",
"i... | This function initialize the Ocean plugin | [
"This",
"function",
"initialize",
"the",
"Ocean",
"plugin"
] | ce70fd202ef3d057d857a23b59f977bb3e2e4402 | https://github.com/oceanprotocol/oceandb-driver-interface/blob/ce70fd202ef3d057d857a23b59f977bb3e2e4402/oceandb_driver_interface/utils.py#L33-L44 | train |
usc-isi-i2/etk | etk/segment.py | Segment.store | def store(self, extractions: List[Extraction], attribute: str, group_by_tags: bool = True) -> None:
"""
Records extractions in the container, and for each individual extraction inserts a
ProvenanceRecord to record where the extraction is stored.
Records the "output_segment" in the proven... | python | def store(self, extractions: List[Extraction], attribute: str, group_by_tags: bool = True) -> None:
"""
Records extractions in the container, and for each individual extraction inserts a
ProvenanceRecord to record where the extraction is stored.
Records the "output_segment" in the proven... | [
"def",
"store",
"(",
"self",
",",
"extractions",
":",
"List",
"[",
"Extraction",
"]",
",",
"attribute",
":",
"str",
",",
"group_by_tags",
":",
"bool",
"=",
"True",
")",
"->",
"None",
":",
"if",
"not",
"isinstance",
"(",
"self",
".",
"_value",
",",
"d... | Records extractions in the container, and for each individual extraction inserts a
ProvenanceRecord to record where the extraction is stored.
Records the "output_segment" in the provenance.
Extractions are always recorded in a list.
Errors out if the segment is primitive, such as a str... | [
"Records",
"extractions",
"in",
"the",
"container",
"and",
"for",
"each",
"individual",
"extraction",
"inserts",
"a",
"ProvenanceRecord",
"to",
"record",
"where",
"the",
"extraction",
"is",
"stored",
".",
"Records",
"the",
"output_segment",
"in",
"the",
"provenanc... | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/segment.py#L40-L115 | train |
usc-isi-i2/etk | etk/dependencies/landmark/landmark_extractor/extraction/Landmark.py | loadRule | def loadRule(rule_json_object):
""" Method to load the rules - when adding a new rule it must be added to the if statement within this method. """
name = rule_json_object['name']
rule_type = rule_json_object['rule_type']
validation_regex = None
required = False
removehtml = False
include_end... | python | def loadRule(rule_json_object):
""" Method to load the rules - when adding a new rule it must be added to the if statement within this method. """
name = rule_json_object['name']
rule_type = rule_json_object['rule_type']
validation_regex = None
required = False
removehtml = False
include_end... | [
"def",
"loadRule",
"(",
"rule_json_object",
")",
":",
"name",
"=",
"rule_json_object",
"[",
"'name'",
"]",
"rule_type",
"=",
"rule_json_object",
"[",
"'rule_type'",
"]",
"validation_regex",
"=",
"None",
"required",
"=",
"False",
"removehtml",
"=",
"False",
"incl... | Method to load the rules - when adding a new rule it must be added to the if statement within this method. | [
"Method",
"to",
"load",
"the",
"rules",
"-",
"when",
"adding",
"a",
"new",
"rule",
"it",
"must",
"be",
"added",
"to",
"the",
"if",
"statement",
"within",
"this",
"method",
"."
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/dependencies/landmark/landmark_extractor/extraction/Landmark.py#L56-L129 | train |
usc-isi-i2/etk | etk/ontology_namespacemanager.py | OntologyNamespaceManager.parse_uri | def parse_uri(self, text: str) -> URIRef:
"""
Parse input text into URI
:param text: can be one of
1. URI, directly return
2. prefix:name, query namespace for prefix, return expanded URI
3. name, use default namespace to expand it and return it
... | python | def parse_uri(self, text: str) -> URIRef:
"""
Parse input text into URI
:param text: can be one of
1. URI, directly return
2. prefix:name, query namespace for prefix, return expanded URI
3. name, use default namespace to expand it and return it
... | [
"def",
"parse_uri",
"(",
"self",
",",
"text",
":",
"str",
")",
"->",
"URIRef",
":",
"if",
"self",
".",
"check_uriref",
"(",
"text",
")",
":",
"return",
"self",
".",
"check_uriref",
"(",
"text",
")",
"elif",
"isinstance",
"(",
"text",
",",
"str",
")",... | Parse input text into URI
:param text: can be one of
1. URI, directly return
2. prefix:name, query namespace for prefix, return expanded URI
3. name, use default namespace to expand it and return it
:return: URIRef | [
"Parse",
"input",
"text",
"into",
"URI"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/ontology_namespacemanager.py#L34-L55 | train |
usc-isi-i2/etk | etk/ontology_namespacemanager.py | OntologyNamespaceManager.bind | def bind(self, prefix: str, namespace: str, override=True, replace=False):
"""
bind a given namespace to the prefix, forbids same prefix with different namespace
:param prefix:
:param namespace:
:param override: if override, rebind, even if the given namespace is already bound t... | python | def bind(self, prefix: str, namespace: str, override=True, replace=False):
"""
bind a given namespace to the prefix, forbids same prefix with different namespace
:param prefix:
:param namespace:
:param override: if override, rebind, even if the given namespace is already bound t... | [
"def",
"bind",
"(",
"self",
",",
"prefix",
":",
"str",
",",
"namespace",
":",
"str",
",",
"override",
"=",
"True",
",",
"replace",
"=",
"False",
")",
":",
"namespace",
"=",
"URIRef",
"(",
"str",
"(",
"namespace",
")",
")",
"if",
"prefix",
"is",
"No... | bind a given namespace to the prefix, forbids same prefix with different namespace
:param prefix:
:param namespace:
:param override: if override, rebind, even if the given namespace is already bound to another prefix.
:param replace: if replace, replace any existing prefix with the new ... | [
"bind",
"a",
"given",
"namespace",
"to",
"the",
"prefix",
"forbids",
"same",
"prefix",
"with",
"different",
"namespace"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/ontology_namespacemanager.py#L57-L91 | train |
usc-isi-i2/etk | etk/etk.py | ETK.parse_json_path | def parse_json_path(self, jsonpath):
"""
Parse a jsonpath
Args:
jsonpath: str
Returns: a parsed json path
"""
if jsonpath not in self.parsed:
try:
self.parsed[jsonpath] = self.parser(jsonpath)
except Exception:
... | python | def parse_json_path(self, jsonpath):
"""
Parse a jsonpath
Args:
jsonpath: str
Returns: a parsed json path
"""
if jsonpath not in self.parsed:
try:
self.parsed[jsonpath] = self.parser(jsonpath)
except Exception:
... | [
"def",
"parse_json_path",
"(",
"self",
",",
"jsonpath",
")",
":",
"if",
"jsonpath",
"not",
"in",
"self",
".",
"parsed",
":",
"try",
":",
"self",
".",
"parsed",
"[",
"jsonpath",
"]",
"=",
"self",
".",
"parser",
"(",
"jsonpath",
")",
"except",
"Exception... | Parse a jsonpath
Args:
jsonpath: str
Returns: a parsed json path | [
"Parse",
"a",
"jsonpath"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/etk.py#L85-L103 | train |
usc-isi-i2/etk | etk/etk.py | ETK.load_glossary | def load_glossary(file_path: str, read_json=False) -> List[str]:
"""
A glossary is a text file, one entry per line.
Args:
file_path (str): path to a text file containing a glossary.
read_json (bool): set True if the glossary is in json format
Returns: List of the... | python | def load_glossary(file_path: str, read_json=False) -> List[str]:
"""
A glossary is a text file, one entry per line.
Args:
file_path (str): path to a text file containing a glossary.
read_json (bool): set True if the glossary is in json format
Returns: List of the... | [
"def",
"load_glossary",
"(",
"file_path",
":",
"str",
",",
"read_json",
"=",
"False",
")",
"->",
"List",
"[",
"str",
"]",
":",
"if",
"read_json",
":",
"if",
"file_path",
".",
"endswith",
"(",
"\".gz\"",
")",
":",
"return",
"json",
".",
"load",
"(",
"... | A glossary is a text file, one entry per line.
Args:
file_path (str): path to a text file containing a glossary.
read_json (bool): set True if the glossary is in json format
Returns: List of the strings in the glossary. | [
"A",
"glossary",
"is",
"a",
"text",
"file",
"one",
"entry",
"per",
"line",
"."
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/etk.py#L189-L203 | train |
usc-isi-i2/etk | etk/etk.py | ETK.load_spacy_rule | def load_spacy_rule(file_path: str) -> Dict:
"""
A spacy rule file is a json file.
Args:
file_path (str): path to a text file containing a spacy rule sets.
Returns: Dict as the representation of spacy rules
"""
with open(file_path) as fp:
return ... | python | def load_spacy_rule(file_path: str) -> Dict:
"""
A spacy rule file is a json file.
Args:
file_path (str): path to a text file containing a spacy rule sets.
Returns: Dict as the representation of spacy rules
"""
with open(file_path) as fp:
return ... | [
"def",
"load_spacy_rule",
"(",
"file_path",
":",
"str",
")",
"->",
"Dict",
":",
"with",
"open",
"(",
"file_path",
")",
"as",
"fp",
":",
"return",
"json",
".",
"load",
"(",
"fp",
")"
] | A spacy rule file is a json file.
Args:
file_path (str): path to a text file containing a spacy rule sets.
Returns: Dict as the representation of spacy rules | [
"A",
"spacy",
"rule",
"file",
"is",
"a",
"json",
"file",
"."
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/etk.py#L206-L216 | train |
usc-isi-i2/etk | etk/etk.py | ETK.load_ems | def load_ems(self, modules_paths: List[str]):
"""
Load all extraction modules from the path
Args:
modules_path: str
Returns:
"""
all_em_lst = []
if modules_paths:
for modules_path in modules_paths:
em_lst = []
... | python | def load_ems(self, modules_paths: List[str]):
"""
Load all extraction modules from the path
Args:
modules_path: str
Returns:
"""
all_em_lst = []
if modules_paths:
for modules_path in modules_paths:
em_lst = []
... | [
"def",
"load_ems",
"(",
"self",
",",
"modules_paths",
":",
"List",
"[",
"str",
"]",
")",
":",
"all_em_lst",
"=",
"[",
"]",
"if",
"modules_paths",
":",
"for",
"modules_path",
"in",
"modules_paths",
":",
"em_lst",
"=",
"[",
"]",
"try",
":",
"for",
"file_... | Load all extraction modules from the path
Args:
modules_path: str
Returns: | [
"Load",
"all",
"extraction",
"modules",
"from",
"the",
"path"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/etk.py#L218-L253 | train |
usc-isi-i2/etk | etk/etk.py | ETK.classes_in_module | def classes_in_module(module) -> List:
"""
Return all classes with super class ExtractionModule
Args:
module:
Returns: List of classes
"""
md = module.__dict__
return [
md[c] for c in md if (
isinstance(md[c], type) a... | python | def classes_in_module(module) -> List:
"""
Return all classes with super class ExtractionModule
Args:
module:
Returns: List of classes
"""
md = module.__dict__
return [
md[c] for c in md if (
isinstance(md[c], type) a... | [
"def",
"classes_in_module",
"(",
"module",
")",
"->",
"List",
":",
"md",
"=",
"module",
".",
"__dict__",
"return",
"[",
"md",
"[",
"c",
"]",
"for",
"c",
"in",
"md",
"if",
"(",
"isinstance",
"(",
"md",
"[",
"c",
"]",
",",
"type",
")",
"and",
"issu... | Return all classes with super class ExtractionModule
Args:
module:
Returns: List of classes | [
"Return",
"all",
"classes",
"with",
"super",
"class",
"ExtractionModule"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/etk.py#L270-L287 | train |
usc-isi-i2/etk | etk/extractors/readability/readability.py | Document.summary | def summary(self, html_partial=False):
"""Generate the summary of the html docuemnt
:param html_partial: return only the div of the document, don't wrap
in html and body tags.
"""
try:
ruthless = True
#Added recall priority flag
... | python | def summary(self, html_partial=False):
"""Generate the summary of the html docuemnt
:param html_partial: return only the div of the document, don't wrap
in html and body tags.
"""
try:
ruthless = True
#Added recall priority flag
... | [
"def",
"summary",
"(",
"self",
",",
"html_partial",
"=",
"False",
")",
":",
"try",
":",
"ruthless",
"=",
"True",
"recallPriority",
"=",
"self",
".",
"recallPriority",
"if",
"recallPriority",
":",
"ruthless",
"=",
"False",
"self",
".",
"TEXT_LENGTH_THRESHOLD",
... | Generate the summary of the html docuemnt
:param html_partial: return only the div of the document, don't wrap
in html and body tags. | [
"Generate",
"the",
"summary",
"of",
"the",
"html",
"docuemnt"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extractors/readability/readability.py#L146-L217 | train |
usc-isi-i2/etk | etk/extraction.py | ExtractableBase.list2str | def list2str(self, l: List, joiner: str) -> str:
"""
Convert list to str as input for tokenizer
Args:
l (list): list for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the list as a string
"""
... | python | def list2str(self, l: List, joiner: str) -> str:
"""
Convert list to str as input for tokenizer
Args:
l (list): list for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the list as a string
"""
... | [
"def",
"list2str",
"(",
"self",
",",
"l",
":",
"List",
",",
"joiner",
":",
"str",
")",
"->",
"str",
":",
"result",
"=",
"str",
"(",
")",
"for",
"item",
"in",
"l",
":",
"if",
"isinstance",
"(",
"item",
",",
"list",
")",
":",
"result",
"=",
"resu... | Convert list to str as input for tokenizer
Args:
l (list): list for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the list as a string | [
"Convert",
"list",
"to",
"str",
"as",
"input",
"for",
"tokenizer"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extraction.py#L48-L67 | train |
usc-isi-i2/etk | etk/extraction.py | ExtractableBase.dict2str | def dict2str(self, d: Dict, joiner: str) -> str:
"""
Convert dict to str as input for tokenizer
Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the dict as a string
"""
... | python | def dict2str(self, d: Dict, joiner: str) -> str:
"""
Convert dict to str as input for tokenizer
Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the dict as a string
"""
... | [
"def",
"dict2str",
"(",
"self",
",",
"d",
":",
"Dict",
",",
"joiner",
":",
"str",
")",
"->",
"str",
":",
"result",
"=",
"str",
"(",
")",
"for",
"key",
"in",
"d",
":",
"result",
"=",
"result",
"+",
"str",
"(",
"key",
")",
"+",
"\" : \"",
"if",
... | Convert dict to str as input for tokenizer
Args:
d (dict): dict for converting
joiner (str): join the elements using this string to separate them.
Returns: the value of the dict as a string | [
"Convert",
"dict",
"to",
"str",
"as",
"input",
"for",
"tokenizer"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extraction.py#L69-L89 | train |
usc-isi-i2/etk | etk/extraction.py | Extractable.get_tokens | def get_tokens(self, tokenizer: Tokenizer) -> List[Token]:
"""
Tokenize this Extractable.
If the value is a string, it returns the tokenized version of the string. Else, convert to string with
get_string method
As it is common to need the same tokens for multiple extractors, th... | python | def get_tokens(self, tokenizer: Tokenizer) -> List[Token]:
"""
Tokenize this Extractable.
If the value is a string, it returns the tokenized version of the string. Else, convert to string with
get_string method
As it is common to need the same tokens for multiple extractors, th... | [
"def",
"get_tokens",
"(",
"self",
",",
"tokenizer",
":",
"Tokenizer",
")",
"->",
"List",
"[",
"Token",
"]",
":",
"if",
"(",
"self",
",",
"tokenizer",
")",
"in",
"self",
".",
"tokenize_results",
":",
"return",
"self",
".",
"tokenize_results",
"[",
"(",
... | Tokenize this Extractable.
If the value is a string, it returns the tokenized version of the string. Else, convert to string with
get_string method
As it is common to need the same tokens for multiple extractors, the Extractable should cache the
tokenize results, keyed by segment and t... | [
"Tokenize",
"this",
"Extractable",
"."
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extraction.py#L103-L127 | train |
usc-isi-i2/etk | examples/ontology_api/create_kg_with_alignment_ontology.py | AlignmentHelper.uri_from_fields | def uri_from_fields(prefix, *fields):
"""Construct a URI out of the fields, concatenating them after removing offensive characters.
When all the fields are empty, return empty"""
string = '_'.join(AlignmentHelper.alpha_numeric(f.strip().lower(), '') for f in fields)
if len(string) == le... | python | def uri_from_fields(prefix, *fields):
"""Construct a URI out of the fields, concatenating them after removing offensive characters.
When all the fields are empty, return empty"""
string = '_'.join(AlignmentHelper.alpha_numeric(f.strip().lower(), '') for f in fields)
if len(string) == le... | [
"def",
"uri_from_fields",
"(",
"prefix",
",",
"*",
"fields",
")",
":",
"string",
"=",
"'_'",
".",
"join",
"(",
"AlignmentHelper",
".",
"alpha_numeric",
"(",
"f",
".",
"strip",
"(",
")",
".",
"lower",
"(",
")",
",",
"''",
")",
"for",
"f",
"in",
"fie... | Construct a URI out of the fields, concatenating them after removing offensive characters.
When all the fields are empty, return empty | [
"Construct",
"a",
"URI",
"out",
"of",
"the",
"fields",
"concatenating",
"them",
"after",
"removing",
"offensive",
"characters",
".",
"When",
"all",
"the",
"fields",
"are",
"empty",
"return",
"empty"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/examples/ontology_api/create_kg_with_alignment_ontology.py#L178-L186 | train |
usc-isi-i2/etk | etk/data_extractors/htiExtractors/parser.py | parse_phone | def parse_phone(parts, allow_multiple=False):
"""
Parse the phone number from the ad's parts
parts -> The backpage ad's posting_body, separated into substrings
allow_multiple -> If false, arbitrarily chooses the most commonly occurring phone
"""
# Get text substitutions (ex: 'three' -> '3')
t... | python | def parse_phone(parts, allow_multiple=False):
"""
Parse the phone number from the ad's parts
parts -> The backpage ad's posting_body, separated into substrings
allow_multiple -> If false, arbitrarily chooses the most commonly occurring phone
"""
# Get text substitutions (ex: 'three' -> '3')
t... | [
"def",
"parse_phone",
"(",
"parts",
",",
"allow_multiple",
"=",
"False",
")",
":",
"text_subs",
"=",
"misc",
".",
"phone_text_subs",
"(",
")",
"Small",
"=",
"text_subs",
"[",
"'Small'",
"]",
"Magnitude",
"=",
"text_subs",
"[",
"'Magnitude'",
"]",
"Others",
... | Parse the phone number from the ad's parts
parts -> The backpage ad's posting_body, separated into substrings
allow_multiple -> If false, arbitrarily chooses the most commonly occurring phone | [
"Parse",
"the",
"phone",
"number",
"from",
"the",
"ad",
"s",
"parts",
"parts",
"-",
">",
"The",
"backpage",
"ad",
"s",
"posting_body",
"separated",
"into",
"substrings",
"allow_multiple",
"-",
">",
"If",
"false",
"arbitrarily",
"chooses",
"the",
"most",
"com... | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/data_extractors/htiExtractors/parser.py#L525-L602 | train |
usc-isi-i2/etk | etk/extractors/date_extractor.py | DateExtractor._wrap_extraction | def _wrap_extraction(self, date_object: datetime.datetime,
original_text: str,
start_char: int,
end_char: int
) -> Extraction or None:
"""
wrap the final result as an Extraction and return
"""
... | python | def _wrap_extraction(self, date_object: datetime.datetime,
original_text: str,
start_char: int,
end_char: int
) -> Extraction or None:
"""
wrap the final result as an Extraction and return
"""
... | [
"def",
"_wrap_extraction",
"(",
"self",
",",
"date_object",
":",
"datetime",
".",
"datetime",
",",
"original_text",
":",
"str",
",",
"start_char",
":",
"int",
",",
"end_char",
":",
"int",
")",
"->",
"Extraction",
"or",
"None",
":",
"try",
":",
"resolution"... | wrap the final result as an Extraction and return | [
"wrap",
"the",
"final",
"result",
"as",
"an",
"Extraction",
"and",
"return"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extractors/date_extractor.py#L287-L310 | train |
usc-isi-i2/etk | etk/extractors/date_extractor.py | DateExtractor._remove_overlapped_date_str | def _remove_overlapped_date_str(self, results: List[List[dict]]) -> List[Extraction]:
"""
some string may be matched by multiple date templates,
deduplicate the results and return a single list
"""
res = []
all_results = []
for x in results:
all_resul... | python | def _remove_overlapped_date_str(self, results: List[List[dict]]) -> List[Extraction]:
"""
some string may be matched by multiple date templates,
deduplicate the results and return a single list
"""
res = []
all_results = []
for x in results:
all_resul... | [
"def",
"_remove_overlapped_date_str",
"(",
"self",
",",
"results",
":",
"List",
"[",
"List",
"[",
"dict",
"]",
"]",
")",
"->",
"List",
"[",
"Extraction",
"]",
":",
"res",
"=",
"[",
"]",
"all_results",
"=",
"[",
"]",
"for",
"x",
"in",
"results",
":",
... | some string may be matched by multiple date templates,
deduplicate the results and return a single list | [
"some",
"string",
"may",
"be",
"matched",
"by",
"multiple",
"date",
"templates",
"deduplicate",
"the",
"results",
"and",
"return",
"a",
"single",
"list"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extractors/date_extractor.py#L312-L371 | train |
usc-isi-i2/etk | etk/extractors/readability/encoding.py | custom_decode | def custom_decode(encoding):
"""Overrides encoding when charset declaration
or charset determination is a subset of a larger
charset. Created because of issues with Chinese websites"""
encoding = encoding.lower()
alternates = {
'big5': 'big5hkscs',
'gb2312': 'gb18030',
... | python | def custom_decode(encoding):
"""Overrides encoding when charset declaration
or charset determination is a subset of a larger
charset. Created because of issues with Chinese websites"""
encoding = encoding.lower()
alternates = {
'big5': 'big5hkscs',
'gb2312': 'gb18030',
... | [
"def",
"custom_decode",
"(",
"encoding",
")",
":",
"encoding",
"=",
"encoding",
".",
"lower",
"(",
")",
"alternates",
"=",
"{",
"'big5'",
":",
"'big5hkscs'",
",",
"'gb2312'",
":",
"'gb18030'",
",",
"'ascii'",
":",
"'utf-8'",
",",
"'MacCyrillic'",
":",
"'cp... | Overrides encoding when charset declaration
or charset determination is a subset of a larger
charset. Created because of issues with Chinese websites | [
"Overrides",
"encoding",
"when",
"charset",
"declaration",
"or",
"charset",
"determination",
"is",
"a",
"subset",
"of",
"a",
"larger",
"charset",
".",
"Created",
"because",
"of",
"issues",
"with",
"Chinese",
"websites"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/extractors/readability/encoding.py#L34-L48 | train |
usc-isi-i2/etk | etk/knowledge_graph_schema.py | KGSchema.iso_date | def iso_date(d) -> str:
"""
Return iso format of a date
Args:
d:
Returns: str
"""
if isinstance(d, datetime):
return d.isoformat()
elif isinstance(d, date):
return datetime.combine(d, datetime.min.time()).isoformat()
e... | python | def iso_date(d) -> str:
"""
Return iso format of a date
Args:
d:
Returns: str
"""
if isinstance(d, datetime):
return d.isoformat()
elif isinstance(d, date):
return datetime.combine(d, datetime.min.time()).isoformat()
e... | [
"def",
"iso_date",
"(",
"d",
")",
"->",
"str",
":",
"if",
"isinstance",
"(",
"d",
",",
"datetime",
")",
":",
"return",
"d",
".",
"isoformat",
"(",
")",
"elif",
"isinstance",
"(",
"d",
",",
"date",
")",
":",
"return",
"datetime",
".",
"combine",
"("... | Return iso format of a date
Args:
d:
Returns: str | [
"Return",
"iso",
"format",
"of",
"a",
"date"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/knowledge_graph_schema.py#L80-L103 | train |
usc-isi-i2/etk | etk/knowledge_graph_schema.py | KGSchema.is_valid | def is_valid(self, field_name, value) -> (bool, object):
"""
Return true if the value type matches or can be coerced to the defined type in schema, otherwise false.
If field not defined, return none
Args:
field_name: str
value:
Returns: bool, value, wher... | python | def is_valid(self, field_name, value) -> (bool, object):
"""
Return true if the value type matches or can be coerced to the defined type in schema, otherwise false.
If field not defined, return none
Args:
field_name: str
value:
Returns: bool, value, wher... | [
"def",
"is_valid",
"(",
"self",
",",
"field_name",
",",
"value",
")",
"->",
"(",
"bool",
",",
"object",
")",
":",
"if",
"self",
".",
"has_field",
"(",
"field_name",
")",
":",
"if",
"self",
".",
"fields_dict",
"[",
"field_name",
"]",
"==",
"FieldType",
... | Return true if the value type matches or can be coerced to the defined type in schema, otherwise false.
If field not defined, return none
Args:
field_name: str
value:
Returns: bool, value, where the value may have been coerced to the required type. | [
"Return",
"true",
"if",
"the",
"value",
"type",
"matches",
"or",
"can",
"be",
"coerced",
"to",
"the",
"defined",
"type",
"in",
"schema",
"otherwise",
"false",
".",
"If",
"field",
"not",
"defined",
"return",
"none"
] | aab077c984ea20f5e8ae33af622fe11d3c4df866 | https://github.com/usc-isi-i2/etk/blob/aab077c984ea20f5e8ae33af622fe11d3c4df866/etk/knowledge_graph_schema.py#L123-L166 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.