示例#1
0
文件: dist.py 项目: jjehannet/Bento
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        if not "bento_info" in attrs:
            bento_info = "bento.info"
        else:
            bento_info = attrs["bento.info"]
        self.pkg = PackageDescription.from_file(bento_info)
        package_options = PackageOptions.from_file(bento_info)

        attrs = _setup_cmd_classes(attrs)

        d = pkg_to_distutils_meta(self.pkg)
        attrs.update(d)

        Distribution.__init__(self, attrs)

        self.packages = self.pkg.packages
        self.py_modules = self.pkg.py_modules
        if hasattr(self, "entry_points"):
            if self.entry_points is None:
                self.entry_points = {}
            console_scripts = [
                e.full_representation() for e in self.pkg.executables.values()
            ]
            if "console_scripts" in self.entry_points:
                self.entry_points["console_scripts"].extend(console_scripts)
            else:
                self.entry_points["console_scripts"] = console_scripts

        source_root = os.getcwd()
        build_root = os.path.join(source_root, "build")
        root = create_root_with_source_tree(source_root, build_root)
        self.top_node = root._ctx.srcnode
        self.build_node = root._ctx.bldnode
        self.run_node = root._ctx.srcnode

        self.global_context = global_context_factory(package_options)
        mods = set_main(self.pkg, self.top_node, self.build_node)
        self._setup_hooks(self.pkg, self.global_context, mods)
示例#2
0
文件: dist.py 项目: pberkes/Bento
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        if not "bento_info" in attrs:
            bento_info = "bento.info"
        else:
            bento_info = attrs["bento.info"]
        self.pkg = PackageDescription.from_file(bento_info)
        self.package_options = PackageOptions.from_file(bento_info)


        attrs = _setup_cmd_classes(attrs)

        d = pkg_to_distutils_meta(self.pkg)
        attrs.update(d)

        Distribution.__init__(self, attrs)

        self.packages = self.pkg.packages
        self.py_modules = self.pkg.py_modules
        if hasattr(self, "entry_points"):
            if self.entry_points is None:
                self.entry_points = {}
            console_scripts = [e.full_representation() for e in self.pkg.executables.values()]
            if "console_scripts" in self.entry_points:
                self.entry_points["console_scripts"].extend(console_scripts)
            else:
                self.entry_points["console_scripts"] = console_scripts

        source_root = os.getcwd()
        build_root = os.path.join(source_root, "build")
        root = create_root_with_source_tree(source_root, build_root)
        self.top_node = root._ctx.srcnode
        self.build_node = root._ctx.bldnode
        self.run_node = root._ctx.srcnode

        self.global_context = global_context_factory(self.package_options)
        modules = set_main(self.top_node, self.build_node, self.pkg)
示例#3
0
def _wrapped_main(global_context, popts, run_node, top_node, build_node):
    # Some commands work without a bento description file (convert, help)
    # FIXME: this should not be called here then - clearly separate commands
    # which require bento.info from the ones who do not
    bento_info_node = top_node.find_node(BENTO_SCRIPT)
    if bento_info_node is not None:
        db_node = build_node.make_node(DB_FILE)
        cached_package = CachedPackage(db_node)
        package = cached_package.get_package(bento_info_node)
        package_options = cached_package.get_options(bento_info_node)

        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])()
        global_context.register_package_options(package_options)

        mods = set_main(package, top_node, build_node)

    else:
        warnings.warn("No %r file in current directory - only generic options "
                      "will be displayed" % BENTO_SCRIPT)
        cached_package = None
        package_options = None
        mods = []

    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)
    register_stuff(global_context)
    for cmd_name in global_context.command_names():
        register_options(global_context, cmd_name)

    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):
            register_options(global_context, cmd_name)

    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)

    try:
        return _main(global_context, cached_package, popts, run_node, top_node,
                     build_node)
    finally:
        if shutdown_hooks:
            shutdown_hooks[0](global_context)
示例#4
0
def _wrapped_main(global_context, popts, run_node, top_node, build_node):
    # Some commands work without a bento description file (convert, help)
    # FIXME: this should not be called here then - clearly separate commands
    # which require bento.info from the ones who do not
    bento_info_node = top_node.find_node(BENTO_SCRIPT)
    if bento_info_node is not None:
        db_node = build_node.make_node(DB_FILE)
        cached_package = CachedPackage(db_node)
        package = cached_package.get_package(bento_info_node)
        package_options = cached_package.get_options(bento_info_node)

        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])()
        global_context.register_package_options(package_options)

        mods = set_main(package, top_node, build_node)

    else:
        warnings.warn("No %r file in current directory - only generic options "
                      "will be displayed" % BENTO_SCRIPT)
        cached_package = None
        package_options = None
        mods = []

    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)
    register_stuff(global_context)
    for cmd_name in global_context.command_names():
        register_options(global_context, cmd_name)

    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):
            register_options(global_context, cmd_name)

    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)

    try:
        return _main(global_context, cached_package, popts, run_node, top_node, build_node)
    finally:
        if shutdown_hooks:
            shutdown_hooks[0](global_context)