Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions oelint_parser/cls_stash.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def ExpandVar(self,
return {}
_exp = {
"PN": self.GuessRecipeName(filename),
"PV": self.GuessRecipeVersion(filename),
"PV": self.GuessRecipeVersion(filename) or "1.0",
"BPN": self.GuessBaseRecipeName(filename),
}
_exp = {**_exp, **CONSTANTS.SetsBase}
Expand Down Expand Up @@ -692,7 +692,7 @@ def GuessBaseRecipeName(self, _file: str) -> str:
return tmp_

@functools.cache # noqa: B019
def GuessRecipeVersion(self, _file: str) -> str:
def GuessRecipeVersion(self, _file: str) -> str | None:
"""Get recipe version from filename

Arguments:
Expand All @@ -702,7 +702,8 @@ def GuessRecipeVersion(self, _file: str) -> str:
str -- recipe version
"""
_name, _ = os.path.splitext(os.path.basename(_file))
return _name.split("_")[-1]
_pn, *_pv = _name.split("_")
return [*_pv, None][0]

def _ReverseInlineBlock(self, varref: Variable) -> str:
res = varref.VarValueStripped
Expand Down Expand Up @@ -763,7 +764,7 @@ def _expand(res, _file, m, quote: str = ''):
elif m.group(1) in ["BPN"]:
res = res.replace(m.group(0), self.GuessBaseRecipeName(_file))
elif m.group(1) in ["PV"]:
res = res.replace(m.group(0), self.GuessRecipeVersion(_file))
res = res.replace(m.group(0), self.GuessRecipeVersion(_file) or "1.0")
elif m.group(1) in ["FILE"]:
res = res.replace(m.group(0), f'{quote}{_file}{quote}')
elif m.group(1) in ["THISDIR"]:
Expand Down
22 changes: 20 additions & 2 deletions tests/test_expand.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

class OelintLinking(unittest.TestCase):

def _create_tempfile(self, _input):
def _create_tempfile(self, _input, _file = 'testfile.bb'):
self.__created_files = getattr(self, '__created_files', {})
self._collected_tmpdirs = getattr(self, '_collect_tmpdirs', [])
self._tmpdir = getattr(self, '_tmpdir', tempfile.mkdtemp())
self._collected_tmpdirs.append(self._tmpdir)
_file = 'testfile.bb'
_path = os.path.join(self._tmpdir, _file)
os.makedirs(os.path.dirname(_path), exist_ok=True)

Expand Down Expand Up @@ -302,3 +301,22 @@ def test_expandvar_file_ref(self):
_file, attribute=Variable.ATTR_VAR, attributeValue='A')
self.assertEqual(' '.join(res.get('A', '')),
f'${{@some.function(d, "{_file}")}}/abc')

def test_expand_pv(self):
from oelint_parser.cls_stash import Stash
from oelint_parser.cls_item import Variable

for file_name, file_content, expected in [
('myrecipe.bb', 'A = "b"', '1.0'),
('myrecipe.bb', 'PV = "2.1"', '2.1'),
('myrecipe_1.0.bb', 'A = "b"', '1.0'),
('myrecipe_3.3.bb', 'A = "b"', '3.3'),
('myrecipe_3.1.bb', 'PV = "4.2"', '4.2'),
]:
self.__stash = Stash()
_file = self._create_tempfile(file_content, file_name)
self.__stash.AddFile(_file)
self.__stash.Finalize()

res = self.__stash.ExpandTerm(_file, '${PV}')
self.assertEqual(res, expected)