change(tools): apply ruff fixes (ci, test_apps, build system, ldgen)

Apply the ruff lint (including pyupgrade) and format fixes for the
Python 3.11 target in the following areas:

- tools (idf_py_actions, install_util, test_bsasm, test_idf_diag,
  test_idf_py, test_idf_size)
- tools/ci
- tools/test_apps
- tools/test_build_system
- tools/ldgen

Findings that are not auto-fixable (long lines, a shadowed builtin,
type comparisons) are fixed by hand. Also fix the typos reported by
codespell and the mypy error in tools/ci/idf_pytest/utils.py that
surfaced once the file was touched, and switch check_for_file_paths.py
to the SPDX header (removing it from the copyright ignore list).
This commit is contained in:
Jan Beran
2026-10-12 15:46:44 +08:00
parent ca07287a71
commit aab610c327
40 changed files with 880 additions and 748 deletions
@@ -4,7 +4,6 @@ import logging
import os
import socket
from typing import Any
from typing import List
from idf_ci_utils import IDF_PATH
@@ -22,7 +21,7 @@ ENV_CONFIG_FILE_SEARCH = [
os.path.join(IDF_PATH, 'EnvConfig.yml'),
os.path.join(IDF_PATH, 'ci-test-runner-configs', os.environ.get('CI_RUNNER_DESCRIPTION', ''), 'EnvConfig.yml'),
]
ENV_CONFIG_TEMPLATE = '''
ENV_CONFIG_TEMPLATE = """
$IDF_PATH/EnvConfig.yml:
```yaml
<env_name>:
@@ -31,19 +30,19 @@ $IDF_PATH/EnvConfig.yml:
<another_env>:
key: var
```
'''
"""
def get_host_ip_by_interface(interface_name: str, ip_type: int = netifaces.AF_INET) -> str:
if ip_type == netifaces.AF_INET:
for _addr in netifaces.ifaddresses(interface_name)[ip_type]:
host_ip = _addr['addr'].replace('%{}'.format(interface_name), '')
host_ip = _addr['addr'].replace(f'%{interface_name}', '')
assert isinstance(host_ip, str)
return host_ip
elif ip_type == netifaces.AF_INET6:
ip6_addrs: List[str] = []
ip6_addrs: list[str] = []
for _addr in netifaces.ifaddresses(interface_name)[ip_type]:
host_ip = _addr['addr'].replace('%{}'.format(interface_name), '')
host_ip = _addr['addr'].replace(f'%{interface_name}', '')
assert isinstance(host_ip, str)
# prefer to use link local address due to example settings
if host_ip.startswith('FE80::'):
@@ -89,7 +88,7 @@ def get_my_interface_by_dest_ip(dest_ip: str = '') -> str:
if my_ip in [a['addr'] for a in addresses]:
assert isinstance(interface, str)
return interface
logging.error('Can not get interface, dest ip is {}'.format(dest_ip))
logging.error(f'Can not get interface, dest ip is {dest_ip}')
return ''
@@ -109,7 +108,7 @@ def get_env_config_variable(env_name: str, key: str, default: Any = None) -> Any
config = dict()
for _file in ENV_CONFIG_FILE_SEARCH:
try:
with open(_file, 'r') as f:
with open(_file) as f:
data = yaml.load(f.read(), Loader=yaml.SafeLoader)
config = data[env_name]
break
@@ -124,7 +123,7 @@ def get_env_config_variable(env_name: str, key: str, default: Any = None) -> Any
logging.info(f'Env config file template: {ENV_CONFIG_TEMPLATE}')
if not os.environ.get('CI_JOB_ID'):
# Try to get variable from stdin
var = input(f'You can input the variable now:')
var = input('You can input the variable now:')
else:
raise ValueError(f'Env variable not found: {env_name}/{key}')
logging.debug(f'Got env variable {env_name}/{key}: {var}')