class TestGlobalContextCustomizedOptions(unittest.TestCase): def setUp(self): self.context = GlobalContext(None) self.maxDiff = None def _test(self, package_options, r_scheme): self.context.register_package_options(package_options) scheme = self.context.retrieve_scheme() default_scheme, _ = get_scheme(sys.platform) r_scheme.update(default_scheme) r_scheme['py_version_short'] = ".".join(str(part) for part in sys.version_info[:2]) r_scheme['pkgname'] = package_options.name self.assertEqual(scheme, r_scheme) def test_no_options(self): package_options = PackageOptions.from_string("""\ Name: foo """) self._test(package_options, {}) def test_path_option(self): package_options = PackageOptions.from_string("""\ Name: foo Path: floupi Description: yoyo Default: /yeah """) self._test(package_options, {"floupi": "/yeah"})
class TestGlobalContextCustomizedOptions(unittest.TestCase): def setUp(self): self.context = GlobalContext(None) self.maxDiff = None def _test(self, package_options, r_scheme): self.context.register_package_options(package_options) scheme = self.context.retrieve_scheme() default_scheme, _ = get_scheme(sys.platform) r_scheme.update(default_scheme) r_scheme['py_version_short'] = ".".join( str(part) for part in sys.version_info[:2]) r_scheme['pkgname'] = package_options.name self.assertEqual(scheme, r_scheme) def test_no_options(self): package_options = PackageOptions.from_string("""\ Name: foo """) self._test(package_options, {}) def test_path_option(self): package_options = PackageOptions.from_string("""\ Name: foo Path: floupi Description: yoyo Default: /yeah """) self._test(package_options, {"floupi": "/yeah"})
def test_register_command_with_options(self): bscript = """\ from bento.commands import hooks from bento.commands.core import Command from bento.commands.options import OptionsContext, Option class DocCommand(Command): def run(self, context): pass @hooks.startup def startup(context): cmd = DocCommand() context.register_command("doc", cmd) options_context = OptionsContext.from_command(cmd) options_context.add_option(Option("--some-weird-option")) context.register_options_context("doc", options_context) """ self.top_node.make_node("bscript").write(bscript) global_context = GlobalContext(None) options_context = create_global_options_context() popts = parse_global_options(options_context, ["doc"]) _wrapped_main(global_context, popts, self.run_node, self.top_node, self.build_node) p = global_context.retrieve_options_context("doc").parser o, a = p.parse_args(["--some-weird-option=46"]) self.assertEqual(o.some_weird_option, "46")
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
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
def test_register_command(self): bscript = """\ from bento.commands import hooks from bento.commands.core import Command @hooks.startup def startup(context): context.register_command("foo", Command()) """ self.top_node.make_node("bscript").write(bscript) global_context = GlobalContext(None) options_context = create_global_options_context() popts = parse_global_options(options_context, ["configure"]) _wrapped_main(global_context, popts, self.run_node, self.top_node, self.build_node) self.assertTrue(global_context.is_command_registered("foo"))
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
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)
def test_register_existing_command(self): bscript = """\ from bento.commands import hooks from bento.commands.core import Command @hooks.startup def startup(context): context.register_command("configure", Command) """ self.top_node.make_node("bscript").write(bscript) global_context = GlobalContext(None) options_context = create_global_options_context() popts = parse_global_options(options_context, ["configure"]) self.assertRaises(ValueError, _wrapped_main, global_context, popts, self.run_node, self.top_node, self.build_node)
def test_simple(self): bscript = """\ from bento.commands import hooks @hooks.startup def startup(context): context.seen = True """ self.top_node.make_node("bscript").write(bscript) global_context = GlobalContext(None) options_context = create_global_options_context() popts = parse_global_options(options_context, ["configure"]) _wrapped_main(global_context, popts, self.run_node, self.top_node, self.build_node) self.assertTrue(getattr(global_context, "seen", False))
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
def setUp(self): self.context = GlobalContext(None) self.maxDiff = None
def main(argv=None): if hasattr(os, "getuid"): if os.getuid() == 0: pprint( "RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N" ) ans = input() if not ans.lower() in ["y", "yes"]: raise bento.errors.UsageException( "bentomaker execution canceld (not using bentomaker with admin privileges)" ) if argv is None: argv = sys.argv[1:] options_context = create_global_options_context() popts = parse_global_options(options_context, argv) cmd_name = popts.cmd_name if popts.show_version: print(bento.__version__) return if popts.show_full_version: print(bento.__version__ + "git" + bento.__git_revision__) return source_root = os.path.join(os.getcwd(), os.path.dirname(popts.bento_info)) build_root = os.path.join(os.getcwd(), popts.build_directory) top_node, build_node, run_node = bento.core.node.create_base_nodes( source_root, build_root) if run_node != top_node and run_node.is_src(): raise bento.errors.UsageException( "You cannot execute bentomaker in a subdirectory of the source tree !" ) if run_node != build_node and run_node.is_bld(): raise bento.errors.UsageException( "You cannot execute bentomaker in a subdirectory of the build tree !" ) global_context = GlobalContext(build_node.make_node(CMD_DATA_DUMP), CommandRegistry(), ContextRegistry(), OptionsRegistry(), CommandScheduler()) global_context.register_options_context_without_command( "", options_context) if not popts.disable_autoconfigure: global_context.set_before("build", "configure") global_context.set_before("build_egg", "build") global_context.set_before("build_wheel", "build") global_context.set_before("build_wininst", "build") global_context.set_before("install", "build") if cmd_name and cmd_name not in ["convert"]: return _wrapped_main(global_context, popts, run_node, top_node, build_node) else: # XXX: is cached package necessary here ? cached_package = None register_stuff(global_context) for cmd_name in global_context.command_names(): register_options(global_context, cmd_name) return _main(global_context, cached_package, popts, run_node, top_node, build_node)
def main(argv=None): if hasattr(os, "getuid"): if os.getuid() == 0: pprint("RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N") ans = input() if not ans.lower() in ["y", "yes"]: raise bento.errors.UsageException("bentomaker execution canceld (not using bentomaker with admin privileges)") if argv is None: argv = sys.argv[1:] options_context = create_global_options_context() popts = parse_global_options(options_context, argv) cmd_name = popts.cmd_name if popts.show_version: print(bento.__version__) return if popts.show_full_version: print(bento.__version__ + "git" + bento.__git_revision__) return source_root = os.path.join(os.getcwd(), os.path.dirname(popts.bento_info)) build_root = os.path.join(os.getcwd(), popts.build_directory) top_node, build_node, run_node = bento.core.node.create_base_nodes(source_root, build_root) if run_node != top_node and run_node.is_src(): raise bento.errors.UsageException("You cannot execute bentomaker in a subdirectory of the source tree !") if run_node != build_node and run_node.is_bld(): raise bento.errors.UsageException("You cannot execute bentomaker in a subdirectory of the build tree !") global_context = GlobalContext(build_node.make_node(CMD_DATA_DUMP), CommandRegistry(), ContextRegistry(), OptionsRegistry(), CommandScheduler()) global_context.register_options_context_without_command("", options_context) if not popts.disable_autoconfigure: global_context.set_before("build", "configure") global_context.set_before("build_egg", "build") global_context.set_before("build_wheel", "build") global_context.set_before("build_wininst", "build") global_context.set_before("install", "build") if cmd_name and cmd_name not in ["convert"]: return _wrapped_main(global_context, popts, run_node, top_node, build_node) else: # XXX: is cached package necessary here ? cached_package = None register_stuff(global_context) for cmd_name in global_context.command_names(): register_options(global_context, cmd_name) return _main(global_context, cached_package, popts, run_node, top_node, build_node)
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