Skip to content

Commit

Permalink
Merge pull request #165 from espressif/fix/using_lambda_function
Browse files Browse the repository at this point in the history
Fix: stop using lambda functions
  • Loading branch information
hfudev authored Sep 26, 2024
2 parents 4ae5d2a + 90a76f3 commit 7b7f4a7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
12 changes: 10 additions & 2 deletions idf_build_apps/manifest/if_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ class BoolExpr(Stmt):
pass


def _and(_l, _r):
return _l and _r


def _or(_l, _r):
return _l or _r


class BoolOrAnd(BoolExpr):
def __init__(self, t: ParseResults):
if len(t[0]) > 3:
Expand All @@ -189,9 +197,9 @@ def __init__(self, t: ParseResults):
self.right: BoolStmt = t[0][2]

if t[0][1] == 'and':
self.operation = lambda l, r: l and r # noqa: E741
self.operation = _and
if t[0][1] == 'or':
self.operation = lambda l, r: l or r # noqa: E741
self.operation = _or

def get_value(self, target: str, config_name: str) -> Any:
return self.operation(self.left.get_value(target, config_name), self.right.get_value(target, config_name))
Expand Down
4 changes: 4 additions & 0 deletions idf_build_apps/manifest/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def from_files(cls, paths: t.Iterable[PathLike], *, root_path: str = os.curdir)

rules: t.List[FolderRule] = []
for path in paths:
LOGGER.debug('Loading manifest file %s', path)
_manifest = cls.from_file(path, root_path=root_path)

for rule in _manifest.rules:
Expand Down Expand Up @@ -351,11 +352,14 @@ def _path(x):
return x

for folder, sha_value in recorded__rel_folder__sha__dict.items():
# removed
if folder not in self__rel_folder__sha__dict:
diff_folders.add(_path(folder))
# modified
elif sha_value != self__rel_folder__sha__dict[folder]:
diff_folders.add(_path(folder))

# new
for folder in self__rel_folder__sha__dict:
if folder not in recorded__rel_folder__sha__dict:
diff_folders.add(_path(folder))
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def sha_of_enable_only_esp32():
)

return sha


@pytest.fixture
def sha_of_enable_esp32_or_esp32s2():
sha = FolderRule('test1', enable=[{'if': 'IDF_TARGET == "esp32" or IDF_TARGET == "esp32s2"'}]).sha

# !!! ONLY CHANGE IT WHEN NECESSARY !!!
assert (
sha
== 'f3408e9bf1d6b9a9e14559e6567917986678a3414229b29f96493aec4dc1bc3e6d0ecc4f79adced0d5c26bc1cd80a4d15fe6aaefa5d1e7033a58290374f4fc7f' # noqa: E501
)

return sha
8 changes: 7 additions & 1 deletion tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
(['--manifest-files', 'test.yml', '--output', 'test.sha1'], None),
],
)
def test_manifest_dump_sha_values(args, expected_error, sha_of_enable_only_esp32, capsys, monkeypatch):
def test_manifest_dump_sha_values(
args, expected_error, sha_of_enable_only_esp32, sha_of_enable_esp32_or_esp32s2, capsys, monkeypatch
):
Path('test.yml').write_text(
"""
foo:
Expand All @@ -31,6 +33,9 @@ def test_manifest_dump_sha_values(args, expected_error, sha_of_enable_only_esp32
baz:
enable:
- if: IDF_TARGET == "esp32"
foobar:
enable:
- if: IDF_TARGET == "esp32" or IDF_TARGET == "esp32s2"
""",
encoding='utf8',
)
Expand Down Expand Up @@ -60,4 +65,5 @@ def test_manifest_dump_sha_values(args, expected_error, sha_of_enable_only_esp32
f'bar:{sha_of_enable_only_esp32}\n'
f'baz:{sha_of_enable_only_esp32}\n'
f'foo:{sha_of_enable_only_esp32}\n'
f'foobar:{sha_of_enable_esp32_or_esp32s2}\n'
)

0 comments on commit 7b7f4a7

Please sign in to comment.