oelint-parser


Nameoelint-parser JSON
Version 3.5.1 PyPI version JSON
download
home_pagehttps://github.com/priv-kweihmann/oelint-parser
SummaryAlternative parser for bitbake recipes
upload_time2024-04-29 20:49:59
maintainerNone
docs_urlNone
authorKonrad Weihmann
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
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) 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'))
```

## 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

```python
from oelint_parser.constants import CONSTANTS

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

will offer access

## Contributing

Before any contribution please run the following (preferably in an virtual environment)

```shell
pip install -r requirements.txt
flake8
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.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Konrad Weihmann",
    "author_email": "kweihmann@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/1c/b8/c476dba9692548dfab9340044369da8dcd0dcdae8fde13b92a9bf8ca8a7c/oelint_parser-3.5.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) 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## 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| variables/mandatory        | list | variables mandatory to a recipe                       | `oelint_parse.constants.CONSTANT.VariablesMandatory`       |\n| variables/order            | list | preferred order of variables                          | `oelint_parse.constants.CONSTANT.VariablesOrder`           |\n| variables/protected        | list | variables not to be used in recipes                   | `oelint_parse.constants.CONSTANT.VariablesProtected`       |\n| variables/protected-append | list | variables not to be used in bbappends                 | `oelint_parse.constants.CONSTANT.VariablesProtectedAppend` |\n| variables/suggested        | list | suggested variable in a recipe                        | `oelint_parse.constants.CONSTANT.VariablesSuggested`       |\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 (preferably in an virtual environment)\n\n```shell\npip install -r requirements.txt\nflake8\npytest\n./gendoc.sh\n```\n\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Alternative parser for bitbake recipes",
    "version": "3.5.1",
    "project_urls": {
        "Homepage": "https://github.com/priv-kweihmann/oelint-parser"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a8389267c4cfc16362e5b50d62b55de59b5147eaaf2cffa620605489c6d7152",
                "md5": "4debfa325650a494ec9d438fc70ca268",
                "sha256": "c01b8885789757ef5824c306d500849d17cf15d39ae5b357c7cb6ee8339bbb4c"
            },
            "downloads": -1,
            "filename": "oelint_parser-3.5.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4debfa325650a494ec9d438fc70ca268",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8",
            "size": 34929,
            "upload_time": "2024-04-29T20:49:57",
            "upload_time_iso_8601": "2024-04-29T20:49:57.608142Z",
            "url": "https://files.pythonhosted.org/packages/2a/83/89267c4cfc16362e5b50d62b55de59b5147eaaf2cffa620605489c6d7152/oelint_parser-3.5.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1cb8c476dba9692548dfab9340044369da8dcd0dcdae8fde13b92a9bf8ca8a7c",
                "md5": "ffad2b49363de3919b19bf9ea3799f5f",
                "sha256": "8bf7d58a197e5e763782b1c6d8e5c9d99401e37a3f68d38657f6ee876cd430e4"
            },
            "downloads": -1,
            "filename": "oelint_parser-3.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ffad2b49363de3919b19bf9ea3799f5f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35409,
            "upload_time": "2024-04-29T20:49:59",
            "upload_time_iso_8601": "2024-04-29T20:49:59.853385Z",
            "url": "https://files.pythonhosted.org/packages/1c/b8/c476dba9692548dfab9340044369da8dcd0dcdae8fde13b92a9bf8ca8a7c/oelint_parser-3.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 20:49:59",
    "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": [],
    "lcname": "oelint-parser"
}
        
Elapsed time: 0.25390s