How to use the lbuild.node.BaseNode function in lbuild

To help you get started, we’ve selected a few lbuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modm-io / lbuild / lbuild / node.py View on Github external
def _resolve(self, query, default):
        # :*   -> non-recursive
        # :**  -> recursive
        query = ":".join(p if p else "*" for p in query.strip().split(":"))
        try:
            qquery = ":" + query.replace(":**", "")
            if self.root._type == self.Type.PARSER:
                qquery = ":lbuild" + qquery
            found_modules = BaseNode.resolver.glob(self.root, qquery)
        except (anytree.resolver.ChildResolverError, anytree.resolver.ResolverError):
            return default

        modules = found_modules
        if query.endswith(":**"):
            for module in found_modules:
                modules.extend(module.descendants)

        return modules if modules else default
github modm-io / lbuild / lbuild / repository.py View on Github external
self._format_short_description = lbuild.format.format_short_description

        self._submodules = []
        self._options = []
        self._filters = []
        self._queries = []
        self._ignore_patterns = []
        self._configurations = []

    def init(self):
        lbuild.utils.with_forward_exception(self,
                lambda: self._functions['init'](lf.RepositoryInitFacade(self)))
        return Repository(self)


class Repository(BaseNode):
    """
    A repository is a set of modules.
    """

    def __init__(self, repo: RepositoryInit):
        """
        Construct a new repository object.

        At the construction time of the object, the name of repository may not
        be known e.g. if the repository is loaded from a `repo.lb` file.
        """
        BaseNode.__init__(self, repo.name, self.Type.REPOSITORY, self)

        self._filename = repo._filename
        self._description = repo.description
        self._functions = repo._functions
github modm-io / lbuild / lbuild / repository.py View on Github external
import sys
import glob
import logging
import fnmatch

import lbuild.utils

import lbuild.exception as le
import lbuild.facade as lf
from .node import BaseNode


LOGGER = logging.getLogger('lbuild.repository')


class Configuration(BaseNode):
    def __init__(self, name, path, description):
        BaseNode.__init__(self, name, BaseNode.Type.CONFIG)
        self._config = path
        if description is None:
            description = ""
        self._description = description


def load_repository_from_file(parser, filename):
    repo = RepositoryInit(parser, filename)
    try:
        repo._functions = lbuild.node.load_functions_from_file(
            repo, filename,
            required=['init', 'prepare'], optional=['build'])
    except FileNotFoundError as error:
        raise le.LbuildParserAddRepositoryNotFoundException(parser, filename)
github modm-io / lbuild / lbuild / exception.py View on Github external
        msg += "\n\n{}".format(root.render(lambda n: n.type in lbuild.node.BaseNode.Type))
    return msg
github modm-io / lbuild / lbuild / module.py View on Github external
for submodule in self._submodules:
            if isinstance(submodule, str):
                modules = load_module_from_file(repository=self.repository,
                                                filename=os.path.join(self.filepath, submodule),
                                                parent=self.fullname)
            else:
                modules = load_module_from_object(repository=self.repository,
                                                  module_obj=submodule,
                                                  filename=self.filename,
                                                  parent=self.fullname)
            all_modules.extend(modules)
        return all_modules


class Module(BaseNode):

    def __init__(self, module: ModuleInit):
        """
        Create new module definition.

        Args:
            repository: Parent repository of the module.
            filename: Full path of the module file.
            path: Path to the module file. Used as base for relative paths
                during the building step of the module.
        """
        BaseNode.__init__(self, module.name, self.Type.MODULE, module.repository)

        self._filename = module.filename
        self._functions = module.functions
        self._description = module.description
github modm-io / lbuild / lbuild / format.py View on Github external
def ansi_escape(obj=None):
    if PLAIN:
        # The terminal does not support color
        return ""

    COLORFUL_REPLACEMENT = {
        "reset": "\033[0m",
        "bold": "\033[1m",
        "underlined": "\033[4m",
        "no_bold": "\033[22m",
        "no_underlined": "\033[24m",
        "close_fg_color": "\033[39m",
    }

    name = obj
    if isinstance(obj, lbuild.node.BaseNode):
        name = obj.type.name.lower()

    col = COLOR_SCHEME.get(name, "nope")
    if col == "nope":
        col = COLORFUL_REPLACEMENT.get(name, None)

    return str(col) if col is not None else ""
github modm-io / lbuild / lbuild / exception.py View on Github external
def _dump(node):
    msg = ""
    if isinstance(node, lbuild.node.BaseNode):
        root = node.root
        msg = "\n\n\n{}".format(_hl("Current project configuration:"))
        # Render configuration if we know it
        if isinstance(root, lbuild.parser.Parser):
            msg += "\n\n{}".format(root._config.root.render())
        # Render as much tree in developer view as possible
        msg += "\n\n{}".format(root.render(lambda n: n.type in lbuild.node.BaseNode.Type))
    return msg