rez.package_repository#

rez.package_repository.get_package_repository_types()#

Returns the available package repository implementations.

rez.package_repository.create_memory_package_repository(repository_data)#

Create a standalone in-memory package repository from the data given.

See rezplugins/package_repository/memory.py for more details.

Parameters:

repository_data (dict) – Package repository data.

Returns:

PackageRepository object.

class rez.package_repository.PackageRepositoryGlobalStats#

Bases: _local

Gathers stats across package repositories.

__init__()#
package_loading()#

Use this around code in your package repository that is loading a package, for example from file or cache.

__new__(**kwargs)#
class rez.package_repository.PackageRepository#

Bases: object

Base class for package repositories implemented in the package_repository plugin type.

Note that, even though a package repository does determine where package payloads should go, it is not responsible for creating or copying these payloads.

remove = <object object>#
classmethod name()#

Return the name of the package repository type.

__init__(location, resource_pool)#

Create a package repository.

Parameters:
  • 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.

register_resource(resource_class)#

Register a resource with the repository.

Your derived repository class should call this method in its __init__ to register all the resource types associated with that plugin.

clear_caches()#

Clear any cached resources in the pool.

uid()#

Returns a unique identifier for this repository.

This must be a persistent identifier, for example a filepath, or database address + index, and so on.

Returns:

Value that uniquely identifies this repository.

Return type:

tuple[str, str]

is_empty()#

Determine if the repository contains any packages.

Returns:

True if there are no packages, False if there are at least one.

get_package_family(name)#

Get a package family.

Parameters:

name (str) – Package name.

Returns:

PackageFamilyResource, or None if not found.

iter_package_families()#

Iterate over the package families in the repository, in no particular order.

Returns:

PackageFamilyResource iterator.

iter_packages(package_family_resource)#

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

Parameters:

package_family_resource (PackageFamilyResource) – Parent family.

Returns:

PackageResource iterator.

iter_variants(package_resource)#

Iterate over the variants within the given package.

Parameters:

package_resource (PackageResource) – Parent package.

Returns:

VariantResource iterator.

get_package(name, version)#

Get a package.

Parameters:
  • name (str) – Package name.

  • version (Version) – Package version.

Returns:

Matching package, or None if not found.

Return type:

PackageResource or None

get_package_from_uri(uri)#

Get a package given its URI.

Parameters:

uri (str) – Package URI

Returns:

PackageResource, or None if the package is not present in this package repository.

get_variant_from_uri(uri)#

Get a variant given its URI.

Parameters:

uri (str) – Variant URI

Returns:

VariantResource, or None if the variant is not present in this package repository.

ignore_package(pkg_name, pkg_version, allow_missing=False)#

Ignore the given package.

Ignoring a package makes it invisible to further resolves.

Parameters:
  • pkg_name (str) – Package name

  • pkg_version (Version) – Package version

  • allow_missing (bool) – if True, allow for ignoring a package that does not exist. This is useful when you want to copy a package to a repo and you don’t want it visible until the copy is completed.

Returns:

  • -1: Package not found

  • 0: Nothing was done, package already ignored

  • 1: Package was ignored

Return type:

int

unignore_package(pkg_name, pkg_version)#

Unignore the given package.

Parameters:
  • pkg_name (str) – Package name

  • pkg_version (Version) – Package version

Returns:

  • -1: Package not found

  • 0: Nothing was done, package already visible

  • 1: Package was unignored

Return type:

int

remove_package(pkg_name, pkg_version)#

Remove a package.

Note that this should work even if the specified package is currently ignored.

Parameters:
  • pkg_name (str) – Package name

  • pkg_version (Version) – Package version

Returns:

True if the package was removed, False if it wasn’t found.

Return type:

bool

remove_package_family(pkg_name, force=False)#

Remove an empty package family.

Parameters:
  • pkg_name (str) – Package name

  • force (bool) – If Trur, delete even if not empty.

Returns:

True if the family was removed, False if it wasn’t found.

Return type:

bool

remove_ignored_since(days, dry_run=False, verbose=False)#

Remove packages ignored for >= specified number of days.

Parameters:
  • days (int) – Remove packages ignored >= this many days

  • dry_run – Dry run mode

  • verbose (bool) – Verbose mode

Returns:

Number of packages removed. In dry-run mode, returns the number of packages that _would_ be removed.

Return type:

int

pre_variant_install(variant_resource)#

Called before a variant is installed.

If any directories are created on disk for the variant to install into, this is called before that happens.

Note that it is the responsibility of the BuildProcess to call this function at the appropriate time.

on_variant_install_cancelled(variant_resource)#

Called when a variant installation is cancelled.

This is called after pre_variant_install, but before install_variant, which is not expected to be called.

Variant install cancellation usually happens for one of two reasons - either the variant installation failed (ie a build error occurred), or one or more of the package tests failed, aborting the installation.

Note that it is the responsibility of the BuildProcess to call this function at the appropriate time.

install_variant(variant_resource, dry_run=False, overrides=None)#

Install a variant into this repository.

Use this function to install a variant from some other package repository into this one.

Parameters:
  • variant_resource (VariantResource) – Variant to install.

  • 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. To remove attributes, set values to PackageRepository.remove.

Returns:

VariantResource object, which is the newly created variant in this repository. If dry_run is True, None may be returned.

get_equivalent_variant(variant_resource)#

Find a variant in this repository that is equivalent to that given.

A variant is equivalent to another if it belongs to a package of the same name and version, and it has the same definition (ie package requirements).

Note that even though the implementation is trivial, this function is provided since using install_variant to find an existing variant is nonintuitive.

Parameters:

variant_resource (VariantResource) – Variant to install.

Returns:

VariantResource object, or None if the variant was not found.

get_parent_package_family(package_resource)#

Get the parent package family of the given package.

Parameters:

package_resource (PackageResource) – Package.

Returns:

PackageFamilyResource.

get_parent_package(variant_resource)#

Get the parent package of the given variant.

Parameters:

variant_resource (VariantResource) – Variant.

Returns:

PackageResource.

get_variant_state_handle(variant_resource)#

Get a value that indicates the state of the variant.

This is used for resolve caching. For example, in the ‘filesystem’ repository type, the ‘state’ is the last modified date of the file associated with the variant (perhaps a package.py). If the state of any variant has changed from a cached resolve - eg, if a file has been modified - the cached resolve is discarded.

This may not be applicable to your repository type, leave as-is if so.

Returns:

A hashable value.

get_last_release_time(package_family_resource)#

Get the last time a package was added to the given family.

This information is used to cache resolves via memcached. It can be left not implemented, but resolve caching is a substantial optimisation that you will be missing out on.

Returns:

Epoch time at which a package was changed/added/removed from

the given package family. Zero signifies an unknown last package update time.

Return type:

int

make_resource_handle(resource_key, **variables)#

Create a ResourceHandle

Nearly all ResourceHandle creation should go through here, because it gives the various resource classes a chance to normalize / standardize the resource handles, to improve caching / comparison / etc.

get_resource(resource_key, **variables)#

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.

Parameters:
  • resource_key (str) – Name of the type of Resources to find

  • variables – data to identify / store on the resource

Returns:

PackageRepositoryResource instance.

get_resource_from_handle(resource_handle, verify_repo=True)#

Get a resource.

Parameters:

resource_handle (ResourceHandle) – Handle of the resource.

Returns:

PackageRepositoryResource instance.

get_package_payload_path(package_name, package_version=None)#

Defines where a package’s payload should be installed to.

Parameters:
  • package_name (str) – Nmae of package.

  • package_version (str or Version) – Package version.

Returns:

Path where package’s payload should be installed to.

Return type:

str

class rez.package_repository.PackageRepositoryManager#

Bases: object

Package repository manager.

Manages retrieval of resources (packages and variants) from PackageRepository instances, and caches these resources in a resource pool.

__init__(resource_pool=None)#

Create a package repo manager.

Parameters:

resource_pool (ResourcePool) – Provide your own resource pool. If None, a default pool is created based on config settings.

get_repository(path)#

Get a package repository.

Parameters:

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 repository plugin type to use.

Returns:

PackageRepository instance.

are_same(path_1, path_2)#

Test that path_1 and path_2 refer to the same repository.

This is more reliable than testing that the strings match, since slightly different strings might refer to the same repository (consider small differences in a filesystem path for example, eg ‘//svr/foo’, ‘/svr/foo’).

Returns:

True if the paths refer to the same repository, False otherwise.

get_resource(resource_key, repository_type, location, **variables)#

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.

Parameters:
  • resource_key (str) – Name of the type of Resources to find

  • repository_type (str) – What sort of repository to look for the resource in

  • location (str) – location for the repository

  • variables – data to identify / store on the resource

Returns:

PackageRepositoryResource instance.

get_resource_from_handle(resource_handle)#

Get a resource.

Parameters:

resource_handle (ResourceHandle) – Handle of the resource.

Returns:

PackageRepositoryResource instance.

clear_caches()#

Clear all cached data.