diff --git a/docs/api-documentation.md b/docs/api-documentation.md index c2b05c3..cf41e80 100644 --- a/docs/api-documentation.md +++ b/docs/api-documentation.md @@ -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__) @@ -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 @@ -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 @@ -2222,6 +2225,21 @@ statement either include or require - `str` - include or require + + +#### FileIncluded + +```python +@property +def FileIncluded() -> str +``` + +The file included + +**Returns**: + +- `str` - path to file + #### get\_items diff --git a/oelint_parser/cls_item.py b/oelint_parser/cls_item.py index 0d03a7f..00f8a99 100644 --- a/oelint_parser/cls_item.py +++ b/oelint_parser/cls_item.py @@ -500,6 +500,7 @@ class Include(Item): CLASSIFIER = "Include" ATTR_INCNAME = "IncName" ATTR_STATEMENT = "Statement" + ATTR_FILEINCLUDED = "FileIncluded" def __init__(self, origin: str, @@ -507,6 +508,7 @@ def __init__(self, infileline: int, rawtext: str, incname: str, + fileincluded: str, statement: str, realraw: str, new_style_override_syntax: bool = False) -> None: @@ -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: @@ -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: @@ -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 diff --git a/oelint_parser/parser.py b/oelint_parser/parser.py index d8f5307..7aeae85 100644 --- a/oelint_parser/parser.py +++ b/oelint_parser/parser.py @@ -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, diff --git a/tests/test_include.py b/tests/test_include.py index bbc3e89..b452702 100644 --- a/tests/test_include.py +++ b/tests/test_include.py @@ -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()