Skip to main content

Alternative parser for bitbake recipes

Project description

oelint-parser

Build status PyPI version Python version Downloads

alternative parser for bitbake recipes

API documentation

Find the full API docs here

Examples

from oelint_parser.cls_stash import Stash

# create an stash object
_stash = Stash()

# add any bitbake like file
_stash.AddFile("/some/file")

# Resolves proper cross file dependencies
_stash.Finalize()

# Use _stash.GetItemsFor() method to filter the stash

Get variables from the files

To get variables from the stash object do

from oelint_parser.cls_item import Variable

# get all variables of the name PV from all files
for x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue="PV"):
    print(x)

this returns the raw object representation

Expand raw variables

from oelint_parser.cls_item import Variable

# get all variables of the name PV from all files
for x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue="PV"):
    # raw unexpanded variable
    print(x.VarValue)
    # raw unexpanded variable without quotes
    print(x.VarValueStripped)
    # expanded variable
    print(expand_term(stash, "/some/file", x.VarValueStripped))
    # single items from a list
    print(x.get_items())
    # expanded single items from a list
    print([_stash.ExpandTerm("/some/file", y) for y in x.get_items()])

Filtering

You can filter by multiple items

from oelint_parser.cls_item import Variable

# get all variables of the name PV or BPV from all files
for x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=["PV", "BPV"]):
    # variable name
    print(x.VarName)
    # raw unexpanded variable
    print(x.VarValue)
    # raw unexpanded variable without quotes
    print(x.VarValueStripped)

and you can reduce the list after the initial filtering even more

from oelint_parser.cls_item import Variable

# get all variables of the name PV or BPV from all files if the value is '1.0'
for x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=["PV", "BPV"]).reduce(
                                attribute=Variable.ATTR_VARVAL, attributeValue=["1.0"]):
    # variable name
    print(x.VarName)
    # raw unexpanded variable -> "1.0"
    print(x.VarValue)
    # raw unexpanded variable without quotes -> 1.0
    print(x.VarValueStripped)

but if you need copies from a wider list to smaller lists use

from oelint_parser.cls_item import Variable

_all = _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=["PV", "BPV"])
_pv = _stash.Reduce(_all, attribute=Variable.ATTR_VAR, attributeValue="PV")
_bpv = _stash.Reduce(_all, attribute=Variable.ATTR_VAR, attributeValue="BPV")

for x in _pv:
    # variable name
    print(x.VarName)
    # raw unexpanded variable -> "1.0"
    print(x.VarValue)
    # raw unexpanded variable without quotes -> 1.0
    print(x.VarValueStripped)

Expanding a Variable

To get the effective value of a Variable after parsing you can use

from oelint_parser.cls_item import Variable

result_set = _stash.ExpandVar(attribute=Variable.ATTR_VAR, attributeValue=["PV"]):
print(result_set.get('PV'))

Inline branch expansion

By default the parser will expand parsable and known inline blocks (${@oe.utils.something(...)}) to the branch value that would match if the programmed condition is true.

You can invert this selection by setting negative_inline to True in the Stash object.

E.g.

with some/file being

VAR_1 = "${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', 'foo', 'bar', d)}"

and

from oelint_parser.cls_stash import Stash

# create an stash object
_stash = Stash()

# add any bitbake like file
_stash.AddFile("/some/file")

# Resolves proper cross file dependencies
_stash.Finalize()

the VAR_1's VarValue value would be foo.

With

from oelint_parser.cls_stash import Stash

# create an stash object
_stash = Stash(negative_inline=True)

# add any bitbake like file
_stash.AddFile("/some/file")

# Resolves proper cross file dependencies
_stash.Finalize()

the VAR_1's VarValue value would be bar.

Working with constants

For this library a few basic sets of constant information, such as basic package definitions, known machines and functions are needed. Those can be easily modified, in case you have additional information to add/remove/modify.

The actual database is not directly accessible by the user, but a few methods in the oelint_parse.constants.CONSTANT class do exist. Each of the method accepts a dictionary with the same key mapping as listed below (multilevel paths are displayed a JSON pointer)

key type description getter for information
functions/known list known functions oelint_parse.constants.CONSTANT.FunctionsKnown
functions/order list preferred order of core functions oelint_parse.constants.CONSTANT.FunctionsOrder
images/known-classes list bbclasses to be known to be used in images oelint_parse.constants.CONSTANT.ImagesClasses
images/known-variables list variables known to be used in images oelint_parse.constants.CONSTANT.ImagesVariables
replacements/distros list known distro overrides oelint_parse.constants.CONSTANT.DistrosKnown
replacements/machines list known machine overrides oelint_parse.constants.CONSTANT.MachinesKnown
replacements/mirrors dict known mirrors oelint_parse.constants.CONSTANT.MirrorsKnown
variables/known list known variables oelint_parse.constants.CONSTANT.VariablesKnown
variables/mandatory list variables mandatory to a recipe oelint_parse.constants.CONSTANT.VariablesMandatory
variables/order list preferred order of variables oelint_parse.constants.CONSTANT.VariablesOrder
variables/protected list variables not to be used in recipes oelint_parse.constants.CONSTANT.VariablesProtected
variables/protected-append list variables not to be used in bbappends oelint_parse.constants.CONSTANT.VariablesProtectedAppend
variables/suggested list suggested variable in a recipe oelint_parse.constants.CONSTANT.VariablesSuggested
sets/base dict base set of variables always used for value expansion oelint_parse.constants.CONSTANT.SetsBase

For additional constants

from oelint_parser.constants import CONSTANTS

CONSTANTS.GetByPath('/-joined path')

will offer access

Contributing

Before any contribution please run the following

python3 -m venv --clear .env
. .env/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
flake8 oelint_parser/ tests/
pytest
./gendoc.sh

Project details


Release history Release notifications | RSS feed

This version

5.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oelint_parser-5.1.0.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

oelint_parser-5.1.0-py2.py3-none-any.whl (49.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file oelint_parser-5.1.0.tar.gz.

File metadata

  • Download URL: oelint_parser-5.1.0.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for oelint_parser-5.1.0.tar.gz
Algorithm Hash digest
SHA256 2e3379f8dab56e2220fd5892b9953b31440df6221ec2d54c4cb32893a34f84f1
MD5 e383cb23581b792f6b3c94daa41eef87
BLAKE2b-256 6e38c5aac33328a09a98d170a26a988ef5e30c229f45cdd772feca1a3b03051f

See more details on using hashes here.

File details

Details for the file oelint_parser-5.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for oelint_parser-5.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fdcd8653746106d48a2291a63cfde323f94de036327727be83114fb025b51d9b
MD5 092f976a8f30e149bbc76fa67817336f
BLAKE2b-256 1ea6d82e34ab23275de7bf0b7a83abdafa636af8881d5a2ee42f26513b934e02

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page