docstring
stringlengths
52
499
function
stringlengths
67
35.2k
__index_level_0__
int64
52.6k
1.16M
Write package data to `buf`. Args: data (dict): Data source - must conform to `package_serialise_schema`. buf (file-like object): Destination stream. format_ (`FileFormat`): Format to dump data in. skip_attributes (list of str): List of attributes to not print.
def dump_package_data(data, buf, format_=FileFormat.py, skip_attributes=None): if format_ == FileFormat.txt: raise ValueError("'txt' format not supported for packages.") data_ = dict((k, v) for k, v in data.iteritems() if v is not None) data_ = package_serialise_schema.validate(data_) skip...
232,028
Create a package maker. Args: name (str): Package name.
def __init__(self, name, data=None, package_cls=None): super(PackageMaker, self).__init__(data) self.name = name self.package_cls = package_cls or Package # set by `make_package` self.installed_variants = [] self.skipped_variants = []
232,047
Convert a dict of Schemas into a Schema. Args: required (bool): Whether to make schema keys optional or required. allow_custom_keys (bool, optional): If True, creates a schema that allows custom items in dicts. modifier (callable): Functor to apply to dict values - it is applied...
def dict_to_schema(schema_dict, required, allow_custom_keys=True, modifier=None): if modifier: modifier = Use(modifier) def _to(value): if isinstance(value, dict): d = {} for k, v in value.iteritems(): if isinstance(k, basestring): ...
232,086
Enter diff mode. Args: context_model (`ContextModel`): Context to diff against. If None, a copy of the current context is used.
def enter_diff_mode(self, context_model=None): assert not self.diff_mode self.diff_mode = True if context_model is None: self.diff_from_source = True self.diff_context_model = self.context_model.copy() else: self.diff_from_source = False ...
232,104
Return the string wrapped with the appropriate styling for the message level. The styling will be determined based on the rez configuration. Args: str_ (str): The string to be wrapped. level (str): The message level. Should be one of 'critical', 'error', 'warning', 'info' or 'debug'. ...
def _color_level(str_, level): fore_color, back_color, styles = _get_style_from_config(level) return _color(str_, fore_color, back_color, styles)
232,129
Iterate over package families, in no particular order. Note that multiple package families with the same name can be returned. Unlike packages, families later in the searchpath are not hidden by earlier families. Args: paths (list of str, optional): paths to search for package families, ...
def iter_package_families(paths=None): for path in (paths or config.packages_path): repo = package_repository_manager.get_repository(path) for resource in repo.iter_package_families(): yield PackageFamily(resource)
232,159
Get an exact version of a package. Args: name (str): Name of the package, eg 'maya'. version (Version or str): Version of the package, eg '1.0.0' paths (list of str, optional): paths to search for package, defaults to `config.packages_path`. Returns: `Package` objec...
def get_package(name, version, paths=None): if isinstance(version, basestring): range_ = VersionRange("==%s" % version) else: range_ = VersionRange.from_version(version, "==") it = iter_packages(name, range_, paths) try: return it.next() except StopIteration: re...
232,161
Create a package given its handle (or serialized dict equivalent) Args: package_handle (`ResourceHandle` or dict): Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict Returns: `Package`.
def get_package_from_handle(package_handle): if isinstance(package_handle, dict): package_handle = ResourceHandle.from_dict(package_handle) package_resource = package_repository_manager.get_resource_from_handle(package_handle) package = Package(package_resource) return package
232,162
Get a package given a string. Args: txt (str): String such as 'foo', 'bah-1.3'. paths (list of str, optional): paths to search for package, defaults to `config.packages_path`. Returns: `Package` instance, or None if no package was found.
def get_package_from_string(txt, paths=None): o = VersionedObject(txt) return get_package(o.name, o.version, paths=paths)
232,163
Create a developer package. Args: path (str): Path to dir containing package definition file. format (str): Package definition file format, detected if None. Returns: `DeveloperPackage`.
def get_developer_package(path, format=None): from rez.developer_package import DeveloperPackage return DeveloperPackage.from_path(path, format=format)
232,164
Create a package given package data. Args: name (str): Package name. data (dict): Package data. Must conform to `package_maker.package_schema`. Returns: `Package` object.
def create_package(name, data, package_cls=None): from rez.package_maker__ import PackageMaker maker = PackageMaker(name, data, package_cls=package_cls) return maker.get_package()
232,165
Create a variant given its handle (or serialized dict equivalent) Args: variant_handle (`ResourceHandle` or dict): Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict context (`ResolvedContext`): The context this variant is associated ...
def get_variant(variant_handle, context=None): if isinstance(variant_handle, dict): variant_handle = ResourceHandle.from_dict(variant_handle) variant_resource = package_repository_manager.get_resource_from_handle(variant_handle) variant = Variant(variant_resource, context=context) return v...
232,166
Get the latest package for a given package name. Args: name (str): Package name. range_ (`VersionRange`): Version range to search within. paths (list of str, optional): paths to search for package families, defaults to `config.packages_path`. error (bool): If True, raise...
def get_latest_package(name, range_=None, paths=None, error=False): it = iter_packages(name, range_=range_, paths=paths) try: return max(it, key=lambda x: x.version) except ValueError: # empty sequence if error: # FIXME this isn't correct, since the pkg fam may exist but a ...
232,169
Get the latest package found within the given request string. Args: txt (str): Request, eg 'foo-1.2+' paths (list of str, optional): paths to search for package families, defaults to `config.packages_path`. error (bool): If True, raise an error if no package is found. Retur...
def get_latest_package_from_string(txt, paths=None, error=False): from rez.utils.formatting import PackageRequest req = PackageRequest(txt) return get_latest_package(name=req.name, range_=req.range_, paths=paths, ...
232,170
Print the contents of the package. Args: buf (file-like object): Stream to write to. format_ (`FileFormat`): Format to write in. skip_attributes (list of str): List of attributes to not print. include_release (bool): If True, include release-related attributes, ...
def print_info(self, buf=None, format_=FileFormat.yaml, skip_attributes=None, include_release=False): data = self.validated_data().copy() # config is a special case. We only really want to show any config settings # that were in the package.py, not the entire Config ...
232,178
Get the requirements of the variant. Args: build_requires (bool): If True, include build requirements. private_build_requires (bool): If True, include private build requirements. Returns: List of `Requirement` objects.
def get_requires(self, build_requires=False, private_build_requires=False): requires = self.requires or [] if build_requires: requires = requires + (self.build_requires or []) if private_build_requires: requires = requires + (self.private_build_requires or []) ...
232,192
Writes both to given filepath, and tmpdir location. This is to get around the problem with some NFS's where immediately reading a file that has just been written is problematic. Instead, any files that we write, we also write to /tmp, and reads of these files are redirected there. Args: filepa...
def open_file_for_write(filepath, mode=None): stream = StringIO() yield stream content = stream.getvalue() filepath = os.path.realpath(filepath) tmpdir = tmpdir_manager.mkdtemp() cache_filepath = os.path.join(tmpdir, os.path.basename(filepath)) debug_print("Writing to %s (local cache ...
232,195
Load data from a file. Note: Any functions from a .py file will be converted to `SourceCode` objects. Args: filepath (str): File to load. format_ (`FileFormat`): Format of file contents. update_data_callback (callable): Used to change data before it is returned or c...
def load_from_file(filepath, format_=FileFormat.py, update_data_callback=None, disable_memcache=False): filepath = os.path.realpath(filepath) cache_filepath = file_cache.get(filepath) if cache_filepath: # file has been written by this process, read it from /tmp to avoid ...
232,196
Load python-formatted data from a stream. Args: stream (file-like object). Returns: dict.
def load_py(stream, filepath=None): with add_sys_paths(config.package_definition_build_python_paths): return _load_py(stream, filepath=filepath)
232,199
Load yaml-formatted data from a stream. Args: stream (file-like object). Returns: dict.
def load_yaml(stream, **kwargs): # if there's an error parsing the yaml, and you pass yaml.load a string, # it will print lines of context, but will print "<string>" instead of a # filename; if you pass a stream, it will print the filename, but no lines # of context. # Get the best of both worl...
232,202
Security mechanism response This method attempts to authenticate, passing a block of SASL data for the security mechanism at the server side. PARAMETERS: response: longstr security response data A block of opaque data passed to the security ...
def _x_secure_ok(self, response): args = AMQPWriter() args.write_longstr(response) self._send_method((10, 21), args)
232,214
Print a list of visible tools. Args: pattern (str): Only list tools that match this glob pattern.
def print_tools(self, pattern=None, buf=sys.stdout): seen = set() rows = [] context = self.context if context: data = context.get_tools() conflicts = set(context.get_conflicting_tools().keys()) for _, (variant, tools) in sorted(data.items()):...
232,221
Load a developer package. A developer package may for example be a package.yaml or package.py in a user's source directory. Args: path: Directory containing the package definition file, or file path for the package file itself format: which FileFormat to...
def from_path(cls, path, format=None): name = None data = None if format is None: formats = (FileFormat.py, FileFormat.yaml) else: formats = (format,) try: mode = os.stat(path).st_mode except (IOError, OSError): r...
232,231
Get a list of running instances. Args: context (`ResolvedContext`): Context the process is running in. process_name (str): Name of the process. Returns: List of (`subprocess.Popen`, start-time) 2-tuples, where start_time is the epoch time the process was...
def running_instances(self, context, process_name): handle = (id(context), process_name) it = self.processes.get(handle, {}).itervalues() entries = [x for x in it if x[0].poll() is None] return entries
232,248
Return the string with non-literal parts formatted. Args: func (callable): Callable that translates a string into a formatted string. Returns: `EscapedString` object.
def formatted(self, func): other = EscapedString.__new__(EscapedString) other.strings = [] for is_literal, value in self.strings: if not is_literal: value = func(value) other.strings.append((is_literal, value)) return other
232,295
Creates an `EnvironmentDict`. Args: override_existing_lists (bool): If True, the first call to append or prepend will override the value in `environ` and effectively act as a setenv operation. If False, pre-existing values will be appended/prepended t...
def __init__(self, manager): self.manager = manager self._var_cache = dict((k, EnvironmentVariable(k, self)) for k in manager.parent_environ.iterkeys())
232,302
Compile and possibly execute rex code. Args: code (str or SourceCode): The python code to compile. filename (str): File to associate with the code, will default to '<string>'. exec_namespace (dict): Namespace to execute the code in. If None, t...
def compile_code(cls, code, filename=None, exec_namespace=None): if filename is None: if isinstance(code, SourceCode): filename = code.sourcename else: filename = "<string>" # compile try: if isinstance(code, SourceCod...
232,315
Execute code within the execution context. Args: code (str or SourceCode): Rex code to execute. filename (str): Filename to report if there are syntax errors. isolate (bool): If True, do not affect `self.globals` by executing this code.
def execute_code(self, code, filename=None, isolate=False): def _apply(): self.compile_code(code=code, filename=filename, exec_namespace=self.globals) # we want to execute the code using self.globals - if for no other ...
232,316
Same as iter_packages in packages.py, but also applies this filter. Args: name (str): Name of the package, eg 'maya'. range_ (VersionRange or str): If provided, limits the versions returned to those in `range_`. paths (list of str, optional): paths to search ...
def iter_packages(self, name, range_=None, paths=None): for package in iter_packages(name, range_, paths): if not self.excludes(package): yield package
232,333
Add a filter to the list. Args: package_filter (`PackageFilter`): Filter to add.
def add_filter(self, package_filter): filters = self.filters + [package_filter] self.filters = sorted(filters, key=lambda x: x.cost)
232,342
Parse a rule from a string. See rezconfig.package_filter for an overview of valid strings. Args: txt (str): String to parse. Returns: `Rule` instance.
def parse_rule(cls, txt): types = {"glob": GlobRule, "regex": RegexRule, "range": RangeRule, "before": TimestampRule, "after": TimestampRule} # parse form 'x(y)' into x, y label, txt = Rule._parse_label(txt) if...
232,349
Create a regex rule. Args: s (str): Regex pattern. Eg '.*\\.beta$'.
def __init__(self, s): self.txt = s self._family = self._extract_family(s) self.regex = re.compile(s)
232,352
Create a timestamp rule. Args: timestamp (int): Epoch time. family (str): Package family to apply the rule to. reverse (bool): If True, reverse the logic so that packages released *after* the timestamp are matched.
def __init__(self, timestamp, family=None, reverse=False): self.timestamp = timestamp self.reverse = reverse self._family = family
232,356
Create an executable script. Args: filepath (str): File to create. body (str or callable): Contents of the script. If a callable, its code is used as the script body. program (str): Name of program to launch the script, 'python' if None
def create_executable_script(filepath, body, program=None): program = program or "python" if callable(body): from rez.utils.sourcecode import SourceCode code = SourceCode(func=body) body = code.source if not body.endswith('\n'): body += '\n' with open(filepath, 'w'...
232,384
Create a PackageHelp object. Args: package_name (str): Package to search. version_range (`VersionRange`): Versions to search.
def __init__(self, package_name, version_range=None, paths=None, verbose=False): self.package = None self._verbose = verbose self._sections = [] # find latest package with a help entry package = None it = iter_packages(package_name, range_=version_range) ...
232,393
Create a standalone, in-memory repository. Using this function bypasses the `package_repository_manager` singleton. This is usually desired however, since in-memory repositories are for temporarily storing programmatically created packages, which we do not want to cache and that do not ...
def create_repository(cls, repository_data): location = "memory{%s}" % hex(id(repository_data)) resource_pool = ResourcePool(cache_size=None) repo = MemoryPackageRepository(location, resource_pool) repo.data = repository_data return repo
232,440
Create an in-memory package repository. Args: location (str): Path containing the package repository.
def __init__(self, location, resource_pool): super(MemoryPackageRepository, self).__init__(location, resource_pool) self.data = {} self.register_resource(MemoryPackageFamilyResource) self.register_resource(MemoryPackageResource) self.register_resource(MemoryVariantResour...
232,441
Create a widget containing an aligned set of widgets. Args: widgets (list of `QWidget`). horizontal (bool). align (str): One of: - 'left', 'right' (horizontal); - 'top', 'bottom' (vertical) parent_widget (`QWidget`): Owner widget, QWidget is created if this ...
def create_pane(widgets, horizontal, parent_widget=None, compact=False, compact_spacing=2): pane = parent_widget or QtGui.QWidget() type_ = QtGui.QHBoxLayout if horizontal else QtGui.QVBoxLayout layout = type_() if compact: layout.setSpacing(compact_spacing) layout.s...
232,447
Create a toolbutton. Args: entries: List of (label, slot) tuples. Returns: `QtGui.QToolBar`.
def create_toolbutton(entries, parent=None): btn = QtGui.QToolButton(parent) menu = QtGui.QMenu() actions = [] for label, slot in entries: action = add_menu_action(menu, label, slot) actions.append(action) btn.setPopupMode(QtGui.QToolButton.MenuButtonPopup) btn.setDefaultA...
232,453
Find packages that are plugins of the given package. Args: package_name (str): Name of the package. paths (list of str): Paths to search for packages, defaults to `config.packages_path`. Returns: list of str: The packages that are plugins of the given package.
def get_plugins(package_name, paths=None): pkg = get_latest_package(package_name, paths=paths, error=True) if not pkg.has_plugins: return [] it = iter_package_families(paths) package_names = set(x.name for x in it) bar = ProgressBar("Searching", len(package_names)) plugin_pkgs = [...
232,479
Search for resources. Args: resources_request (str): Resource to search, glob-style patterns are supported. If None, returns all matching resource types. Returns: 2-tuple: - str: resource type (family, package, variant); - List of `Resour...
def search(self, resources_request=None): # Find matching package families name_pattern, version_range = self._parse_request(resources_request) family_names = set( x.name for x in iter_package_families(paths=self.package_paths) if fnmatch.fnmatch(x.name, name_p...
232,482
Print formatted search results. Args: search_results (list of `ResourceSearchResult`): Search to format.
def print_search_results(self, search_results, buf=sys.stdout): formatted_lines = self.format_search_results(search_results) pr = Printer(buf) for txt, style in formatted_lines: pr(txt, style)
232,485
Format search results. Args: search_results (list of `ResourceSearchResult`): Search to format. Returns: List of 2-tuple: Text and color to print in.
def format_search_results(self, search_results): formatted_lines = [] for search_result in search_results: lines = self._format_search_result(search_result) formatted_lines.extend(lines) return formatted_lines
232,486
Create a memcached client. Args: servers (str or list of str): Server URI(s), eg '127.0.0.1:11211'. debug (bool): If True, quasi human readable keys are used. This helps debugging - run 'memcached -vv' in the foreground to see the keys being get/set/store...
def __init__(self, servers, debug=False): self.servers = [servers] if isinstance(servers, basestring) else servers self.key_hasher = self._debug_key_hash if debug else self._key_hash self._client = None self.debug = debug self.current = ''
232,544
Drop existing entries from the cache. Args: hard (bool): If True, all current entries are flushed from the server(s), which affects all users. If False, only the local process is affected.
def flush(self, hard=False): if not self.servers: return if hard: self.client.flush_all() self.reset_stats() else: from uuid import uuid4 tag = uuid4().hex if self.debug: tag = "flushed" + tag ...
232,550
Create a reorderer. Args: order_dict (dict of (str, `PackageOrder`): Orderers to apply to each package family. default_order (`PackageOrder`): Orderer to apply to any packages not specified in `order_dict`.
def __init__(self, order_dict, default_order=None): self.order_dict = order_dict.copy() self.default_order = default_order
232,588
Create a reorderer. Args: timestamp (int): Epoch time of timestamp. Packages before this time are preferred. rank (int): If non-zero, allow version changes at this rank or above past the timestamp.
def __init__(self, timestamp, rank=0): self.timestamp = timestamp self.rank = rank
232,594
Find an executable. Args: name (str): Program name. check_syspaths (bool): If True, check the standard system paths as well, if program was not found on current $PATH. Returns: str: Full filepath of executable.
def find_executable(cls, name, check_syspaths=False): exe = which(name) if not exe and check_syspaths: paths = cls.get_syspaths() env = os.environ.copy() env["PATH"] = os.pathsep.join(paths) exe = which(name, env=env) if not exe: ...
232,626
Create a package variant. Args: variant (`Variant`): Package variant. building (bool): True if a build is occurring.
def __init__(self, variant, building): self.variant = variant self.building = building
232,657
Get a list of variants that intersect with the given range. Args: range_ (`VersionRange`): Package version range. Returns: List of `_PackageEntry` objects.
def get_intersection(self, range_): result = [] for entry in self.entries: package, value = entry if value is None: continue # package was blocked by package filters if package.version not in range_: continue i...
232,665
Get a list of variants from the cache. Args: package_name (str): Name of package. range_ (`VersionRange`): Package version range. Returns: `_PackageVariantSlice` object.
def get_variant_slice(self, package_name, range_): variant_list = self.variant_lists.get(package_name) if variant_list is None: variant_list = _PackageVariantList(package_name, self.solver) self.variant_lists[package_name] = variant_list entries = variant_list....
232,681
Get packages involved in a failure. Args: failure_index: See `failure_reason`. Returns: A list of Requirement objects.
def failure_packages(self, failure_index=None): phase, _ = self._get_failed_phase(failure_index) fr = phase.failure_reason return fr.involved_requirements() if fr else None
232,709
Returns a graph showing a solve failure. Args: failure_index: See `failure_reason` Returns: A pygraph.digraph object.
def get_fail_graph(self, failure_index=None): phase, _ = self._get_failed_phase(failure_index) return phase.get_graph()
232,711
Create a filesystem package repository. Args: location (str): Path containing the package repository.
def __init__(self, location, resource_pool): super(FileSystemPackageRepository, self).__init__(location, resource_pool) global _settings _settings = config.plugins.package_repository.filesystem self.register_resource(FileSystemPackageFamilyResource) self.register_resou...
232,746
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
def make_path_writable(path): from rez.config import config try: orig_mode = os.stat(path).st_mode new_mode = orig_mode if config.make_package_temporarily_writable and \ not os.access(path, os.W_OK): new_mode = orig_mode | stat.S_IWUSR # make w...
232,764
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.
def get_existing_path(path, topmost_path=None): prev_path = None if topmost_path: topmost_path = os.path.normpath(topmost_path) while True: if os.path.exists(path): return path path = os.path.dirname(path) if path == prev_path: return None ...
232,765
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.
def check_version(version, range_=None): if range_ and version not in range_: raise RezBindError("found version %s is not within range %s" % (str(version), str(range_)))
232,808
Find an executable. Args: name: Name of the program, eg 'python'. filepath: Path to executable, a search is performed if None. Returns: Path to the executable if found, otherwise an error is raised.
def find_exe(name, filepath=None): if filepath: if not os.path.exists(filepath): open(filepath) # raise IOError elif not os.path.isfile(filepath): raise RezBindError("not a file: %s" % filepath) else: filepath = which(name) if not filepath: ...
232,809
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 version. version_rank: Cap the version to this many tokens. Returns: ...
def extract_version(exepath, version_arg, word_index=-1, version_rank=3): if isinstance(version_arg, basestring): version_arg = [version_arg] args = [exepath] + version_arg stdout, stderr, returncode = _run_command(args) if returncode: raise RezBindError("failed to execute %s: %s\n...
232,810
Create a VersionedObject directly from an object name and version. Args: name: Object name string. version: Version object.
def construct(cls, name, version=None): other = VersionedObject(None) other.name_ = name other.version_ = Version() if version is None else version return other
232,820
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.
def construct(cls, name, range=None): other = Requirement(None) other.name_ = name other.range_ = VersionRange() if range is None else range return other
232,824
Create a RequirementList. Args: requirements: List of Requirement objects.
def __init__(self, requirements): self.requirements_ = [] self.conflict_ = None self.requirements_dict = {} self.names_ = set() self.conflict_names_ = set() for req in requirements: existing_req = self.requirements_dict.get(req.name) if ...
232,829
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: Graph in dot format.
def write_dot(g): lines = ["digraph g {"] def attrs_txt(items): if items: txt = ", ".join(('%s="%s"' % (k, str(v).strip('"'))) for k, v in items) return '[' + txt + ']' else: return '' for node in g.nodes(): atxt ...
232,834
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.
def prune_graph(graph_str, package_name): # find nodes of interest g = read_dot(graph_str) nodes = set() for node, attrs in g.node_attr.iteritems(): attr = [x for x in attrs if x[0] == "label"] if attr: label = attr[0][1] try: req_str = _requ...
232,835
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. Returns: String representing format that was written, such as 'png'.
def save_graph(graph_str, dest_file, fmt=None, image_ratio=None): g = pydot.graph_from_dot_data(graph_str) # determine the dest format if fmt is None: fmt = os.path.splitext(dest_file)[1].lower().strip('.') or "png" if hasattr(g, "write_" + fmt): write_fn = getattr(g, "write_" + fm...
232,836
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: True means the peer will start sending or...
def _x_flow_ok(self, active): args = AMQPWriter() args.write_bit(active) self._send_method((20, 21), args)
232,901
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 settings Configur...
def _x_open(self): if self.is_open: return args = AMQPWriter() args.write_shortstr('') # out_of_band: deprecated self._send_method((20, 10), args) return self.wait(allowed_methods=[ (20, 11), # Channel.open_ok ])
232,902
Return the installation path for a package (where its payload goes). Args: path (str): Package repository path.
def get_package_install_path(self, path): from rez.package_repository import package_repository_manager pkg_repo = package_repository_manager.get_repository(path) return pkg_repo.get_package_payload_path( package_name=self.package.name, package_version=self.pac...
232,931
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.
def find_bind_module(name, verbose=False): bindnames = get_bind_modules(verbose=verbose) bindfile = bindnames.get(name) if bindfile: return bindfile if not verbose: return None # suggest close matches fuzzy_matches = get_close_pkgs(name, bindnames.keys()) if fuzzy_ma...
232,973
Create a release hook. Args: source_path: Path containing source that was released.
def __init__(self, source_path): self.source_path = source_path self.package = get_developer_package(source_path) self.type_settings = self.package.config.plugins.release_hook self.settings = self.type_settings.get(self.name())
232,991
Recursively convert dict and UserDict types. Note that `d` is unchanged. Args: to_class (type): Dict-like type to convert values to, usually UserDict subclass, or dict. from_class (type): Dict-like type to convert values from. If a tuple, multiple types are converted. ...
def convert_dicts(d, to_class=AttrDictWrapper, from_class=dict): d_ = to_class() for key, value in d.iteritems(): if isinstance(value, from_class): d_[key] = convert_dicts(value, to_class=to_class, from_class=from_class) else: d_[k...
233,059
Create a package repository. Args: location (str): A string specifying the location of the repository. This could be a filesystem path, or a database uri, etc. resource_pool (`ResourcePool`): The pool used to manage package resources.
def __init__(self, location, resource_pool): self.location = location self.pool = resource_pool
233,083
Get a resource. Attempts to get and return a cached version of the resource if available, otherwise a new resource object is created and returned. Args: resource_key (`str`): Name of the type of `Resources` to find variables: data to identify / store on the resource ...
def get_resource(self, resource_key, **variables): handle = self.make_resource_handle(resource_key, **variables) return self.get_resource_from_handle(handle, verify_repo=False)
233,087
Get a resource. Args: resource_handle (`ResourceHandle`): Handle of the resource. Returns: `PackageRepositoryResource` instance.
def get_resource_from_handle(self, resource_handle, verify_repo=True): if verify_repo: # we could fix the handle at this point, but handles should # always be made from repo.make_resource_handle... for now, # at least, error to catch any "incorrect" construction of ...
233,088
Get a package repository. Args: path (str): Entry from the 'packages_path' config setting. This may simply be a path (which is managed by the 'filesystem' package repository plugin), or a string in the form "type@location", where 'type' identifies the...
def get_repository(self, path): # normalise parts = path.split('@', 1) if len(parts) == 1: parts = ("filesystem", parts[0]) repo_type, location = parts if repo_type == "filesystem": # choice of abspath here vs realpath is deliberate. Realpath giv...
233,090
Get a resource. Args: resource_handle (`ResourceHandle`): Handle of the resource. Returns: `PackageRepositoryResource` instance.
def get_resource_from_handle(self, resource_handle): repo_type = resource_handle.get("repository_type") location = resource_handle.get("location") if not (repo_type and location): raise ValueError("PackageRepositoryManager requires " "resource_ha...
233,093
Get a context. Args: name (str): Name to store the context under. Returns: `ResolvedContext` object.
def context(self, name): data = self._context(name) context = data.get("context") if context: return context assert self.load_path context_path = os.path.join(self.load_path, "contexts", "%s.rxt" % name) context = ResolvedContext.load(context_path) ...
233,287
Add a context to the suite. Args: name (str): Name to store the context under. context (ResolvedContext): Context to add.
def add_context(self, name, context, prefix_char=None): if name in self.contexts: raise SuiteError("Context already in suite: %r" % name) if not context.success: raise SuiteError("Context is not resolved: %r" % name) self.contexts[name] = dict(name=name, ...
233,288
Remove a context from the suite. Args: name (str): Name of the context to remove.
def remove_context(self, name): self._context(name) del self.contexts[name] self._flush_tools()
233,290
Set a context's prefix. This will be applied to all wrappers for the tools in this context. For example, a tool called 'foo' would appear as '<prefix>foo' in the suite's bin path. Args: name (str): Name of the context to prefix. prefix (str): Prefix to apply to ...
def set_context_prefix(self, name, prefix): data = self._context(name) data["prefix"] = prefix self._flush_tools()
233,291
Set a context's suffix. This will be applied to all wrappers for the tools in this context. For example, a tool called 'foo' would appear as 'foo<suffix>' in the suite's bin path. Args: name (str): Name of the context to suffix. suffix (str): Suffix to apply to ...
def set_context_suffix(self, name, suffix): data = self._context(name) data["suffix"] = suffix self._flush_tools()
233,292
Hide a tool so that it is not exposed in the suite. Args: context_name (str): Context containing the tool. tool_name (str): Name of tool to hide.
def hide_tool(self, context_name, tool_name): data = self._context(context_name) hidden_tools = data["hidden_tools"] if tool_name not in hidden_tools: self._validate_tool(context_name, tool_name) hidden_tools.add(tool_name) self._flush_tools()
233,294
Unhide a tool so that it may be exposed in a suite. Note that unhiding a tool doesn't guarantee it can be seen - a tool of the same name from a different context may be overriding it. Args: context_name (str): Context containing the tool. tool_name (str): Name of tool t...
def unhide_tool(self, context_name, tool_name): data = self._context(context_name) hidden_tools = data["hidden_tools"] if tool_name in hidden_tools: hidden_tools.remove(tool_name) self._flush_tools()
233,295
Register an alias for a specific tool. Note that a tool alias takes precedence over a context prefix/suffix. Args: context_name (str): Context containing the tool. tool_name (str): Name of tool to alias. tool_alias (str): Alias to give the tool.
def alias_tool(self, context_name, tool_name, tool_alias): data = self._context(context_name) aliases = data["tool_aliases"] if tool_name in aliases: raise SuiteError("Tool %r in context %r is already aliased to %r" % (tool_name, context_name, al...
233,296
Deregister an alias for a specific tool. Args: context_name (str): Context containing the tool. tool_name (str): Name of tool to unalias.
def unalias_tool(self, context_name, tool_name): data = self._context(context_name) aliases = data["tool_aliases"] if tool_name in aliases: del aliases[tool_name] self._flush_tools()
233,297
Given a visible tool alias, return the full path to the executable. Args: tool_alias (str): Tool alias to search for. Returns: (str): Filepath of executable, or None if the tool is not in the suite. May also return None because this suite has not been saved ...
def get_tool_filepath(self, tool_alias): tools_dict = self.get_tools() if tool_alias in tools_dict: if self.tools_path is None: return None else: return os.path.join(self.tools_path, tool_alias) else: return None
233,298
Given a visible tool alias, return the name of the context it belongs to. Args: tool_alias (str): Tool alias to search for. Returns: (str): Name of the context that exposes a visible instance of this tool alias, or None if the alias is not available.
def get_tool_context(self, tool_alias): tools_dict = self.get_tools() data = tools_dict.get(tool_alias) if data: return data["context_name"] return None
233,299
Save the suite to disk. Args: path (str): Path to save the suite to. If a suite is already saved at `path`, then it will be overwritten. Otherwise, if `path` exists, an error is raised.
def save(self, path, verbose=False): path = os.path.realpath(path) if os.path.exists(path): if self.load_path and self.load_path == path: if verbose: print "saving over previous suite..." for context_name in self.context_names: ...
233,303
Print table of tools available in the suite. Args: context_name (str): If provided, only print the tools from this context.
def print_tools(self, buf=sys.stdout, verbose=False, context_name=None): def _get_row(entry): context_name_ = entry["context_name"] tool_alias = entry["tool_alias"] tool_name = entry["tool_name"] properties = [] col = None variant...
233,308
Run a pip command. Args: command_args (list of str): Args to pip. Returns: `subprocess.Popen`: Pip process.
def run_pip_command(command_args, pip_version=None, python_version=None): pip_exe, context = find_pip(pip_version, python_version) command = [pip_exe] + list(command_args) if context is None: return popen(command) else: return context.execute_shell(command=command, block=False)
233,321
Create a context containing the specific pip and python. Args: pip_version (str or `Version`): Version of pip to use, or latest if None. python_version (str or `Version`): Python version to use, or latest if None. Returns: `ResolvedContext`: Context containing pip and pytho...
def create_context(pip_version=None, python_version=None): # determine pip pkg to use for install, and python variants to install on if pip_version: pip_req = "pip-%s" % str(pip_version) else: pip_req = "pip" if python_version: ver = Version(str(python_version)) maj...
233,323
Get packages in the request. Args: include_implicit (bool): If True, implicit packages are appended to the result. Returns: List of `PackageRequest` objects.
def requested_packages(self, include_implicit=False): if include_implicit: return self._package_requests + self.implicit_packages else: return self._package_requests
233,399
Get the resolve graph. Args: as_dot: If True, get the graph as a dot-language string. Otherwise, a pygraph.digraph object is returned. Returns: A string or `pygraph.digraph` object, or None if there is no graph associated with the resolve.
def graph(self, as_dot=False): if not self.has_graph: return None if not as_dot: if self.graph_ is None: # reads either dot format or our compact format self.graph_ = read_graph_from_string(self.graph_string) return self.graph...
233,404
Print the difference between the resolve of two contexts. Args: other (`ResolvedContext`): Context to compare to. heading: One of: - None: Do not display a heading; - True: Display the filename of each context as a heading, if both conte...
def print_resolve_diff(self, other, heading=None): d = self.get_resolve_diff(other) if not d: return rows = [] if heading is True and self.load_path and other.load_path: a = os.path.basename(self.load_path) b = os.path.basename(other.load_pat...
233,412
Get a data key value for each resolved package. Args: key (str): String key of property, eg 'tools'. request_only (bool): If True, only return the key from resolved packages that were also present in the request. Returns: Dict of {pkg-name: (variant,...
def get_key(self, key, request_only=False): values = {} requested_names = [x.name for x in self._package_requests if not x.conflict] for pkg in self.resolved_packages: if (not request_only) or (pkg.name in requested_names): value =...
233,417
Get the variant(s) that provide the named tool. If there are more than one variants, the tool is in conflict, and Rez does not know which variant's tool is actually exposed. Args: tool_name(str): Name of the tool to search for. Returns: Set of `Variant` objects...
def get_tool_variants(self, tool_name): variants = set() tools_dict = self.get_tools(request_only=False) for variant, tools in tools_dict.itervalues(): if tool_name in tools: variants.add(variant) return variants
233,418
Returns tools of the same name provided by more than one package. Args: request_only: If True, only return the key from resolved packages that were also present in the request. Returns: Dict of {tool-name: set([Variant])}.
def get_conflicting_tools(self, request_only=False): from collections import defaultdict tool_sets = defaultdict(set) tools_dict = self.get_tools(request_only=request_only) for variant, tools in tools_dict.itervalues(): for tool in tools: tool_sets[t...
233,419
Get the shell code resulting from intepreting this context. Args: shell (str): Shell type, for eg 'bash'. If None, the current shell type is used. parent_environ (dict): Environment to interpret the context within, defaults to os.environ if None. ...
def get_shell_code(self, shell=None, parent_environ=None, style=OutputStyle.file): executor = self._create_executor(interpreter=create_shell(shell), parent_environ=parent_environ) if self.load_path and os.path.isfile(self.load_path): executo...
233,420
Get the list of rex.Action objects resulting from interpreting this context. This is provided mainly for testing purposes. Args: parent_environ Environment to interpret the context within, defaults to os.environ if None. Returns: A list of rex.Action sub...
def get_actions(self, parent_environ=None): interp = Python(target_environ={}, passive=True) executor = self._create_executor(interp, parent_environ) self._execute(executor) return executor.actions
233,421
Apply the context to the current python session. Note that this updates os.environ and possibly sys.path, if `parent_environ` is not provided. Args: parent_environ: Environment to interpret the context within, defaults to os.environ if None.
def apply(self, parent_environ=None): interpreter = Python(target_environ=os.environ) executor = self._create_executor(interpreter, parent_environ) self._execute(executor) interpreter.apply_environ()
233,422