def command(opts, parser, extra_arg_groups=None): from rez.exceptions import BuildContextResolveError from rez.build_process_ import create_build_process from rez.build_system import create_build_system from rez.serialise import FileFormat import sys # load package working_dir = os.getcwd() package = get_current_developer_package() if opts.view_pre: package.print_info(format_=FileFormat.py, skip_attributes=["preprocess"]) sys.exit(0) # create build system build_args, child_build_args = get_build_args(opts, parser, extra_arg_groups) buildsys = create_build_system(working_dir, package=package, buildsys_type=opts.buildsys, opts=opts, write_build_scripts=opts.scripts, verbose=True, build_args=build_args, child_build_args=child_build_args) # create and execute build process builder = create_build_process(opts.process, working_dir, build_system=buildsys, verbose=True) package = builder.package config = package.config release_path = config.release_packages_path local_path = config.local_packages_path install_path = opts.prefix if opts.release: opts.install = True install_path = release_path try: print("Building into: '%s'" % (install_path or local_path)) builder.build(install_path=install_path, clean=opts.clean, install=opts.install, variants=opts.variants) except BuildContextResolveError as e: print(str(e), file=sys.stderr) if opts.fail_graph: if e.context.graph: from rez.utils.graph_utils import view_graph g = e.context.graph(as_dot=True) view_graph(g) else: print("the failed resolve context did not generate a graph.", file=sys.stderr) sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.exceptions import BuildContextResolveError from rez.packages_ import get_developer_package from rez.build_process_ import create_build_process from rez.build_system import create_build_system from rez.serialise import FileFormat import sys # load package working_dir = os.getcwd() package = get_developer_package(working_dir) if opts.view_pre: package.print_info(format_=FileFormat.py, skip_attributes=["preprocess"]) sys.exit(0) # create build system build_args, child_build_args = get_build_args(opts, parser, extra_arg_groups) buildsys_type = opts.buildsys if ("buildsys" in opts) else None buildsys = create_build_system(working_dir, package=package, buildsys_type=buildsys_type, opts=opts, write_build_scripts=opts.scripts, verbose=True, build_args=build_args, child_build_args=child_build_args) # create and execute build process builder = create_build_process(opts.process, working_dir, package=package, build_system=buildsys, verbose=True) try: builder.build(install_path=opts.prefix, clean=opts.clean, install=opts.install, variants=opts.variants) except BuildContextResolveError as e: print >> sys.stderr, str(e) if opts.fail_graph: if e.context.graph: from rez.utils.graph_utils import view_graph g = e.context.graph(as_dot=True) view_graph(g) else: print >> sys.stderr, \ "the failed resolve context did not generate a graph." sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.exceptions import BuildContextResolveError from rez.build_process_ import create_build_process from rez.build_system import create_build_system import sys working_dir = os.getcwd() # create build system build_args, child_build_args = get_build_args(opts, parser, extra_arg_groups) buildsys_type = opts.buildsys if ("buildsys" in opts) else None buildsys = create_build_system(working_dir, buildsys_type=buildsys_type, opts=opts, write_build_scripts=opts.scripts, verbose=True, build_args=build_args, child_build_args=child_build_args) # create and execute build process builder = create_build_process(opts.process, working_dir, build_system=buildsys, verbose=True) try: builder.build(install_path=opts.prefix, clean=opts.clean, install=opts.install, variants=opts.variants) except BuildContextResolveError as e: print >> sys.stderr, str(e) if opts.fail_graph: if e.context.graph: from rez.utils.graph_utils import view_graph g = e.context.graph(as_dot=True) view_graph(g) else: print >> sys.stderr, \ "the failed resolve context did not generate a graph." sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.package_search import get_reverse_dependency_tree from rez.utils.graph_utils import save_graph, view_graph from rez.config import config from rez.vendor.pygraph.readwrite.dot import write as write_dot import os import os.path config.override("warn_none", True) config.override("show_progress", (not opts.quiet)) if opts.paths is None: pkg_paths = None else: pkg_paths = opts.paths.split(os.pathsep) pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x] pkgs_list, g = get_reverse_dependency_tree( package_name=opts.PKG, depth=opts.depth, paths=pkg_paths, build_requires=opts.build_requires, private_build_requires=opts.private_build_requires) if opts.graph or opts.print_graph or opts.write_graph: gstr = write_dot(g) if opts.print_graph: print(gstr) elif opts.write_graph: save_graph(gstr, dest_file=opts.write_graph) else: view_graph(gstr) return 0 for i, pkgs in enumerate(pkgs_list): if opts.quiet: toks = pkgs else: toks = ["#%d:" % i] + pkgs print(' '.join(toks))
def command(opts, parser, extra_arg_groups=None): from rez.package_search import get_reverse_dependency_tree from rez.utils.graph_utils import save_graph, view_graph from rez.config import config from rez.vendor.pygraph.readwrite.dot import write as write_dot import os import os.path config.override("warn_none", True) config.override("show_progress", (not opts.quiet)) if opts.paths is None: pkg_paths = None else: pkg_paths = opts.paths.split(os.pathsep) pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x] pkgs_list, g = get_reverse_dependency_tree( package_name=opts.PKG, depth=opts.depth, paths=pkg_paths, build_requires=opts.build_requires, private_build_requires=opts.private_build_requires) if opts.graph or opts.print_graph or opts.write_graph: gstr = write_dot(g) if opts.print_graph: print gstr elif opts.write_graph: save_graph(gstr, dest_file=opts.write_graph) else: view_graph(gstr) return 0 for i, pkgs in enumerate(pkgs_list): if opts.quiet: toks = pkgs else: toks = ["#%d:" % i] + pkgs print ' '.join(toks)
def command(opts, parser, extra_arg_groups=None): from rez.resolved_context import ResolvedContext from rez.resolver import ResolverStatus from rez.package_filter import PackageFilterList, Rule from rez.utils.formatting import get_epoch_time_from_str from rez.config import config import select import sys import os import os.path command = opts.command if extra_arg_groups: if opts.command: parser.error("argument --command: not allowed with arguments after '--'") command = extra_arg_groups[0] or None context = None request = opts.PKG t = get_epoch_time_from_str(opts.time) if opts.time else None if opts.isolated: config.inherit_parent_environment = False if opts.inherited: config.inherit_parent_environment = True 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 opts.self: from rez.utils._version import _rez_version request += ["bleeding_rez==%s" % _rez_version] request += ["python"] # Required by Rez if context is None: # 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) success = (context.status == ResolverStatus.solved) if not success: context.print_info(buf=sys.stderr) if opts.fail_graph: if context.graph: from rez.utils.graph_utils import view_graph g = context.graph(as_dot=True) view_graph(g) else: print("the failed resolve context did not generate a graph.", file=sys.stderr) if opts.output: if opts.output == '-': # print to stdout context.write_to_buffer(sys.stdout) else: context.save(opts.output) sys.exit(0 if success else 1) if not success: sys.exit(1) if opts.env: env = {} for pair in opts.env: key, value = pair.split("=") env[key.upper()] = value config.additional_environment = env # generally shells will behave as though the '-s' flag was not present when # no stdin is available. So here we replicate this behaviour. try: if opts.stdin and not select.select([sys.stdin], [], [], 0.0)[0]: opts.stdin = False except select.error: pass # because windows quiet = opts.quiet or bool(command) returncode, _, _ = context.execute_shell( shell=opts.shell, rcfile=opts.rcfile, norc=opts.norc, command=command, stdin=opts.stdin, quiet=quiet, start_new_session=opts.new_session, detached=opts.detached, pre_command=opts.pre_command, block=True) sys.exit(returncode)
def command(opts, parser, extra_arg_groups=None): from rez.resolved_context import ResolvedContext from rez.resolver import ResolverStatus from rez.package_filter import PackageFilterList, Rule from rez.utils.formatting import get_epoch_time_from_str from rez.config import config import select import sys import os import os.path command = opts.command if extra_arg_groups: if opts.command: parser.error("argument --command: not allowed with arguments after '--'") command = extra_arg_groups[0] or None 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 >> sys.stderr, "cannot patch: not in a context" 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: # 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) success = (context.status == ResolverStatus.solved) if not success: context.print_info(buf=sys.stderr) if opts.fail_graph: if context.graph: from rez.utils.graph_utils import view_graph g = context.graph(as_dot=True) view_graph(g) else: print >> sys.stderr, \ "the failed resolve context did not generate a graph." if opts.output: if opts.output == '-': # print to stdout context.write_to_buffer(sys.stdout) else: context.save(opts.output) sys.exit(0 if success else 1) if not success: sys.exit(1) # generally shells will behave as though the '-s' flag was not present when # no stdin is available. So here we replicate this behaviour. try: if opts.stdin and not select.select([sys.stdin], [], [], 0.0)[0]: opts.stdin = False except select.error: pass # because windows quiet = opts.quiet or bool(command) returncode, _, _ = context.execute_shell( shell=opts.shell, rcfile=opts.rcfile, norc=opts.norc, command=command, stdin=opts.stdin, quiet=quiet, start_new_session=opts.new_session, detached=opts.detached, pre_command=opts.pre_command, block=True) sys.exit(returncode)
def build(path, install_path=''): '''Build the given Rez package directory into a Rez package. This command is basically a copy/paste of the `rez.cli.build.command` function and, essentially is the same as running ```bash cd path rez-build --install ``` Args: path (str): The path to a package definition folder (which must contain a package.py file). install_path (str, optional): The absolute path to a directory on-disk which will be used to build `path`. If no path is given then the user's local_package_path is used instead (which is what Rez defaults to). Default: "". ''' # import subprocess # command = 'cd "{path}" && rez-build --install'.format(path=path) # if install_path: # command += ' --prefix {install_path}'.format(install_path=install_path) # process = subprocess.Popen( # [command], # stdout=subprocess.PIPE, # stderr=subprocess.PIPE, # shell=True # ) # (_, stderr) = process.communicate() # if stderr: # raise ValueError(stderr) package = packages_.get_developer_package(path) build_system_ = build_system.create_build_system( path, package=package, buildsys_type=None, write_build_scripts=False, verbose=True, build_args=[], child_build_args=[], ) # create and execute build process builder = build_process_.create_build_process( 'local', path, package=package, build_system=build_system_, verbose=True, ) try: builder.build( install_path=install_path or None, clean=False, install=True, variants=None, ) except exceptions.BuildContextResolveError as err: LOGGER.exception('Path "%s" failed to build.', path) if err.context.graph: graph = err.context.graph(as_dot=True) view_graph(graph) else: LOGGER.error( 'the failed resolve context did not generate a graph.') raise
def command(opts, parser, extra_arg_groups=None): from rez.resolved_context import ResolvedContext from rez.resolver import ResolverStatus from rez.package_filter import PackageFilterList, Rule from rez.utils.formatting import get_epoch_time_from_str from rez.config import config import select import sys import os import os.path command = opts.command if extra_arg_groups: if opts.command: parser.error("argument --command: not allowed with arguments after '--'") command = extra_arg_groups[0] or None 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: parser.error("Cannot use --input and provide PKG(s) at the same time") context = ResolvedContext.load(opts.input) if context.status != ResolverStatus.solved: print >> sys.stderr, "cannot rez-env into a failed context" sys.exit(1) if opts.patch: # TODO: patching is lagging behind in options, and needs to be updated # anyway. if context is None: from rez.status import status context = status.context if context is None: print >> sys.stderr, "cannot patch: not in a context" sys.exit(1) request = context.get_patched_request(request, strict=opts.strict, rank=opts.patch_rank) context = None if context is None: # 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) success = (context.status == ResolverStatus.solved) if not success: context.print_info(buf=sys.stderr) if opts.fail_graph: if context.graph: from rez.utils.graph_utils import view_graph g = context.graph(as_dot=True) view_graph(g) else: print >> sys.stderr, \ "the failed resolve context did not generate a graph." if opts.output: if opts.output == '-': # print to stdout context.write_to_buffer(sys.stdout) else: context.save(opts.output) sys.exit(0 if success else 1) if not success: sys.exit(1) # generally shells will behave as though the '-s' flag was not present when # no stdin is available. So here we replicate this behaviour. if opts.stdin and not select.select([sys.stdin], [], [], 0.0)[0]: opts.stdin = False quiet = opts.quiet or bool(command) returncode, _, _ = context.execute_shell( shell=opts.shell, rcfile=opts.rcfile, norc=opts.norc, command=command, stdin=opts.stdin, quiet=quiet, start_new_session=opts.new_session, detached=opts.detached, pre_command=opts.pre_command, block=True) sys.exit(returncode)