Пример #1
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["yeah.info",
                                                        op.join("foo", "__init__.py"),
                                                        op.join("foo", "bar", "__init__.py"),
                                                        "fubar.py"]]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.failUnless(op.join("foo-1.0", f) in files)
Пример #2
0
    def _run_configure_and_build(self, bento_info, install_prefix):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, bento_info)

        context = GlobalContext(None)
        options = PackageOptions.from_string(bento_info)
        context.register_package_options(options)

        cmd_argv = ["--prefix=%s" % install_prefix, "--exec-prefix=%s" % install_prefix]

        conf, configure = prepare_configure(top_node, bento_info, ConfigureYakuContext, cmd_argv)

        context.register_command("configure", configure)
        options_context = OptionsContext.from_command(configure)
        if not context.is_options_context_registered("configure"):
            context.register_options_context("configure", options_context)
        context.save_command_argv("configure", cmd_argv)

        run_command_in_context(conf, configure)

        bld, build = prepare_build(top_node, bento_info)
        run_command_in_context(bld, build)

        return context, conf, configure, bld, build
Пример #3
0
def register_options(global_context, cmd_name):
    """Register options for the given command."""
    cmd = global_context.retrieve_command(cmd_name)
    context = OptionsContext.from_command(cmd)

    if not global_context.is_options_context_registered(cmd_name):
        global_context.register_options_context(cmd_name, context)
Пример #4
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f)
            for f in ["fubar.py", "yeah.info", "PKG_INFO"]
        ]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #5
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info"]]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.failUnless(op.join("foo-1.0", f) in files)
Пример #6
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFiles: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f)
            for f in ["fubar.py", "release.py.in", "release.py", "PKG_INFO"]
        ]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #7
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f) for f in [
                "yeah.info", "PKG_INFO",
                op.join("foo", "__init__.py"),
                op.join("foo", "bar", "__init__.py"), "fubar.py"
            ]
        ]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #8
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFile: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py"]]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.fail("File %s not found in archive" % (f,))
Пример #9
0
    def _run_configure_and_build(self, bento_info, install_prefix):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, bento_info)

        context = GlobalContext(None)
        options = PackageOptions.from_string(bento_info)
        context.register_package_options(options)

        cmd_argv = [
            "--prefix=%s" % install_prefix,
            "--exec-prefix=%s" % install_prefix
        ]

        conf, configure = prepare_configure(top_node, bento_info,
                                            ConfigureYakuContext, cmd_argv)

        context.register_command("configure", configure)
        options_context = OptionsContext.from_command(configure)
        if not context.is_options_context_registered("configure"):
            context.register_options_context("configure", options_context)
        context.save_command_argv("configure", cmd_argv)

        run_command_in_context(conf, configure)

        bld, build = prepare_build(top_node, bento_info)
        run_command_in_context(bld, build)

        return context, conf, configure, bld, build
Пример #10
0
def register_options(global_context, cmd_name):
    """Register options for the given command."""
    cmd = global_context.retrieve_command(cmd_name)
    context = OptionsContext.from_command(cmd)

    if not global_context.is_options_context_registered(cmd_name):
        global_context.register_options_context(cmd_name, context)
Пример #11
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["yeah.info",
                                                        op.join("foo", "__init__.py"),
                                                        op.join("foo", "bar", "__init__.py"),
                                                        "fubar.py"]]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #12
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFile: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py"]]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #13
0
    def test_compiled_library(self):
        from bento.backends.distutils_backend import DistutilsBuildContext

        r_full_name = "lib/_foo"

        bento_info = """\
Name: foo

Library:
    CompiledLibrary: lib/_foo
        Sources: foo.c
"""
        package = PackageDescription.from_string(bento_info)
        create_fake_package_from_bento_info(self.top_node, bento_info)

        options = OptionsContext.from_command(BuildCommand())
        context = DistutilsBuildContext(None, [], options, package,
                                        self.run_node)
        context.pre_recurse(self.top_node)
        try:

            def builder(a):
                self.assertEqual(a.name, r_full_name)
                builder.is_called = True

            builder.is_called = False
            context.register_compiled_library_builder("lib/_foo", builder)
        finally:
            context.post_recurse()
        context.compile()

        self.assertTrue(builder.is_called, "registered builder not called")
Пример #14
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info"]]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Пример #15
0
    def test_compiled_library(self):
        from bento.backends.distutils_backend import DistutilsBuildContext

        r_full_name = "lib/_foo"

        bento_info = """\
Name: foo

Library:
    CompiledLibrary: lib/_foo
        Sources: foo.c
"""
        package = PackageDescription.from_string(bento_info)
        create_fake_package_from_bento_info(self.top_node, bento_info)

        options = OptionsContext.from_command(BuildCommand())
        context = DistutilsBuildContext(None, [], options, package, self.run_node)
        context.pre_recurse(self.top_node)
        try:
            def builder(a):
                self.assertEqual(a.name, r_full_name)
                builder.is_called = True
            builder.is_called = False
            context.register_compiled_library_builder("lib/_foo", builder)
        finally:
            context.post_recurse()
        context.compile()

        self.assertTrue(builder.is_called, "registered builder not called")
Пример #16
0
def prepare_options(cmd_name, cmd, context_klass):
    opts = OptionsContext.from_command(cmd)
    g_context = FakeGlobalContext()
    g_context._cmd_opts[cmd_name] = opts
    # FIXME: the way new options are registered for custom contexts sucks:
    # there should be a context class independent way to do it
    if context_klass.__name__ == "BuildWafContext":
        from bento.commands.extras.waf import register_options
        register_options(g_context)
    return opts
Пример #17
0
    def _test_dry_run(self, bento_info):
        install_prefix = tempfile.mkdtemp()
        try:
            context, conf, configure, bld, build = self._run_configure_and_build(bento_info, install_prefix)

            install = InstallCommand()
            opts = OptionsContext.from_command(install)

            inst = ContextWithBuildDirectory(context, ["--list-files"], opts, conf.pkg, self.top_node)
            run_command_in_context(inst, install)
        finally:
            shutil.rmtree(install_prefix)
Пример #18
0
    def _test_run(self, bento_info):
        install_prefix = tempfile.mkdtemp()
        try:
            conf, configure, bld, build = self._run_configure_and_build(bento_info, install_prefix)

            install = InstallCommand()
            opts = OptionsContext.from_command(install)

            inst = CmdContext(None, [], opts, conf.pkg, self.top_node)
            install.run(inst)
        finally:
            shutil.rmtree(install_prefix)
Пример #19
0
    def test_simple_distutils(self):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT)
        conf, configure = prepare_configure(top_node, BENTO_INFO_WITH_EXT, DistutilsConfigureContext)
        run_command_in_context(conf, configure)

        build = BuildCommand()
        opts = OptionsContext.from_command(build)

        bld = DistutilsBuildContext(None, [], opts, conf.pkg, top_node)
        run_command_in_context(bld, build)
Пример #20
0
    def test_simple_distutils(self):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT)
        conf, configure = prepare_configure(top_node, BENTO_INFO_WITH_EXT, DistutilsConfigureContext)
        run_command_in_context(conf, configure)

        build = BuildCommand()
        opts = OptionsContext.from_command(build)

        bld = DistutilsBuildContext(None, [], opts, conf.pkg, top_node)
        run_command_in_context(bld, build)
Пример #21
0
    def test_simple_yaku(self):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT)
        conf, configure = prepare_configure(top_node, BENTO_INFO_WITH_EXT, ConfigureYakuContext)
        configure.run(conf)
        conf.shutdown()

        build = BuildCommand()
        opts = OptionsContext.from_command(build)

        bld = BuildYakuContext([], opts, conf.pkg, top_node)
        build.run(bld)
Пример #22
0
    def test_simple(self):
        root = self.root
        top_node = root.find_node(self.d)

        create_fake_package_from_bento_info(top_node, BENTO_INFO)
        conf, configure = prepare_configure(top_node, BENTO_INFO, ConfigureYakuContext)
        configure.run(conf)
        conf.shutdown()

        build = BuildCommand()
        opts = OptionsContext.from_command(build)

        bld = BuildYakuContext([], opts, conf.pkg, top_node)
        build.run(bld)
Пример #23
0
def _run_convert_command(top_node, run_node, setup_py, bento_info, cmd_argv):
    setup_node = top_node.make_node("setup.py")
    setup_node.safe_write(setup_py)

    create_fake_package_from_bento_info(top_node, bento_info)
    package = PackageDescription.from_string(bento_info)

    cmd = ConvertCommand()
    opts = OptionsContext.from_command(cmd)

    context = CmdContext(None, cmd_argv, opts, package, run_node)
    cmd.run(context)
    cmd.finish(context)
    context.finish()
Пример #24
0
    def _run_command(self):
        setup_node = self.top_node.make_node("setup.py")
        setup_node.safe_write("")

        create_fake_package_from_bento_info(self.top_node, "")
        package = PackageDescription.from_string("")

        cmd = DetectTypeCommand()
        opts = OptionsContext.from_command(cmd)

        context = CmdContext(None, [], opts, package, self.run_node)
        cmd.run(context)
        cmd.finish(context)
        context.finish()
Пример #25
0
def _run_convert_command(top_node, run_node, setup_py, bento_info, cmd_argv):
    setup_node = top_node.make_node("setup.py")
    setup_node.safe_write(setup_py)

    create_fake_package_from_bento_info(top_node, bento_info)
    package = PackageDescription.from_string(bento_info)

    cmd = ConvertCommand()
    opts = OptionsContext.from_command(cmd)

    context = CmdContext(None, cmd_argv, opts, package, run_node)
    cmd.run(context)
    cmd.finish(context)
    context.finish()
Пример #26
0
    def _test_dry_run(self, bento_info):
        install_prefix = tempfile.mkdtemp()
        try:
            context, conf, configure, bld, build = self._run_configure_and_build(
                bento_info, install_prefix)

            install = InstallCommand()
            opts = OptionsContext.from_command(install)

            inst = ContextWithBuildDirectory(context, ["--list-files"], opts,
                                             conf.pkg, self.top_node)
            run_command_in_context(inst, install)
        finally:
            shutil.rmtree(install_prefix)
Пример #27
0
    def _run_command(self):
        setup_node = self.top_node.make_node("setup.py")
        setup_node.safe_write("")

        create_fake_package_from_bento_info(self.top_node, "")
        package = PackageDescription.from_string("")

        cmd = DetectTypeCommand()
        opts = OptionsContext.from_command(cmd)

        context = CmdContext(None, [], opts, package, self.run_node)
        cmd.run(context)
        cmd.finish(context)
        context.finish()
Пример #28
0
def global_context_factory(package_options):
    # FIXME: factor this out with the similar code in bentomakerlib
    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)

    register_commands(global_context)
    register_command_contexts(global_context)
    for cmd_name in global_context.command_names():
        cmd = global_context.retrieve_command(cmd_name)
        options_context = OptionsContext.from_command(cmd)

        if not global_context.is_options_context_registered(cmd_name):
            global_context.register_options_context(cmd_name, options_context)

    return global_context
Пример #29
0
def global_context_factory(package_options):
    # FIXME: factor this out with the similar code in bentomakerlib
    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)

    register_commands(global_context)
    register_command_contexts(global_context)
    for cmd_name in global_context.command_names():
        cmd = global_context.retrieve_command(cmd_name)
        options_context = OptionsContext.from_command(cmd)

        if not global_context.is_options_context_registered(cmd_name):
            global_context.register_options_context(cmd_name, options_context)

    return global_context
Пример #30
0
    def _setup_hooks(self, package, global_context, mods):
        if package.use_backends:
            if len(package.use_backends) > 1:
                raise ValueError("Only up to one backend supported for now")
            else:
                assert global_context.backend is None
                global_context.backend = load_backend(
                    package.use_backends[0])()

        startup_hooks = find_startup_hooks(mods)
        option_hooks = find_options_hooks(mods)
        shutdown_hooks = find_shutdown_hooks(mods)

        if startup_hooks:
            # FIXME: there should be an error or a warning if startup defined in
            # mods beyond the first one
            startup_hooks[0](global_context)

        if global_context.backend:
            global_context.backend.register_command_contexts(global_context)
        for command in find_command_hooks(mods):
            global_context.register_command(command.name, command)

        if global_context.backend:
            global_context.backend.register_options_contexts(global_context)

        if option_hooks:
            # FIXME: there should be an error or a warning if shutdown defined in
            # mods beyond the first one
            option_hooks[0](global_context)

        # FIXME: this registered options for new commands registered in hook. It
        # should be made all in one place (hook and non-hook)
        for cmd_name in global_context.command_names(public_only=False):
            if not global_context.is_options_context_registered(cmd_name):
                # FIXME: this should be supported in global context directly
                # (redundant with bentomakerlib)
                cmd = global_context.retrieve_command(cmd_name)
                context = OptionsContext.from_command(cmd)

                if not global_context.is_options_context_registered(cmd_name):
                    global_context.register_options_context(cmd_name, context)

        for cmd_name in global_context.command_names():
            for hook in find_pre_hooks(mods, cmd_name):
                global_context.add_pre_hook(hook, cmd_name)
            for hook in find_post_hooks(mods, cmd_name):
                global_context.add_post_hook(hook, cmd_name)
Пример #31
0
    def test_simple(self):
        n = self.top_node.make_node("doc/conf.py")
        n.parent.mkdir()
        n.write("")

        n = self.top_node.make_node("doc/contents.rst")
        n.write("")

        bento_info = "Name: foo"
        package = PackageDescription.from_string(bento_info)

        sphinx = SphinxCommand()
        opts = OptionsContext.from_command(sphinx)
        context = ContextWithBuildDirectory(None, [], opts, package, self.run_node)

        run_command_in_context(context, sphinx)
Пример #32
0
    def test_simple(self):
        n = self.top_node.make_node("doc/conf.py")
        n.parent.mkdir()
        n.write("")

        n = self.top_node.make_node("doc/contents.rst")
        n.write("")

        bento_info = "Name: foo"
        package = PackageDescription.from_string(bento_info)

        sphinx = SphinxCommand()
        opts = OptionsContext.from_command(sphinx)
        context = ContextWithBuildDirectory(None, [], opts, package, self.run_node)

        run_command_in_context(context, sphinx)
Пример #33
0
    def _setup_hooks(self, package, global_context, mods):
        if package.use_backends:
            if len(package.use_backends) > 1:
                raise ValueError("Only up to one backend supported for now")
            else:
                assert global_context.backend is None
                global_context.backend = load_backend(package.use_backends[0])()

        startup_hooks = find_startup_hooks(mods)
        option_hooks = find_options_hooks(mods)
        shutdown_hooks = find_shutdown_hooks(mods)

        if startup_hooks:
            # FIXME: there should be an error or a warning if startup defined in
            # mods beyond the first one
            startup_hooks[0](global_context)

        if global_context.backend:
            global_context.backend.register_command_contexts(global_context)
        for command in find_command_hooks(mods):
            global_context.register_command(command.name, command)

        if global_context.backend:
            global_context.backend.register_options_contexts(global_context)

        if option_hooks:
            # FIXME: there should be an error or a warning if shutdown defined in
            # mods beyond the first one
            option_hooks[0](global_context)

        # FIXME: this registered options for new commands registered in hook. It
        # should be made all in one place (hook and non-hook)
        for cmd_name in global_context.command_names(public_only=False):
            if not global_context.is_options_context_registered(cmd_name):
                # FIXME: this should be supported in global context directly
                # (redundant with bentomakerlib)
                cmd = global_context.retrieve_command(cmd_name)
                context = OptionsContext.from_command(cmd)

                if not global_context.is_options_context_registered(cmd_name):
                    global_context.register_options_context(cmd_name, context)

        for cmd_name in global_context.command_names():
            for hook in find_pre_hooks(mods, cmd_name):
                global_context.add_pre_hook(hook, cmd_name)
            for hook in find_post_hooks(mods, cmd_name):
                global_context.add_post_hook(hook, cmd_name)
Пример #34
0
Файл: utils.py Проект: pv/bento
def _prepare_command(run_node, bento_info, cmd_klass, context_klass, cmd_argv):
    top_node = run_node._ctx.srcnode
    top_node.make_node("bento.info").safe_write(bento_info)

    package = PackageDescription.from_string(bento_info)
    package_options = PackageOptions.from_string(bento_info)

    cmd = cmd_klass()
    options_context = OptionsContext.from_command(cmd)

    cmd.register_options(options_context, package_options)

    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)

    context = context_klass(global_context, cmd_argv, options_context, package, run_node)
    return context, cmd
Пример #35
0
def _prepare_command(run_node, bento_info, cmd_klass, context_klass, cmd_argv):
    top_node = run_node._ctx.srcnode
    top_node.make_node("bento.info").safe_write(bento_info)

    package = PackageDescription.from_string(bento_info)
    package_options = PackageOptions.from_string(bento_info)

    cmd = cmd_klass()
    options_context = OptionsContext.from_command(cmd)

    cmd.register_options(options_context, package_options)

    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)

    context = context_klass(global_context, cmd_argv, options_context, package, run_node)
    return context, cmd
Пример #36
0
    def write_record(self):
        dist = self.distribution

        install = InstallCommand()
        options_context = OptionsContext.from_command(install)
        context = CmdContext([], options_context, dist.pkg, dist.run_node)
        if self.record:
            n = context.build_node.make_node(IPKG_PATH)
            ipkg = InstalledPkgDescription.from_file(n.abspath())
            scheme = context.get_paths_scheme()
            ipkg.update_paths(scheme)
            file_sections = ipkg.resolve_paths(src_root_dir=context.build_node.abspath())

            fid = open(self.record, "w")
            try:
                for kind, source, target in iter_files(file_sections):
                    fid.write("%s\n" % target)
            finally:
                fid.close()
Пример #37
0
def global_context_factory(package_options):
    # FIXME: factor this out with the similar code in bentomakerlib
    options_registry = OptionsRegistry()
    # This is a dummy for now, to fulfill global_context API
    cmd_scheduler = CommandScheduler()
    commands_registry = CommandRegistry()
    register_commands(commands_registry)
    register_command_contexts()
    for cmd_name in commands_registry.command_names():
        if not options_registry.is_registered(cmd_name):
            cmd = commands_registry.retrieve(cmd_name)
            options_context = OptionsContext.from_command(cmd)
            options_registry.register(cmd_name, options_context)

    configure_options_context = options_registry.retrieve("configure")
    _setup_options_parser(configure_options_context, package_options)
    global_context = GlobalContext(commands_registry, CONTEXT_REGISTRY,
                                   options_registry, cmd_scheduler)
    return global_context
Пример #38
0
def prepare_configure(run_node, bento_info, context_klass=ConfigureYakuContext, cmd_argv=None):
    if cmd_argv is None:
        cmd_argv = []

    top_node = run_node._ctx.srcnode
    top_node.make_node("bento.info").safe_write(bento_info)

    package = PackageDescription.from_string(bento_info)
    package_options = PackageOptions.from_string(bento_info)

    configure = ConfigureCommand()
    opts = OptionsContext.from_command(configure)

    # FIXME: this emulates the big ugly hack inside bentomaker.
    _setup_options_parser(opts, package_options)

    context = context_klass(None, cmd_argv, opts, package, run_node)
    context.package_options = package_options

    return context, configure
Пример #39
0
    def test_simple(self):
        root = self.root
        top_node = self.top_node
        run_node = self.run_node

        bento_info = """\
Name: foo

Recurse:
    bar
"""
        bento_info2 = """\
Recurse:
    foo

Library:
    Modules: fubar
    Extension: _foo
        Sources: foo.c
"""

        bento_info3 = """\
Library:
    Modules: foufoufou
    Packages: sub2
"""
        bentos = {"bento.info": bento_info, os.path.join("bar", "bento.info"): bento_info2,
                  os.path.join("bar", "foo", "bento.info"): bento_info3}
        create_fake_package_from_bento_infos(run_node, bentos)

        conf, configure = prepare_configure(run_node, bento_info, ConfigureYakuContext)
        configure.run(conf)
        conf.shutdown()

        build = BuildCommand()
        opts = OptionsContext.from_command(build)

        cmd_argv = []
        bld = BuildYakuContext(cmd_argv, opts, conf.pkg, run_node)
        build.run(bld)
Пример #40
0
def create_global_context(package, package_options, backend=None):
    if backend is None:
        backend = YakuBackend()

    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)
    if backend:
        global_context.backend = backend

    build = BuildCommand()
    configure = ConfigureCommand()

    commands = (("configure", configure), ("build", build))

    for cmd_name, cmd in commands:
        global_context.register_command(cmd_name, cmd)
        options_context = OptionsContext.from_command(cmd)
        global_context.register_options_context(cmd_name, options_context)

    global_context.backend.register_command_contexts(global_context)
    global_context.backend.register_options_contexts(global_context)

    return global_context
Пример #41
0
Файл: utils.py Проект: pv/bento
def create_global_context(package, package_options, backend=None):
    if backend is None:
        backend = YakuBackend()

    global_context = GlobalContext(None)
    global_context.register_package_options(package_options)
    if backend:
        global_context.backend = backend

    build = BuildCommand()
    configure = ConfigureCommand()

    commands = (("configure", configure), ("build", build))

    for cmd_name, cmd in commands:
        global_context.register_command(cmd_name, cmd)
        options_context = OptionsContext.from_command(cmd)
        global_context.register_options_context(cmd_name, options_context)

    global_context.backend.register_command_contexts(global_context)
    global_context.backend.register_options_contexts(global_context)

    return global_context
Пример #42
0
    def _test_run(self, bento_info):
        top_node = self.top_node

        create_fake_package_from_bento_info(top_node, bento_info)

        install_dir = tempfile.mkdtemp()
        cmd_argv = ["--prefix=%s" % install_dir, "--exec-prefix=%s" % install_dir]

        conf, configure = prepare_configure(top_node, bento_info, ConfigureYakuContext, cmd_argv)
        configure.run(conf)
        conf.shutdown()

        bld, build = prepare_build(top_node, conf.pkg)
        build.run(bld)
        build.shutdown(bld)

        install = InstallCommand()
        opts = OptionsContext.from_command(install)

        inst = CmdContext(["--list-files"], opts, conf.pkg, top_node)
        try:
            install.run(inst)
        finally:
            shutil.rmtree(install_dir)
Пример #43
0
def register_options(cmd_name):
    cmd_klass = COMMANDS_REGISTRY.get_command(cmd_name)
    usage = cmd_klass.long_descr.splitlines()[1]
    context = OptionsContext.from_command(cmd_klass, usage=usage)
    OPTIONS_REGISTRY.register_command(cmd_name, context)
Пример #44
0
def register_options(global_context, cmd_name):
    cmd_klass = global_context.retrieve_command(cmd_name)
    usage = cmd_klass.long_descr.splitlines()[1]
    context = OptionsContext.from_command(cmd_klass, usage=usage)
    OPTIONS_REGISTRY.register(cmd_name, context)