rez.packages

class rez.packages.PackageRepositoryResourceWrapper

Bases: ResourceWrapper, StringFormatMixin

format_expand = 3
validated_data() dict
property repository: PackageRepository

The package repository this resource comes from.

Returns:

PackageRepository.

__init__(resource: Resource) None
property data: dict[str, Any] | None
format(s: str, pretty: bool | None = None, expand: StringFormatType | None = None) str

Format a string.

Parameters:
  • s (str) – String to format, eg “hello {name}”

  • pretty (bool) – If True, references to non-string attributes such as lists are converted to basic form, with characters such as brackets and parenthesis removed. If None, defaults to the object’s ‘format_pretty’ attribute.

  • expand (StringFormatType) – Expansion mode. If None, will default to the object’s ‘format_expand’ attribute.

Returns:

The formatting string.

format_pretty = True
property handle: ResourceHandle
keys = None
property resource: Resource
validate_data() None
class rez.packages.PackageFamily

Bases: PackageRepositoryResourceWrapper

A package family.

Note

Do not instantiate this class directly, instead use the function iter_package_families.

keys = {'name'}
__init__(resource: PackageFamilyResource) None
iter_packages() Iterator[Package]

Iterate over the packages within this family, in no particular order.

Returns:

Package iterator.

property data: dict[str, Any] | None
format(s: str, pretty: bool | None = None, expand: StringFormatType | None = None) str

Format a string.

Parameters:
  • s (str) – String to format, eg “hello {name}”

  • pretty (bool) – If True, references to non-string attributes such as lists are converted to basic form, with characters such as brackets and parenthesis removed. If None, defaults to the object’s ‘format_pretty’ attribute.

  • expand (StringFormatType) – Expansion mode. If None, will default to the object’s ‘format_expand’ attribute.

Returns:

The formatting string.

format_expand = 3
format_pretty = True
property handle: ResourceHandle
property name
property repository: PackageRepository

The package repository this resource comes from.

Returns:

PackageRepository.

property resource: Resource
validate_data() None
validated_data() dict
class rez.packages.PackageBaseResourceWrapper

Bases: PackageRepositoryResourceWrapper

Abstract base class for Package and Variant.

late_bind_schemas = {'build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'private_build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))])}
__init__(resource: PackageResource | VariantResource, context: ResolvedContext | None = None) None
set_context(context: ResolvedContext | None) None
arbitrary_keys() set[str]
property uri: str
property config: Config

Returns the config for this package.

Defaults to global config if this package did not provide a ‘config’ section.

is_local() bool

Returns True if the package is in the local package repository

print_info(buf: SupportsWrite | None = None, format_: FileFormat = FileFormat.yaml, skip_attributes: list[str] | None = None, include_release: bool = False) None

Print the contents of the package.

Parameters:
  • buf (IO) – 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, such as ‘timestamp’ and ‘changelog’

property data: dict[str, Any] | None
format(s: str, pretty: bool | None = None, expand: StringFormatType | None = None) str

Format a string.

Parameters:
  • s (str) – String to format, eg “hello {name}”

  • pretty (bool) – If True, references to non-string attributes such as lists are converted to basic form, with characters such as brackets and parenthesis removed. If None, defaults to the object’s ‘format_pretty’ attribute.

  • expand (StringFormatType) – Expansion mode. If None, will default to the object’s ‘format_expand’ attribute.

Returns:

The formatting string.

format_expand = 3
format_pretty = True
property handle: ResourceHandle
keys = None
property repository: PackageRepository

The package repository this resource comes from.

Returns:

PackageRepository.

property resource: Resource
validate_data() None
validated_data() dict
class rez.packages.Package

Bases: PackageBaseResourceWrapper

A package.

Warning

Do not instantiate this class directly, instead use the function iter_packages() or PackageFamily.iter_packages().

keys = {'authors', 'base', 'build_requires', 'cachable', 'changelog', 'commands', 'config', 'description', 'has_plugins', 'hashed_variants', 'help', 'name', 'plugin_for', 'post_commands', 'pre_build_commands', 'pre_commands', 'pre_test_commands', 'previous_revision', 'previous_version', 'private_build_requires', 'release_message', 'relocatable', 'requires', 'revision', 'tests', 'timestamp', 'tools', 'uuid', 'variants', 'vcs', 'version'}
is_package = True

Allows for a simple check like this.is_package in late-bound funcs, where this may be a package or variant.

is_variant = False

Allows for a simple check like this.is_variant in late-bound funcs, where this may be a package or variant.

__init__(resource: PackageResource, context: ResolvedContext | None = None) None
arbitrary_keys() set[str]

Get the arbitrary keys present in this package.

These are any keys not in the standard list (‘name’, ‘version’ etc).

Returns:

Arbitrary keys.

Return type:

set of str

qualified_name() str

Get the qualified name of the package.

Returns:

Name of the package with version, eg “maya-2016.1”.

Return type:

str

as_exact_requirement() str

Get the package, as an exact requirement string.

Returns:

Equivalent requirement string, eg “maya==2016.1”

parent() PackageFamily | None

Get the parent package family.

Returns:

PackageFamily.

num_variants() int
property is_relocatable: bool

True if the package and its payload is safe to copy.

property is_cachable: bool

True if the package and its payload is safe to cache locally.

iter_variants() Iterator[Variant]

Iterate over the variants within this package, in index order.

Returns:

Variant iterator.

get_variant(index: int | None = None) Variant | None

Get the variant with the associated index.

Returns:

Variant object, or None if no variant with the given index exists.

property authors
property base
property build_requires
property cachable
property changelog
property commands
property config: Config

Returns the config for this package.

Defaults to global config if this package did not provide a ‘config’ section.

property data: dict[str, Any] | None
property description
format(s: str, pretty: bool | None = None, expand: StringFormatType | None = None) str

Format a string.

Parameters:
  • s (str) – String to format, eg “hello {name}”

  • pretty (bool) – If True, references to non-string attributes such as lists are converted to basic form, with characters such as brackets and parenthesis removed. If None, defaults to the object’s ‘format_pretty’ attribute.

  • expand (StringFormatType) – Expansion mode. If None, will default to the object’s ‘format_expand’ attribute.

Returns:

The formatting string.

format_expand = 3
format_pretty = True
property handle: ResourceHandle
property has_plugins
property hashed_variants
property help
is_local() bool

Returns True if the package is in the local package repository

late_bind_schemas = {'build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'private_build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))])}
property name
property plugin_for
property post_commands
property pre_build_commands
property pre_commands
property pre_test_commands
property previous_revision
property previous_version
print_info(buf: SupportsWrite | None = None, format_: FileFormat = FileFormat.yaml, skip_attributes: list[str] | None = None, include_release: bool = False) None

Print the contents of the package.

Parameters:
  • buf (IO) – 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, such as ‘timestamp’ and ‘changelog’

property private_build_requires
property release_message
property relocatable
property repository: PackageRepository

The package repository this resource comes from.

Returns:

PackageRepository.

property requires
property resource: Resource
property revision
set_context(context: ResolvedContext | None) None
property tests
property timestamp
property tools
property uri: str
property uuid
validate_data() None
validated_data() dict
property variants
property vcs
property version
class rez.packages.Variant

Bases: PackageBaseResourceWrapper

A package variant.

Warning

Do not instantiate this class directly, instead use the function Package.iter_variants().

keys = {'authors', 'base', 'build_requires', 'cachable', 'changelog', 'commands', 'config', 'description', 'has_plugins', 'hashed_variants', 'help', 'index', 'name', 'plugin_for', 'post_commands', 'pre_build_commands', 'pre_commands', 'pre_test_commands', 'previous_revision', 'previous_version', 'private_build_requires', 'release_message', 'relocatable', 'requires', 'revision', 'root', 'subpath', 'tests', 'timestamp', 'tools', 'uuid', 'vcs', 'version'}
is_package = False

See Package.is_package.

is_variant = True

See Package.is_variant.

__init__(resource: VariantResource, context: ResolvedContext | None = None, parent: Package | None = None) None
arbitrary_keys() set[str]
qualified_package_name() str
qualified_name() str

Get the qualified name of the variant.

Returns:

Name of the variant with version and index, eg “maya-2016.1[1]”.

Return type:

str

parent() Package

Get the parent package.

Returns:

Package.

property variant_requires: list[Requirement]

Get the subset of requirements specific to this variant.

Returns:

List of Requirement objects.

property requires: list[Requirement]

Get variant requirements.

This is a concatenation of the package requirements and those of this specific variant.

Returns:

List of Requirement objects.

get_requires(build_requires: bool = False, private_build_requires: bool = False) list[Requirement]

Get the requirements of the variant.

Parameters:
  • build_requires (bool) – If True, include build requirements.

  • private_build_requires (bool) – If True, include private build requirements.

Returns:

List of Requirement objects.

install(path: str, dry_run: bool = False, overrides: dict[str, Any] | None = None) Variant | None

Install this variant into another package repository.

If the package already exists, this variant will be correctly merged into the package. If the variant already exists in this package, the existing variant is returned.

Parameters:
  • path (str) – Path to destination package repository.

  • dry_run (bool) – If True, do not actually install the variant. In this mode, a Variant instance is only returned if the equivalent variant already exists in this repository; otherwise, None is returned.

  • overrides (dict) – Use this to change or add attributes to the installed variant.

Returns:

Variant object - the (existing or newly created) variant in the specified repository. If dry_run is True, None may be returned.

property authors
property base
property build_requires
property cachable
property changelog
property commands
property config: Config

Returns the config for this package.

Defaults to global config if this package did not provide a ‘config’ section.

property data: dict[str, Any] | None
property description
format(s: str, pretty: bool | None = None, expand: StringFormatType | None = None) str

Format a string.

Parameters:
  • s (str) – String to format, eg “hello {name}”

  • pretty (bool) – If True, references to non-string attributes such as lists are converted to basic form, with characters such as brackets and parenthesis removed. If None, defaults to the object’s ‘format_pretty’ attribute.

  • expand (StringFormatType) – Expansion mode. If None, will default to the object’s ‘format_expand’ attribute.

Returns:

The formatting string.

format_expand = 3
format_pretty = True
property handle: ResourceHandle
property has_plugins
property hashed_variants
property help
property index
is_local() bool

Returns True if the package is in the local package repository

late_bind_schemas = {'build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'private_build_requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))]), 'requires': Schema([Or(<class 'rez.utils.formatting.PackageRequest'>, And(<class 'str'>, Use(<class 'rez.utils.formatting.PackageRequest'>)))])}
property name
property plugin_for
property post_commands
property pre_build_commands
property pre_commands
property pre_test_commands
property previous_revision
property previous_version
print_info(buf: SupportsWrite | None = None, format_: FileFormat = FileFormat.yaml, skip_attributes: list[str] | None = None, include_release: bool = False) None

Print the contents of the package.

Parameters:
  • buf (IO) – 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, such as ‘timestamp’ and ‘changelog’

property private_build_requires
property release_message
property relocatable
property repository: PackageRepository

The package repository this resource comes from.

Returns:

PackageRepository.

property resource: Resource
property revision
property root
set_context(context: ResolvedContext | None) None
property subpath
property tests
property timestamp
property tools
property uri: str
property uuid
validate_data() None
validated_data() dict
property vcs
property version
class rez.packages.PackageSearchPath

Bases: object

A list of package repositories.

For example, $REZ_PACKAGES_PATH refers to a list of repositories.

__init__(packages_path: list[str]) None

Create a package repository list.

Parameters:

packages_path (list of str) – List of package repositories.

iter_packages(name: str, range_: VersionRange | str | None = None) Iterator[Package]

See iter_packages.

Returns:

Package iterator.

rez.packages.iter_package_families(paths: list[str] | None = None) Iterator[PackageFamily]

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.

Parameters:

paths (Optional[list[str]]) – paths to search for package families, defaults to config.packages_path.

Returns:

PackageFamily iterator.

rez.packages.iter_packages(name: str, range_: VersionRange | str | None = None, paths: list[str] | None = None) Iterator[Package]

Iterate over Package instances, in no particular order.

Packages of the same name and version earlier in the search path take precedence - equivalent packages later in the paths are ignored. Packages are not returned in any specific order.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • range (VersionRange or str) – If provided, limits the versions returned to those in range_.

  • paths (Optional[list[str]]) – paths to search for packages, defaults to config.packages_path.

Returns:

Package iterator.

rez.packages.get_package(name: str, version: Version | str, paths: list[str] | None = None) Package | None

Get a package by searching a list of repositories.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • version (Version or str) – Version of the package, eg ‘1.0.0’

  • paths (Optional[list[str]]) – paths to search for package, defaults to config.packages_path.

Returns:

Package object, or None if the package was not found.

rez.packages.get_package_family_from_repository(name: str, path: str) PackageFamily | None

Get a package family from a repository.

Parameters:

name (str) – Name of the package, eg ‘maya’.

Returns:

PackageFamily object, or None if the family was not found.

rez.packages.get_package_from_repository(name: str, version: Version | str, path: str) Package | None

Get a package from a repository.

Parameters:
  • name (str) – Name of the package, eg ‘maya’.

  • version (Version or str) – Version of the package, eg ‘1.0.0’

Returns:

Package object, or None if the package was not found.

rez.packages.get_package_from_handle(package_handle: ResourceHandle | dict) Package

Create a package given its handle (or serialized dict equivalent)

Parameters:

package_handle (ResourceHandle or dict) – Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict

Returns:

Package.

rez.packages.get_package_from_string(txt: str, paths: list[str] | None = None) Package | None

Get a package given a string.

Parameters:
  • txt (str) – String such as ‘foo’, ‘bah-1.3’.

  • paths (Optional[list[str]]) – paths to search for package, defaults to config.packages_path.

Returns:

Package instance, or None if no package was found.

rez.packages.get_developer_package(path: str, format: FileFormat | None = None) DeveloperPackage

Create a developer package.

Parameters:
  • path (str) – Path to dir containing package definition file.

  • format (FileFormat) – Package definition file format, detected if None.

Returns:

DeveloperPackage.

rez.packages.create_package(name: str, data: dict, package_cls: type[PackageT]) PackageT
rez.packages.create_package(name: str, data: dict) Package

Create a package given package data.

Parameters:
  • name (str) – Package name.

  • data (dict) – Package data. Must conform to package_maker.package_schema.

Returns:

Package object.

rez.packages.get_variant(variant_handle: ResourceHandle | dict, context: ResolvedContext | None = None) Variant

Create a variant given its handle (or serialized dict equivalent)

Parameters:
  • variant_handle (ResourceHandle or dict) – Resource handle, or equivalent serialized dict representation from ResourceHandle.to_dict

  • context (ResolvedContext) – The context this variant is associated with, if any.

Returns:

Variant.

rez.packages.get_package_from_uri(uri: str, paths: list[str] | None = None) Package | None

Get a package given its URI.

Parameters:
  • uri (str) – Variant URI

  • paths (list of str) – paths to search for packages, defaults to config.packages_path. If None, attempts to find a package that may have come from any package repo.

Returns:

Package, or None if the package could not be found.

rez.packages.get_variant_from_uri(uri: str, paths: list[str] | None = None) Variant | None

Get a variant given its URI.

Parameters:
  • uri (str) – Variant URI

  • paths (list of str) – paths to search for variants, defaults to config.packages_path. If None, attempts to find a variant that may have come from any package repo.

Returns:

Variant, or None if the variant could not be found.

rez.packages.get_last_release_time(name: str, paths: list[str] | None = None) int

Returns the most recent time this package was released.

Note that releasing a variant into an already-released package is also considered a package release.

Parameters:
  • name (str) – Package family name.

  • paths (list of str) – paths to search for packages, defaults to config.packages_path.

Returns:

Epoch time of last package release, or zero if this cannot be determined.

Return type:

int

rez.packages.get_completions(prefix: str, paths: list[str] | None = None, family_only: bool = False) set[str]

Get autocompletion options given a prefix string.

Example

>>> get_completions("may")
set(["maya", "maya_utils"])
>>> get_completions("maya-")
set(["maya-2013.1", "maya-2015.0.sp1"])
Parameters:
  • prefix (str) – Prefix to match.

  • paths (list of str) – paths to search for packages, defaults to config.packages_path.

  • family_only (bool) – If True, only match package names, do not include version component.

Returns:

Set of strings, may be empty.

rez.packages.get_latest_package(name, range_=None, paths=None, error=False)

Get the latest package for a given package name.

Parameters:
  • name (str) – Package name.

  • range (VersionRange) – Version range to search within.

  • paths (Optional[list[str]]) – paths to search for package families, defaults to config.packages_path.

  • error (bool) – If True, raise an error if no package is found.

Returns:

Package object, or None if no package is found.

rez.packages.get_latest_package_from_string(txt: str, paths: list[str] | None = None, error: bool = False) Package | None

Get the latest package found within the given request string.

Parameters:
  • txt (str) – Request, eg ‘foo-1.2+’

  • paths (Optional[list[str]]) – paths to search for packages, defaults to config.packages_path.

  • error (bool) – If True, raise an error if no package is found.

Returns:

Package object, or None if no package is found.