How to use the rez.resolved_context.ResolvedContext function in rez

To help you get started, we’ve selected a few rez examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nerdvegas / rez / src / rezplugins / build_system / custom.py View on Github external
def _FWD__spawn_build_shell(working_dir, build_path, variant_index, install,
                            install_path=None):
    # This spawns a shell that the user can run the build command in directly
    context = ResolvedContext.load(os.path.join(build_path, "build.rxt"))
    package = get_developer_package(working_dir)
    variant = package.get_variant(variant_index)
    config.override("prompt", "BUILD>")

    callback = functools.partial(CustomBuildSystem._add_build_actions,
                                 context=context,
                                 package=package,
                                 variant=variant,
                                 build_type=BuildType.local,
                                 install=install,
                                 build_path=build_path,
                                 install_path=install_path)

    retcode, _, _ = context.execute_shell(block=True, cwd=build_path,
                                          post_actions_callback=callback)
    sys.exit(retcode)
github nerdvegas / rez / src / rez / cli / env.py View on Github external
context = None
    request = opts.PKG
    t = get_epoch_time_from_str(opts.time) if opts.time else None

    if opts.paths is None:
        pkg_paths = (config.nonlocal_packages_path
                     if opts.no_local else None)
    else:
        pkg_paths = opts.paths.split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    if opts.input:
        if opts.PKG and not opts.patch:
            parser.error("Cannot use --input and provide PKG(s), unless patching.")

        context = ResolvedContext.load(opts.input)

    if opts.patch:
        if context is None:
            from rez.status import status
            context = status.context
            if context is None:
                print("cannot patch: not in a context", file=sys.stderr)
                sys.exit(1)

        # modify the request in terms of the given patch request
        request = context.get_patched_request(request,
                                              strict=opts.strict,
                                              rank=opts.patch_rank)
        context = None

    if context is None:
github nerdvegas / rez / src / support / shotgun_toolkit / rez_app_launch.py View on Github external
use_rez = False
        if self.check_rez():
            from rez.resolved_context import ResolvedContext
            from rez.config import config

            # Define variables used to bootstrap tank from overwrite on first reference
            # PYTHONPATH is used by tk-maya
            # NUKE_PATH is used by tk-nuke
            # HIERO_PLUGIN_PATH is used by tk-nuke (nukestudio)
            # KATANA_RESOURCES is used by tk-katana
            parent_variables = ["PYTHONPATH", "HOUDINI_PATH", "NUKE_PATH",
                                "HIERO_PLUGIN_PATH", "KATANA_RESOURCES"]

            rez_packages = extra["rez_packages"]
            context = ResolvedContext(rez_packages)

            use_rez = True

        # Rez env callback to restore sgtk paths setup by the shotgun launcher
        # and the individual engines.
        def restore_sgtk_env(executor):
            """
            Restore the settings from the current tank environment setup
            that happened before rez was able to run.
            
            """
            for envvar in parent_variables:
                paths = os.environ.get(envvar, '').split(';')
                #TODO: Remove this when P:\code is removed from domain policy
                # P:\code is normally removed by rez, but since we have to
                # restore some of the env vars setup by tank, we need to
github nerdvegas / rez / src / rez / cli / context.py View on Github external
def command(opts, parser, extra_arg_groups=None):
    from rez.cli._util import print_items
    from rez.status import status
    from rez.utils.formatting import columnise, PackageRequest
    from rez.resolved_context import ResolvedContext
    from rez.utils.graph_utils import save_graph, view_graph, prune_graph
    from pprint import pformat

    rxt_file = opts.RXT if opts.RXT else status.context_file
    if not rxt_file:
        print("not in a resolved environment context.", file=sys.stderr)
        sys.exit(1)

    if rxt_file == '-':  # read from stdin
        rc = ResolvedContext.read_from_buffer(sys.stdin, 'STDIN')
    else:
        rc = ResolvedContext.load(rxt_file)

    def _graph():
        if rc.has_graph:
            return rc.graph(as_dot=True)
        else:
            print("The context does not contain a graph.", file=sys.stderr)
            sys.exit(1)

    parent_env = {} if opts.no_env else None

    if not opts.interpret:
        if opts.print_request:
            print_items(rc.requested_packages(False))
        elif opts.print_resolve:
github mikrosimage / OpenRenderManagement / src / octopus / worker / process.py View on Github external
from rez.resolver import ResolverStatus
    except ImportError as e:
        LOGGER.error("Unable to load rez package in a rez managed environment.")
        raise e

    try:
        if watcherPackages is None:
            LOGGER.warning("No package specified for this command, it might not find the runner for this command.")
            watcherPackagesList = []
        elif type(watcherPackages) in [str, unicode]:
            watcherPackagesList = watcherPackages.split()
        else:
            watcherPackagesList = watcherPackages

        clear_caches()
        context = ResolvedContext(watcherPackagesList)
        success = (context.status == ResolverStatus.solved)
        if not success:
            context.print_info(buf=sys.stderr)
            raise

        # normalize environment
        envN = os.environ.copy()
        for key in env:
            envN[str(key)] = str(env[key])

        proc = context.execute_shell(
            command=args,
            shell='bash',
            stdin=False,
            stdout=logfile,
            stderr=subprocess.STDOUT,
github nerdvegas / rez / src / rez / cli / env.py View on Github external
# create package filters
        if opts.no_filters:
            package_filter = PackageFilterList()
        else:
            package_filter = PackageFilterList.singleton.copy()

        for rule_str in (opts.exclude or []):
            rule = Rule.parse_rule(rule_str)
            package_filter.add_exclusion(rule)

        for rule_str in (opts.include or []):
            rule = Rule.parse_rule(rule_str)
            package_filter.add_inclusion(rule)

        # perform the resolve
        context = ResolvedContext(
            package_requests=request,
            timestamp=t,
            package_paths=pkg_paths,
            building=opts.build,
            package_filter=package_filter,
            add_implicit_packages=(not opts.no_implicit),
            verbosity=opts.verbose,
            max_fails=opts.max_fails,
            time_limit=opts.time_limit,
            caching=(not opts.no_cache),
            suppress_passive=opts.no_passive,
            print_stats=opts.stats,
            package_caching=(not opts.no_pkg_cache)
        )

    success = (context.status == ResolverStatus.solved)
github nerdvegas / rez / src / rez / pip.py View on Github external
python_package = "python-%s" % str(python_major_minor_ver)

    package_request.append(python_package)

    if pip_version:
        target = "pip"
        if pip_version == "latest":
            package_request.append("pip")
        else:
            package_request.append("pip-%s" % str(pip_version))

    print_info("Trying to use pip from %s package", target)

    try:
        context = ResolvedContext(package_request)
    except (PackageFamilyNotFoundError, PackageNotFoundError):
        print_debug("No rez package called %s found", target)
        return None, None, None

    py_exe = find_python_in_context(context)

    proc = context.execute_command(
        # -E and -s are used to isolate the environment as much as possible.
        # See python --help for more details. We absolutely don't want to get
        # pip from the user home.
        [py_exe, "-E", "-s", "-c", "import pip, sys; sys.stdout.write(pip.__version__)"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        text=True
    )
    out, err = proc.communicate()
github nerdvegas / rez / src / rez / env.py View on Github external
def get_context():
    """Returns the ResolvedContext associated with the current environment, or
    None if the environment is not Rez-configured.
    """
    global _context
    if _context is None:
        file = get_context_file()
        if file and os.path.exists(file):
            _context = ResolvedContext.load(file)
    return _context or None
github nerdvegas / rez / src / rezgui / models / ContextModel.py View on Github external
def resolve_context(self, verbosity=0, max_fails=-1, timestamp=None,
                        callback=None, buf=None, package_load_callback=None):
        """Update the current context by performing a re-resolve.

        The newly resolved context is only applied if it is a successful solve.

        Returns:
            `ResolvedContext` object, which may be a successful or failed solve.
        """
        package_filter = PackageFilterList.from_pod(self.package_filter)

        context = ResolvedContext(
            self.request,
            package_paths=self.packages_path,
            package_filter=package_filter,
            verbosity=verbosity,
            max_fails=max_fails,
            timestamp=timestamp,
            buf=buf,
            callback=callback,
            package_load_callback=package_load_callback,
            caching=self.caching)

        if context.success:
            if self._context and self._context.load_path:
                context.set_load_path(self._context.load_path)
            self._set_context(context)
            self._modified = True