def run_from_package( package, tests, shell="", build_requires=False, private_build_requires=False, ): """Create an environment from a Rez package + tests. Args: package (:class:`rez.packages.Package`): Some Rez package to include in the resolve. tests (iter[str]): The user's raw CLI test input. These could be real test names, like "my_foo_unittest", or a glob expression, like "my_*_unittest". shell (str, optional): If provided, this shell will be used for rez-env instead of the user's current shell. Default: "". build_requires (bool, optional): If added, the package `build_requires` will be included in the resolve. private_build_requires (bool, optional): If added, the package `private_build_requires` will be included in the resolve. """ def _to_request(package): try: return "{package.name}=={package.version}".format(package=package) except AttributeError: return str(package) requirements = set(_expand_requirements(package, tests)) package_request = _to_request(package) full_request = {package_request} full_request.update(requirements) if build_requires: full_request.update( [_to_request(requirement) for requirement in package.build_requires or []] ) if private_build_requires: full_request.update( [ _to_request(requirement) for requirement in package.private_build_requires or [] ] ) _LOGGER.debug('Making environment for "%s" request.', full_request) with _patch_main(sorted(full_request), shell=shell): _main.run("env")
def run_rez_benchmark(): check_production_install() # Special case - we have to override config settings here, before rez is # loaded. TODO this would be cleaner if we had an Application object, see # https://github.com/nerdvegas/rez/issues/1043 # # /start import json settings = { "memcached_uri": [], "package_filter": [], "package_orderers": [], "allow_unversioned_packages": False, "resource_caching_maxsize": -1, "cache_packages_path": None } for setting, value in settings.items(): os.environ.pop("REZ_" + setting.upper(), None) os.environ["REZ_" + setting.upper() + "_JSON"] = json.dumps(value) # /end from rez.cli._main import run return run("benchmark")
def rez_cli(): from rez.cli._main import run from rez.cli._entry_points import check_production_install check_production_install() try: return run("sweet") except KeyError: pass # for rez version that doesn't have Command type plugin return standalone_cli()
def run_from_request(package_request, tests, shell=""): """Convert a Rez package + tests. See Also: https://github.com/nerdvegas/rez/wiki/Basic-Concepts#package-requests Args: package_request (str): The user's raw CLI input. It can be any Rez package request. tests (iter[str]): The user's raw CLI test input. These could be real test names, like "my_foo_unittest", or a glob expression, like "my_*_unittest". shell (str, optional): If provided, this shell will be used for rez-env instead of the user's current shell. Default: "". Raises: :class:`.NoValidPackageFound`: If `package_request` doesn't match a valid Rez package' """ package = packages.get_latest_package_from_string(package_request) if not package: raise exceptions.NoValidPackageFound( 'Request "{package_request}" doesn\'t match a Rez package.'.format( package_request=package_request ) ) _LOGGER.debug('Found package "%s".', package) requirements = _expand_requirements(package, tests) with _patch_main([package_request] + sorted(requirements), shell=shell): _main.run("env")
def run_rez_pkg_ignore(): check_production_install() from rez.cli._main import run return run("pkg-ignore")
def run_rez_yaml2py(): check_production_install() from rez.cli._main import run return run("yaml2py")
def run_rez_selftest(): check_production_install() from rez.cli._main import run return run("selftest")
def run_rez_memcache(): check_production_install() from rez.cli._main import run return run("memcache")
def get_cli_output(args): """Invoke the named command-line rez command, with the given string command line args Note that it does this by calling rez.cli._main.run within the same python process, for efficiency; if for some reason this is not sufficient encapsulation / etc, you can use subprocess to invoke the rez as a separate process Returns ------- stdout : basestring the captured output to sys.stdout exitcode : int the returncode from the command """ import sys from StringIO import StringIO command = args[0] other_args = list(args[1:]) if command.startswith('rez-'): command = command[4:] exitcode = None # first swap sys.argv... old_argv = sys.argv new_argv = ['rez-%s' % command] + other_args sys.argv = new_argv try: # then redirect stdout using os.dup2 # we can't just ye' ol sys.stdout swap trick, because some places may # still be holding onto references to the "real" sys.stdout - ie, if # a function has a kwarg default (as in rez.status.Status.print_info) # So, instead we swap at a file-descriptor level... potentially less # portable, but has been tested to work on linux, osx, and windows... with tempfile.TemporaryFile(bufsize=0, prefix='rez_cliout') as tf: new_fileno = tf.fileno() old_fileno = sys.stdout.fileno() old_fileno_dupe = os.dup(old_fileno) # make sure we flush before any switches... sys.stdout.flush() # ...then redirect stdout to our temp file... os.dup2(new_fileno, old_fileno) try: try: # and finally invoke the "command-line" rez-COMMAND from rez.cli._main import run run(command) except SystemExit as e: exitcode = e.args[0] finally: # restore stdout sys.stdout.flush() tf.flush() os.dup2(old_fileno_dupe, old_fileno) # ok, now read the output we redirected to the file... tf.seek(0, os.SEEK_SET) output = tf.read() finally: # restore argv... sys.argv = old_argv return output, exitcode
def run_rez_complete(): check_production_install() from rez.cli._main import run return run("complete")
def run_rez_context(): check_production_install() from rez.cli._main import run return run("context")
def rez_gui_source(): from rez.cli._main import run run("gui")
def run_bez(): # TODO: Deprecate. Use custom build commands instead. # https://github.com/nerdvegas/rez/wiki/Building-Packages#custom-build-commands check_production_install() from rez.cli._bez import run run()
def run_rez(): check_production_install() from rez.cli._main import run return run()
def run_rezolve(): # alias for osx, where rez is a different tool # https://www.unix.com/man-page/osx/1/REZ/ check_production_install() from rez.cli._main import run return run()
def run_rez_depends(): check_production_install() from rez.cli._main import run return run("depends")
def run_rez_fwd(): check_production_install() from rez.cli._main import run return run("forward")
def run_rez_interpret(): check_production_install() from rez.cli._main import run return run("interpret")