_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q251400 | usage | train | def usage():
"""
Return the usage for the help command.
"""
l_bracket = clr.stringc("[", "dark gray")
r_bracket = clr.stringc("]", "dark gray")
pipe = clr.stringc("|", "dark gray")
app_name = clr.stringc("%prog", "bright blue")
commands = clr.stringc("{0}".format(pipe).join(c.VALID_ACTI... | python | {
"resource": ""
} |
q251401 | epilogue | train | def epilogue(app_name):
"""
Return the epilogue for the help command.
"""
app_name = clr.stringc(app_name, "bright blue")
command = clr.stringc("command", "cyan")
help = clr.stringc("--help", "green")
return "\n%s | python | {
"resource": ""
} |
q251402 | command_name | train | def command_name(app_name, command, help_text):
"""
Return a snippet of help text for this command.
"""
command = clr.stringc(command, "cyan")
help = clr.stringc("--help", "green")
return "{0} | python | {
"resource": ""
} |
q251403 | role | train | def role(name, report, role_name_length):
"""
Print the role information.
"""
pad_role_name_by = 11 + role_name_length
defaults = field_value(report["total_defaults"], "defaults", "blue", 16)
facts = field_value(report["total_facts"], "facts", "purple", 16)
files = field_value(report["total... | python | {
"resource": ""
} |
q251404 | field_value | train | def field_value(key, label, color, padding):
"""
Print a specific field's stats.
"""
if not clr.has_colors and padding > 0:
padding = 7
if color == "bright gray" or color == "dark gray":
bright_prefix = ""
else:
bright_prefix = "bright "
| python | {
"resource": ""
} |
q251405 | totals | train | def totals(report, total_roles, role_name_length):
"""
Print the totals for each role's stats.
"""
roles_len_string = len(str(total_roles))
roles_label_len = 6 # "r" "o" "l" "e" "s" " "
if clr.has_colors:
roles_count_offset = 22
else:
roles_count_offset = 13
roles_coun... | python | {
"resource": ""
} |
q251406 | gen_totals | train | def gen_totals(report, file_type):
"""
Print the gen totals.
"""
label = clr.stringc(file_type + " files ", "bright purple")
ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0)
skipped = field_value(report["skipped_role"], "skipped",
c.LOG_COLOR["skipped"... | python | {
"resource": ""
} |
q251407 | scan_totals | train | def scan_totals(report):
"""
Print the scan totals.
"""
ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0)
missing_readme = field_value(report["missing_readme_role"],
| python | {
"resource": ""
} |
q251408 | has_colors | train | def has_colors(stream):
"""
Determine if the terminal supports ansi colors.
"""
if not hasattr(stream, "isatty"):
return False
if not stream.isatty():
return False # auto color only on TTYs
try:
| python | {
"resource": ""
} |
q251409 | stringc | train | def stringc(text, color):
"""
Return a string with terminal colors.
"""
if has_colors:
text = str(text)
| python | {
"resource": ""
} |
q251410 | Run.execute_command | train | def execute_command(self):
"""
Execute the shell command.
"""
stderr = ""
role_count = 0
for role in utils.roles_dict(self.roles_path):
self.command = self.command.replace("%role_name", role)
(_, err) = utils.capture_shell("cd {0} && {1}".
... | python | {
"resource": ""
} |
q251411 | mkdir_p | train | def mkdir_p(path):
"""
Emulate the behavior of mkdir -p.
"""
try:
os.makedirs(path)
except OSError as err:
if err.errno == errno.EEXIST and os.path.isdir(path):
| python | {
"resource": ""
} |
q251412 | string_to_file | train | def string_to_file(path, input):
"""
Write a file from a given string.
| python | {
"resource": ""
} |
q251413 | file_to_string | train | def file_to_string(path):
"""
Return the contents of a file when given a path.
"""
if not os.path.exists(path):
ui.error(c.MESSAGES["path_missing"], path)
| python | {
"resource": ""
} |
q251414 | file_to_list | train | def file_to_list(path):
"""
Return the contents of a file as a list when given a path.
"""
if not os.path.exists(path):
ui.error(c.MESSAGES["path_missing"], path)
| python | {
"resource": ""
} |
q251415 | url_to_string | train | def url_to_string(url):
"""
Return the contents of a web site url as a string.
"""
try:
page = | python | {
"resource": ""
} |
q251416 | template | train | def template(path, extend_path, out):
"""
Return a jinja2 template instance with extends support.
"""
files = []
# add the "extender" template when it exists
if len(extend_path) > 0:
# determine the base readme path
base_path = os.path.dirname(extend_path)
new_base_path ... | python | {
"resource": ""
} |
q251417 | files_in_path | train | def files_in_path(path):
"""
Return a list of all files in a path but exclude git folders.
"""
aggregated_files = []
for dir_, _, files in os.walk(path):
for file in files:
relative_dir = os.path.relpath(dir_, path)
| python | {
"resource": ""
} |
q251418 | exit_if_path_not_found | train | def exit_if_path_not_found(path):
"""
Exit if the path is not found.
"""
if not os.path.exists(path):
| python | {
"resource": ""
} |
q251419 | yaml_load | train | def yaml_load(path, input="", err_quit=False):
"""
Return a yaml dict from a file or string with error handling.
"""
try:
if len(input) > 0:
return yaml.safe_load(input)
elif len(path) > 0:
return yaml.safe_load(file_to_string(path))
except Exception as err:
... | python | {
"resource": ""
} |
q251420 | to_nice_yaml | train | def to_nice_yaml(yaml_input, indentation=2):
"""
Return condensed yaml into human readable yaml.
"""
| python | {
"resource": ""
} |
q251421 | keys_in_dict | train | def keys_in_dict(d, parent_key, keys):
"""
Create a list of keys from a dict recursively.
"""
for key, value in d.iteritems():
if isinstance(value, dict):
keys_in_dict(value, key, keys)
else:
| python | {
"resource": ""
} |
q251422 | swap_yaml_string | train | def swap_yaml_string(file_path, swaps):
"""
Swap a string in a yaml file without touching the existing formatting.
"""
original_file = file_to_string(file_path)
new_file = original_file
changed = False
for item in swaps:
match = re.compile(r'(?<={0}: )(["\']?)(.*)\1'.format(item[0])... | python | {
"resource": ""
} |
q251423 | exit_if_no_roles | train | def exit_if_no_roles(roles_count, roles_path):
"""
Exit if there were no roles found.
"""
if roles_count == 0:
| python | {
"resource": ""
} |
q251424 | roles_dict | train | def roles_dict(path, repo_prefix="", repo_sub_dir=""):
"""
Return a dict of role names and repo paths.
"""
exit_if_path_not_found(path)
aggregated_roles = {}
roles = os.walk(path).next()[1]
# First scan all directories
for role in roles:
for sub_role in roles_dict(path + "/" +... | python | {
"resource": ""
} |
q251425 | is_role | train | def is_role(path):
"""
Determine if a path is an ansible role.
"""
seems_legit = False
| python | {
"resource": ""
} |
q251426 | stripped_args | train | def stripped_args(args):
"""
Return the stripped version of the arguments.
"""
stripped_args = []
for arg | python | {
"resource": ""
} |
q251427 | normalize_role | train | def normalize_role(role, config):
"""
Normalize a role name.
"""
if role.startswith(config["scm_repo_prefix"]):
role_name = role.replace(config["scm_repo_prefix"], "")
else:
if "." in role:
galaxy_prefix = "{0}.".format(config["scm_user"])
| python | {
"resource": ""
} |
q251428 | create_meta_main | train | def create_meta_main(create_path, config, role, categories):
"""
Create a meta template.
"""
meta_file = c.DEFAULT_META_FILE.replace(
"%author_name", config["author_name"])
meta_file = meta_file.replace(
"%author_company", config["author_company"])
meta_file = meta_file.replace("... | python | {
"resource": ""
} |
q251429 | get_version | train | def get_version(path, default="master"):
"""
Return the version from a VERSION file
"""
version = default
if os.path.exists(path):
version_contents = file_to_string(path)
| python | {
"resource": ""
} |
q251430 | write_config | train | def write_config(path, config):
"""
Write the config with a little post-converting formatting.
| python | {
"resource": ""
} |
q251431 | Scan.limit_roles | train | def limit_roles(self):
"""
Limit the roles being scanned.
"""
new_roles = {}
roles = self.options.limit.split(",")
for key, value in self.roles.iteritems():
for role in roles:
| python | {
"resource": ""
} |
q251432 | Scan.scan_roles | train | def scan_roles(self):
"""
Iterate over each role and report its stats.
"""
for key, value in sorted(self.roles.iteritems()):
self.paths["role"] = os.path.join(self.roles_path, key)
self.paths["meta"] = os.path.join(self.paths["role"], "meta",
... | python | {
"resource": ""
} |
q251433 | Scan.export_roles | train | def export_roles(self):
"""
Export the roles to one of the export types.
"""
# prepare the report by removing unnecessary fields
del self.report["state"]
del self.report["stats"]
for role in self.report["roles"]:
del self.report["roles"][role]["state"]... | python | {
"resource": ""
} |
q251434 | Scan.report_role | train | def report_role(self, role):
"""
Return the fields gathered.
"""
self.yaml_files = []
fields = {
"state": "skipped",
"total_files": self.gather_files(),
"total_lines": self.gather_lines(),
| python | {
"resource": ""
} |
q251435 | Scan.gather_meta | train | def gather_meta(self):
"""
Return the meta file.
"""
if not os.path.exists(self.paths["meta"]):
return ""
meta_dict = utils.yaml_load(self.paths["meta"])
# gather the dependencies
if meta_dict and "dependencies" in meta_dict:
# create a s... | python | {
"resource": ""
} |
q251436 | Scan.gather_readme | train | def gather_readme(self):
"""
Return the readme file.
"""
if not os.path.exists(self.paths["readme"]):
| python | {
"resource": ""
} |
q251437 | Scan.gather_defaults | train | def gather_defaults(self):
"""
Return the number of default variables.
"""
total_defaults = 0
defaults_lines = []
if not os.path.exists(self.paths["defaults"]):
# reset the defaults if no defaults were found
self.defaults = ""
return 0... | python | {
"resource": ""
} |
q251438 | Scan.gather_facts | train | def gather_facts(self):
"""
Return the number of facts.
"""
facts = []
for file in self.yaml_files:
facts += self.gather_facts_list(file)
| python | {
"resource": ""
} |
q251439 | Scan.gather_facts_list | train | def gather_facts_list(self, file):
"""
Return a list of facts.
"""
facts = []
contents = utils.file_to_string(os.path.join(self.paths["role"],
| python | {
"resource": ""
} |
q251440 | Scan.gather_files | train | def gather_files(self):
"""
Return the number of files.
| python | {
"resource": ""
} |
q251441 | Scan.gather_lines | train | def gather_lines(self):
"""
Return the number of lines.
"""
total_lines = 0
for file in self.all_files:
full_path = os.path.join(self.paths["role"], file)
with open(full_path, "r") as f:
for | python | {
"resource": ""
} |
q251442 | Scan.tally_role_columns | train | def tally_role_columns(self):
"""
Sum up all of the stat columns.
"""
totals = self.report["totals"]
roles = self.report["roles"]
totals["dependencies"] = sum(roles[item]
["total_dependencies"] for item in | python | {
"resource": ""
} |
q251443 | Scan.valid_meta | train | def valid_meta(self, role):
"""
Return whether or not the meta file being read is valid.
"""
if os.path.exists(self.paths["meta"]):
self.meta_dict = utils.yaml_load(self.paths["meta"])
else:
| python | {
"resource": ""
} |
q251444 | Scan.make_or_augment_meta | train | def make_or_augment_meta(self, role):
"""
Create or augment a meta file.
"""
if not os.path.exists(self.paths["meta"]):
utils.create_meta_main(self.paths["meta"], self.config, role, "")
self.report["state"]["ok_role"] += 1
self.report["roles"][role]["s... | python | {
"resource": ""
} |
q251445 | Scan.write_readme | train | def write_readme(self, role):
"""
Write out a new readme file.
"""
j2_out | python | {
"resource": ""
} |
q251446 | Scan.write_meta | train | def write_meta(self, role):
"""
Write out a new meta file.
"""
| python | {
"resource": ""
} |
q251447 | Scan.update_scan_report | train | def update_scan_report(self, role):
"""
Update the role state and adjust the scan totals.
"""
state = self.report["state"]
# ensure the missing meta state is colored up and the ok count is good
if self.gendoc:
if self.report["roles"][role]["state"] == "missin... | python | {
"resource": ""
} |
q251448 | Scan.update_gen_report | train | def update_gen_report(self, role, file, original):
"""
Update the role state and adjust the gen totals.
"""
state = self.report["state"]
if not os.path.exists(self.paths[file]):
state["ok_role"] += 1
self.report["roles"][role]["state"] = "ok"
| python | {
"resource": ""
} |
q251449 | Scan.make_meta_dict_consistent | train | def make_meta_dict_consistent(self):
"""
Remove the possibility of the main keys being undefined.
"""
if self.meta_dict is None:
self.meta_dict = {}
if "galaxy_info" not in self.meta_dict:
self.meta_dict["galaxy_info"] = {}
if "dependencies" | python | {
"resource": ""
} |
q251450 | Scan.set_readme_template_vars | train | def set_readme_template_vars(self, role, repo_name):
"""
Set the readme template variables.
"""
# normalize and expose a bunch of fields to the template
authors = []
author = {
"name": self.config["author_name"],
"company": self.config["author_com... | python | {
"resource": ""
} |
q251451 | Init.exit_if_path_exists | train | def exit_if_path_exists(self):
"""
Exit early if the path cannot be found.
"""
if os.path.exists(self.output_path):
| python | {
"resource": ""
} |
q251452 | Init.create_skeleton | train | def create_skeleton(self):
"""
Create the role's directory and file structure.
"""
utils.string_to_file(os.path.join(self.output_path, "VERSION"),
"master\n")
for folder in c.ANSIBLE_FOLDERS:
create_folder_path = os.path.join(self.output_... | python | {
"resource": ""
} |
q251453 | Init.create_travis_config | train | def create_travis_config(self):
"""
Create a travis test setup.
"""
test_runner = self.config["options_test_runner"]
role_url = "{0}".format(os.path.join(self.config["scm_host"],
self.config["scm_user"],
... | python | {
"resource": ""
} |
q251454 | Export.set_format | train | def set_format(self, format):
"""
Pick the correct default format.
"""
if self.options.format:
self.format = self.options.format
| python | {
"resource": ""
} |
q251455 | Export.validate_format | train | def validate_format(self, allowed_formats):
"""
Validate the allowed formats for a specific type.
"""
if self.format in allowed_formats: | python | {
"resource": ""
} |
q251456 | Export.graph_dot | train | def graph_dot(self):
"""
Export a graph of the data in dot format.
"""
default_graphviz_template = """
digraph role_dependencies {
size="%size"
dpi=%dpi
ratio="fill"
landscape=false
rankdir="BT";
node [shape = "box",
style = ... | python | {
"resource": ""
} |
q251457 | Export.exit_if_missing_graphviz | train | def exit_if_missing_graphviz(self):
"""
Detect the presence of the dot utility to make a png graph.
"""
| python | {
"resource": ""
} |
q251458 | Export.reqs_txt | train | def reqs_txt(self):
"""
Export a requirements file in txt format.
"""
role_lines = ""
for role in sorted(self.report["roles"]):
name = utils.normalize_role(role, self.config)
galaxy_name = "{0}.{1}".format(self.config["scm_user"], name)
versi... | python | {
"resource": ""
} |
q251459 | Export.reqs_yml | train | def reqs_yml(self):
"""
Export a requirements file in yml format.
"""
default_yml_item = """
- src: '%src'
name: '%name'
scm: '%scm'
version: '%version'
"""
role_lines = "---\n"
for role in sorted(self.report["roles"]):
name = utils.normalize... | python | {
"resource": ""
} |
q251460 | Export.dump | train | def dump(self):
"""
Dump the output to json.
"""
report_as_json_string = utils.dict_to_json(self.report)
if self.out_file:
| python | {
"resource": ""
} |
q251461 | fast_float | train | def fast_float(
x,
key=lambda x: x,
nan=None,
_uni=unicodedata.numeric,
_nan_inf=NAN_INF,
_first_char=POTENTIAL_FIRST_CHAR,
):
"""
Convert a string to a float quickly, return input as-is if not possible.
We don't need to accept all input that the real fast_int accepts because
na... | python | {
"resource": ""
} |
q251462 | fast_int | train | def fast_int(
x,
key=lambda x: x,
_uni=unicodedata.digit,
_first_char=POTENTIAL_FIRST_CHAR,
):
"""
Convert a string to a int quickly, return input as-is if not possible.
We don't need to accept all input that the real fast_int accepts because
natsort is controlling what is passed to thi... | python | {
"resource": ""
} |
q251463 | check_filters | train | def check_filters(filters):
"""
Execute range_check for every element of an iterable.
Parameters
----------
filters : iterable
The collection of filters to check. Each element
must be a two-element tuple of floats or ints.
| python | {
"resource": ""
} |
q251464 | keep_entry_range | train | def keep_entry_range(entry, lows, highs, converter, regex):
"""
Check if an entry falls into a desired range.
Every number in the entry will be extracted using *regex*,
if any are within a given low to high range the entry will
be kept.
Parameters
----------
entry : str
lows : iter... | python | {
"resource": ""
} |
q251465 | keep_entry_value | train | def keep_entry_value(entry, values, converter, regex):
"""
Check if an entry does not match a given value.
Every number in the entry will be extracted using *regex*,
if any match a given value the entry will not be kept.
Parameters
----------
entry : str
| python | {
"resource": ""
} |
q251466 | sort_and_print_entries | train | def sort_and_print_entries(entries, args):
"""Sort the entries, applying the filters first if necessary."""
# Extract the proper number type.
is_float = args.number_type in ("float", "real", "f", "r")
signed = args.signed or args.number_type in ("real", "r")
alg = (
natsort.ns.FLOAT * is_fl... | python | {
"resource": ""
} |
q251467 | regex_chooser | train | def regex_chooser(alg):
"""
Select an appropriate regex for the type of number of interest.
Parameters
----------
alg : ns enum
Used to indicate the regular expression to select.
Returns
-------
regex : compiled regex object
Regular expression object that matches the de... | python | {
"resource": ""
} |
q251468 | _normalize_input_factory | train | def _normalize_input_factory(alg):
"""
Create a function that will normalize unicode input data.
Parameters
----------
alg : ns enum
Used to indicate how to normalize unicode.
Returns
-------
func : callable
A function that accepts string (unicode) input and returns the... | python | {
"resource": ""
} |
q251469 | natsort_key | train | def natsort_key(val, key, string_func, bytes_func, num_func):
"""
Key to sort strings and numbers naturally.
It works by splitting the string into components of strings and numbers,
and then converting the numbers into actual ints or floats.
Parameters
----------
val : str | unicode | byte... | python | {
"resource": ""
} |
q251470 | parse_number_factory | train | def parse_number_factory(alg, sep, pre_sep):
"""
Create a function that will format a number into a tuple.
Parameters
----------
alg : ns enum
Indicate how to format the *bytes*.
sep : str
The string character to be inserted before the number
in the returned tuple.
p... | python | {
"resource": ""
} |
q251471 | sep_inserter | train | def sep_inserter(iterable, sep):
"""
Insert '' between numbers in an iterable.
Parameters
----------
iterable
sep : str
The string character to be inserted between adjacent numeric objects.
Yields
------
The values of *iterable* in order, with *sep* inserted where adjacent
... | python | {
"resource": ""
} |
q251472 | input_string_transform_factory | train | def input_string_transform_factory(alg):
"""
Create a function to transform a string.
Parameters
----------
alg : ns enum
Indicate how to format the *str*.
Returns
-------
func : callable
A function to be used as the *input_transform* argument to
*parse_string_f... | python | {
"resource": ""
} |
q251473 | string_component_transform_factory | train | def string_component_transform_factory(alg):
"""
Create a function to either transform a string or convert to a number.
Parameters
----------
alg : ns enum
Indicate how to format the *str*.
Returns
-------
func : callable
A function to be used as the *component_transfor... | python | {
"resource": ""
} |
q251474 | final_data_transform_factory | train | def final_data_transform_factory(alg, sep, pre_sep):
"""
Create a function to transform a tuple.
Parameters
----------
alg : ns enum
Indicate how to format the *str*.
sep : str
Separator that was passed to *parse_string_factory*.
pre_sep : str
String separator to ins... | python | {
"resource": ""
} |
q251475 | groupletters | train | def groupletters(x, _low=lower_function):
"""
Double all characters, making doubled letters lowercase.
Parameters
----------
x : str
Returns
-------
str
Examples
--------
| python | {
"resource": ""
} |
q251476 | chain_functions | train | def chain_functions(functions):
"""
Chain a list of single-argument functions together and return.
The functions are applied in list order, and the output of the
previous functions is passed to the next function.
Parameters
----------
functions : list
A list of single-argument func... | python | {
"resource": ""
} |
q251477 | path_splitter | train | def path_splitter(s, _d_match=re.compile(r"\.\d").match):
"""
Split a string into its path components.
Assumes a string is a path or is path-like.
Parameters
----------
s : str | pathlib.Path
Returns
-------
split : tuple
The path split by directory components and extensio... | python | {
"resource": ""
} |
q251478 | NumericalRegularExpressions._construct_regex | train | def _construct_regex(cls, fmt):
"""Given a format string, construct the regex with class attributes."""
| python | {
"resource": ""
} |
q251479 | natsort_keygen | train | def natsort_keygen(key=None, alg=ns.DEFAULT):
"""
Generate a key to sort strings and numbers naturally.
This key is designed for use as the `key` argument to
functions such as the `sorted` builtin.
The user may customize the generated function with the
arguments to `natsort_keygen`, including ... | python | {
"resource": ""
} |
q251480 | natsorted | train | def natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT):
"""
Sorts an iterable naturally.
Parameters
----------
seq : iterable
The input to sort.
key : callable, optional
A key used to determine how to sort each element of the iterable.
It is **not** applied recursi... | python | {
"resource": ""
} |
q251481 | humansorted | train | def humansorted(seq, key=None, reverse=False, alg=ns.DEFAULT):
"""
Convenience function to properly sort non-numeric characters.
This is a wrapper around ``natsorted(seq, alg=ns.LOCALE)``.
Parameters
----------
seq : iterable
The input to sort.
key : callable, optional
A k... | python | {
"resource": ""
} |
q251482 | realsorted | train | def realsorted(seq, key=None, reverse=False, alg=ns.DEFAULT):
"""
Convenience function to properly sort signed floats.
A signed float in a string could be "a-5.7". This is a wrapper around
``natsorted(seq, alg=ns.REAL)``.
The behavior of :func:`realsorted` for `natsort` version >= 4.0.0
was th... | python | {
"resource": ""
} |
q251483 | index_natsorted | train | def index_natsorted(seq, key=None, reverse=False, alg=ns.DEFAULT):
"""
Determine the list of the indexes used to sort the input sequence.
Sorts a sequence naturally, but returns a list of sorted the
indexes and not the sorted list itself. This list of indexes
can be used to sort multiple lists by t... | python | {
"resource": ""
} |
q251484 | order_by_index | train | def order_by_index(seq, index, iter=False):
"""
Order a given sequence by an index sequence.
The output of `index_natsorted` is a
sequence of integers (index) that correspond to how its input
sequence **would** be sorted. The idea is that this index can
be used to reorder multiple sequences by ... | python | {
"resource": ""
} |
q251485 | ZopeMixIn._iterOutFiles | train | def _iterOutFiles(self):
"""
Yields path, data, mimetype for each file involved on or produced by
profiling.
"""
out = StringIO()
self.callgrind(out, relative_path=True)
yield (
'cachegrind.out.pprofile',
out.getvalue(),
'applic... | python | {
"resource": ""
} |
q251486 | run | train | def run(cmd, filename=None, threads=True, verbose=False):
"""Similar to profile.run ."""
| python | {
"resource": ""
} |
q251487 | runctx | train | def runctx(cmd, globals, locals, filename=None, threads=True, verbose=False):
"""Similar to profile.runctx ."""
| python | {
"resource": ""
} |
q251488 | runfile | train | def runfile(fd, argv, fd_name='<unknown>', compile_flags=0, dont_inherit=1,
filename=None, threads=True, verbose=False):
"""
Run code from given file descriptor with profiling enabled.
Closes fd before executing contained code. | python | {
"resource": ""
} |
q251489 | runpath | train | def runpath(path, argv, filename=None, threads=True, verbose=False):
"""
Run code from open-accessible file path with profiling enabled.
| python | {
"resource": ""
} |
q251490 | pprofile | train | def pprofile(line, cell=None):
"""
Profile line execution.
"""
if cell is None:
# TODO: detect and use arguments (statistical profiling, ...) ?
return run(line)
| python | {
"resource": ""
} |
q251491 | _FileTiming.hit | train | def hit(self, code, line, duration):
"""
A line has finished executing.
code (code)
container function's code object
line (int)
line number of just executed line
duration (float)
| python | {
"resource": ""
} |
q251492 | _FileTiming.call | train | def call(self, code, line, callee_file_timing, callee, duration, frame):
"""
A call originating from this file returned.
code (code)
caller's code object
line (int)
caller's line number
callee_file_timing (FileTiming)
callee's FileTiming
cal... | python | {
"resource": ""
} |
q251493 | ProfileBase.dump_stats | train | def dump_stats(self, filename):
"""
Similar to profile.Profile.dump_stats - but different output format !
"""
if _isCallgrindName(filename):
with open(filename, 'w') as out:
self.callgrind(out)
| python | {
"resource": ""
} |
q251494 | ProfileRunnerBase.runctx | train | def runctx(self, cmd, globals, locals):
"""Similar to profile.Profile.runctx ."""
with self():
| python | {
"resource": ""
} |
q251495 | Profile.enable | train | def enable(self):
"""
Enable profiling.
"""
if self.enabled_start:
warn('Duplicate "enable" call')
| python | {
"resource": ""
} |
q251496 | Profile._disable | train | def _disable(self):
"""
Overload this method when subclassing. Called after actually disabling
| python | {
"resource": ""
} |
q251497 | FlexFieldsSerializerMixin._make_expanded_field_serializer | train | def _make_expanded_field_serializer(
self, name, nested_expand, nested_fields, nested_omit
):
"""
Returns an instance of the dynamically created nested serializer.
"""
field_options = self.expandable_fields[name]
serializer_class = field_options[0]
serializer_... | python | {
"resource": ""
} |
q251498 | FlexFieldsSerializerMixin._clean_fields | train | def _clean_fields(self, omit_fields, sparse_fields, next_level_omits):
"""
Remove fields that are found in omit list, and if sparse names
are passed, remove any fields not found in that list.
"""
sparse = len(sparse_fields) > 0
to_remove = []
if not spars... | python | {
"resource": ""
} |
q251499 | FlexFieldsSerializerMixin._can_access_request | train | def _can_access_request(self):
"""
Can access current request object if all are true
- The serializer is the root.
- A request context was passed in.
- The request method is GET.
"""
if self.parent:
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.