change(tools): shell_types.py ruff formatting

This commit is contained in:
Marek Fiala
2025-07-21 11:05:42 +02:00
parent 75809d4397
commit b7efec31d2

View File

@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
import argparse import argparse
import os import os
@@ -21,29 +21,29 @@ from utils import run_cmd
def parse_arguments() -> argparse.Namespace: def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(prog='activate', parser = argparse.ArgumentParser(
description='Activate ESP-IDF environment', prog='activate',
epilog='On Windows, run `python activate.py` to execute this script in the current terminal window.') description='Activate ESP-IDF environment',
parser.add_argument('-s', '--shell', epilog='On Windows, run `python activate.py` to execute this script in the current terminal window.',
metavar='SHELL', )
default=os.environ.get('ESP_IDF_SHELL', 'detect'), parser.add_argument(
help='Explicitly specify shell to start. For example bash, zsh, powershell.exe, cmd.exe') '-s',
parser.add_argument('-l', '--list', '--shell',
action='store_true', metavar='SHELL',
help=('List supported shells.')) default=os.environ.get('ESP_IDF_SHELL', 'detect'),
parser.add_argument('-e', '--export', help='Explicitly specify shell to start. For example bash, zsh, powershell.exe, cmd.exe',
action='store_true', )
help=('Generate commands to run in the terminal.')) parser.add_argument('-l', '--list', action='store_true', help=('List supported shells.'))
parser.add_argument('-n', '--no-color', parser.add_argument('-e', '--export', action='store_true', help=('Generate commands to run in the terminal.'))
action='store_true', parser.add_argument('-n', '--no-color', action='store_true', help=('Disable ANSI color escape sequences.'))
help=('Disable ANSI color escape sequences.')) parser.add_argument(
parser.add_argument('-d', '--debug', '-d',
action='store_true', '--debug',
default=bool(os.environ.get('ESP_IDF_EXPORT_DEBUG')), action='store_true',
help=('Enable debug information.')) default=bool(os.environ.get('ESP_IDF_EXPORT_DEBUG')),
parser.add_argument('-q', '--quiet', help=('Enable debug information.'),
action='store_true', )
help=('Suppress all output.')) parser.add_argument('-q', '--quiet', action='store_true', help=('Suppress all output.'))
return parser.parse_args() return parser.parse_args()
@@ -72,11 +72,13 @@ def get_deactivate_cmd() -> str:
@status_message('Establishing a new ESP-IDF environment') @status_message('Establishing a new ESP-IDF environment')
def get_idf_env() -> Dict[str,str]: def get_idf_env() -> Dict[str, str]:
# Get ESP-IDF system environment variables # Get ESP-IDF system environment variables
extra_paths_list = [os.path.join('components', 'espcoredump'), extra_paths_list = [
os.path.join('components', 'partition_table'), os.path.join('components', 'espcoredump'),
os.path.join('components', 'app_update')] os.path.join('components', 'partition_table'),
os.path.join('components', 'app_update'),
]
extra_paths = os.pathsep.join([os.path.join(conf.IDF_PATH, path) for path in extra_paths_list]) extra_paths = os.pathsep.join([os.path.join(conf.IDF_PATH, path) for path in extra_paths_list])
cmd = [sys.executable, conf.IDF_TOOLS_PY, 'export', '--format', 'key-value', '--add_paths_extras', extra_paths] cmd = [sys.executable, conf.IDF_TOOLS_PY, 'export', '--format', 'key-value', '--add_paths_extras', extra_paths]
stdout = run_cmd(cmd) stdout = run_cmd(cmd)
@@ -93,11 +95,16 @@ def get_idf_env() -> Dict[str,str]:
var, val = line.split('=') var, val = line.split('=')
idf_env[var] = val idf_env[var] = val
except ValueError as e: except ValueError as e:
debug('\n'.join(['Output from `./tools/idf_tools.py export --format key-value`:', debug('\n'.join(['Output from `./tools/idf_tools.py export --format key-value`:', f'{stdout}']))
f'{stdout}'])) raise ValueError(
raise ValueError('\n'.join(['Please ensure your ESP-IDF installation is clean, especially file `./tools/idf_tools.py`.', '\n'.join(
'The command `./tools/idf_tools.py export` appears to be returning unexpected values.', [
f'Details: {e}'])) 'Please ensure your ESP-IDF installation is clean, especially file `./tools/idf_tools.py`.',
'The command `./tools/idf_tools.py export` appears to be returning unexpected values.',
f'Details: {e}',
]
)
)
if 'PATH' in idf_env: if 'PATH' in idf_env:
idf_env['PATH'] = os.pathsep.join([extra_paths, idf_env['PATH']]) idf_env['PATH'] = os.pathsep.join([extra_paths, idf_env['PATH']])
@@ -135,10 +142,12 @@ def print_uninstall_msg() -> Any:
stdout = run_cmd([sys.executable, conf.IDF_TOOLS_PY, 'uninstall', '--dry-run']) stdout = run_cmd([sys.executable, conf.IDF_TOOLS_PY, 'uninstall', '--dry-run'])
if stdout: if stdout:
python_cmd = 'python.exe' if sys.platform == 'win32' else 'python' python_cmd = 'python.exe' if sys.platform == 'win32' else 'python'
msg = (f'Found tools that are not used by active ESP-IDF version.\n' msg = (
f'[bright_cyan]{stdout}\n' f'Found tools that are not used by active ESP-IDF version.\n'
f'To free up even more space, remove installation packages of those tools.\n' f'[bright_cyan]{stdout}\n'
f'Use option {python_cmd} {conf.IDF_TOOLS_PY} uninstall --remove-archives.') f'To free up even more space, remove installation packages of those tools.\n'
f'Use option {python_cmd} {conf.IDF_TOOLS_PY} uninstall --remove-archives.'
)
else: else:
msg = 'OK - no outdated tools found' msg = 'OK - no outdated tools found'
@@ -186,9 +195,11 @@ def main() -> None:
shell.export() shell.export()
sys.exit() sys.exit()
eprint(f'[dark_orange]Starting new \'{shell.shell}\' shell with ESP-IDF environment... (use "exit" command to quit)') eprint(
f'[dark_orange]Starting new \'{shell.shell}\' shell with ESP-IDF environment... (use "exit" command to quit)'
)
shell.spawn() shell.spawn()
eprint(f'[dark_orange]ESP-IDF environment exited.') eprint('[dark_orange]ESP-IDF environment exited.')
if __name__ == '__main__': if __name__ == '__main__':