rez.suite

class rez.suite.Suite[source]

Bases: object

A collection of contexts.

A suite is a collection of contexts. A suite stores its contexts in a single directory, and creates wrapper scripts for each tool in each context, which it stores into a single bin directory. When a tool is invoked, it executes the actual tool in its associated context. When you add a suite’s bin directory to PATH, you have access to all these tools, which will automatically run in correctly configured environments.

Tool clashes can occur when a tool of the same name is present in more than one context. When a context is added to a suite, or prefixed/suffixed, that context’s tools override tools from other contexts.

There are several ways to avoid tool name clashes: - Hide a tool. This removes it from the suite even if it does not clash; - Prefix/suffix a context. When you do this, all the tools in the context

have the prefix/suffix applied;

  • Explicitly alias a tool using the alias_tool method. This takes precedence over context prefix/suffixing.

activation_shell_code(shell=None)[source]

Get shell code that should be run to activate this suite.

add_context(name, context, prefix_char=None)[source]

Add a context to the suite.

Parameters
  • name (str) – Name to store the context under.

  • context (ResolvedContext) – Context to add.

alias_tool(context_name, tool_name, tool_alias)[source]

Register an alias for a specific tool.

Note that a tool alias takes precedence over a context prefix/suffix.

Parameters
  • context_name (str) – Context containing the tool.

  • tool_name (str) – Name of tool to alias.

  • tool_alias (str) – Alias to give the tool.

bump_context(name)[source]

Causes the context’s tools to take priority over all others.

context(name)[source]

Get a context.

Parameters

name (str) – Name to store the context under.

Returns

ResolvedContext object.

property context_names

Get the names of the contexts in the suite.

Reurns:

List of strings.

find_contexts(in_request=None, in_resolve=None)[source]

Find contexts in the suite based on search criteria.

Parameters
  • in_request (str) – Match contexts that contain the given package in their request.

  • in_resolve (str or Requirement) – Match contexts that contain the given package in their resolve. You can also supply a conflict requirement - ‘!foo’ will match any contexts whos resolve does not contain any version of package ‘foo’.

Returns

List of context names that match the search criteria.

classmethod from_dict(d)[source]
get_alias_conflicts(tool_alias)[source]

Get a list of conflicts on the given tool alias.

Parameters

tool_alias (str) – Alias to check for conflicts.

Returns: None if the alias has no conflicts, or a list of dicts, where

each dict contains: - tool_name (str): The original, non-aliased name of the tool; - tool_alias (str): Aliased tool name (same as key); - context_name (str): Name of the context containing the tool; - variant (Variant): Variant providing the tool.

get_conflicting_aliases()[source]

Get a list of tool aliases that have one or more conflicts.

Returns

List of strings.

get_hidden_tools()[source]

Get the tools hidden in this suite.

Hidden tools are those that have been explicitly hidden via hide_tool.

Returns

  • tool_name (str): The original, non-aliased name of the tool;

  • tool_alias (str): Aliased tool name (same as key);

  • context_name (str): Name of the context containing the tool;

  • variant (Variant): Variant providing the tool.

Return type

A list of dicts, where each dict contains

get_tool_context(tool_alias)[source]

Given a visible tool alias, return the name of the context it belongs to.

Parameters

tool_alias (str) – Tool alias to search for.

Returns

Name of the context that exposes a visible instance of this tool alias, or None if the alias is not available.

Return type

(str)

get_tool_filepath(tool_alias)[source]

Given a visible tool alias, return the full path to the executable.

Parameters

tool_alias (str) – Tool alias to search for.

Returns

Filepath of executable, or None if the tool is not in the

suite. May also return None because this suite has not been saved to disk, so a filepath hasn’t yet been established.

Return type

(str)

get_tools()[source]

Get the tools exposed by this suite.

Returns

  • tool_name (str): The original, non-aliased name of the tool;

  • tool_alias (str): Aliased tool name (same as key);

  • context_name (str): Name of the context containing the tool;

  • variant (Variant or set): Variant providing the tool. If the tool is in conflict within the context (more than one package has a tool of the same name), this will be a set of Variants.

Return type

A dict, keyed by aliased tool name, with dict entries

hide_tool(context_name, tool_name)[source]

Hide a tool so that it is not exposed in the suite.

Parameters
  • context_name (str) – Context containing the tool.

  • tool_name (str) – Name of tool to hide.

classmethod load(path)[source]
classmethod load_visible_suites(paths=None)[source]

Get a list of suites whos bin paths are visible on $PATH.

Returns

List of Suite objects.

print_info(buf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, verbose=False)[source]

Prints a message summarising the contents of the suite.

print_tools(buf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>, verbose=False, context_name=None)[source]

Print table of tools available in the suite.

Parameters

context_name (str) – If provided, only print the tools from this context.

remove_context(name)[source]

Remove a context from the suite.

Parameters

name (str) – Name of the context to remove.

remove_context_prefix(name)[source]

Remove a context’s prefix.

Parameters

name (str) – Name of the context to de-prefix.

remove_context_suffix(name)[source]

Remove a context’s suffix.

Parameters

name (str) – Name of the context to de-suffix.

save(path, verbose=False)[source]

Save the suite to disk.

Parameters

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.

set_context_prefix(name, prefix)[source]

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.

Parameters
  • name (str) – Name of the context to prefix.

  • prefix (str) – Prefix to apply to tools.

set_context_suffix(name, suffix)[source]

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.

Parameters
  • name (str) – Name of the context to suffix.

  • suffix (str) – Suffix to apply to tools.

to_dict()[source]
tools_path

Simple property caching descriptor.

Example

>>> class Foo(object):
>>>     @cached_property
>>>     def bah(self):
>>>         print('bah')
>>>         return 1
>>>
>>> f = Foo()
>>> f.bah
bah
1
>>> f.bah
1
unalias_tool(context_name, tool_name)[source]

Deregister an alias for a specific tool.

Parameters
  • context_name (str) – Context containing the tool.

  • tool_name (str) – Name of tool to unalias.

unhide_tool(context_name, tool_name)[source]

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.

Parameters
  • context_name (str) – Context containing the tool.

  • tool_name (str) – Name of tool to unhide.

validate()[source]

Validate the suite.

classmethod visible_suite_paths(paths=None)[source]

Get a list of paths to suites that are visible on $PATH.

Returns

List of str.