예제 #1
0
파일: test_core.py 프로젝트: abadger/Bento
    def test_simple(self):
        help = HelpCommand()
        options = OptionsContext()
        for option in HelpCommand.common_options:
            options.add_option(option)
        context = CmdContext([], options, None, None)

        help.run(context)
예제 #2
0
파일: test_core.py 프로젝트: pberkes/Bento
    def test_simple(self):
        help = HelpCommand()
        options = OptionsContext()
        for option in HelpCommand.common_options:
            options.add_option(option)
        global_context = GlobalContext(self.registry, None, None, None)
        context = HelpContext(global_context, [], options, None, None)

        help.run(context)
예제 #3
0
파일: test_core.py 프로젝트: abadger/Bento
    def test_command(self):
        help = HelpCommand()
        options = OptionsContext()
        for option in HelpCommand.common_options:
            options.add_option(option)
        context = CmdContext(["configure"], options, None, None)
        context.options_registry = self.options_registry

        help.run(context)
예제 #4
0
    def test_simple(self):
        help = HelpCommand()
        options = OptionsContext()
        for option in HelpCommand.common_options:
            options.add_option(option)
        global_context = GlobalContext(None,
                commands_registry=self.registry,
                options_registry=self.options_registry)
        pkg = PackageDescription()
        context = HelpContext(global_context, [], options, pkg, self.run_node)

        run_command_in_context(context, help)
예제 #5
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")
예제 #6
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
예제 #7
0
파일: test_sdist.py 프로젝트: tonysyu/Bento
    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)
예제 #8
0
파일: test_sdist.py 프로젝트: tonysyu/Bento
    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 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)
예제 #10
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)
예제 #11
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
예제 #12
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)
예제 #13
0
파일: bentomaker.py 프로젝트: dholth/Bento
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)
예제 #14
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)
예제 #15
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)
예제 #16
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)
예제 #17
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)
예제 #18
0
파일: test_build.py 프로젝트: pfmoore/Bento
    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")
예제 #19
0
파일: test_sdist.py 프로젝트: tonysyu/Bento
    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)
예제 #20
0
파일: utils.py 프로젝트: pberkes/Bento
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
예제 #21
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)
예제 #22
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)
예제 #23
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)
예제 #24
0
def register_options_special(global_context):
    # Register options for special topics not attached to a "real" command
    # (e.g. 'commands')
    context = OptionsContext()

    def print_usage():
        print(get_usage(global_context))

    context.parser.print_help = print_usage
    global_context.register_options_context_without_command(
        "commands", context)

    context = OptionsContext()

    def print_help():
        global_options = global_context.retrieve_options_context("")
        p = global_options.parser
        return (p.print_help())

    context.parser.print_help = print_help
    global_context.register_options_context_without_command("globals", context)
예제 #25
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)
예제 #26
0
파일: test_build.py 프로젝트: abadger/Bento
    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)
예제 #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 _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)
예제 #29
0
파일: test_build.py 프로젝트: abadger/Bento
    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)
예제 #30
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()
예제 #31
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()
예제 #32
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()
예제 #33
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
예제 #34
0
파일: dist.py 프로젝트: Web5design/Bento
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
예제 #35
0
파일: dist.py 프로젝트: jjehannet/Bento
    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)
예제 #36
0
파일: test_sphinx.py 프로젝트: B-Rich/Bento
    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)
예제 #37
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)
예제 #38
0
    def setUp(self):
        self.run_node = create_first_node(os.getcwd())

        registry = bento.commands.registries.CommandRegistry()

        # help command assumes those always exist
        registry.register("configure", Command)
        registry.register("build", Command)
        registry.register("install", Command)
        registry.register("sdist", Command)
        registry.register("build_wininst", Command)
        registry.register("build_egg", Command)
        self.registry = registry

        self.options_registry = bento.commands.registries.OptionsRegistry()
        self.options_registry.register("configure", OptionsContext())
예제 #39
0
파일: dist.py 프로젝트: Web5design/Bento
    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)
예제 #40
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
예제 #41
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
예제 #42
0
파일: dist.py 프로젝트: pberkes/Bento
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
예제 #43
0
파일: install.py 프로젝트: abadger/Bento
    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()
예제 #44
0
파일: utils.py 프로젝트: pberkes/Bento
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
예제 #45
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)
예제 #46
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
예제 #47
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
예제 #48
0
def create_global_options_context():
    context = OptionsContext(usage="%prog [options] [cmd_name [cmd_options]]")
    context.add_option(
        Option("--version",
               "-v",
               dest="show_version",
               action="store_true",
               help="Version"))
    context.add_option(
        Option("--full-version",
               dest="show_full_version",
               action="store_true",
               help="Full version"))
    context.add_option(
        Option(
            "--build-directory",
            dest="build_directory",
            help=
            "Build directory as relative path from cwd (default: '%default')"))
    context.add_option(Option("--bento-info", dest="bento_info",
                              help="Bento location as a relative path from cwd (default: '%default'). " \
                                   "The base name (without its component) must be 'bento.info("))
    context.add_option(
        Option("--disable-autoconfigure",
               dest="disable_autoconfigure",
               action="store_true",
               default=False,
               help="""\
Do not automatically run configure before build. In this mode, the user is
expected to know what he is doing. This is mainly useful for developers, to
avoid running configure everytime (default: '%default')."""))
    context.add_option(
        Option("-h",
               "--help",
               dest="show_help",
               action="store_true",
               help="Display help and exit"))
    context.parser.set_defaults(show_version=False,
                                show_full_version=False,
                                show_help=False,
                                build_directory="build",
                                bento_info="bento.info")
    return context