rez.package_py_utils#

This sourcefile is intended to be imported in package.py files, in functions including:

  • the special ‘preprocess’ function;

  • early bound functions that use the @early decorator.

rez.package_py_utils.expand_requirement(request, paths=None)#

Expands a requirement string like ‘python-2.*’, ‘foo-2.*+<*’, etc.

Wildcards are expanded to the latest version that matches. There is also a special wildcard ‘**’ that will expand to the full version, but it cannot be used in combination with ‘*’.

Wildcards MUST placehold a whole version token, not partial - while ‘foo-2.*’ is valid, ‘foo-2.v*’ is not.

Wildcards MUST appear at the end of version numbers - while ‘foo-1.*.*’ is valid, ‘foo-1.*.0’ is not.

It is possible that an expansion will result in an invalid request string (such as ‘foo-2+<2’). The appropriate exception will be raised if this happens.

Examples

>>> print(expand_requirement('python-2.*'))
python-2.7
>>> print(expand_requirement('python==2.**'))
python==2.7.12
>>> print(expand_requirement('python<**'))
python<3.0.5
Parameters:
  • request (str) – Request to expand, eg ‘python-2.*’

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

Returns:

Expanded request string.

Return type:

str

rez.package_py_utils.expand_requires(*requests)#

Create an expanded requirements list.

Example

>>> print(expand_requires(["boost-1.*.*"]))
["boost-1.55.0"]
>>> print(expand_requires(["boost-1.*"]))
["boost-1.55"]
Parameters:

requests (list of str) – Requirements to expand. Each value may have trailing wildcards.

Returns:

Expanded requirements.

Return type:

List of str

rez.package_py_utils.exec_command(attr, cmd)#

Runs a subproc to calculate a package attribute.

rez.package_py_utils.exec_python(attr, src, executable='python')#

Runs a python subproc to calculate a package attribute.

Parameters:
  • attr (str) – Name of package attribute being created.

  • src (list of str) – Python code to execute, will be converted into semicolon-delimited single line of code.

Returns:

Output of python process.

Return type:

str

rez.package_py_utils.find_site_python(module_name, paths=None)#

Find the rez native python package that contains the given module.

This function is used by python ‘native’ rez installers to find the native rez python package that represents the python installation that this module is installed into.

Note

This function is dependent on the behavior found in the python ‘_native’ package found in the ‘rez-recipes’ repository. Specifically, it expects to find a python package with a ‘_site_paths’ list attribute listing the site directories associated with the python installation.

Parameters:
  • module_name (str) – Target python module.

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

Returns:

Native python package containing the named module.

Return type:

Package