Skip to content

Commit 96ff174

Browse files
Marek Fialaespressif-bot
authored andcommitted
feat(tools): idf.py extension - added interface version
1 parent 7ac1c54 commit 96ff174

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

docs/en/api-guides/tools/idf-py.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ An extension file defines an ``action_extensions`` function which returns additi
333333
print(f"About to execute {len(tasks)} task(s): {[t.name for t in tasks]}")
334334
335335
return {
336+
"version": "1",
336337
"global_options": [
337338
{
338339
"names": ["--detail", "-d"],
@@ -362,8 +363,9 @@ An extension file defines an ``action_extensions`` function which returns additi
362363
Extension API Reference
363364
-----------------------
364365

365-
The ``action_extensions`` function takes arguments ``base_actions`` (all currently registered commands) and ``project_path`` (absolute project directory) and returns a dictionary with up to three keys:
366+
The ``action_extensions`` function takes arguments ``base_actions`` (all currently registered commands) and ``project_path`` (absolute project directory) and returns a dictionary with up to four keys:
366367

368+
- ``version``: A string representing the interface version of the extension. Currently, the API version is ``1``. **This key is mandatory** and must be provided.
367369
- ``global_options``: A list of options available globally for all commands. Each option is a dictionary with fields such as ``names``, ``help``, ``type``, ``is_flag``, ``scope``, etc.
368370
- ``global_action_callbacks``: A list of functions called once before any task execution. Each global action callback function accepts three arguments:
369371

tools/idf_py_actions/tools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,12 @@ def _check_action_conflicts(name: str, action: dict[str, Any], existing_identifi
768768
if not custom_actions:
769769
return merged_actions
770770

771+
if not custom_actions.get('version'):
772+
raise AttributeError(
773+
'Attribute "version" is required in custom extension. '
774+
'Please update your extension dictionary to contain the "version" attribute.'
775+
)
776+
771777
existing_identifiers = _get_all_action_identifiers(merged_actions['actions'])
772778
for name, action in custom_actions.get('actions', {}).items():
773779
try:

tools/test_build_system/test_idf_extension.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_extension_action(target_name, ctx, args):
2323
return 0
2424
2525
return {{
26+
'version': '1',
2627
'global_options': [{global_options}],
2728
'actions': {{
2829
{actions}
@@ -211,6 +212,26 @@ def some_function():
211212
ret = idf_py('--help')
212213
assert "has no attribute 'action_extensions'" in ret.stderr
213214

215+
idf_ext_py.write_text(
216+
textwrap.dedent(
217+
TEST_EXT_TEMPLATE.format(
218+
suffix='component extension',
219+
global_options='',
220+
actions="""'test-component-action': {
221+
'callback': test_extension_action,
222+
'help': 'Test action from component extension'
223+
}""",
224+
)
225+
)
226+
)
227+
replace_in_file(
228+
idf_ext_py,
229+
"'version': '1',",
230+
'\n',
231+
)
232+
ret = idf_py('--help')
233+
assert 'Attribute "version" is required in custom extension.' in ret.stderr
234+
214235

215236
# ----------- Test cases for entry point extension -----------
216237

0 commit comments

Comments
 (0)