feat(tools): adjusted create_ext.py by ruff formatter

This commit is contained in:
Marek Fiala
2025-06-09 10:43:17 +02:00
parent a2257490d2
commit 5ec67f5e2c

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import os
import re
@@ -8,6 +8,7 @@ from shutil import copytree
from typing import Dict
import click
from idf_py_actions.tools import PropertyDict
@@ -29,12 +30,16 @@ def is_empty_and_create(path: str, action: str) -> None:
if not os.path.exists(abspath):
os.makedirs(abspath)
elif not os.path.isdir(abspath):
print('Your target path is not a directory. Please remove the', os.path.abspath(abspath),
'or use different target path.')
print(
f'Your target path is not a directory.'
f'Please remove the {os.path.abspath(abspath)} or use different target path.'
)
sys.exit(4)
elif len(os.listdir(path)) > 0:
print('The directory', abspath, 'is not empty. To create a', get_type(action),
'you must empty the directory or choose a different path.')
print(
f'The directory {abspath} is not empty. To create a {get_type(action)} you must '
f'empty the directory or choose a different path.'
)
sys.exit(3)
@@ -61,8 +66,9 @@ def create_component(target_path: str, name: str) -> None:
dirs_exist_ok=True,
)
os.rename(os.path.join(target_path, 'main.c'), os.path.join(target_path, '.'.join((name, 'c'))))
os.rename(os.path.join(target_path, 'include', 'main.h'),
os.path.join(target_path, 'include', '.'.join((name, 'h'))))
os.rename(
os.path.join(target_path, 'include', 'main.h'), os.path.join(target_path, 'include', '.'.join((name, 'h')))
)
replace_in_file(os.path.join(target_path, '.'.join((name, 'c'))), 'main', name)
replace_in_file(os.path.join(target_path, 'CMakeLists.txt'), 'main', name)
@@ -87,45 +93,50 @@ def action_extensions(base_actions: Dict, project_path: str) -> Dict:
'create-project': {
'callback': create_new,
'short_help': 'Create a new project.',
'help': ('Create a new project with the name NAME specified as argument. '
'For example: '
'`idf.py create-project new_proj` '
'will create a new project in subdirectory called `new_proj` '
'of the current working directory. '
"For specifying the new project's path, use either the option --path for specifying the "
'destination directory, or the global option -C if the project should be created as a '
'subdirectory of the specified directory. '
'If the target path does not exist it will be created. If the target folder is not empty '
'then the operation will fail with return code 3. '
'If the target path is not a folder, the script will fail with return code 4. '
'After the execution idf.py terminates '
'so this operation should be used alone.'),
'help': (
'Create a new project with the name NAME specified as argument. '
'For example: '
'`idf.py create-project new_proj` '
'will create a new project in subdirectory called `new_proj` '
'of the current working directory. '
"For specifying the new project's path, use either the option --path for specifying the "
'destination directory, or the global option -C if the project should be created as a '
'subdirectory of the specified directory. '
'If the target path does not exist it will be created. If the target folder is not empty '
'then the operation will fail with return code 3. '
'If the target path is not a folder, the script will fail with return code 4. '
'After the execution idf.py terminates '
'so this operation should be used alone.'
),
'arguments': [{'names': ['name']}],
'options': [
{
'names': ['-p', '--path'],
'help': ('Set the path for the new project. The project '
'will be created directly in the given folder if it does not contain anything'),
'help': (
'Set the path for the new project. The project '
'will be created directly in the given folder if it does not contain anything'
),
},
],
},
'create-component': {
'callback': create_new,
'short_help': 'Create a new component.',
'help': ('Create a new component with the name NAME specified as argument. '
'For example: '
'`idf.py create-component new_comp` '
'will create a new component in subdirectory called `new_comp` '
'of the current working directory. '
"For specifying the new component's path use the option -C. "
'If the target path does not exist then it will be created. '
'If the target folder is not empty '
'then the operation will fail with return code 3. '
'If the target path is not a folder, the script will fail with return code 4. '
'After the execution idf.py terminates '
'so this operation should be used alone.'),
'help': (
'Create a new component with the name NAME specified as argument. '
'For example: '
'`idf.py create-component new_comp` '
'will create a new component in subdirectory called `new_comp` '
'of the current working directory. '
"For specifying the new component's path use the option -C. "
'If the target path does not exist then it will be created. '
'If the target folder is not empty '
'then the operation will fail with return code 3. '
'If the target path is not a folder, the script will fail with return code 4. '
'After the execution idf.py terminates '
'so this operation should be used alone.'
),
'arguments': [{'names': ['name']}],
}
},
}
}