Esempio n. 1
0
    def _setup_release(self):
       # start fresh
        system.clear_caches()
        if os.path.exists(self.install_root):
            shutil.rmtree(self.install_root)
        if os.path.exists(self.src_root):
            shutil.rmtree(self.src_root)
        shutil.copytree(self.src_path, self.src_root)

        self.packagefile = os.path.join(self.src_root, "package.yaml")
        with open(self.packagefile) as f:
            self.package_data = yaml.load(f.read())

        # create the build system
        self.buildsys = create_build_system(self.src_root, verbose=True)
        self.assertEqual(self.buildsys.name(), "bez")

        # create the vcs - should error because stub file doesn't exist yet
        with self.assertRaises(ReleaseVCSError):
            create_release_vcs(self.src_root)

        # make the stub file
        self.stubfile = os.path.join(self.src_root, ".stub")
        with open(self.stubfile, 'w'):
            pass

        # create the vcs - should work now
        self.vcs = create_release_vcs(self.src_root)
        self.assertEqual(self.vcs.name(), "stub")
Esempio n. 2
0
File: build.py Progetto: opcg/rez
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)
Esempio n. 3
0
    def _setup_release(self):
        # start fresh
        system.clear_caches()
        if os.path.exists(self.install_root):
            shutil.rmtree(self.install_root)
        if os.path.exists(self.src_root):
            shutil.rmtree(self.src_root)
        shutil.copytree(self.src_path, self.src_root)

        self.packagefile = os.path.join(self.src_root, "package.yaml")
        with open(self.packagefile) as f:
            self.package_data = yaml.load(f.read(), Loader=yaml.FullLoader)

        # check build system type
        buildsys = create_build_system(self.src_root, verbose=True)
        self.assertEqual(buildsys.name(), "bez")

        # create the vcs - should error because stub file doesn't exist yet
        with self.assertRaises(ReleaseVCSError):
            create_release_vcs(self.src_root)

        # make the stub file
        self.stubfile = os.path.join(self.src_root, ".stub")
        with open(self.stubfile, 'w'):
            pass

        # create the vcs - should work now
        self.vcs = create_release_vcs(self.src_root)
        self.assertEqual(self.vcs.name(), "stub")
def _make_temporary_build(package):
    working_directory = os.path.dirname(package.filepath)

    system = build_system.create_build_system(working_directory,
                                              package=package,
                                              verbose=True)

    # create and execute build process
    builder = build_process_.create_build_process(
        "local",  # See :func:`rez.build_process_.get_build_process_types` for possible values
        working_directory,
        build_system=system,
        verbose=True,
    )

    install_path = tempfile.mkdtemp(suffix="package_{package.name}".format(
        package=package))

    _LOGGER.debug('Building to "%s" path.', install_path)

    with wurlitzer.pipes() as (stdout, stderr):
        builder.build(clean=True, install=True, install_path=install_path)

    stdout.close()
    stderr.close()

    return install_path
Esempio n. 5
0
File: release.py Progetto: skral/rez
def command(opts, parser, extra_arg_groups=None):
    from rez.build_process_ import create_build_process
    from rez.build_system import create_build_system
    from rez.release_vcs import create_release_vcs
    from rez.cli.build import get_build_args

    working_dir = os.getcwd()

    # create vcs
    vcs = create_release_vcs(working_dir, opts.vcs)

    # 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,
                                   verbose=True,
                                   build_args=build_args,
                                   child_build_args=child_build_args)

    # create and execute release process
    builder = create_build_process(opts.process,
                                   working_dir,
                                   build_system=buildsys,
                                   vcs=vcs,
                                   ensure_latest=(not opts.no_latest),
                                   skip_repo_errors=opts.skip_repo_errors,
                                   ignore_existing_tag=opts.ignore_existing_tag,
                                   verbose=True)

    builder.release(release_message=opts.message,
                    variants=opts.variants)
Esempio n. 6
0
    def _create_builder(self, ensure_latest=True):
        buildsys = create_build_system(self.src_root, verbose=True)

        return create_build_process(process_type="local",
                                    working_dir=self.src_root,
                                    build_system=buildsys,
                                    vcs=self.vcs,
                                    ensure_latest=ensure_latest,
                                    ignore_existing_tag=True,
                                    verbose=True)
Esempio n. 7
0
    def _create_builder(self, ensure_latest=True):
        buildsys = create_build_system(self.src_root, verbose=True)

        return create_build_process(process_type="local",
                                    working_dir=self.src_root,
                                    build_system=buildsys,
                                    vcs=self.vcs,
                                    ensure_latest=ensure_latest,
                                    ignore_existing_tag=True,
                                    verbose=True)
Esempio n. 8
0
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)
Esempio n. 9
0
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)
Esempio n. 10
0
def command(opts, parser, extra_arg_groups=None):
    from rez.build_process_ import create_build_process
    from rez.build_system import create_build_system
    from rez.release_vcs import create_release_vcs
    from rez.cli.build import get_build_args
    from rez.config import config

    release_msg = opts.message
    filename = None

    if config.prompt_release_message and not release_msg and not opts.no_message:
        filename = os.path.join(config.tmpdir, "rez_release_message.tmp")

        with open(filename, "a+") as f:
            ed = config.editor
            call([ed, filename])

            read_data = f.read()
            if read_data:
                release_msg = read_data

    working_dir = os.getcwd()

    # create vcs
    vcs = create_release_vcs(working_dir, opts.vcs)

    # 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,
                                   verbose=True,
                                   build_args=build_args,
                                   child_build_args=child_build_args)

    # create and execute release process
    builder = create_build_process(
        opts.process,
        working_dir,
        build_system=buildsys,
        vcs=vcs,
        ensure_latest=(not opts.no_latest),
        skip_repo_errors=opts.skip_repo_errors,
        ignore_existing_tag=opts.ignore_existing_tag,
        verbose=True)

    builder.release(release_message=release_msg, variants=opts.variants)

    # remove the release message file
    if filename:
        os.remove(filename)
Esempio n. 11
0
def command(opts, parser, extra_arg_groups=None):
    from rez.build_process_ import create_build_process
    from rez.build_system import create_build_system
    from rez.release_vcs import create_release_vcs
    from rez.cli.build import get_build_args
    from rez.config import config

    release_msg = opts.message
    filename = None

    if config.prompt_release_message and not release_msg and not opts.no_message:
        filename = os.path.join(config.tmpdir, "rez_release_message.tmp")

        with open(filename, "a+") as f:
            ed = config.editor
            call([ed, filename])

            read_data = f.read()
            if read_data:
                release_msg = read_data

    working_dir = os.getcwd()

    # create vcs
    vcs = create_release_vcs(working_dir, opts.vcs)

    # 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,
                                   verbose=True,
                                   build_args=build_args,
                                   child_build_args=child_build_args)

    # create and execute release process
    builder = create_build_process(opts.process,
                                   working_dir,
                                   build_system=buildsys,
                                   vcs=vcs,
                                   ensure_latest=(not opts.no_latest),
                                   skip_repo_errors=opts.skip_repo_errors,
                                   ignore_existing_tag=opts.ignore_existing_tag,
                                   verbose=True)

    builder.release(release_message=release_msg,
                    variants=opts.variants)

    # remove the release message file
    if filename:
        os.remove(filename)
Esempio n. 12
0
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)
Esempio n. 13
0
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)
Esempio n. 14
0
def _run_build(package, paths=None):
    # TODO : Figure out where to put `paths`
    root = finder.get_package_root(package)

    system = build_system.create_build_system(root,
                                              package=package,
                                              verbose=True)

    # create and execute build process
    builder = build_process_.create_build_process(
        "local",  # See :func:`rez.build_process_.get_build_process_types` for possible values
        root,
        build_system=system,
        verbose=True,
    )

    try:
        builder.build(clean=True, install=True)
    except Exception:  # pylint: disable=broad-except
        return False

    return True
Esempio n. 15
0
def command(opts, parser, extra_arg_groups=None):
    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.release_vcs import create_release_vcs
    from rez.cli.build import get_build_args
    from rez.config import config

    # load package
    working_dir = os.getcwd()
    package = get_developer_package(working_dir)

    # create vcs
    vcs = create_release_vcs(working_dir, opts.vcs)

    # 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,
                                   verbose=True,
                                   build_args=build_args,
                                   child_build_args=child_build_args)

    # create and execute release process
    builder = create_build_process(opts.process,
                                   working_dir,
                                   package=package,
                                   build_system=buildsys,
                                   vcs=vcs,
                                   ensure_latest=(not opts.no_latest),
                                   skip_repo_errors=opts.skip_repo_errors,
                                   ignore_existing_tag=opts.ignore_existing_tag,
                                   verbose=True)

    # get release message
    release_msg = opts.message
    filepath = None

    if config.prompt_release_message and not release_msg and not opts.no_message:
        from hashlib import sha1

        h = sha1(working_dir).hexdigest()
        filename = "rez-release-message-%s.txt" % h
        filepath = os.path.join(config.tmpdir, filename)

        header = "<Enter your release notes here>"
        changelog_token = "###<CHANGELOG>"

        if not os.path.exists(filepath):
            txt = header

            # get changelog and add to release notes file, for reference. They
            # get stripped out again before being added as package release notes.
            try:
                changelog = builder.get_changelog()
            except:
                pass

            if changelog:
                txt += ("\n\n%s This is for reference only - this line and all "
                        "following lines will be stripped from the release "
                        "notes.\n\n" % changelog_token)
                txt += changelog

            with open(filepath, 'w') as f:
                print >> f, txt

        call([config.editor, filepath])

        with open(filepath) as f:
            release_msg = f.read()

        # strip changelog out
        try:
            i = release_msg.index(changelog_token)
            release_msg = release_msg[:i]
        except ValueError:
            pass

        # strip header out
        release_msg = release_msg.replace(header, "")

        release_msg = release_msg.strip()

        if not release_msg:
            ch = None
            while ch not in ('A', 'a', 'C', 'c'):
                print "Empty release message. [A]bort or [C]ontinue release?"
                ch = raw_input()

            if ch in ('A', 'a'):
                print "Release aborted."
                sys.exit(1)

    # perform the release
    builder.release(release_message=release_msg or None,
                    variants=opts.variants)

    # remove the release message file
    if filepath:
        try:
            os.remove(filepath)
        except:
            pass
Esempio n. 16
0
 def _create_builder(cls, working_dir):
     buildsys = create_build_system(working_dir)
     return create_build_process(process_type="local",
                                 working_dir=working_dir,
                                 build_system=buildsys)
Esempio n. 17
0
 def _create_builder(cls, working_dir):
     buildsys = create_build_system(working_dir)
     return create_build_process(process_type="local",
                                 working_dir=working_dir,
                                 build_system=buildsys)
Esempio n. 18
0
    def test_1(self):
        """Basic release."""

        # start fresh
        system.clear_caches()
        if os.path.exists(self.install_root):
            shutil.rmtree(self.install_root)
        if os.path.exists(self.src_root):
            shutil.rmtree(self.src_root)
        shutil.copytree(self.src_path, self.src_root)

        working_dir = self.src_root
        packagefile = os.path.join(working_dir, "package.yaml")
        with open(packagefile) as f:
            package_data = yaml.load(f.read())

        def _write_package():
            with open(packagefile, 'w') as f:
                dump_package_data(package_data, f, format_=FileFormat.yaml)

        # create the build system
        buildsys = create_build_system(working_dir, verbose=True)
        self.assertEqual(buildsys.name(), "bez")

        # create the vcs
        with self.assertRaises(ReleaseVCSError):
            vcs = create_release_vcs(working_dir)

        stubfile = os.path.join(working_dir, ".stub")
        with open(stubfile, 'w'):
            pass
        vcs = create_release_vcs(working_dir)
        self.assertEqual(vcs.name(), "stub")

        def _create_builder(ensure_latest=True):
            return create_build_process(process_type="local",
                                        working_dir=working_dir,
                                        build_system=buildsys,
                                        vcs=vcs,
                                        ensure_latest=ensure_latest,
                                        ignore_existing_tag=True,
                                        verbose=True)

        # release should fail because release path does not exist
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # release should work this time
        os.mkdir(self.install_root)
        builder.release()

        # check a file to see the release made it
        filepath = os.path.join(self.install_root, "foo", "1.0", "data",
                                "data.txt")
        self.assertTrue(os.path.exists(filepath))

        # failed release (same version released again)
        builder = _create_builder()
        num_variants = builder.release()
        self.assertEqual(num_variants, 0)

        # update package version and release again
        package_data["version"] = "1.1"
        _write_package()
        builder = _create_builder()
        builder.release()

        # change version to earlier and do failed release attempt
        package_data["version"] = "1.0.1"
        _write_package()
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # release again, this time allow not latest
        builder = _create_builder(ensure_latest=False)
        builder.release()

        # change uuid and do failed release attempt
        package_data["version"] = "1.2"
        package_data["uuid"] += "_CHANGED"
        _write_package()
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # check the vcs contains the tags we expect
        expected_value = set(["foo-1.0", "foo-1.0.1", "foo-1.1"])
        with open(stubfile) as f:
            stub_data = yaml.load(f.read())
        tags = set(stub_data.get("tags", {}).keys())
        self.assertEqual(tags, expected_value)

        # check the package install path contains the packages we expect
        it = iter_packages("foo", paths=[self.install_root])
        qnames = set(x.qualified_name for x in it)
        self.assertEqual(qnames, expected_value)
Esempio n. 19
0
def command(opts, parser, extra_arg_groups=None):
    from rez.build_process_ import create_build_process
    from rez.build_system import create_build_system
    from rez.release_vcs import create_release_vcs
    from rez.cli.build import get_build_args, get_current_developer_package
    from rez.config import config

    # load package
    working_dir = os.getcwd()
    package = get_current_developer_package()

    # create vcs
    vcs = create_release_vcs(working_dir, opts.vcs)

    # 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,
                                   verbose=True,
                                   build_args=build_args,
                                   child_build_args=child_build_args)

    # create and execute release process
    builder = create_build_process(
        opts.process,
        working_dir,
        package=package,
        build_system=buildsys,
        vcs=vcs,
        ensure_latest=(not opts.no_latest),
        skip_repo_errors=opts.skip_repo_errors,
        ignore_existing_tag=opts.ignore_existing_tag,
        verbose=True)

    # get release message
    release_msg = opts.message
    filepath = None

    if config.prompt_release_message and not release_msg and not opts.no_message:
        from hashlib import sha1

        h = sha1(working_dir).hexdigest()
        filename = "rez-release-message-%s.txt" % h
        filepath = os.path.join(config.tmpdir, filename)

        header = "<Enter your release notes here>"
        changelog_token = "###<CHANGELOG>"

        if not os.path.exists(filepath):
            txt = header

            # get changelog and add to release notes file, for reference. They
            # get stripped out again before being added as package release notes.
            try:
                changelog = builder.get_changelog()
            except:
                changelog = None

            if changelog:
                txt += (
                    "\n\n%s This is for reference only - this line and all "
                    "following lines will be stripped from the release "
                    "notes.\n\n" % changelog_token)
                txt += changelog

            with open(filepath, 'w') as f:
                print(txt, file=f)

        call([config.editor, filepath])

        with open(filepath) as f:
            release_msg = f.read()

        # strip changelog out
        try:
            i = release_msg.index(changelog_token)
            release_msg = release_msg[:i]
        except ValueError:
            pass

        # strip header out
        release_msg = release_msg.replace(header, "")

        release_msg = release_msg.strip()

        if not release_msg:
            ch = None
            while ch not in ('A', 'a', 'C', 'c'):
                print("Empty release message. [A]bort or [C]ontinue release?")
                ch = raw_input()

            if ch in ('A', 'a'):
                print("Release aborted.")
                sys.exit(1)

    # perform the release
    builder.release(release_message=release_msg or None,
                    variants=opts.variants)

    # remove the release message file
    if filepath:
        try:
            os.remove(filepath)
        except:
            pass
def _build(package, install_path, directory, quiet=False):
    """Build the given Rez `package` to the given `install_path`.

    Args:
        package (:class:`rez.developer_package.DeveloperPackage`):
            The package to build.
        install_path (str):
            The absolute directory on-disk to build the package at.
            This path represents a path that you might add to the
            REZ_PACKAGES_PATH environment variable (for example) so it
            should not contain the package's name or version.
        packages_path (list[str], optional):
            The paths that will be used to search for Rez packages while
            building. This is usually to make it easier to find package
            dependencies. If `packages_path` is not defined, Rez will
            use its default paths. Default is None.
        quiet (bool, optional):
            If True, Rez won't print anything to the terminal while
            If building. False, print everything. Default is False.

    Raises:
        RuntimeError: If the package fails to build for any reason.

    Returns:
        :class:`rez.developer_package.DeveloperPackage`:
            The package the represents the newly-built package.

    """
    system = build_system.create_build_system(directory,
                                              package=package,
                                              verbose=True)

    builder = build_process_.create_build_process(
        "local",  # See :func:`rez.build_process_.get_build_process_types` for possible values
        directory,
        build_system=system,
        verbose=True,
    )

    _LOGGER.info('Now building package "%s".', package)

    if quiet:
        context = rez_configuration.get_context()
    else:
        context = _null_context()

    with context:
        number_of_variants_visited = builder.build(
            clean=True,
            install=True,
            install_path=install_path,
        )

    if not number_of_variants_visited:
        raise RuntimeError(
            'Building "{package}" failed. No variants were installed.'.format(
                package=package))

    if not os.listdir(install_path):
        raise RuntimeError(
            'Package "{package}" has an installed variant '
            "but no files were written to-disk.".format(package=package))

    return packages_.get_developer_package(
        os.path.join(install_path, package.name, str(package.version)))
Esempio n. 21
0
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
Esempio n. 22
0
    def test_1(self):
        """Basic release."""

        # start fresh
        system.clear_caches()
        if os.path.exists(self.install_root):
            shutil.rmtree(self.install_root)
        if os.path.exists(self.src_root):
            shutil.rmtree(self.src_root)
        shutil.copytree(self.src_path, self.src_root)

        working_dir = self.src_root
        packagefile = os.path.join(working_dir, "package.yaml")
        with open(packagefile) as f:
            package_data = yaml.load(f.read())

        def _write_package():
            with open(packagefile, 'w') as f:
                dump_package_data(package_data, f, format_=FileFormat.yaml)

        # create the build system
        buildsys = create_build_system(working_dir, verbose=True)
        self.assertEqual(buildsys.name(), "bez")

        # create the vcs
        with self.assertRaises(ReleaseVCSError):
            vcs = create_release_vcs(working_dir)

        stubfile = os.path.join(working_dir, ".stub")
        with open(stubfile, 'w'):
            pass
        vcs = create_release_vcs(working_dir)
        self.assertEqual(vcs.name(), "stub")

        def _create_builder(ensure_latest=True):
            return create_build_process(process_type="local",
                                        working_dir=working_dir,
                                        build_system=buildsys,
                                        vcs=vcs,
                                        ensure_latest=ensure_latest,
                                        ignore_existing_tag=True,
                                        verbose=True)

        # release should fail because release path does not exist
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # release should work this time
        os.mkdir(self.install_root)
        builder.release()

        # check a file to see the release made it
        filepath = os.path.join(self.install_root,
                                "foo", "1.0", "data", "data.txt")
        self.assertTrue(os.path.exists(filepath))

        # failed release (same version released again)
        builder = _create_builder()
        num_variants = builder.release()
        self.assertEqual(num_variants, 0)

        # update package version and release again
        package_data["version"] = "1.1"
        _write_package()
        builder = _create_builder()
        builder.release()

        # change version to earlier and do failed release attempt
        package_data["version"] = "1.0.1"
        _write_package()
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # release again, this time allow not latest
        builder = _create_builder(ensure_latest=False)
        builder.release()

        # change uuid and do failed release attempt
        package_data["version"] = "1.2"
        package_data["uuid"] += "_CHANGED"
        _write_package()
        builder = _create_builder()
        with self.assertRaises(ReleaseError):
            builder.release()

        # check the vcs contains the tags we expect
        expected_value = set(["foo-1.0", "foo-1.0.1", "foo-1.1"])
        with open(stubfile) as f:
            stub_data = yaml.load(f.read())
        tags = set(stub_data.get("tags", {}).keys())
        self.assertEqual(tags, expected_value)

        # check the package install path contains the packages we expect
        it = iter_packages("foo", paths=[self.install_root])
        qnames = set(x.qualified_name for x in it)
        self.assertEqual(qnames, expected_value)