mirror of
https://github.com/espressif/esp-idf.git
synced 2026-09-22 13:01:16 +03:00
feat(tools): Replaced click with rich_click
This commit is contained in:
@@ -12,7 +12,7 @@ Usage:
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
import rich_click as click
|
||||
from src.app import BLELogApp
|
||||
from src.backend.models import format_bytes
|
||||
from src.backend.uart_transport import validate_uart_port
|
||||
|
||||
37
tools/idf.py
37
tools/idf.py
@@ -156,9 +156,12 @@ def _safe_relpath(path: str, start: str | None = None) -> str:
|
||||
|
||||
|
||||
def init_cli(verbose_output: list | None = None) -> Any:
|
||||
# Click is imported here to run it after check_environment()
|
||||
import click
|
||||
# rich-click is imported here to run it after check_environment()
|
||||
import rich_click as click
|
||||
from click.shell_completion import CompletionItem
|
||||
from rich_click import Context
|
||||
from rich_click import RichHelpConfiguration
|
||||
from rich_click.rich_click import MAX_WIDTH
|
||||
|
||||
class Deprecation:
|
||||
"""Construct deprecation notice for help messages"""
|
||||
@@ -210,7 +213,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
text = text or ''
|
||||
return ('Deprecated! ' + text) if self.deprecated else text
|
||||
|
||||
def check_deprecation(ctx: click.core.Context) -> None:
|
||||
def check_deprecation(ctx: Context) -> None:
|
||||
"""Prints deprecation warnings for arguments in given context"""
|
||||
for option in ctx.command.params:
|
||||
default = () if option.multiple else option.default
|
||||
@@ -240,15 +243,13 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
self.action_args = action_args
|
||||
self.aliases = aliases
|
||||
|
||||
def __call__(
|
||||
self, context: click.core.Context, global_args: PropertyDict, action_args: dict | None = None
|
||||
) -> None:
|
||||
def __call__(self, context: Context, global_args: PropertyDict, action_args: dict | None = None) -> None:
|
||||
if action_args is None:
|
||||
action_args = self.action_args
|
||||
|
||||
self.callback(self.name, context, global_args, **action_args)
|
||||
|
||||
class Action(click.Command):
|
||||
class Action(click.RichCommand):
|
||||
callback: Callable
|
||||
|
||||
def __init__(
|
||||
@@ -309,7 +310,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
|
||||
self.callback: Callable = wrapped_callback
|
||||
|
||||
def invoke(self, ctx: click.core.Context) -> click.core.Context:
|
||||
def invoke(self, ctx: Context) -> Context:
|
||||
if self.deprecated:
|
||||
deprecation = Deprecation(self.deprecated)
|
||||
message = deprecation.full_message(f'Command "{self.name}"')
|
||||
@@ -325,7 +326,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
check_deprecation(ctx)
|
||||
return super().invoke(ctx)
|
||||
|
||||
class Argument(click.Argument):
|
||||
class Argument(click.RichArgument):
|
||||
"""
|
||||
Positional argument
|
||||
|
||||
@@ -368,7 +369,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
def __str__(self) -> str:
|
||||
return self._scope
|
||||
|
||||
class Option(click.Option):
|
||||
class Option(click.RichOption):
|
||||
"""Option that knows whether it should be global"""
|
||||
|
||||
def __init__(
|
||||
@@ -406,14 +407,14 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
if self.scope.is_global:
|
||||
self.help += ' This option can be used at most once either globally, or for one subcommand.'
|
||||
|
||||
def get_help_record(self, ctx: click.core.Context) -> Any:
|
||||
def get_help_record(self, ctx: Context) -> Any:
|
||||
# Backport "hidden" parameter to click 5.0
|
||||
if self.hidden:
|
||||
return None
|
||||
|
||||
return super().get_help_record(ctx)
|
||||
|
||||
class CLI(click.Group):
|
||||
class CLI(click.RichGroup):
|
||||
"""Action list contains all actions with options available for CLI"""
|
||||
|
||||
def __init__(
|
||||
@@ -427,7 +428,10 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
invoke_without_command=True,
|
||||
result_callback=self.execute_tasks,
|
||||
no_args_is_help=True,
|
||||
context_settings={'max_content_width': 140},
|
||||
context_settings={
|
||||
'help_option_names': ['-h', '--help'],
|
||||
'rich_help_config': RichHelpConfiguration(max_width=MAX_WIDTH),
|
||||
},
|
||||
help=cli_help,
|
||||
)
|
||||
self._actions = {}
|
||||
@@ -467,6 +471,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
options = []
|
||||
|
||||
self._actions[name] = Action(name=name, **action)
|
||||
self.commands[name] = self._actions[name]
|
||||
for alias in [name] + action.get('aliases', []):
|
||||
self.commands_with_aliases[alias] = name
|
||||
|
||||
@@ -492,10 +497,10 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
|
||||
self._actions[name].params.append(option)
|
||||
|
||||
def list_commands(self, ctx: click.core.Context) -> list:
|
||||
def list_commands(self, ctx: Context) -> list:
|
||||
return sorted(filter(lambda name: not self._actions[name].hidden, self._actions))
|
||||
|
||||
def get_command(self, ctx: click.core.Context, name: str) -> Action | None:
|
||||
def get_command(self, ctx: Context, name: str) -> Action | None:
|
||||
if name in self.commands_with_aliases:
|
||||
return self._actions.get(self.commands_with_aliases.get(name))
|
||||
|
||||
@@ -506,7 +511,7 @@ def init_cli(verbose_output: list | None = None) -> Any:
|
||||
return Action(name=name, callback=callback.unwrapped_callback)
|
||||
return None
|
||||
|
||||
def shell_complete(self, ctx: click.core.Context, incomplete: str) -> list[CompletionItem]:
|
||||
def shell_complete(self, ctx: Context, incomplete: str) -> list[CompletionItem]:
|
||||
# Enable @-argument completion in bash only if @ is not present in
|
||||
# COMP_WORDBREAKS. When @ is included, the @-argument is not considered
|
||||
# part of the completion word, causing @-argument completion to function
|
||||
|
||||
@@ -15,8 +15,8 @@ from urllib.request import Request
|
||||
from urllib.request import urlopen
|
||||
from webbrowser import open_new_tab
|
||||
|
||||
import click
|
||||
from click.core import Context
|
||||
import rich_click as click
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.constants import GENERATORS
|
||||
from idf_py_actions.constants import PREVIEW_TARGETS
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import os
|
||||
import re
|
||||
@@ -6,9 +6,8 @@ import stat
|
||||
import sys
|
||||
from shutil import copyfile
|
||||
from shutil import copytree
|
||||
from typing import Dict
|
||||
|
||||
import click
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
|
||||
@@ -100,8 +99,8 @@ def create_component(target_path: str, name: str) -> None:
|
||||
replace_in_file(os.path.join(target_path, 'CMakeLists.txt'), 'main', name)
|
||||
|
||||
|
||||
def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
def create_new(action: str, ctx: click.core.Context, global_args: PropertyDict, **action_args: str) -> Dict:
|
||||
def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
def create_new(action: str, ctx: Context, global_args: PropertyDict, **action_args: str) -> dict:
|
||||
target_path = action_args.get('path') or os.path.join(project_path, action_args['name'])
|
||||
|
||||
is_empty_and_create(target_path, action)
|
||||
|
||||
@@ -11,9 +11,9 @@ import time
|
||||
from threading import Thread
|
||||
from typing import Any
|
||||
|
||||
from click import INT
|
||||
from click.core import Context
|
||||
from esp_coredump import CoreDump
|
||||
from rich_click import INT
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.errors import FatalError
|
||||
from idf_py_actions.serial_ext import BAUD_RATE
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from typing import Dict
|
||||
|
||||
from click.core import Context
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.errors import FatalError
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
from idf_py_actions.tools import ensure_build_directory
|
||||
from idf_py_actions.tools import is_target_supported
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
from idf_py_actions.tools import run_target
|
||||
|
||||
|
||||
def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
|
||||
def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
SUPPORTED_TARGETS = ['esp32s2', 'esp32s3', 'esp32p4']
|
||||
|
||||
def dfu_target(target_name: str, ctx: Context, args: PropertyDict, part_size: str) -> None:
|
||||
@@ -29,8 +28,10 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
run_target(target_name, args, {'ESP_DFU_PATH': path})
|
||||
except FatalError:
|
||||
# Cannot capture the error from dfu-util here so the best advise is:
|
||||
print('Please have a look at the "Device Firmware Upgrade through USB" chapter in API Guides of the '
|
||||
'ESP-IDF documentation for solving common dfu-util issues.')
|
||||
print(
|
||||
'Please have a look at the "Device Firmware Upgrade through USB" chapter in API Guides of the '
|
||||
'ESP-IDF documentation for solving common dfu-util issues.'
|
||||
)
|
||||
raise
|
||||
|
||||
dfu_actions = {
|
||||
@@ -43,8 +44,8 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
{
|
||||
'names': ['--part-size'],
|
||||
'help': 'Large files are split up into smaller partitions in order to avoid timeout during '
|
||||
'erasing flash. This option allows to overwrite the default partition size of '
|
||||
'mkdfu.py.'
|
||||
'erasing flash. This option allows to overwrite the default partition size of '
|
||||
'mkdfu.py.',
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -62,8 +63,8 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
|
||||
'names': ['--path'],
|
||||
'default': '',
|
||||
'help': 'Specify path to DFU device. The default empty path works if there is just one '
|
||||
'ESP device with the same product identifier. See the device list for paths '
|
||||
'of available devices.'
|
||||
'ESP device with the same product identifier. See the device list for paths '
|
||||
'of available devices.',
|
||||
}
|
||||
],
|
||||
},
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
import sys
|
||||
import uuid
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
import click
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
from idf_py_actions.tools import RunTool
|
||||
@@ -16,20 +13,20 @@ from idf_py_actions.tools import yellow_print
|
||||
|
||||
def diag(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
debug: bool,
|
||||
log_prefix: bool,
|
||||
force: bool,
|
||||
no_color: bool,
|
||||
zip_directory: Optional[str],
|
||||
zip_directory: str | None,
|
||||
list_recipes: bool,
|
||||
check_recipes: bool,
|
||||
cmdl_recipes: Tuple,
|
||||
cmdl_tags: Tuple,
|
||||
purge_file: Optional[str],
|
||||
cmdl_recipes: tuple,
|
||||
cmdl_tags: tuple,
|
||||
purge_file: str | None,
|
||||
append: bool,
|
||||
output: Optional[str],
|
||||
output: str | None,
|
||||
) -> None:
|
||||
diag_args: list = [sys.executable, '-m', 'esp_idf_diag']
|
||||
|
||||
@@ -106,12 +103,10 @@ def diag(
|
||||
diag_args += ['--port', args.port]
|
||||
else:
|
||||
yellow_print(
|
||||
(
|
||||
'The target serial port is not specified, so '
|
||||
'autodetection will be used. To set it manually, use '
|
||||
'the "--port" option. Example: "idf.py --port '
|
||||
'/dev/ttyUSB0 diag".'
|
||||
)
|
||||
'The target serial port is not specified, so '
|
||||
'autodetection will be used. To set it manually, use '
|
||||
'the "--port" option. Example: "idf.py --port '
|
||||
'/dev/ttyUSB0 diag".'
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -121,18 +116,16 @@ def diag(
|
||||
|
||||
if command == 'create':
|
||||
yellow_print(
|
||||
(
|
||||
f'Please make sure to thoroughly check it for any sensitive '
|
||||
f'information before sharing and remove files you do not want '
|
||||
f'to share. Kindly include any additional files you find '
|
||||
f'relevant that were not automatically added. Please archive '
|
||||
f'the contents of the final report directory using the command:\n'
|
||||
f'"idf.py diag --zip {output}".'
|
||||
)
|
||||
f'Please make sure to thoroughly check it for any sensitive '
|
||||
f'information before sharing and remove files you do not want '
|
||||
f'to share. Kindly include any additional files you find '
|
||||
f'relevant that were not automatically added. Please archive '
|
||||
f'the contents of the final report directory using the command:\n'
|
||||
f'"idf.py diag --zip {output}".'
|
||||
)
|
||||
|
||||
|
||||
def action_extensions(base_actions: Dict, project_path: str) -> Any:
|
||||
def action_extensions(base_actions: dict, project_path: str) -> Any:
|
||||
return {
|
||||
'actions': {
|
||||
'diag': {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from click.core import Context
|
||||
from rich_click import Context
|
||||
|
||||
|
||||
class FatalError(RuntimeError):
|
||||
@@ -8,7 +8,7 @@ class FatalError(RuntimeError):
|
||||
Wrapper class for runtime errors that aren't caused by bugs in idf.py or the build process.
|
||||
"""
|
||||
|
||||
def __init__(self, message: str, ctx: Context=None):
|
||||
def __init__(self, message: str, ctx: Context = None):
|
||||
super(RuntimeError, self).__init__(message)
|
||||
# if context is defined, check for the cleanup tasks
|
||||
if ctx is not None and 'cleanup' in ctx.meta:
|
||||
|
||||
@@ -8,7 +8,7 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from click.core import Context
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.errors import FatalError
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
|
||||
@@ -14,7 +14,7 @@ import time
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from click.core import Context
|
||||
from rich_click import Context
|
||||
|
||||
try:
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
|
||||
@@ -8,7 +8,9 @@ import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import click
|
||||
import rich_click as click
|
||||
from click.core import ParameterSource
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.errors import FatalError
|
||||
from idf_py_actions.global_options import global_options
|
||||
@@ -50,7 +52,7 @@ def yellow_print(message: str, newline: str | None = '\n') -> None:
|
||||
|
||||
|
||||
def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
def _get_project_desc(ctx: click.core.Context, args: PropertyDict) -> Any:
|
||||
def _get_project_desc(ctx: Context, args: PropertyDict) -> Any:
|
||||
desc_path = os.path.join(args.build_dir, 'project_description.json')
|
||||
if not os.path.exists(desc_path):
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
@@ -83,7 +85,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
result += ['--no-stub']
|
||||
return result
|
||||
|
||||
def _get_commandline_options(ctx: click.core.Context) -> list:
|
||||
def _get_commandline_options(ctx: Context) -> list:
|
||||
"""Return all the command line options up to first action"""
|
||||
# This approach ignores argument parsing done Click
|
||||
result = []
|
||||
@@ -98,7 +100,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def monitor(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
print_filter: str,
|
||||
monitor_baud: str,
|
||||
@@ -136,7 +138,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
# Use the global baud rate if it has been changed by the command line.
|
||||
# Use project_desc['monitor_baud'] as the last option.
|
||||
|
||||
global_baud_defined = ctx._parameter_source['baud'] == click.core.ParameterSource.COMMANDLINE
|
||||
global_baud_defined = ctx._parameter_source['baud'] == ParameterSource.COMMANDLINE
|
||||
baud = args.baud if global_baud_defined else project_desc['monitor_baud']
|
||||
|
||||
monitor_args += ['-b', baud]
|
||||
@@ -205,7 +207,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def flash(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
force: bool,
|
||||
extra_args: str,
|
||||
@@ -240,13 +242,13 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
}
|
||||
run_target(action, args, env, force_progression=True, interactive=True)
|
||||
|
||||
def erase_flash(action: str, ctx: click.core.Context, args: PropertyDict) -> None:
|
||||
def erase_flash(action: str, ctx: Context, args: PropertyDict) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
esptool_args = _get_esptool_args(args)
|
||||
esptool_args += ['erase-flash']
|
||||
RunTool('esptool', esptool_args, args.build_dir, hints=not args.no_hints, interactive=True)()
|
||||
|
||||
def global_callback(ctx: click.core.Context, global_args: dict, tasks: PropertyDict) -> None:
|
||||
def global_callback(ctx: Context, global_args: dict, tasks: PropertyDict) -> None:
|
||||
encryption = any([task.name in ('encrypted-flash', 'encrypted-app-flash') for task in tasks])
|
||||
if encryption:
|
||||
for task in tasks:
|
||||
@@ -254,7 +256,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
task.action_args['encrypted'] = True
|
||||
break
|
||||
|
||||
def ota_targets(target_name: str, ctx: click.core.Context, args: PropertyDict) -> None:
|
||||
def ota_targets(target_name: str, ctx: Context, args: PropertyDict) -> None:
|
||||
"""
|
||||
Execute the target build system to build target 'target_name'.
|
||||
Additionally set global variables for baud and port.
|
||||
@@ -267,7 +269,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def merge_bin(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
output: str,
|
||||
format: str, # noqa: A002
|
||||
@@ -315,7 +317,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def secure_decrypt_flash_data(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
aes_xts: bool,
|
||||
keyfile: str,
|
||||
@@ -341,7 +343,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', decrypt_flash_data_args, args.build_dir)()
|
||||
|
||||
def secure_digest_secure_bootloader(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, keyfile: str, output: str, iv: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, keyfile: str, output: str, iv: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
digest_secure_bootloader_args = [PYTHON, '-m', 'espsecure', 'digest-secure-bootloader']
|
||||
@@ -357,7 +359,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def secure_encrypt_flash_data(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
aes_xts: bool,
|
||||
keyfile: str,
|
||||
@@ -383,7 +385,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', encrypt_flash_data_args, args.build_dir)()
|
||||
|
||||
def secure_generate_flash_encryption_key(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, keylen: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, keylen: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
generate_flash_encryption_key_args = [PYTHON, '-m', 'espsecure', 'generate-flash-encryption-key']
|
||||
@@ -394,7 +396,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', generate_flash_encryption_key_args, args.project_dir)()
|
||||
|
||||
def secure_generate_signing_key(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, version: str, scheme: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, version: str, scheme: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
generate_signing_key_args = [PYTHON, '-m', 'espsecure', 'generate-signing-key']
|
||||
@@ -415,7 +417,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', generate_signing_key_args, args.project_dir)()
|
||||
|
||||
def secure_generate_key_digest(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, keyfile: str, output: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, keyfile: str, output: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
generate_key_digest_args = [PYTHON, '-m', 'espsecure', 'digest-sbv2-public-key']
|
||||
@@ -427,7 +429,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def secure_sign_data(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
version: str,
|
||||
keyfile: str,
|
||||
@@ -456,7 +458,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', sign_data_args, args.build_dir)()
|
||||
|
||||
def secure_verify_signature(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, version: str, keyfile: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, version: str, keyfile: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
verify_signature_args = [PYTHON, '-m', 'espsecure', 'verify-signature']
|
||||
@@ -470,7 +472,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def secure_generate_nvs_partition_key(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
encryption_scheme: str,
|
||||
keyfile: str,
|
||||
@@ -488,7 +490,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
RunTool('espsecure', generate_nvs_partition_key_args, args.project_dir)()
|
||||
|
||||
def secure_encrypt_nvs_partition(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, keyfile: str, **extra_args: str
|
||||
action: str, ctx: Context, args: PropertyDict, keyfile: str, **extra_args: str
|
||||
) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
encrypt_nvs_partition_args = [PYTHON, '-m', 'esp_idf_nvs_partition_gen', 'encrypt']
|
||||
@@ -501,7 +503,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
encrypt_nvs_partition_args += [extra_args['partition_size']]
|
||||
RunTool('espsecure', encrypt_nvs_partition_args, args.project_dir)()
|
||||
|
||||
def _parse_efuse_args(ctx: click.core.Context, args: PropertyDict, extra_args: dict) -> list:
|
||||
def _parse_efuse_args(ctx: Context, args: PropertyDict, extra_args: dict) -> list:
|
||||
efuse_args = []
|
||||
if args.port:
|
||||
efuse_args += ['-p', args.port]
|
||||
@@ -518,7 +520,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
efuse_args += ['--do-not-confirm']
|
||||
return efuse_args
|
||||
|
||||
def efuse_burn(action: str, ctx: click.core.Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
def efuse_burn(action: str, ctx: Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
burn_efuse_args = [PYTHON, '-m', 'espefuse']
|
||||
burn_efuse_args += _parse_efuse_args(ctx, args, extra_args)
|
||||
@@ -527,7 +529,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
burn_efuse_args += list(extra_args['efuse_positional_args'])
|
||||
RunTool('espefuse', burn_efuse_args, args.build_dir)()
|
||||
|
||||
def efuse_burn_key(action: str, ctx: click.core.Context, args: PropertyDict, **extra_args: str) -> None:
|
||||
def efuse_burn_key(action: str, ctx: Context, args: PropertyDict, **extra_args: str) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
burn_key_args = [PYTHON, '-m', 'espefuse']
|
||||
burn_key_args += _parse_efuse_args(ctx, args, extra_args)
|
||||
@@ -542,9 +544,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
burn_key_args += extra_args['efuse_positional_args']
|
||||
RunTool('espefuse', burn_key_args, args.project_dir, build_dir=args.build_dir)()
|
||||
|
||||
def efuse_dump(
|
||||
action: str, ctx: click.core.Context, args: PropertyDict, file_name: str, **extra_args: dict
|
||||
) -> None:
|
||||
def efuse_dump(action: str, ctx: Context, args: PropertyDict, file_name: str, **extra_args: dict) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
dump_args = [PYTHON, '-m', 'espefuse']
|
||||
dump_args += _parse_efuse_args(ctx, args, extra_args)
|
||||
@@ -553,7 +553,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
dump_args += ['--file-name', file_name]
|
||||
RunTool('espefuse', dump_args, args.build_dir)()
|
||||
|
||||
def efuse_read_protect(action: str, ctx: click.core.Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
def efuse_read_protect(action: str, ctx: Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
read_protect_args = [PYTHON, '-m', 'espefuse']
|
||||
read_protect_args += _parse_efuse_args(ctx, args, extra_args)
|
||||
@@ -564,7 +564,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
|
||||
def efuse_summary(
|
||||
action: str,
|
||||
ctx: click.core.Context,
|
||||
ctx: Context,
|
||||
args: PropertyDict,
|
||||
format: str, # noqa: A002
|
||||
**extra_args: dict,
|
||||
@@ -579,7 +579,7 @@ def action_extensions(base_actions: dict, project_path: str) -> dict:
|
||||
summary_args += [str(extra_args['efuse_name'])]
|
||||
RunTool('espefuse', summary_args, args.build_dir)()
|
||||
|
||||
def efuse_write_protect(action: str, ctx: click.core.Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
def efuse_write_protect(action: str, ctx: Context, args: PropertyDict, **extra_args: dict) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
write_protect_args = [PYTHON, '-m', 'espefuse']
|
||||
write_protect_args += _parse_efuse_args(ctx, args, extra_args)
|
||||
|
||||
@@ -16,7 +16,7 @@ from typing import Any
|
||||
from typing import TextIO
|
||||
from typing import cast
|
||||
|
||||
import click
|
||||
import rich_click as click
|
||||
import yaml
|
||||
from esp_idf_monitor import get_ansi_converter
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
from typing import Dict, List
|
||||
|
||||
from click.core import Context
|
||||
from idf_py_actions.tools import PropertyDict, ensure_build_directory, run_target
|
||||
from rich_click import Context
|
||||
|
||||
from idf_py_actions.tools import PropertyDict
|
||||
from idf_py_actions.tools import ensure_build_directory
|
||||
from idf_py_actions.tools import run_target
|
||||
|
||||
|
||||
def action_extensions(base_actions: Dict, project_path: List) -> Dict:
|
||||
def action_extensions(base_actions: dict, project_path: list) -> dict:
|
||||
def uf2_target(target_name: str, ctx: Context, args: PropertyDict, md5_disable: bool) -> None:
|
||||
ensure_build_directory(args, ctx.info_name)
|
||||
extra = list()
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
setuptools
|
||||
packaging
|
||||
click
|
||||
rich-click
|
||||
pyserial
|
||||
cryptography
|
||||
pyparsing
|
||||
|
||||
@@ -33,6 +33,28 @@ py_actions_path = os.path.join(current_dir, '..', 'idf_py_actions')
|
||||
link_path = os.path.join(py_actions_path, 'test_ext')
|
||||
|
||||
|
||||
# As idf.py uses rich-click, unite modification variables to ensure constant results on various CI terminals
|
||||
_idf_py_test_env_saved: dict[str, str | None] = {}
|
||||
|
||||
|
||||
def setUpModule() -> None:
|
||||
for key in ('COLUMNS', 'LINES', 'NO_COLOR', 'FORCE_COLOR', 'PY_COLORS', 'TERM'):
|
||||
_idf_py_test_env_saved[key] = os.environ.get(key)
|
||||
os.environ['COLUMNS'] = '200'
|
||||
os.environ['LINES'] = '40'
|
||||
os.environ['NO_COLOR'] = '1'
|
||||
for unset in ('FORCE_COLOR', 'PY_COLORS'):
|
||||
os.environ.pop(unset, None)
|
||||
|
||||
|
||||
def tearDownModule() -> None:
|
||||
for key, previous in _idf_py_test_env_saved.items():
|
||||
if previous is None:
|
||||
os.environ.pop(key, None)
|
||||
else:
|
||||
os.environ[key] = previous
|
||||
|
||||
|
||||
class TestWithoutExtensions(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
||||
Reference in New Issue
Block a user