How to use lbuild - 10 common examples

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 / format.py View on Github external
if node._type == node.Type.REPOSITORY:
        name = _cw(node.name + " @ " + os.path.relpath(node._filepath))
    elif node._type == node.Type.OPTION:
        name = format_option_name(node, fullname=False)
    elif node._type in {node.Type.MODULE, node.Type.CONFIG}:
        name = _cw(node.fullname).wrap(node)
    elif node._type in {node.Type.QUERY, node.Type.COLLECTOR}:
        name = name.wrap("bold")
    if node._type in {node.Type.MODULE} and node._selected:
        name = name.wrap("underlined")

    descr = (class_name + _cw("(") + name + _cw(")")).wrap(node)

    offset = (node.depth - depth) * 4
    if node._type == node.Type.OPTION:
        descr += _cw(" = ")
        descr += format_option_value_description(node, offset=offset + len(descr), single_line=True)
    elif node._type == node.Type.COLLECTOR:
        descr += _cw(" in [")
        descr += format_option_values(node, offset=offset + len(descr), single_line=True)
        descr += _cw("]")

    descr += _cw("   " + node.short_description)

    return descr.limit(offset)
github modm-io / lbuild / lbuild / format.py View on Github external
if node._type == node.Type.QUERY:
        class_name = class_name.wrap("underlined")

    name = _cw(node.name)
    if node._type == node.Type.REPOSITORY:
        name = _cw(node.name + " @ " + os.path.relpath(node._filepath))
    elif node._type == node.Type.OPTION:
        name = format_option_name(node, fullname=False)
    elif node._type in {node.Type.MODULE, node.Type.CONFIG}:
        name = _cw(node.fullname).wrap(node)
    elif node._type in {node.Type.QUERY, node.Type.COLLECTOR}:
        name = name.wrap("bold")
    if node._type in {node.Type.MODULE} and node._selected:
        name = name.wrap("underlined")

    descr = (class_name + _cw("(") + name + _cw(")")).wrap(node)

    offset = (node.depth - depth) * 4
    if node._type == node.Type.OPTION:
        descr += _cw(" = ")
        descr += format_option_value_description(node, offset=offset + len(descr), single_line=True)
    elif node._type == node.Type.COLLECTOR:
        descr += _cw(" in [")
        descr += format_option_values(node, offset=offset + len(descr), single_line=True)
        descr += _cw("]")

    descr += _cw("   " + node.short_description)

    return descr.limit(offset)
github modm-io / lbuild / lbuild / option.py View on Github external
def to_set(self, values):
        if isinstance(values, str):
            values = [v.strip() for v in values.split(",")]
        values = list(map(self._option._in, lbuild.utils.listify(values)))
        return values
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
.format(_hl(module), _hl(_rel(file)), _call_site(), _hl(conflict)))
        super().__init__(msg)


# =========================== REPOSITORY EXCEPTIONS ===========================
class LbuildRepositoryNoNameException(LbuildDumpConfigException):
    def __init__(self, parser, repo): # RepositoryInit
        msg = ("The '{}' function must set a repo name!\n{}\n"
               "Hint:\n\n"
               "    def init(repo):\n"
               "        {}"
               .format(_hl("init"), _call_site(repo._functions['init']),
                       _hl("repo.name = \":parent:name\"")))
        super().__init__(msg, parser)

class LbuildRepositoryAddModuleNotFoundException(LbuildDumpConfigException):
    def __init__(self, repo, path):
        msg = ("Module file '{}' not found!\n{}\n"
               "Hint: Use '{}' or '{}' for relative paths."
               .format(_hl(_rel(path)), _call_site(),
                       _hl("localpath(path)"), _hl("repopath(path)")))
        super().__init__(msg, repo)

class LbuildRepositoryAddModuleRecursiveNotFoundException(LbuildDumpConfigException):
    def __init__(self, repo, path):
        msg = ("Found no module files in '{}'!\n{}\n"
               "Hint: Use '{}' or '{}' for relative paths."
               .format(_hl(_rel(path)), _call_site(),
                       _hl("localpath(path)"), _hl("repopath(path)")))
        super().__init__(msg, repo)

class LbuildRepositoryDuplicateChildException(LbuildDumpConfigException):
github modm-io / lbuild / lbuild / exception.py View on Github external
"    prepare(repo, options):\n"
               "        repo.add_modules({})\n"
               "        repo.add_modules_recursive({})\n"
               .format(_hl(repo.fullname), _hl(_rel(repo._filename)),
                       _hl("prepare"), _hl('"path/to/module.lb"'), _hl('"directory"')))
        super().__init__(msg, repo)

class LbuildParserDuplicateModuleException(LbuildDumpConfigException):
    def __init__(self, parser, error):
        msg = ("{}({}) already has a submodule named '{}'!\n{}"
               .format(error.parent.class_name, _hl(error.parent.fullname),
                       _hl(error.child.fullname), error.hint))
        super().__init__(msg, parser)

# ============================= MODULE EXCEPTIONS =============================
class LbuildModuleNoNameException(LbuildDumpConfigException):
    def __init__(self, module): # ModuleInit
        msg = ("The '{}' function must set a module name!\n{}\n"
               "Hint:\n\n"
               "    def init(module):\n"
               "        {}"
               .format(_hl("init"), _call_site(module.functions['init']),
                       _hl("module.name = \":parent:name\"")))
        super().__init__(msg, module.repository)

class LbuildModuleNoReturnAvailableException(LbuildDumpConfigException):
    def __init__(self, module): # ModuleInit
        msg = ("The '{}' function of Module({}) must return a {}!\n{}\n"
               "Hint: The return value indicates whether or not this module"
               "is available given the repository options:\n\n"
               "    def prepare(module, options):\n"
               "        is_available = {{check repo options}}\n"
github modm-io / lbuild / lbuild / exception.py View on Github external
msg = "{}{}\n{}".format(
                error.prompt, _call_site(module._functions["prepare"]), error.hint)
        super().__init__(msg, error.node)


# ============================ BUILDLOG EXCEPTIONS ============================
class LbuildBuildlogOverwritingFileException(LbuildException):
    def __init__(self, module, file, conflict): # RepositoryInit
        msg = ("Module({}) is overwriting file '{}'!\n{}\n"
               "Hint: File previously generated by Module({})!"
               .format(_hl(module), _hl(_rel(file)), _call_site(), _hl(conflict)))
        super().__init__(msg)


# =========================== REPOSITORY EXCEPTIONS ===========================
class LbuildRepositoryNoNameException(LbuildDumpConfigException):
    def __init__(self, parser, repo): # RepositoryInit
        msg = ("The '{}' function must set a repo name!\n{}\n"
               "Hint:\n\n"
               "    def init(repo):\n"
               "        {}"
               .format(_hl("init"), _call_site(repo._functions['init']),
                       _hl("repo.name = \":parent:name\"")))
        super().__init__(msg, parser)

class LbuildRepositoryAddModuleNotFoundException(LbuildDumpConfigException):
    def __init__(self, repo, path):
        msg = ("Module file '{}' not found!\n{}\n"
               "Hint: Use '{}' or '{}' for relative paths."
               .format(_hl(_rel(path)), _call_site(),
                       _hl("localpath(path)"), _hl("repopath(path)")))
        super().__init__(msg, repo)
github modm-io / lbuild / lbuild / exception.py View on Github external
"Hint: Check your config paths in '{}':\n\n"
            "   def init(repo):\n"
            "       repo.add_configuration(name, \"{}\", description)"
            .format(_call_site(repo._functions['init']),
                    _hl(_rel(repo._filename)), _hl(filename)))
        super().__init__(filename, message)
        self.node = repo

class LbuildConfigAliasNotFoundException(LbuildConfigException):
    def __init__(self, parser, alias):
        message = (": alias '{}' not found in any repository!"
                   .format(_hl(alias)) + _dump(parser))
        filename = next( (f for f, a in parser._config_flat._extends.items() if alias in a), None)
        super().__init__(filename, message)

class LbuildConfigAliasAmbiguousException(LbuildConfigException):
    def __init__(self, parser, alias, matches):
        aliases = _bp(sorted(c.fullname for c in matches))
        message = (": alias '{}' is ambiguous!\n"
                   "Hint: Found multiple matches:\n\n{}"
                   .format(_hl(alias), aliases) + _dump(parser))
        filename = next( (f for f, a in parser._config_flat._extends.items() if alias in a), None)
        super().__init__(filename, message)


# ============================= OPTION EXCEPTIONS =============================
class LbuildOptionException(LbuildException):
    def __init__(self, message, option):
        msg = ("{}({}){}\n{}\n"
               .format(option.class_name, _hl(_rel(option.fullname)),
                       message, option.description))
        super().__init__(msg, option)