rez.utils.sourcecode

rez.utils.sourcecode.early() Callable[[CallabeT], CallabeT]

Used by functions in package.py to harden to the return value at build time.

The term ‘early’ refers to the fact these package attribute are evaluated early, ie at build time and before a package is installed.

rez.utils.sourcecode.late() Callable[[CallabeT], CallabeT]

Used by functions in package.py that are evaluated lazily.

The term ‘late’ refers to the fact these package attributes are evaluated late, ie when the attribute is queried for the first time.

If you want to implement a package.py attribute as a function, you MUST use this decorator - otherwise it is understood that you want your attribute to be a function, not the return value of that function.

rez.utils.sourcecode.include(module_name: str, *module_names: str) Callable[[CallabeT], CallabeT]

Used by functions in package.py to have access to named modules.

See the ‘package_definition_python_path’ config setting for more info.

exception rez.utils.sourcecode.SourceCodeError

Bases: Exception

__init__(msg: str, short_msg: str) None
classmethod __new__(*args, **kwargs)
add_note(object, /)

Exception.add_note(note) – add a note to the exception

args
with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception rez.utils.sourcecode.SourceCodeCompileError

Bases: SourceCodeError

__init__(msg: str, short_msg: str) None
classmethod __new__(*args, **kwargs)
add_note(object, /)

Exception.add_note(note) – add a note to the exception

args
with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception rez.utils.sourcecode.SourceCodeExecError

Bases: SourceCodeError

__init__(msg: str, short_msg: str) None
classmethod __new__(*args, **kwargs)
add_note(object, /)

Exception.add_note(note) – add a note to the exception

args
with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class rez.utils.sourcecode.SourceCode

Bases: Generic[T]

Wrapper for python source code.

This object is aware of the decorators defined in this sourcefile (such as ‘include’) and deals with them appropriately.

__init__(source: str | None = None, func: Callable[[], T] | None = None, filepath: str | None = None, eval_as_function: bool = True) None
package: PackageBaseResourceWrapper | None
funcname: str | None
decorators: list[dict]
copy() SourceCode[T]
includes() set | None
late_binding() bool
evaluated_code() str
property sourcename: str
compiled() CodeType
set_package(package: PackageBaseResourceWrapper) None
exec_(globals_={}) T
to_text(funcname: str) str
class rez.utils.sourcecode.IncludeModuleManager

Bases: object

Manages a cache of modules imported via @include’ decorator.

include_modules_subpath = '.rez/include'
__init__() None
load_module(name: str, package: PackageBaseResourceWrapper) ModuleType | None