_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q227800 | Solver.solve | train | def solve(self):
"""Attempt to solve the request.
"""
if self.solve_begun:
raise ResolveError("cannot run solve() on a solve that has "
"already been started")
t1 = time.time()
pt1 = package_repo_stats.package_load_time
# itera... | python | {
"resource": ""
} |
q227801 | Solver.solve_step | train | def solve_step(self):
"""Perform a single solve step.
"""
self.solve_begun = True
if self.status != SolverStatus.unsolved:
return
if self.pr:
self.pr.header("SOLVE #%d (%d fails so far)...",
self.solve_count + 1, self.num_fails)... | python | {
"resource": ""
} |
q227802 | Solver.failure_reason | train | def failure_reason(self, failure_index=None):
"""Get the reason for a failure.
Args:
failure_index: Index of the fail to return the graph for (can be
negative). If None, the most appropriate failure is chosen
according to these rules:
- If the... | python | {
"resource": ""
} |
q227803 | Solver.failure_packages | train | def failure_packages(self, failure_index=None):
"""Get packages involved in a failure.
Args:
failure_index: See `failure_reason`.
Returns:
A list of Requirement objects.
"""
phase, _ = self._get_failed_phase(failure_index)
fr = phase.failure_reas... | python | {
"resource": ""
} |
q227804 | Solver.get_graph | train | def get_graph(self):
"""Returns the most recent solve graph.
This gives a graph showing the latest state of the solve. The specific
graph returned depends on the solve status. When status is:
unsolved: latest unsolved graph is returned;
solved: final solved graph is returned;
... | python | {
"resource": ""
} |
q227805 | Solver.get_fail_graph | train | def get_fail_graph(self, failure_index=None):
"""Returns a graph showing a solve failure.
Args:
failure_index: See `failure_reason`
Returns:
A pygraph.digraph object.
"""
phase, _ = self._get_failed_phase(failure_index)
return phase.get_graph() | python | {
"resource": ""
} |
q227806 | Solver.dump | train | def dump(self):
"""Print a formatted summary of the current solve state."""
from rez.utils.formatting import columnise
rows = []
for i, phase in enumerate(self.phase_stack):
rows.append((self._depth_label(i), phase.status, str(phase)))
print "status: %s (%s)" % (sel... | python | {
"resource": ""
} |
q227807 | make_path_writable | train | def make_path_writable(path):
"""Temporarily make `path` writable, if possible.
Does nothing if:
- config setting 'make_package_temporarily_writable' is False;
- this can't be done (eg we don't own `path`).
Args:
path (str): Path to make temporarily writable
"""
from rez.co... | python | {
"resource": ""
} |
q227808 | get_existing_path | train | def get_existing_path(path, topmost_path=None):
"""Get the longest parent path in `path` that exists.
If `path` exists, it is returned.
Args:
path (str): Path to test
topmost_path (str): Do not test this path or above
Returns:
str: Existing path, or None if no path was found.
... | python | {
"resource": ""
} |
q227809 | safe_makedirs | train | def safe_makedirs(path):
"""Safe makedirs.
Works in a multithreaded scenario.
"""
if not os.path.exists(path):
try:
os.makedirs(path)
except OSError:
if not os.path.exists(path):
raise | python | {
"resource": ""
} |
q227810 | safe_remove | train | def safe_remove(path):
"""Safely remove the given file or directory.
Works in a multithreaded scenario.
"""
if not os.path.exists(path):
return
try:
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
else:
os.remove(path)
ex... | python | {
"resource": ""
} |
q227811 | replacing_symlink | train | def replacing_symlink(source, link_name):
"""Create symlink that overwrites any existing target.
"""
with make_tmp_name(link_name) as tmp_link_name:
os.symlink(source, tmp_link_name)
replace_file_or_dir(link_name, tmp_link_name) | python | {
"resource": ""
} |
q227812 | replacing_copy | train | def replacing_copy(src, dest, follow_symlinks=False):
"""Perform copy that overwrites any existing target.
Will copy/copytree `src` to `dest`, and will remove `dest` if it exists,
regardless of what it is.
If `follow_symlinks` is False, symlinks are preserved, otherwise their
contents are copied.
... | python | {
"resource": ""
} |
q227813 | replace_file_or_dir | train | def replace_file_or_dir(dest, source):
"""Replace `dest` with `source`.
Acts like an `os.rename` if `dest` does not exist. Otherwise, `dest` is
deleted and `src` is renamed to `dest`.
"""
from rez.vendor.atomicwrites import replace_atomic
if not os.path.exists(dest):
try:
o... | python | {
"resource": ""
} |
q227814 | make_tmp_name | train | def make_tmp_name(name):
"""Generates a tmp name for a file or dir.
This is a tempname that sits in the same dir as `name`. If it exists on
disk at context exit time, it is deleted.
"""
path, base = os.path.split(name)
tmp_base = ".tmp-%s-%s" % (base, uuid4().hex)
tmp_name = os.path.join(pa... | python | {
"resource": ""
} |
q227815 | is_subdirectory | train | def is_subdirectory(path_a, path_b):
"""Returns True if `path_a` is a subdirectory of `path_b`."""
path_a = os.path.realpath(path_a)
path_b = os.path.realpath(path_b)
relative = os.path.relpath(path_a, path_b)
return (not relative.startswith(os.pardir + os.sep)) | python | {
"resource": ""
} |
q227816 | find_matching_symlink | train | def find_matching_symlink(path, source):
"""Find a symlink under `path` that points at `source`.
If source is relative, it is considered relative to `path`.
Returns:
str: Name of symlink found, or None.
"""
def to_abs(target):
if os.path.isabs(target):
return target
... | python | {
"resource": ""
} |
q227817 | copy_or_replace | train | def copy_or_replace(src, dst):
'''try to copy with mode, and if it fails, try replacing
'''
try:
shutil.copy(src, dst)
except (OSError, IOError), e:
# It's possible that the file existed, but was owned by someone
# else - in that situation, shutil.copy might then fail when it
... | python | {
"resource": ""
} |
q227818 | movetree | train | def movetree(src, dst):
"""Attempts a move, and falls back to a copy+delete if this fails
"""
try:
shutil.move(src, dst)
except:
copytree(src, dst, symlinks=True, hardlinks=True)
shutil.rmtree(src) | python | {
"resource": ""
} |
q227819 | safe_chmod | train | def safe_chmod(path, mode):
"""Set the permissions mode on path, but only if it differs from the current mode.
"""
if stat.S_IMODE(os.stat(path).st_mode) != mode:
os.chmod(path, mode) | python | {
"resource": ""
} |
q227820 | encode_filesystem_name | train | def encode_filesystem_name(input_str):
"""Encodes an arbitrary unicode string to a generic filesystem-compatible
non-unicode filename.
The result after encoding will only contain the standard ascii lowercase
letters (a-z), the digits (0-9), or periods, underscores, or dashes
(".", "_", or "-"). No... | python | {
"resource": ""
} |
q227821 | decode_filesystem_name | train | def decode_filesystem_name(filename):
"""Decodes a filename encoded using the rules given in encode_filesystem_name
to a unicode string.
"""
result = []
remain = filename
i = 0
while remain:
# use match, to ensure it matches from the start of the string...
match = _FILESYSTEM... | python | {
"resource": ""
} |
q227822 | walk_up_dirs | train | def walk_up_dirs(path):
"""Yields absolute directories starting with the given path, and iterating
up through all it's parents, until it reaches a root directory"""
prev_path = None
current_path = os.path.abspath(path)
while current_path != prev_path:
yield current_path
prev_path = c... | python | {
"resource": ""
} |
q227823 | Wrapper.run | train | def run(self, *args):
"""Invoke the wrapped script.
Returns:
Return code of the command, or 0 if the command is not run.
"""
if self.prefix_char is None:
prefix_char = config.suite_alias_prefix_char
else:
prefix_char = self.prefix_char
... | python | {
"resource": ""
} |
q227824 | Wrapper.print_about | train | def print_about(self):
"""Print an info message about the tool."""
filepath = os.path.join(self.suite_path, "bin", self.tool_name)
print "Tool: %s" % self.tool_name
print "Path: %s" % filepath
print "Suite: %s" % self.suite_path
msg = "%s (%r)" % (self.context... | python | {
"resource": ""
} |
q227825 | Wrapper.print_package_versions | train | def print_package_versions(self):
"""Print a list of versions of the package this tool comes from, and
indicate which version this tool is from."""
variants = self.context.get_tool_variants(self.tool_name)
if variants:
if len(variants) > 1:
self._print_conflic... | python | {
"resource": ""
} |
q227826 | generate_hypergraph | train | def generate_hypergraph(num_nodes, num_edges, r = 0):
"""
Create a random hyper graph.
@type num_nodes: number
@param num_nodes: Number of nodes.
@type num_edges: number
@param num_edges: Number of edges.
@type r: number
@param r: Uniform edges of size r.
"""
# ... | python | {
"resource": ""
} |
q227827 | check_version | train | def check_version(version, range_=None):
"""Check that the found software version is within supplied range.
Args:
version: Version of the package as a Version object.
range_: Allowable version range as a VersionRange object.
"""
if range_ and version not in range_:
raise RezBind... | python | {
"resource": ""
} |
q227828 | extract_version | train | def extract_version(exepath, version_arg, word_index=-1, version_rank=3):
"""Run an executable and get the program version.
Args:
exepath: Filepath to executable.
version_arg: Arg to pass to program, eg "-V". Can also be a list.
word_index: Expect the Nth word of output to be the versio... | python | {
"resource": ""
} |
q227829 | VersionedObject.construct | train | def construct(cls, name, version=None):
"""Create a VersionedObject directly from an object name and version.
Args:
name: Object name string.
version: Version object.
"""
other = VersionedObject(None)
other.name_ = name
other.version_ = Version() ... | python | {
"resource": ""
} |
q227830 | Requirement.construct | train | def construct(cls, name, range=None):
"""Create a requirement directly from an object name and VersionRange.
Args:
name: Object name string.
range: VersionRange object. If None, an unversioned requirement is
created.
"""
other = Requirement(None)
... | python | {
"resource": ""
} |
q227831 | Requirement.conflicts_with | train | def conflicts_with(self, other):
"""Returns True if this requirement conflicts with another `Requirement`
or `VersionedObject`."""
if isinstance(other, Requirement):
if (self.name_ != other.name_) or (self.range is None) \
or (other.range is None):
... | python | {
"resource": ""
} |
q227832 | Requirement.merged | train | def merged(self, other):
"""Returns the merged result of two requirements.
Two requirements can be in conflict and if so, this function returns
None. For example, requests for "foo-4" and "foo-6" are in conflict,
since both cannot be satisfied with a single version of foo.
Some... | python | {
"resource": ""
} |
q227833 | read_graph_from_string | train | def read_graph_from_string(txt):
"""Read a graph from a string, either in dot format, or our own
compressed format.
Returns:
`pygraph.digraph`: Graph object.
"""
if not txt.startswith('{'):
return read_dot(txt) # standard dot format
def conv(value):
if isinstance(value... | python | {
"resource": ""
} |
q227834 | write_compacted | train | def write_compacted(g):
"""Write a graph in our own compacted format.
Returns:
str.
"""
d_nodes = {}
d_edges = {}
def conv(value):
if isinstance(value, basestring):
return value.strip('"')
else:
return value
for node in g.nodes():
la... | python | {
"resource": ""
} |
q227835 | write_dot | train | def write_dot(g):
"""Replacement for pygraph.readwrite.dot.write, which is dog slow.
Note:
This isn't a general replacement. It will work for the graphs that
Rez generates, but there are no guarantees beyond that.
Args:
g (`pygraph.digraph`): Input graph.
Returns:
str:... | python | {
"resource": ""
} |
q227836 | prune_graph | train | def prune_graph(graph_str, package_name):
"""Prune a package graph so it only contains nodes accessible from the
given package.
Args:
graph_str (str): Dot-language graph string.
package_name (str): Name of package of interest.
Returns:
Pruned graph, as a string.
"""
# f... | python | {
"resource": ""
} |
q227837 | save_graph | train | def save_graph(graph_str, dest_file, fmt=None, image_ratio=None):
"""Render a graph to an image file.
Args:
graph_str (str): Dot-language graph string.
dest_file (str): Filepath to save the graph to.
fmt (str): Format, eg "png", "jpg".
image_ratio (float): Image ratio.
Retu... | python | {
"resource": ""
} |
q227838 | view_graph | train | def view_graph(graph_str, dest_file=None):
"""View a dot graph in an image viewer."""
from rez.system import system
from rez.config import config
if (system.platform == "linux") and (not os.getenv("DISPLAY")):
print >> sys.stderr, "Unable to open display."
sys.exit(1)
dest_file = _... | python | {
"resource": ""
} |
q227839 | Platform.physical_cores | train | def physical_cores(self):
"""Return the number of physical cpu cores on the system."""
try:
return self._physical_cores_base()
except Exception as e:
from rez.utils.logging_ import print_error
print_error("Error detecting physical core count, defaulting to 1: ... | python | {
"resource": ""
} |
q227840 | Platform.logical_cores | train | def logical_cores(self):
"""Return the number of cpu cores as reported to the os.
May be different from physical_cores if, ie, intel's hyperthreading is
enabled.
"""
try:
return self._logical_cores()
except Exception as e:
from rez.utils.logging_ ... | python | {
"resource": ""
} |
q227841 | AnsiToWin32.write_and_convert | train | def write_and_convert(self, text):
'''
Write the given text to our wrapped stream, stripping any ANSI
sequences from the text, and optionally converting them into win32
calls.
'''
cursor = 0
for match in self.ANSI_RE.finditer(text):
start, end = match.... | python | {
"resource": ""
} |
q227842 | ContextModel.copy | train | def copy(self):
"""Returns a copy of the context."""
other = ContextModel(self._context, self.parent())
other._stale = self._stale
other._modified = self._modified
other.request = self.request[:]
other.packages_path = self.packages_path
other.implicit_packages = s... | python | {
"resource": ""
} |
q227843 | ContextModel.get_lock_requests | train | def get_lock_requests(self):
"""Take the current context, and the current patch locks, and determine
the effective requests that will be added to the main request.
Returns:
A dict of (PatchLock, [Requirement]) tuples. Each requirement will be
a weak package reference. If... | python | {
"resource": ""
} |
q227844 | ContextModel.resolve_context | train | def resolve_context(self, verbosity=0, max_fails=-1, timestamp=None,
callback=None, buf=None, package_load_callback=None):
"""Update the current context by performing a re-resolve.
The newly resolved context is only applied if it is a successful solve.
Returns:
... | python | {
"resource": ""
} |
q227845 | ContextModel.set_context | train | def set_context(self, context):
"""Replace the current context with another."""
self._set_context(context, emit=False)
self._modified = (not context.load_path)
self.dataChanged.emit(self.CONTEXT_CHANGED |
self.REQUEST_CHANGED |
... | python | {
"resource": ""
} |
q227846 | get_resources_dests | train | def get_resources_dests(resources_root, rules):
"""Find destinations for resources files"""
def get_rel_path(base, path):
# normalizes and returns a lstripped-/-separated path
base = base.replace(os.path.sep, '/')
path = path.replace(os.path.sep, '/')
assert path.startswith(base... | python | {
"resource": ""
} |
q227847 | find_cycle | train | def find_cycle(graph):
"""
Find a cycle in the given graph.
This function will return a list of nodes which form a cycle in the graph or an empty list if
no cycle exists.
@type graph: graph, digraph
@param graph: Graph.
@rtype: list
@return: List of nodes.
"""
... | python | {
"resource": ""
} |
q227848 | create_release_vcs | train | def create_release_vcs(path, vcs_name=None):
"""Return a new release VCS that can release from this source path."""
from rez.plugin_managers import plugin_manager
vcs_types = get_release_vcs_types()
if vcs_name:
if vcs_name not in vcs_types:
raise ReleaseVCSError("Unknown version con... | python | {
"resource": ""
} |
q227849 | ReleaseVCS.find_vcs_root | train | def find_vcs_root(cls, path):
"""Try to find a version control root directory of this type for the
given path.
If successful, returns (vcs_root, levels_up), where vcs_root is the
path to the version control root directory it found, and levels_up is an
integer indicating how many... | python | {
"resource": ""
} |
q227850 | ReleaseVCS._cmd | train | def _cmd(self, *nargs):
"""Convenience function for executing a program such as 'git' etc."""
cmd_str = ' '.join(map(quote, nargs))
if self.package.config.debug("package_release"):
print_debug("Running command: %s" % cmd_str)
p = popen(nargs, stdout=subprocess.PIPE, stderr=... | python | {
"resource": ""
} |
q227851 | Channel._close | train | def _close(self, args):
"""Request a channel close
This method indicates that the sender wants to close the
channel. This may be due to internal conditions (e.g. a forced
shut-down) or due to an error handling a specific method, i.e.
an exception. When a close is due to an exce... | python | {
"resource": ""
} |
q227852 | Channel._x_flow_ok | train | def _x_flow_ok(self, active):
"""Confirm a flow method
Confirms to the peer that a flow command was received and
processed.
PARAMETERS:
active: boolean
current flow setting
Confirms the setting of the processed flow method:
... | python | {
"resource": ""
} |
q227853 | Channel._x_open | train | def _x_open(self):
"""Open a channel for use
This method opens a virtual connection (a channel).
RULE:
This method MUST NOT be called when the channel is already
open.
PARAMETERS:
out_of_band: shortstr (DEPRECATED)
out-of-band sett... | python | {
"resource": ""
} |
q227854 | Channel.exchange_declare | train | def exchange_declare(self, exchange, type, passive=False, durable=False,
auto_delete=True, nowait=False, arguments=None):
"""Declare exchange, create if needed
This method creates an exchange if it does not already exist,
and if the exchange exists, verifies that it is ... | python | {
"resource": ""
} |
q227855 | Channel.exchange_bind | train | def exchange_bind(self, destination, source='', routing_key='',
nowait=False, arguments=None):
"""This method binds an exchange to an exchange.
RULE:
A server MUST allow and ignore duplicate bindings - that
is, two or more bind methods for a specific excha... | python | {
"resource": ""
} |
q227856 | Channel.queue_declare | train | def queue_declare(self, queue='', passive=False, durable=False,
exclusive=False, auto_delete=True, nowait=False,
arguments=None):
"""Declare queue, create if needed
This method creates or checks a queue. When creating a new
queue the client can speci... | python | {
"resource": ""
} |
q227857 | Channel._queue_declare_ok | train | def _queue_declare_ok(self, args):
"""Confirms a queue definition
This method confirms a Declare method and confirms the name of
the queue, essential for automatically-named queues.
PARAMETERS:
queue: shortstr
Reports the name of the queue. If the server ge... | python | {
"resource": ""
} |
q227858 | Channel.queue_delete | train | def queue_delete(self, queue='',
if_unused=False, if_empty=False, nowait=False):
"""Delete a queue
This method deletes a queue. When a queue is deleted any
pending messages are sent to a dead-letter queue if this is
defined in the server configuration, and all cons... | python | {
"resource": ""
} |
q227859 | Channel.queue_purge | train | def queue_purge(self, queue='', nowait=False):
"""Purge a queue
This method removes all messages from a queue. It does not
cancel consumers. Purged messages are deleted without any
formal "undo" mechanism.
RULE:
A call to purge MUST result in an empty queue.
... | python | {
"resource": ""
} |
q227860 | Channel.basic_ack | train | def basic_ack(self, delivery_tag, multiple=False):
"""Acknowledge one or more messages
This method acknowledges one or more messages delivered via
the Deliver or Get-Ok methods. The client can ask to confirm
a single message or a set of messages up to and including a
specific m... | python | {
"resource": ""
} |
q227861 | Channel.basic_cancel | train | def basic_cancel(self, consumer_tag, nowait=False):
"""End a queue consumer
This method cancels a consumer. This does not affect already
delivered messages, but it does mean the server will not send
any more messages for that consumer. The client may receive
an abitrary number ... | python | {
"resource": ""
} |
q227862 | Channel._basic_cancel_notify | train | def _basic_cancel_notify(self, args):
"""Consumer cancelled by server.
Most likely the queue was deleted.
"""
consumer_tag = args.read_shortstr()
callback = self._on_cancel(consumer_tag)
if callback:
callback(consumer_tag)
else:
raise Con... | python | {
"resource": ""
} |
q227863 | Channel.basic_consume | train | def basic_consume(self, queue='', consumer_tag='', no_local=False,
no_ack=False, exclusive=False, nowait=False,
callback=None, arguments=None, on_cancel=None):
"""Start a queue consumer
This method asks the server to start a "consumer", which is a
tra... | python | {
"resource": ""
} |
q227864 | Channel._basic_deliver | train | def _basic_deliver(self, args, msg):
"""Notify the client of a consumer message
This method delivers a message to the client, via a consumer.
In the asynchronous message delivery model, the client starts
a consumer using the Consume method, then the server responds
with Deliver ... | python | {
"resource": ""
} |
q227865 | Channel._basic_get_ok | train | def _basic_get_ok(self, args, msg):
"""Provide client with a message
This method delivers a message to the client following a get
method. A message delivered by 'get-ok' must be acknowledged
unless the no-ack option was set in the get method.
PARAMETERS:
delivery_t... | python | {
"resource": ""
} |
q227866 | Channel._basic_publish | train | def _basic_publish(self, msg, exchange='', routing_key='',
mandatory=False, immediate=False):
"""Publish a message
This method publishes a message to a specific exchange. The
message will be routed to queues as defined by the exchange
configuration and distributed... | python | {
"resource": ""
} |
q227867 | Channel.basic_qos | train | def basic_qos(self, prefetch_size, prefetch_count, a_global):
"""Specify quality of service
This method requests a specific quality of service. The QoS
can be specified for the current channel or for all channels
on the connection. The particular properties and semantics of
a ... | python | {
"resource": ""
} |
q227868 | Channel.basic_recover | train | def basic_recover(self, requeue=False):
"""Redeliver unacknowledged messages
This method asks the broker to redeliver all unacknowledged
messages on a specified channel. Zero or more messages may be
redelivered. This method is only allowed on non-transacted
channels.
R... | python | {
"resource": ""
} |
q227869 | Channel.basic_reject | train | def basic_reject(self, delivery_tag, requeue):
"""Reject an incoming message
This method allows a client to reject a message. It can be
used to interrupt and cancel large incoming messages, or
return untreatable messages to their original queue.
RULE:
The server S... | python | {
"resource": ""
} |
q227870 | Channel._basic_return | train | def _basic_return(self, args, msg):
"""Return a failed message
This method returns an undeliverable message that was
published with the "immediate" flag set, or an unroutable
message published with the "mandatory" flag set. The reply
code and text provide information about the r... | python | {
"resource": ""
} |
q227871 | create_build_process | train | def create_build_process(process_type, working_dir, build_system, package=None,
vcs=None, ensure_latest=True, skip_repo_errors=False,
ignore_existing_tag=False, verbose=False, quiet=False):
"""Create a `BuildProcess` instance."""
from rez.plugin_managers import ... | python | {
"resource": ""
} |
q227872 | BuildProcessHelper.visit_variants | train | def visit_variants(self, func, variants=None, **kwargs):
"""Iterate over variants and call a function on each."""
if variants:
present_variants = range(self.package.num_variants)
invalid_variants = set(variants) - set(present_variants)
if invalid_variants:
... | python | {
"resource": ""
} |
q227873 | BuildProcessHelper.create_build_context | train | def create_build_context(self, variant, build_type, build_path):
"""Create a context to build the variant within."""
request = variant.get_requires(build_requires=True,
private_build_requires=True)
req_strs = map(str, request)
quoted_req_strs = map... | python | {
"resource": ""
} |
q227874 | BuildProcessHelper.get_release_data | train | def get_release_data(self):
"""Get release data for this release.
Returns:
dict.
"""
previous_package = self.get_previous_release()
if previous_package:
previous_version = previous_package.version
previous_revision = previous_package.revision
... | python | {
"resource": ""
} |
q227875 | minimal_spanning_tree | train | def minimal_spanning_tree(graph, root=None):
"""
Minimal spanning tree.
@attention: Minimal spanning tree is meaningful only for weighted graphs.
@type graph: graph
@param graph: Graph.
@type root: node
@param root: Optional root node (will explore only root's connected component)
... | python | {
"resource": ""
} |
q227876 | cut_value | train | def cut_value(graph, flow, cut):
"""
Calculate the value of a cut.
@type graph: digraph
@param graph: Graph
@type flow: dictionary
@param flow: Dictionary containing a flow for each edge.
@type cut: dictionary
@param cut: Dictionary mapping each node to a subset index. The function on... | python | {
"resource": ""
} |
q227877 | cut_tree | train | def cut_tree(igraph, caps = None):
"""
Construct a Gomory-Hu cut tree by applying the algorithm of Gusfield.
@type igraph: graph
@param igraph: Graph
@type caps: dictionary
@param caps: Dictionary specifying a maximum capacity for each edge. If not given, the weight of the edge
will be use... | python | {
"resource": ""
} |
q227878 | Locator.locate | train | def locate(self, requirement, prereleases=False):
"""
Find the most recent distribution which matches the given
requirement.
:param requirement: A requirement of the form 'foo (1.0)' or perhaps
'foo (>= 1.0, < 2.0, != 1.3)'
:param prereleases: If ``Tr... | python | {
"resource": ""
} |
q227879 | get_bind_modules | train | def get_bind_modules(verbose=False):
"""Get available bind modules.
Returns:
dict: Map of (name, filepath) listing all bind modules.
"""
builtin_path = os.path.join(module_root_path, "bind")
searchpaths = config.bind_module_path + [builtin_path]
bindnames = {}
for path in searchpat... | python | {
"resource": ""
} |
q227880 | find_bind_module | train | def find_bind_module(name, verbose=False):
"""Find the bind module matching the given name.
Args:
name (str): Name of package to find bind module for.
verbose (bool): If True, print extra output.
Returns:
str: Filepath to bind module .py file, or None if not found.
"""
bind... | python | {
"resource": ""
} |
q227881 | bind_package | train | def bind_package(name, path=None, version_range=None, no_deps=False,
bind_args=None, quiet=False):
"""Bind software available on the current system, as a rez package.
Note:
`bind_args` is provided when software is bound via the 'rez-bind'
command line tool. Bind modules can def... | python | {
"resource": ""
} |
q227882 | create_release_hook | train | def create_release_hook(name, source_path):
"""Return a new release hook of the given type."""
from rez.plugin_managers import plugin_manager
return plugin_manager.create_instance('release_hook',
name,
source_path=source_pat... | python | {
"resource": ""
} |
q227883 | ReleaseHook.pre_build | train | def pre_build(self, user, install_path, variants=None, release_message=None,
changelog=None, previous_version=None,
previous_revision=None, **kwargs):
"""Pre-build hook.
Args:
user: Name of person who did the release.
install_path: Directory t... | python | {
"resource": ""
} |
q227884 | traversal | train | def traversal(graph, node, order):
"""
Graph traversal iterator.
@type graph: graph, digraph
@param graph: Graph.
@type node: node
@param node: Node.
@type order: string
@param order: traversal ordering. Possible values are:
2. 'pre' - Preordering (default)
... | python | {
"resource": ""
} |
q227885 | is_zipfile | train | def is_zipfile(filename):
"""Quickly see if file is a ZIP file by checking the magic number."""
try:
fpin = open(filename, "rb")
endrec = _EndRecData(fpin)
fpin.close()
if endrec:
return True # file has correct magic number
except IOError:
... | python | {
"resource": ""
} |
q227886 | _EndRecData | train | def _EndRecData(fpin):
"""Return data from the "End of Central Directory" record, or None.
The data is a list of the nine items in the ZIP "End of central dir"
record followed by a tenth item, the file seek offset of this record."""
# Determine file size
fpin.seek(0, 2)
filesize = fpin.tell()
... | python | {
"resource": ""
} |
q227887 | _ZipDecrypter._GenerateCRCTable | train | def _GenerateCRCTable():
"""Generate a CRC-32 table.
ZIP encryption uses the CRC32 one-byte primitive for scrambling some
internal keys. We noticed that a direct implementation is faster than
relying on binascii.crc32().
"""
poly = 0xedb88320
table = [0] * 256
... | python | {
"resource": ""
} |
q227888 | _ZipDecrypter._crc32 | train | def _crc32(self, ch, crc):
"""Compute the CRC32 primitive on one byte."""
return ((crc >> 8) & 0xffffff) ^ self.crctable[(crc ^ ord(ch)) & 0xff] | python | {
"resource": ""
} |
q227889 | ZipExtFile.readline | train | def readline(self, size = -1):
"""Read a line with approx. size. If size is negative,
read a whole line.
"""
if size < 0:
size = sys.maxint
elif size == 0:
return ''
# check for a newline already in buffer
nl, nllen = self._checkfornewl... | python | {
"resource": ""
} |
q227890 | ZipFile._GetContents | train | def _GetContents(self):
"""Read the directory, making sure we close the file if the format
is bad."""
try:
self._RealGetContents()
except BadZipfile:
if not self._filePassed:
self.fp.close()
self.fp = None
raise | python | {
"resource": ""
} |
q227891 | ZipFile.namelist | train | def namelist(self):
"""Return a list of file names in the archive."""
l = []
for data in self.filelist:
l.append(data.filename)
return l | python | {
"resource": ""
} |
q227892 | ZipFile.printdir | train | def printdir(self):
"""Print a table of contents for the zip file."""
print "%-46s %19s %12s" % ("File Name", "Modified ", "Size")
for zinfo in self.filelist:
date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6]
print "%-46s %s %12d" % (zinfo.filename, date, zinf... | python | {
"resource": ""
} |
q227893 | ZipFile.getinfo | train | def getinfo(self, name):
"""Return the instance of ZipInfo given 'name'."""
info = self.NameToInfo.get(name)
if info is None:
raise KeyError(
'There is no item named %r in the archive' % name)
return info | python | {
"resource": ""
} |
q227894 | ZipFile.extract | train | def extract(self, member, path=None, pwd=None):
"""Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately
as possible. `member' may be a filename or a ZipInfo object. You can
specify a different di... | python | {
"resource": ""
} |
q227895 | PyZipFile.writepy | train | def writepy(self, pathname, basename = ""):
"""Add all files from "pathname" to the ZIP archive.
If pathname is a package directory, search the directory and
all package subdirectories recursively for all *.py and enter
the modules into the archive. If pathname is a plain
direc... | python | {
"resource": ""
} |
q227896 | AtomicWriter.get_fileobject | train | def get_fileobject(self, dir=None, **kwargs):
'''Return the temporary file to use.'''
if dir is None:
dir = os.path.normpath(os.path.dirname(self._path))
descriptor, name = tempfile.mkstemp(dir=dir)
# io.open() will take either the descriptor or the name, but we need
... | python | {
"resource": ""
} |
q227897 | AtomicWriter.commit | train | def commit(self, f):
'''Move the temporary file to the target location.'''
if self._overwrite:
replace_atomic(f.name, self._path)
else:
move_atomic(f.name, self._path) | python | {
"resource": ""
} |
q227898 | read_pid_from_pidfile | train | def read_pid_from_pidfile(pidfile_path):
""" Read the PID recorded in the named PID file.
Read and return the numeric PID recorded as text in the named
PID file. If the PID file cannot be read, or if the content is
not a valid PID, return ``None``.
"""
pid = None
try:
... | python | {
"resource": ""
} |
q227899 | ConfiguredSplitter.apply_saved_layout | train | def apply_saved_layout(self):
"""Call this after adding your child widgets."""
num_widgets = self.config.get(self.config_key + "/num_widgets", int)
if num_widgets:
sizes = []
for i in range(num_widgets):
key = "%s/size_%d" % (self.config_key, i)
... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.