Skip to content

Commit

Permalink
Merge pull request #124 from espressif/ci/update_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev authored Feb 8, 2024
2 parents 1e843c3 + bf1e4f6 commit 5f16486
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 112 deletions.
21 changes: 4 additions & 17 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending
args: [ '-f=lf' ]
- id: double-quote-string-fixer
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
Expand All @@ -16,26 +15,14 @@ repos:
- --license-filepath
- license_header.txt # defaults to: LICENSE.txt
- --use-current-year
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.7'
rev: 'v0.2.0'
hooks:
- id: ruff
args: ['--fix']
args: ['--fix', '--preview']
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.7.1'
rev: 'v1.8.0'
hooks:
- id: mypy
args: ['--warn-unused-ignores']
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import os
Expand All @@ -15,7 +15,7 @@

project = 'idf-build-apps'
project_homepage = 'https://github.com/espressif/idf-build-apps'
copyright = '2023, Espressif Systems (Shanghai) Co., Ltd.'
copyright = '2023, Espressif Systems (Shanghai) Co., Ltd.' # noqa: A001
author = 'Fu Hanxi'

# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion idf_build_apps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
'AppDeserializer',
'CMakeApp',
'MakeApp',
'find_apps',
'build_apps',
'find_apps',
'json_to_app',
'setup_logging',
]
14 changes: 7 additions & 7 deletions idf_build_apps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class App(BaseModel):
IDF_VERSION_PLACEHOLDER: t.ClassVar[str] = '@v' # replace it with the IDF version
INDEX_PLACEHOLDER: t.ClassVar[str] = '@i' # replace it with the build index (while build_apps)

SDKCONFIG_LINE_REGEX: t.ClassVar[t.Pattern] = re.compile(r"^([^=]+)=\"?([^\"\n]*)\"?\n*$")
SDKCONFIG_LINE_REGEX: t.ClassVar[t.Pattern] = re.compile(r'^([^=]+)=\"?([^\"\n]*)\"?\n*$')

# could be assigned later, used for filtering out apps by supported_targets
MANIFEST: t.ClassVar[t.Optional[Manifest]] = None
Expand Down Expand Up @@ -622,10 +622,10 @@ def _post_build(self) -> None:
def _build(
self,
*,
manifest_rootpath: t.Optional[str] = None,
modified_components: t.Optional[t.List[str]] = None,
modified_files: t.Optional[t.List[str]] = None,
check_app_dependencies: bool = False,
manifest_rootpath: t.Optional[str] = None, # noqa: ARG002
modified_components: t.Optional[t.List[str]] = None, # noqa: ARG002
modified_files: t.Optional[t.List[str]] = None, # noqa: ARG002
check_app_dependencies: bool = False, # noqa: ARG002
) -> None:
self._build_stage = BuildStage.BUILD

Expand Down Expand Up @@ -793,7 +793,7 @@ def supported_targets(self) -> t.List[str]:
if self.sdkconfig_files_defined_idf_target:
return [self.sdkconfig_files_defined_idf_target]

return ['esp8266'] + FolderRule.DEFAULT_BUILD_TARGETS
return ['esp8266', *FolderRule.DEFAULT_BUILD_TARGETS]

def _build(
self,
Expand Down Expand Up @@ -914,7 +914,7 @@ def _build(

if modified_components is not None and check_app_dependencies and self.build_status == BuildStatus.UNKNOWN:
subprocess_run(
common_args + ['reconfigure'],
[*common_args, 'reconfigure'],
log_terminal=self._is_build_log_path_temp,
log_fs=self.build_log_path,
check=True,
Expand Down
4 changes: 2 additions & 2 deletions idf_build_apps/junit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

from .report import (
Expand All @@ -7,4 +7,4 @@
TestSuite,
)

__all__ = ['TestReport', 'TestCase', 'TestSuite']
__all__ = ['TestCase', 'TestReport', 'TestSuite']
24 changes: 13 additions & 11 deletions idf_build_apps/junit/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

"""
Expand Down Expand Up @@ -39,7 +39,9 @@
from datetime import (
datetime,
)
from xml.etree import ElementTree as ET
from xml.etree import (
ElementTree,
)
from xml.sax.saxutils import (
escape,
)
Expand Down Expand Up @@ -118,8 +120,8 @@ def is_skipped(self) -> bool:
def is_error(self) -> bool:
return self.error_reason is not None

def to_xml_elem(self) -> ET.Element:
elem = ET.Element(
def to_xml_elem(self) -> ElementTree.Element:
elem = ElementTree.Element(
'testcase',
{
'name': self.name,
Expand All @@ -128,11 +130,11 @@ def to_xml_elem(self) -> ET.Element:
},
)
if self.error_reason:
ET.SubElement(elem, 'error', {'message': escape(self.error_reason)})
ElementTree.SubElement(elem, 'error', {'message': escape(self.error_reason)})
elif self.failure_reason:
ET.SubElement(elem, 'failure', {'message': escape(self.failure_reason)})
ElementTree.SubElement(elem, 'failure', {'message': escape(self.failure_reason)})
elif self.skipped_reason:
ET.SubElement(elem, 'skipped', {'message': escape(self.skipped_reason)})
ElementTree.SubElement(elem, 'skipped', {'message': escape(self.skipped_reason)})

if self.properties:
for k, v in self.properties.items():
Expand Down Expand Up @@ -171,8 +173,8 @@ def add_test_case(self, test_case: TestCase) -> None:

self.duration_sec += test_case.duration_sec

def to_xml_elem(self) -> ET.Element:
elem = ET.Element(
def to_xml_elem(self) -> ElementTree.Element:
elem = ElementTree.Element(
'testsuite',
{
'name': self.name,
Expand All @@ -199,10 +201,10 @@ def __init__(self, test_suites: t.List[TestSuite], filepath: str) -> None:
self.filepath = filepath

def create_test_report(self) -> None:
xml = ET.Element('testsuites')
xml = ElementTree.Element('testsuites')

for test_suite in self.test_suites:
xml.append(test_suite.to_xml_elem())

ET.ElementTree(xml).write(self.filepath, encoding='utf-8')
ElementTree.ElementTree(xml).write(self.filepath, encoding='utf-8')
LOGGER.info('Test report written to %s', self.filepath)
4 changes: 2 additions & 2 deletions idf_build_apps/log.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import logging
Expand Down Expand Up @@ -51,7 +51,7 @@ def format(self, record: logging.LogRecord) -> str:

if record.levelno in [logging.WARNING, logging.ERROR]:
record.msg = '>>> ' + str(record.msg)
elif record.levelno in [logging.CRITICAL]:
elif record.levelno == logging.CRITICAL:
record.msg = '!!! ' + str(record.msg)

formatter = logging.Formatter(log_fmt, datefmt=self.datefmt)
Expand Down
8 changes: 4 additions & 4 deletions idf_build_apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def get_parser() -> argparse.ArgumentParser:
type=str,
help='The --override-sdkconfig-items option is a comma-separated list '
'that permits the overriding of specific configuration items defined '
'in the SDK\'s sdkconfig file and Kconfig using a command-line argument. '
"in the SDK's sdkconfig file and Kconfig using a command-line argument. "
'The sdkconfig items specified here override the same sdkconfig '
'item defined in the --override-sdkconfig-files, if exists.',
)
Expand Down Expand Up @@ -669,16 +669,16 @@ def validate_args(parser: argparse.ArgumentParser, args: argparse.Namespace) ->
if not args.target:
raise InvalidCommand(
'Must specify current build target with CLI option "-t <target>" or "--target <target>". '
'(choices: [{}]'.format(','.join(ALL_TARGETS + ['all']))
'(choices: [{}]'.format(','.join([*ALL_TARGETS, 'all']))
)

default_build_targets = []
if args.default_build_targets:
for target in args.default_build_targets:
if target not in ALL_TARGETS:
raise InvalidCommand(
'Unrecognizable target {} specified with "--default-build-targets". '
'Current ESP-IDF available targets: {}'.format(target, ALL_TARGETS)
f'Unrecognizable target {target} specified with "--default-build-targets". '
f'Current ESP-IDF available targets: {ALL_TARGETS}'
)

if target not in default_build_targets:
Expand Down
19 changes: 10 additions & 9 deletions idf_build_apps/manifest/if_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import operator
import os
from ast import (
literal_eval,
Expand Down Expand Up @@ -113,15 +114,15 @@ class Integer(Stmt):
def __init__(self, t: ParseResults):
self.expr: str = t[0]

def get_value(self, target: str, config_name: str) -> Any:
def get_value(self, target: str, config_name: str) -> Any: # noqa: ARG002
return literal_eval(self.expr)


class String(Stmt):
def __init__(self, t: ParseResults):
self.expr: str = t[0]

def get_value(self, target: str, config_name: str) -> Any:
def get_value(self, target: str, config_name: str) -> Any: # noqa: ARG002
return literal_eval(f'"{self.expr}"') # double quotes is swallowed by QuotedString


Expand All @@ -135,12 +136,12 @@ def get_value(self, target: str, config_name: str) -> Any:

class BoolStmt(Stmt):
_OP_DICT = {
'==': lambda x, y: x == y,
'!=': lambda x, y: x != y,
'>': lambda x, y: x > y,
'>=': lambda x, y: x >= y,
'<': lambda x, y: x < y,
'<=': lambda x, y: x <= y,
'==': operator.eq,
'!=': operator.ne,
'>': operator.gt,
'>=': operator.ge,
'<': operator.lt,
'<=': operator.le,
'not in': lambda x, y: x not in y,
'in': lambda x, y: x in y,
}
Expand Down
6 changes: 3 additions & 3 deletions idf_build_apps/session_args.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import logging
Expand Down Expand Up @@ -51,7 +51,7 @@ def _get_override_sdkconfig_files_items(self, override_sdkconfig_files: t.Tuple[

with open(f) as fr:
for line in fr:
m = re.compile(r"^([^=]+)=\"?([^\"\n]*)\"?\n*$").match(line)
m = re.compile(r'^([^=]+)=\"?([^\"\n]*)\"?\n*$').match(line)
if not m:
continue
d[m.group(1)] = m.group(2)
Expand All @@ -60,7 +60,7 @@ def _get_override_sdkconfig_files_items(self, override_sdkconfig_files: t.Tuple[
def _get_override_sdkconfig_items(self, override_sdkconfig_items: t.Tuple[str]) -> t.Dict:
d = {}
for line in override_sdkconfig_items:
m = re.compile(r"^([^=]+)=\"?([^\"\n]*)\"?\n*$").match(line)
m = re.compile(r'^([^=]+)=\"?([^\"\n]*)\"?\n*$').match(line)
if m:
d[m.group(1)] = m.group(2)
return d
Expand Down
2 changes: 1 addition & 1 deletion idf_build_apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,4 @@ def __hash__(self) -> int:
else:
hash_list.append(v)

return hash((type(self),) + tuple(hash_list))
return hash((type(self), *tuple(hash_list)))
Loading

0 comments on commit 5f16486

Please sign in to comment.