oelint-parser


Nameoelint-parser JSON
Version 8.4.1 PyPI version JSON
download
home_pagehttps://github.com/priv-kweihmann/oelint-parser
SummaryAlternative parser for bitbake recipes
upload_time2025-09-02 11:27:37
maintainerNone
docs_urlNone
authorKonrad Weihmann
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements regex Deprecated
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # oelint-parser

![Build status](https://github.com/priv-kweihmann/oelint-parser/workflows/Python%20package/badge.svg)
[![PyPI version](https://badge.fury.io/py/oelint-parser.svg)](https://badge.fury.io/py/oelint-parser)
[![Python version](https://img.shields.io/pypi/pyversions/oelint-parser)](https://img.shields.io/pypi/pyversions/oelint-parser)
[![Downloads](https://img.shields.io/pypi/dm/oelint-parser)](https://img.shields.io/pypi/dm/oelint-parser)

alternative parser for bitbake recipes

## API documentation

Find the full API docs [here](docs/api-documentation.md)

## Examples

```python
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

```python
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

```python
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, objref=x) for y in x.get_items()])
```

### Filtering

You can filter by multiple items

```python
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

```python
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

```python
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

```python
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

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

and

```python
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

```python
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`           |
| sets/base                  | dict | base set of variables always used for value expansion | `oelint_parse.constants.CONSTANT.SetsBase`                 |

For additional constants

```python
from oelint_parser.constants import CONSTANTS

CONSTANTS.GetByPath('/-joined path')
```

will offer access

## Contributing

Before any contribution please run the following

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/priv-kweihmann/oelint-parser",
    "name": "oelint-parser",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Konrad Weihmann",
    "author_email": "kweihmann@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/3e/31c81833ee9a45253ac8ca6c6d0ab80016b93365b3972a51fd16181c2e7e/oelint_parser-8.4.1.tar.gz",
    "platform": null,
    "description": "# oelint-parser\n\n![Build status](https://github.com/priv-kweihmann/oelint-parser/workflows/Python%20package/badge.svg)\n[![PyPI version](https://badge.fury.io/py/oelint-parser.svg)](https://badge.fury.io/py/oelint-parser)\n[![Python version](https://img.shields.io/pypi/pyversions/oelint-parser)](https://img.shields.io/pypi/pyversions/oelint-parser)\n[![Downloads](https://img.shields.io/pypi/dm/oelint-parser)](https://img.shields.io/pypi/dm/oelint-parser)\n\nalternative parser for bitbake recipes\n\n## API documentation\n\nFind the full API docs [here](docs/api-documentation.md)\n\n## Examples\n\n```python\nfrom oelint_parser.cls_stash import Stash\n\n# create an stash object\n_stash = Stash()\n\n# add any bitbake like file\n_stash.AddFile(\"/some/file\")\n\n# Resolves proper cross file dependencies\n_stash.Finalize()\n\n# Use _stash.GetItemsFor() method to filter the stash\n```\n\n### Get variables from the files\n\nTo get variables from the stash object do\n\n```python\nfrom oelint_parser.cls_item import Variable\n\n# get all variables of the name PV from all files\nfor x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=\"PV\"):\n    print(x)\n```\n\nthis returns the raw object representation\n\n### Expand raw variables\n\n```python\nfrom oelint_parser.cls_item import Variable\n\n# get all variables of the name PV from all files\nfor x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=\"PV\"):\n    # raw unexpanded variable\n    print(x.VarValue)\n    # raw unexpanded variable without quotes\n    print(x.VarValueStripped)\n    # expanded variable\n    print(expand_term(stash, \"/some/file\", x.VarValueStripped))\n    # single items from a list\n    print(x.get_items())\n    # expanded single items from a list\n    print([_stash.ExpandTerm(\"/some/file\", y, objref=x) for y in x.get_items()])\n```\n\n### Filtering\n\nYou can filter by multiple items\n\n```python\nfrom oelint_parser.cls_item import Variable\n\n# get all variables of the name PV or BPV from all files\nfor x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=[\"PV\", \"BPV\"]):\n    # variable name\n    print(x.VarName)\n    # raw unexpanded variable\n    print(x.VarValue)\n    # raw unexpanded variable without quotes\n    print(x.VarValueStripped)\n```\n\nand you can reduce the list after the initial filtering even more\n\n```python\nfrom oelint_parser.cls_item import Variable\n\n# get all variables of the name PV or BPV from all files if the value is '1.0'\nfor x in _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=[\"PV\", \"BPV\"]).reduce(\n                                attribute=Variable.ATTR_VARVAL, attributeValue=[\"1.0\"]):\n    # variable name\n    print(x.VarName)\n    # raw unexpanded variable -> \"1.0\"\n    print(x.VarValue)\n    # raw unexpanded variable without quotes -> 1.0\n    print(x.VarValueStripped)\n```\n\nbut if you need copies from a wider list to smaller lists use\n\n```python\nfrom oelint_parser.cls_item import Variable\n\n_all = _stash.GetItemsFor(attribute=Variable.ATTR_VAR, attributeValue=[\"PV\", \"BPV\"])\n_pv = _stash.Reduce(_all, attribute=Variable.ATTR_VAR, attributeValue=\"PV\")\n_bpv = _stash.Reduce(_all, attribute=Variable.ATTR_VAR, attributeValue=\"BPV\")\n\nfor x in _pv:\n    # variable name\n    print(x.VarName)\n    # raw unexpanded variable -> \"1.0\"\n    print(x.VarValue)\n    # raw unexpanded variable without quotes -> 1.0\n    print(x.VarValueStripped)\n```\n\n### Expanding a Variable\n\nTo get the effective value of a Variable after parsing you can use\n\n```python\nfrom oelint_parser.cls_item import Variable\n\nresult_set = _stash.ExpandVar(attribute=Variable.ATTR_VAR, attributeValue=[\"PV\"]):\nprint(result_set.get('PV'))\n```\n\n### Inline branch expansion\n\nBy default the parser will expand parsable and known inline blocks (``${@oe.utils.something(...)}``) to the branch\nvalue that would match if the programmed condition is ``true``.\n\nYou can invert this selection by setting ``negative_inline`` to ``True`` in the ``Stash`` object.\n\nE.g.\n\nwith ``some/file`` being\n\n```text\nVAR_1 = \"${@bb.utils.contains('BUILDHISTORY_FEATURES', 'image', 'foo', 'bar', d)}\"\n```\n\nand\n\n```python\nfrom oelint_parser.cls_stash import Stash\n\n# create an stash object\n_stash = Stash()\n\n# add any bitbake like file\n_stash.AddFile(\"/some/file\")\n\n# Resolves proper cross file dependencies\n_stash.Finalize()\n```\n\nthe ``VAR_1``'s  ``VarValue`` value would be ``foo``.\n\nWith\n\n```python\nfrom oelint_parser.cls_stash import Stash\n\n# create an stash object\n_stash = Stash(negative_inline=True)\n\n# add any bitbake like file\n_stash.AddFile(\"/some/file\")\n\n# Resolves proper cross file dependencies\n_stash.Finalize()\n```\n\nthe ``VAR_1``'s ``VarValue`` value would be ``bar``.\n\n## Working with constants\n\nFor this library a few basic sets of constant information, such as basic package definitions, known machines and functions are\nneeded.\nThose can be easily modified, in case you have additional information to add/remove/modify.\n\nThe actual database is not directly accessible by the user, but a few methods in the `oelint_parse.constants.CONSTANT` class do exist.\nEach of the method accepts a dictionary with the same key mapping as listed below (multilevel paths are displayed a JSON pointer)\n\n| key                        | type | description                                           | getter for information                                     |\n| -------------------------- | ---- | ----------------------------------------------------- | ---------------------------------------------------------- |\n| functions/known            | list | known functions                                       | `oelint_parse.constants.CONSTANT.FunctionsKnown`           |\n| functions/order            | list | preferred order of core functions                     | `oelint_parse.constants.CONSTANT.FunctionsOrder`           |\n| images/known-classes       | list | bbclasses to be known to be used in images            | `oelint_parse.constants.CONSTANT.ImagesClasses`            |\n| images/known-variables     | list | variables known to be used in images                  | `oelint_parse.constants.CONSTANT.ImagesVariables`          |\n| replacements/distros       | list | known distro overrides                                | `oelint_parse.constants.CONSTANT.DistrosKnown`             |\n| replacements/machines      | list | known machine overrides                               | `oelint_parse.constants.CONSTANT.MachinesKnown`            |\n| replacements/mirrors       | dict | known mirrors                                         | `oelint_parse.constants.CONSTANT.MirrorsKnown`             |\n| variables/known            | list | known variables                                       | `oelint_parse.constants.CONSTANT.VariablesKnown`           |\n| sets/base                  | dict | base set of variables always used for value expansion | `oelint_parse.constants.CONSTANT.SetsBase`                 |\n\nFor additional constants\n\n```python\nfrom oelint_parser.constants import CONSTANTS\n\nCONSTANTS.GetByPath('/-joined path')\n```\n\nwill offer access\n\n## Contributing\n\nBefore any contribution please run the following\n\n```shell\npython3 -m venv --clear .env\n. .env/bin/activate\npip install -r requirements.txt -r requirements-dev.txt\nflake8 oelint_parser/ tests/\npytest\n./gendoc.sh\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Alternative parser for bitbake recipes",
    "version": "8.4.1",
    "project_urls": {
        "Homepage": "https://github.com/priv-kweihmann/oelint-parser"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d7455b3d0c08d1965151fa01648eff506d1ddce864af105d47d25e843588bfb9",
                "md5": "bafe96dba211d2ffc9407aba88e7c422",
                "sha256": "1ddc6b6893d0be1f001b5c441aa4eca635bfe7f7a8ab813f5622ce2c6a62a3b8"
            },
            "downloads": -1,
            "filename": "oelint_parser-8.4.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bafe96dba211d2ffc9407aba88e7c422",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.9",
            "size": 41876,
            "upload_time": "2025-09-02T11:27:36",
            "upload_time_iso_8601": "2025-09-02T11:27:36.677594Z",
            "url": "https://files.pythonhosted.org/packages/d7/45/5b3d0c08d1965151fa01648eff506d1ddce864af105d47d25e843588bfb9/oelint_parser-8.4.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0d3e31c81833ee9a45253ac8ca6c6d0ab80016b93365b3972a51fd16181c2e7e",
                "md5": "79fc7abc4f73091304a1937c12cf32f8",
                "sha256": "990dae6bb70f08428dcd239d0f1c552d6d58df18e609263256e4b4a191c12a1f"
            },
            "downloads": -1,
            "filename": "oelint_parser-8.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "79fc7abc4f73091304a1937c12cf32f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 35471,
            "upload_time": "2025-09-02T11:27:37",
            "upload_time_iso_8601": "2025-09-02T11:27:37.977663Z",
            "url": "https://files.pythonhosted.org/packages/0d/3e/31c81833ee9a45253ac8ca6c6d0ab80016b93365b3972a51fd16181c2e7e/oelint_parser-8.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-02 11:27:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "priv-kweihmann",
    "github_project": "oelint-parser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "regex",
            "specs": [
                [
                    "==",
                    "2025.8.29"
                ]
            ]
        },
        {
            "name": "Deprecated",
            "specs": [
                [
                    "~=",
                    "1.2"
                ]
            ]
        }
    ],
    "lcname": "oelint-parser"
}
        
Elapsed time: 3.66285s