Rez Package Manager

repository·main·Indexed 22 days ago

https://github.com/academysoftwarefoundation/rez

A cross-platform package manager that uses a central repository to dynamically construct lightweight, high-performance software environments. It is designed for complex workflows where multiple versions of software components must coexist. Key tools include rez-env for creating resolved shells, rez-build for building and installing packages, and rez-bind for binding existing system software. Packages are defined via package.py files and support custom Python build scripts or CMake.

Tokens
67.2K
Snippets
223
Records
320
Agent score
78%

What's inside Rez

  1. What is a Context Bundle

    main

    A context bundle is a relocatable, standalone directory containing a Rez context (an .rxt file) and a local package repository.

    Unlike a standard context that uses absolute references to shared package repositories on disk, a bundle stores all required packages within its own ./packages directory. This makes bundles ideal for:

    • Copying to remote servers.
    • Including in containers.
    • Ensuring no external dependencies on shared network storage.
  2. What is Rez?

    main

    Rez is a cross-platform package manager designed to create standalone environments configured for a specific set of packages.

    Unlike traditional package managers that install package files directly into an environment, Rez uses a central repository where all package versions are stored. When you create an environment, Rez dynamically constructs it by resolving dependencies and referencing the existing packages in the central repository.

    Key Benefits:

    • Lightweight Environments: Environments are not heavy copies of files; they are configurations that reference a central store.
    • Speed: Because environments are constructed via references rather than file copies, they can be created in seconds, even when containing hundreds of packages.
    • Versatility: Rez supports various software types, including compiled binaries, Python packages, applications, and libraries.
  3. What is a Rez Suite?

    main
    A suite is a collection of tools provided to users that may execute in different environments. Conceptually, a suite is a directory containing a set of contexts (baked environment files, e.g., .rxt files) and wrapper scripts that run tools within those specific contexts. This allows users to run commands like maya or nuke from the command line without needing to manually manage the underlying environment requirements.
  4. What is a Rez context?

    main

    A context is a lightweight JSON-formatted store (with the .rxt extension) that represents a resolved environment. Instead of storing actual package files, a context stores handles that allow Rez to fetch package definitions and contents.

    A context includes:

    • The initial list of requested packages.
    • The resolve (the specific list of variants chosen during resolution).
    • A visual graph of the resolve.

    When you run rez-env, Rez creates a temporary context file on disk. You can find the path to this file in the $REZ_RXT_FILE environment variable.

    $ rez-env foo bah
    
    > $ echo $REZ_RXT_FILE
    /tmp/rez_context_0tMS4U/context.rxt
  5. What is a Rez package?

    main

    A package is a self-contained, versioned piece of software. Every package must include a definition file, typically named package.py, located at the root of the package installation directory. This file describes the package's metadata, dependencies, and how it modifies the environment.

    Common attributes in package.py include:

    • name: The package name.
    • version: The version string.
    • requires: A list of package dependencies (e.g., "python-2.6").
    • tools: A list of tools provided by the package.
    • commands(): A Python function that defines environment modifications.
    name = "foo"
    version = "1.0.0"
    description = "Something that does foo-like things."
    requires = [
       "python-2.6",
       "utils-1.1+<2"
    ]
    tools = [
       "fooify"
    ]
    
    def commands():
        env.PYTHONPATH.append("{root}/python")
        env.PATH.append("{root}/bin")
  6. Expose tools from a package in a suite

    main

    The tools available in a suite context are determined by the tools attribute in the package's package.py file.

    Important Note on Dependencies: Only packages listed in the context requests (that are not weak or conflict requests) have their tools exposed. Packages pulled in as dependencies do not. If you need to control the version of a package without exposing its command-line tools, add it as a weak reference to the request list.

    You can explicitly hide tools using the rez-suite --hide argument during suite creation.

    # in maya package.py
    tools = [
       "maya",
       "mayapy",
       "fcheck"
    ]
  7. Use the Rez Python API with caution

    main

    The Rez Python API is available for programmatic interaction with Rez, but users should be aware of the following constraints:

    • No Compatibility Guarantees: There are no guaranteed compatibility guarantees between different versions of Rez. Code written for one version may break in another.
    • Configuration Limitations: The Python API does not support rereading configuration files or switching to new configuration files once the API has been initially imported. If your workflow requires dynamic configuration reloading, use the Rez CLI instead.
  8. Append and prepend to path-like environment variables

    main

    You can modify path-like variables using .append() or .prepend().

    Behavioral Nuance:

    • Overwrite on first use: The very first append/prepend operation on a variable will overwrite the existing value rather than appending to it. This prevents pollution from the pre-existing system environment (e.g., preventing a system PYTHONPATH from interfering with a Rez-managed one).
    • Special Case: PATH: The PATH variable is handled differently. To prevent losing essential system utilities (like ls or cd), Rez automatically appends the system paths back to PATH after all commands are interpreted.

    Best Practice: Use POSIX-style forward slashes (/) for filepaths. Rez will automatically normalize them for the target platform (e.g., Windows) if the variable is recognized as a path variable (by default, any variable ending in PATH).

    # Use forward slashes even on Windows
    env.PATH.append("{root}/bin")
  9. How Rez dependency resolving works

    main

    Rez uses a solving algorithm that converts a request (a list of package requests) into a resolve (a final list of specific package versions).

    Key behaviors of the solver:

    1. Goal: It aims to provide the latest possible version of each package.
    2. Conflict Avoidance: It avoids version conflicts (ensuring no two different versions of the same package are present simultaneously).
    3. Constraint Satisfaction: If the latest version of a package causes a conflict with another dependency, the solver will automatically try the next latest version to find a valid solution.
    4. Failure: If no combination of versions can satisfy the request without conflict, the resolve fails and Rez reports the conflict.
  10. Requirements expansion for build-time and runtime dependencies

    main
    Requirements expansion is a mechanism to handle complex dependency relationships where a package might have different requirements at build-time versus runtime. For example, a package might require a specific version of a library (like Boost) to compile, but at runtime, it might only require a more general or different set of dependencies. Implementing requirements expansion allows users to specify additional requirements specifically for the build phase that are not necessarily part of the final resolved runtime environment.
  11. Cross-compiling and managing implicits with rez-build

    main
    When performing cross-compilation (e.g., building for Windows on a Linux host), the default behavior of rez-env can cause conflicts due to 'implicits'. To support cross-compilation effectively, users often need a way to drop these implicits during the build process. While the current discussion identifies this as a need, the conceptual goal is to provide a flag for rez-build (similar to what rez-env supports) that allows removing implicits and adding specific constraints to a cross-compiler build environment.