Skip to content

Commit

Permalink
include: add FileIncluded property
Browse files Browse the repository at this point in the history
to reveal which file has been used, if any.
As it could be that includes of the same name
actually point to completely different file in the fs

Signed-off-by: Konrad Weihmann <[email protected]>
  • Loading branch information
priv-kweihmann committed Nov 3, 2024
1 parent 7e90d93 commit 3d7668d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
* [\_\_init\_\_](#oelint_parser.cls_item.Include.__init__)
* [IncName](#oelint_parser.cls_item.Include.IncName)
* [Statement](#oelint_parser.cls_item.Include.Statement)
* [FileIncluded](#oelint_parser.cls_item.Include.FileIncluded)
* [get\_items](#oelint_parser.cls_item.Include.get_items)
* [Export](#oelint_parser.cls_item.Export)
* [\_\_init\_\_](#oelint_parser.cls_item.Export.__init__)
Expand Down Expand Up @@ -2170,6 +2171,7 @@ def __init__(origin: str,
infileline: int,
rawtext: str,
incname: str,
fileincluded: str,
statement: str,
realraw: str,
new_style_override_syntax: bool = False) -> None
Expand All @@ -2185,6 +2187,7 @@ constructor
- `rawtext` _str_ - Raw input string (except inline code blocks)
- `realraw` _str_ - Unprocessed input
- `incname` _str_ - raw name of the include file
- `fileincluded` _str_ - path of the file included
- `statement` _str_ - either include or require


Expand Down Expand Up @@ -2222,6 +2225,21 @@ statement either include or require

- `str` - include or require

<a id="oelint_parser.cls_item.Include.FileIncluded"></a>

#### FileIncluded

```python
@property
def FileIncluded() -> str
```

The file included

**Returns**:

- `str` - path to file

<a id="oelint_parser.cls_item.Include.get_items"></a>

#### get\_items
Expand Down
13 changes: 13 additions & 0 deletions oelint_parser/cls_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,15 @@ class Include(Item):
CLASSIFIER = "Include"
ATTR_INCNAME = "IncName"
ATTR_STATEMENT = "Statement"
ATTR_FILEINCLUDED = "FileIncluded"

def __init__(self,
origin: str,
line: int,
infileline: int,
rawtext: str,
incname: str,
fileincluded: str,
statement: str,
realraw: str,
new_style_override_syntax: bool = False) -> None:
Expand All @@ -519,6 +521,7 @@ def __init__(self,
rawtext {str} -- Raw input string (except inline code blocks)
realraw {str} -- Unprocessed input
incname {str} -- raw name of the include file
fileincluded {str} -- path of the file included
statement {str} -- either include or require
Keyword Arguments:
Expand All @@ -527,6 +530,7 @@ def __init__(self,
super().__init__(origin, line, infileline, rawtext, realraw, new_style_override_syntax)
self.__IncName = incname
self.__Statement = statement
self.__FileIncluded = fileincluded

@property
def IncName(self) -> str:
Expand All @@ -546,6 +550,15 @@ def Statement(self) -> str:
"""
return self.__Statement

@property
def FileIncluded(self) -> str:
"""The file included
Returns:
str: path to file
"""
return self.__FileIncluded

def get_items(self) -> Tuple[str, str]:
"""Get items
Expand Down
1 change: 1 addition & 0 deletions oelint_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ def get_items(stash: object,
line["line"] - lineOffset,
line["raw"],
m.group("incname"),
_path or '',
m.group("statement"),
line["realraw"],
new_style_override_syntax=override_syntax_new,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ def test_linking(self):
values = sorted({y.VarValueStripped for y in _stash})
self.assertEqual(values, ["1"])

def test_include_filename(self):
from oelint_parser.cls_stash import Stash
from oelint_parser.cls_item import Include

self.__stash = Stash()
self.__stash.AddFile(self.RECIPE)
self.__stash.Finalize()

_stash = self.__stash.GetItemsFor(filename=self.RECIPE,
classifier=Include.CLASSIFIER)
self.assertTrue(_stash, msg="Stash has items")
values = sorted({y.FileIncluded for y in _stash})
expected = [
os.path.join(os.path.dirname(self.RECIPE), 'test.inc'),
os.path.join(os.path.dirname(self.RECIPE), 'test2.inc'),
os.path.join(os.path.dirname(self.RECIPE), 'test3.inc'),
]

assert values == expected


if __name__ == "__main__":
unittest.main()

0 comments on commit 3d7668d

Please sign in to comment.