Skip to content

Commit

Permalink
Merge pull request #103 from espressif/feat/small_fixes
Browse files Browse the repository at this point in the history
some small fixes
  • Loading branch information
hfudev authored Dec 22, 2023
2 parents cf2c080 + c4fc8a9 commit a7a37e3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-build-idf-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
needs: build-python-packages
strategy:
matrix:
idf-branch: [ release-v5.0, release-v5.1 ]
idf-branch: [ release-v5.0, release-v5.1, release-v5.2 ]
runs-on: ubuntu-latest
container:
image: espressif/idf:${{ matrix.idf-branch }}
Expand Down
28 changes: 14 additions & 14 deletions idf_build_apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ class App(BaseModel):

# build status related
build_status: BuildStatus = BuildStatus.UNKNOWN
build_comment: t.Optional[str] = None

_build_comment: t.Optional[str] = None
_build_stage: t.Optional[BuildStage] = None
_build_duration: float = 0
_build_timestamp: t.Optional[datetime] = None

__EQ_IGNORE_FIELDS__ = [
'build_comment',
]

def __init__(
self,
app_dir: str,
Expand Down Expand Up @@ -297,14 +301,6 @@ def build_path(self) -> str:

return os.path.join(self.work_dir, self.build_dir)

@property
def build_comment(self) -> str:
return self._build_comment or ''

@build_comment.setter
def build_comment(self, value: str) -> None:
self._build_comment = value

@computed_field # type: ignore
@property
def build_log_filename(self) -> t.Optional[str]:
Expand Down Expand Up @@ -340,17 +336,21 @@ def _process_sdkconfig_files(self) -> t.Tuple[t.List[str], t.Optional[str]]:
real_sdkconfig_files: t.List[str] = []
sdkconfig_files_defined_target: t.Optional[str] = None

# put the expanded variable files in a temporary directory
# will remove if the content is the same as the original one
expanded_dir = os.path.join(self.work_dir, 'expanded_sdkconfig_files', os.path.basename(self.build_dir))
if not os.path.isdir(expanded_dir):
os.makedirs(expanded_dir)

for f in self.sdkconfig_defaults_candidates + ([self.sdkconfig_path] if self.sdkconfig_path else []):
if not os.path.isabs(f):
f = os.path.join(self.work_dir, f)

# use filepath if abs/rel already point to itself
if not os.path.isfile(f):
self._logger.debug('sdkconfig file %s not exists, skipping...', f)
continue
# find it in the app_dir
self._logger.debug('sdkconfig file %s not found, checking under app_dir...', f)
f = os.path.join(self.app_dir, f)
if not os.path.isfile(f):
self._logger.debug('sdkconfig file %s not found, skipping...', f)
continue

expanded_fp = os.path.join(expanded_dir, os.path.basename(f))
with open(f) as fr:
Expand Down
6 changes: 3 additions & 3 deletions idf_build_apps/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
if _BUILDING_DOCS:
_idf_env = tempfile.gettempdir()
else:
_idf_env = os.getenv('IDF_PATH', '')
if not os.path.isdir(_idf_env):
raise ValueError(f'Invalid value for IDF_PATH: {_idf_env}')
_idf_env = os.getenv('IDF_PATH') or ''
if not _idf_env:
raise SystemExit('environment variable IDF_PATH must be set')


IDF_PATH = os.path.abspath(_idf_env)
Expand Down
2 changes: 1 addition & 1 deletion idf_build_apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def main():
os.makedirs(os.path.dirname(os.path.realpath(args.output)), exist_ok=True)
with open(args.output, 'w') as fw:
for app in apps:
fw.write(app.model_dump_json() + '\n')
fw.write(app.to_json() + '\n')
else:
for app in apps:
print(app)
Expand Down
26 changes: 17 additions & 9 deletions idf_build_apps/session_args.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import logging
import os
import re
import typing as t

LOGGER = logging.getLogger(__name__)


class SessionArgs:
workdir: str = os.getcwd()
Expand Down Expand Up @@ -35,27 +38,32 @@ def _setup_override_sdkconfig(self, args):
self.override_sdkconfig_file_path = override_sdkconfig_merged_file

def _get_override_sdkconfig_files_items(self, override_sdkconfig_files: t.Tuple[str]) -> t.Dict:
dct = {}
d = {}
for f in override_sdkconfig_files:
if not os.path.isabs(f):
f = os.path.join(self.workdir, f)
# use filepath if abs/rel already point to itself
if not os.path.isfile(f):
continue
# find it in the workdir
LOGGER.debug('override sdkconfig file %s not found, checking under app_dir...', f)
f = os.path.join(self.workdir, f)
if not os.path.isfile(f):
LOGGER.debug('override sdkconfig file %s not found, skipping...', f)
continue

with open(f) as fr:
for line in fr:
m = re.compile(r"^([^=]+)=\"?([^\"\n]*)\"?\n*$").match(line)
if not m:
continue
dct[m.group(1)] = m.group(2)
return dct
d[m.group(1)] = m.group(2)
return d

def _get_override_sdkconfig_items(self, override_sdkconfig_items: t.Tuple[str]) -> t.Dict:
dct = {}
d = {}
for line in override_sdkconfig_items:
m = re.compile(r"^([^=]+)=\"?([^\"\n]*)\"?\n*$").match(line)
if m:
dct[m.group(1)] = m.group(2)
return dct
d[m.group(1)] = m.group(2)
return d

def _create_override_sdkconfig_merged_file(self, override_sdkconfig_merged_items) -> t.Optional[str]:
if not override_sdkconfig_merged_items:
Expand Down
11 changes: 10 additions & 1 deletion idf_build_apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ class BaseModel(_BaseModel):
BaseModel that is hashable
"""

__EQ_IGNORE_FIELDS__: t.List[str] = []

def __lt__(self, other: t.Any) -> bool:
if isinstance(other, self.__class__):
for k in self.model_dump():
Expand All @@ -323,7 +325,14 @@ def __lt__(self, other: t.Any) -> bool:
def __eq__(self, other: t.Any) -> bool:
if isinstance(other, self.__class__):
# we only care the public attributes
return self.model_dump() == other.model_dump()
self_model_dump = self.model_dump()
other_model_dump = other.model_dump()

for _field in self.__EQ_IGNORE_FIELDS__:
self_model_dump.pop(_field, None)
other_model_dump.pop(_field, None)

return self_model_dump == other_model_dump

return NotImplemented

Expand Down

0 comments on commit a7a37e3

Please sign in to comment.