# Path: bento/core/options.py
# class PackageOptions(object):
#     @classmethod
#     def __from_data(cls, data):
#         raw = raw_parse(data)
#         kw = raw_to_options_kw(raw)
#         return cls(**kw)
# 
#     @classmethod
#     def from_string(cls, str):
#         """Create a PackageOptions instance from a bento.info content."""
#         return cls.__from_data(str)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """Create a PackageOptions instance from a bento.info file."""
#         fid = open(filename, 'r')
#         try:
#             data = fid.read()
#             return cls.__from_data(data)
#         finally:
#             fid.close()
# 
#     def __init__(self, name, path_options=None, flag_options=None):
#         """Create a PackageOptions instance
# 
#         Parameters
#         ----------
#         name: str
#             name of the package
#         path_options: dict
#             dict of path options
#         flag_options: dict
#             dict of flag options
#         """
#         self.name = name
# 
#         if not path_options:
#             self.path_options = {}
#         else:
#             self.path_options = path_options
# 
#         if not flag_options:
#             self.flag_options = {}
#         else:
#             self.flag_options = flag_options
# 
# Path: bento/commands/wrapper_utils.py
# def run_command_in_context(context, cmd, pre_hooks=None, post_hooks=None):
#     """Run the given command instance with the hooks within its context. """
#     if pre_hooks is None:
#         pre_hooks = []
#     if post_hooks is None:
#         post_hooks = []
# 
#     top_node = context.top_node
#     cmd_funcs = [(cmd.run, top_node.abspath())]
# 
#     def _run_hooks(hooks):
#         for hook in hooks:
#             local_node = top_node.find_dir(relpath(hook.local_dir, top_node.abspath()))
#             context.pre_recurse(local_node)
#             try:
#                 hook(context)
#             finally:
#                 context.post_recurse()
# 
#     context.init()
#     try:
#         cmd.init(context)
# 
#         _run_hooks(pre_hooks)
# 
#         context.configure()
# 
#         while cmd_funcs:
#             cmd_func, local_dir = cmd_funcs.pop(0)
#             local_node = top_node.find_dir(relpath(local_dir, top_node.abspath()))
#             context.pre_recurse(local_node)
#             try:
#                 cmd_func(context)
#             finally:
#                 context.post_recurse()
# 
#         _run_hooks(post_hooks)
# 
#         cmd.finish(context)
#     finally:
#         context.finish()
# 
#     return cmd, context
# 
# Path: bento/backends/yaku_backend.py
# class ConfigureYakuContext(ConfigureContext):
#     def __init__(self, global_context, cmd_argv, options_context, pkg, run_node):
#         super(ConfigureYakuContext, self).__init__(global_context, cmd_argv, options_context, pkg, run_node)
#         build_path = run_node._ctx.bldnode.path_from(run_node)
#         source_path = run_node._ctx.srcnode.path_from(run_node)
#         self.yaku_context = yaku.context.get_cfg(src_path=source_path, build_path=build_path)
# 
#     def configure(self):
#         extensions = get_extensions(self.pkg, self.run_node)
#         libraries = get_compiled_libraries(self.pkg, self.run_node)
# 
#         yaku_ctx = self.yaku_context
#         if extensions or libraries:
#             for t in ["ctasks", "pyext"]:
#                 try:
#                     yaku_ctx.use_tools([t])
#                 except yaku.errors.ConfigurationFailure:
#                     e = extract_exception()
#                     raise ConfigurationError(str(e))
# 
#     def finish(self):
#         super(ConfigureYakuContext, self).finish()
#         self.yaku_context.store()
# 
#     def pre_recurse(self, local_node):
#         super(ConfigureYakuContext, self).pre_recurse(local_node)
#         self._old_path = self.yaku_context.path
#         self.yaku_context.path = self.yaku_context.path.make_node(self.local_node.path_from(self.top_node))
# 
#     def post_recurse(self):
#         self.yaku_context.path = self._old_path
#         super(ConfigureYakuContext, self).post_recurse()


import os
import sys
import shutil
import tempfile
import posixpath
import mock
from bento.compat.api.moves \
    import \
        unittest
from bento.core.options \
    import \
        PackageOptions
from bento.core \
    import \
        PackageDescription
from bento.core.node \
    import \
        create_root_with_source_tree
from bento.commands.wrapper_utils \
    import \
        run_command_in_context
from bento.commands.tests.utils \
    import \
        prepare_configure
from bento.backends.yaku_backend \
    import \
        ConfigureYakuContext
from bento.commands.configure \
    import \
        _compute_scheme, set_scheme_unix, set_scheme_win32

class TestConfigureCommand(unittest.TestCase):
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.root = create_root_with_source_tree(self.d, os.path.join(self.d, "build"))

        self.old_dir = os.getcwd()
        os.chdir(self.d)

    def tearDown(self):
        os.chdir(self.old_dir)
        shutil.rmtree(self.d)

    def test_simple(self):
        root = self.root
        run_node = root.find_node(self.d)

        conf, configure = prepare_configure(run_node, BENTO_INFO, ConfigureYakuContext)
        run_command_in_context(conf, configure)

    def test_flags(self):
        bento_info = """\
Name: foo

Flag: floupi
    Description: some floupi flag
    Default: true
"""
        run_node = self.root.find_node(self.d)


# Path: bento/core/options.py
# class PackageOptions(object):
#     @classmethod
#     def __from_data(cls, data):
#         raw = raw_parse(data)
#         kw = raw_to_options_kw(raw)
#         return cls(**kw)
# 
#     @classmethod
#     def from_string(cls, str):
#         """Create a PackageOptions instance from a bento.info content."""
#         return cls.__from_data(str)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """Create a PackageOptions instance from a bento.info file."""
#         fid = open(filename, 'r')
#         try:
#             data = fid.read()
#             return cls.__from_data(data)
#         finally:
#             fid.close()
# 
#     def __init__(self, name, path_options=None, flag_options=None):
#         """Create a PackageOptions instance
# 
#         Parameters
#         ----------
#         name: str
#             name of the package
#         path_options: dict
#             dict of path options
#         flag_options: dict
#             dict of flag options
#         """
#         self.name = name
# 
#         if not path_options:
#             self.path_options = {}
#         else:
#             self.path_options = path_options
# 
#         if not flag_options:
#             self.flag_options = {}
#         else:
#             self.flag_options = flag_options
# 
# Path: bento/commands/wrapper_utils.py
# def run_command_in_context(context, cmd, pre_hooks=None, post_hooks=None):
#     """Run the given command instance with the hooks within its context. """
#     if pre_hooks is None:
#         pre_hooks = []
#     if post_hooks is None:
#         post_hooks = []
# 
#     top_node = context.top_node
#     cmd_funcs = [(cmd.run, top_node.abspath())]
# 
#     def _run_hooks(hooks):
#         for hook in hooks:
#             local_node = top_node.find_dir(relpath(hook.local_dir, top_node.abspath()))
#             context.pre_recurse(local_node)
#             try:
#                 hook(context)
#             finally:
#                 context.post_recurse()
# 
#     context.init()
#     try:
#         cmd.init(context)
# 
#         _run_hooks(pre_hooks)
# 
#         context.configure()
# 
#         while cmd_funcs:
#             cmd_func, local_dir = cmd_funcs.pop(0)
#             local_node = top_node.find_dir(relpath(local_dir, top_node.abspath()))
#             context.pre_recurse(local_node)
#             try:
#                 cmd_func(context)
#             finally:
#                 context.post_recurse()
# 
#         _run_hooks(post_hooks)
# 
#         cmd.finish(context)
#     finally:
#         context.finish()
# 
#     return cmd, context
# 
# Path: bento/backends/yaku_backend.py
# class ConfigureYakuContext(ConfigureContext):
#     def __init__(self, global_context, cmd_argv, options_context, pkg, run_node):
#         super(ConfigureYakuContext, self).__init__(global_context, cmd_argv, options_context, pkg, run_node)
#         build_path = run_node._ctx.bldnode.path_from(run_node)
#         source_path = run_node._ctx.srcnode.path_from(run_node)
#         self.yaku_context = yaku.context.get_cfg(src_path=source_path, build_path=build_path)
# 
#     def configure(self):
#         extensions = get_extensions(self.pkg, self.run_node)
#         libraries = get_compiled_libraries(self.pkg, self.run_node)
# 
#         yaku_ctx = self.yaku_context
#         if extensions or libraries:
#             for t in ["ctasks", "pyext"]:
#                 try:
#                     yaku_ctx.use_tools([t])
#                 except yaku.errors.ConfigurationFailure:
#                     e = extract_exception()
#                     raise ConfigurationError(str(e))
# 
#     def finish(self):
#         super(ConfigureYakuContext, self).finish()
#         self.yaku_context.store()
# 
#     def pre_recurse(self, local_node):
#         super(ConfigureYakuContext, self).pre_recurse(local_node)
#         self._old_path = self.yaku_context.path
#         self.yaku_context.path = self.yaku_context.path.make_node(self.local_node.path_from(self.top_node))
# 
#     def post_recurse(self):
#         self.yaku_context.path = self._old_path
#         super(ConfigureYakuContext, self).post_recurse()


# Path: bento/commands/tests/test_configure.py
import os
import sys
import shutil
import tempfile
import posixpath
import mock
from bento.compat.api.moves \
    import \
        unittest
from bento.core.options \
    import \
        PackageOptions
from bento.core \
    import \
        PackageDescription
from bento.core.node \
    import \
        create_root_with_source_tree
from bento.commands.wrapper_utils \
    import \
        run_command_in_context
from bento.commands.tests.utils \
    import \
        prepare_configure
from bento.backends.yaku_backend \
    import \
        ConfigureYakuContext
from bento.commands.configure \
    import \
        _compute_scheme, set_scheme_unix, set_scheme_win32


class TestConfigureCommand(unittest.TestCase):
    def setUp(self):
        self.d = tempfile.mkdtemp()
        self.root = create_root_with_source_tree(self.d, os.path.join(self.d, "build"))

        self.old_dir = os.getcwd()
        os.chdir(self.d)

    def tearDown(self):
        os.chdir(self.old_dir)
        shutil.rmtree(self.d)

    def test_simple(self):
        root = self.root
        run_node = root.find_node(self.d)

        conf, configure = prepare_configure(run_node, BENTO_INFO, ConfigureYakuContext)
        run_command_in_context(conf, configure)

    def test_flags(self):
        bento_info = """\
Name: foo

Flag: floupi
    Description: some floupi flag
    Default: true
"""
        run_node = self.root.find_node(self.d)


        conf, configure = prepare_configure(run_node, bento_info, ConfigureYakuContext, ["--floupi=false"])