Public API#

rezbuild_utils.extract_zip(zip_path: Path, remove_zip=True)

Exract the given zip archive content in the directory it is in.

Parameters:
  • zip_path – path to an existing zip file on the filesystem.

  • remove_zip – True to delete the zip once extracted

Returns:

root directory the extracted file can be found at

Warning

preserved for backward compatibility

rezbuild_utils.move_directory_content(src_directory: Path, target_directory: Path, exists_ok: bool = False, recursive: bool = True)

Move (NOT a copy) all the files and directories in the source to the target.

Handle move between different disk roots.

Parameters:
  • src_directory – filesystem path to an existing directory

  • target_directory – filesystem path to an existing directory

  • exists_ok – True to ignore if the target file already exists, else will raise en error.

  • recursive – True to also process all subdirectory recursively to not miss any files.

Warning

preserved for backward compatibility

rezbuild_utils.download_file(url: str, target_file: Path, use_cache: bool = False, step_callback: Callable[[int, int, int], object] | None = None, user_agent: str = 'Mozilla/5.0')

Download a single file from the web at the given url and display download progress in terminal.

You can cache the result when you know that you may call this function multiple time for the same url.

Tip to download Google Drive files:

Extract the ID from whatever url you got and replace it in the following: https://drive.usercontent.google.com/download?id=YOURID&export=download&authuser=0&confirm=t

Parameters:
  • url – url to download from, ensure it’s a file.

  • target_file – filesytem path of the file to download

  • use_cache – True to use the cached downloaded file. Will create it the first time.

  • step_callback – function called everytime the download progress one step. Arguments for the function are (block_number, block_size, total_size)

  • user_agent – change the User-Agent header to fake the browser used for the connection

Warning

preserved for backward compatibility

class rezbuild_utils.BuildPackageVersion#

An object to manipulate the version attribute following Knots conventions.

It assumes a package with a traditional semver versioning is being built.

Knots specificities:

  • The extra-patch is an additional “sub-patch” token for rez versioning of vendor packages.

property extra_patch: str#
property full_version: str#
property major: str#
property minor: str#
property patch: str#
property vendor_version: str#
rezbuild_utils.clear_build_dir()#

Remove the content of the build installation directory.

rezbuild_utils.copy_and_install_zip(zip_path: Path, dir_name: str | None, show_progress: bool = True, use_cache: bool = True) Path#

Copy the given zip to the build directory and extract it to the given directory name.

A progress bar can be displayed for the copy operation (and not the extraction).

Parameters:
  • zip_path – filesystem path to an existing .zip file

  • dir_name – name of the directory to extract the zip content in. If None just extracts at the root of the build dir.

  • show_progress – True to show a progress bar in the console.

  • use_cache – True to cache the source zip locally. This might reduce build time when the zip is stored on slow network drives and you need to trigger the build multiple times in a short period.

Returns:

the path of the directory that contain the extracted zip content filesystem path to an existing directory.

rezbuild_utils.copy_build_files(files: List[Path], target_directory: list[str] | None = None)#

Copy individual file/directories from the source build directory to the build install path.

Each path in file is copied individually so hierachy are not preserved.

Examples

The following:

(file=["./python/myModule.py"], sub_directories=None)

correspond to:

{REZ_BUILD_SOURCE_PATH}/python/myModule.py > {REZ_BUILD_INSTALL_PATH}/myModule.py

The following:

(file=["./python/myModule.py"], sub_directories=["src", "demo"])

correspond to:

{REZ_BUILD_SOURCE_PATH}/python/myModule.py > {REZ_BUILD_INSTALL_PATH}/src/demo/myModule.py
Parameters:
  • files – list of absolute paths or paths relative to the build source directory, to copy. can be files or directory

  • target_directory – destination directory to copy the file to relative to the build directory. Expressed as list of directory names combined to a single path where the root is the left-most name in the list.

rezbuild_utils.copytree_to_build(src_dir: Path, show_progress: bool = True)#

Recursively copy the src_dir to the rez build directory.

Parameters:
  • src_dir – filesystem path to an existing directory

  • show_progress – True to display a progress bar in the console.

rezbuild_utils.download_and_install_build(url: str, install_dir_name: str, extract_if_zip: bool = True, use_cache: bool = False) Path#

Download the given url

Can only be called during rez build.

Parameters:
  • url – url to download from, ensure it’s a file.

  • install_dir_name – name of the directory to put the extracted file in.

  • extract_if_zip – if True automatically extract the file if it is a .zip

  • use_cache – True to use the cached downloaded file. Will create it the first time.

Returns:

directory path where the files have been installed.

rezbuild_utils.install_pip_package(pip_package: str, python_version: str, target_dir: Path, pip_args: List[str] | None = None)#

Install the given pip package AND its dependencies at the given location.

Example structure of target_dir with pip_package=PySide2:

target_dir/
    PySide2/
    PySide2-5.15.2.1.dist-info/
    shiboken2/
    shiboken2-5.15.2.1.dist-info/
Parameters:
  • pip_package – pip name of the package and its version. specified like packageName==version.

  • python_version – version to use for python. can be a shortened variant like 3.9.

  • target_dir – path to a non-existing directory.

  • pip_args – additional argument directly passed to pip

rezbuild_utils.preserve_build_attributes()#

Dirty hack to avoid package creation to remove build attributes.

Use at your own risk.

Example:

with preserve_build_attributes(), make_package("python", ".") as package:
    package.version = "0.1.0"
    package.build_command = "python {root}/build.py"
    # ...
rezbuild_utils.set_installed_path_read_only() list[Path]#

Set recursively all path in the rez build install dir to read-only (including directories).

Returns:

list of path that have been set to read-only