kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bug/interactive_hints_v5.1' into 'release/v5.1'
tools: fix hints processing in interactive mode (v5.1) See merge request espressif/esp-idf!23795pull/11519/head
commit
82c6c8149c
|
@ -134,13 +134,15 @@ def debug_print_idf_version() -> None:
|
|||
print_warning(f'ESP-IDF {idf_version() or "version unknown"}')
|
||||
|
||||
|
||||
def generate_hints(*filenames: str) -> Generator:
|
||||
"""Getting output files and printing hints on how to resolve errors based on the output."""
|
||||
def load_hints() -> Any:
|
||||
"""Helper function to load hints yml file"""
|
||||
with open(os.path.join(os.path.dirname(__file__), 'hints.yml'), 'r') as file:
|
||||
hints = yaml.safe_load(file)
|
||||
for file_name in filenames:
|
||||
with open(file_name, 'r') as file:
|
||||
output = ' '.join(line.strip() for line in file if line.strip())
|
||||
return hints
|
||||
|
||||
|
||||
def generate_hints_buffer(output: str, hints: list) -> Generator:
|
||||
"""Helper function to process hints within a string buffer"""
|
||||
for hint in hints:
|
||||
variables_list = hint.get('variables')
|
||||
hint_list, hint_vars, re_vars = [], [], []
|
||||
|
@ -176,6 +178,15 @@ def generate_hints(*filenames: str) -> Generator:
|
|||
raise KeyError("Argument 'hint' missing in {}. Check hints.yml file.".format(hint))
|
||||
|
||||
|
||||
def generate_hints(*filenames: str) -> Generator:
|
||||
"""Getting output files and printing hints on how to resolve errors based on the output."""
|
||||
hints = load_hints()
|
||||
for file_name in filenames:
|
||||
with open(file_name, 'r') as file:
|
||||
output = ' '.join(line.strip() for line in file if line.strip())
|
||||
yield from generate_hints_buffer(output, hints)
|
||||
|
||||
|
||||
def fit_text_in_terminal(out: str) -> str:
|
||||
"""Fit text in terminal, if the string is not fit replace center with `...`"""
|
||||
space_for_dots = 3 # Space for "..."
|
||||
|
@ -236,6 +247,8 @@ class RunTool:
|
|||
return
|
||||
|
||||
if stderr_output_file and stdout_output_file:
|
||||
# hints in interactive mode were already processed, don't print them again
|
||||
if not self.interactive:
|
||||
for hint in generate_hints(stderr_output_file, stdout_output_file):
|
||||
yellow_print(hint)
|
||||
raise FatalError('{} failed with exit code {}, output of the command is in the {} and {}'.format(self.tool_name, process.returncode,
|
||||
|
@ -308,6 +321,10 @@ class RunTool:
|
|||
# use ANSI color converter for Monitor on Windows
|
||||
output_converter = get_ansi_converter(output_stream) if self.convert_output else output_stream
|
||||
|
||||
# used in interactive mode to print hints after matched line
|
||||
hints = load_hints()
|
||||
last_line = ''
|
||||
|
||||
try:
|
||||
with open(output_filename, 'w', encoding='utf8') as output_file:
|
||||
while True:
|
||||
|
@ -317,6 +334,7 @@ class RunTool:
|
|||
output = await read_stream()
|
||||
if not output:
|
||||
break
|
||||
|
||||
output_noescape = delete_ansi_escape(output)
|
||||
# Always remove escape sequences when writing the build log.
|
||||
output_file.write(output_noescape)
|
||||
|
@ -332,6 +350,14 @@ class RunTool:
|
|||
else:
|
||||
output_converter.write(output)
|
||||
output_converter.flush()
|
||||
|
||||
# process hints for last line and print them right away
|
||||
if self.interactive:
|
||||
last_line += output
|
||||
if last_line[-1] == '\n':
|
||||
for hint in generate_hints_buffer(last_line, hints):
|
||||
yellow_print(hint)
|
||||
last_line = ''
|
||||
except (RuntimeError, EnvironmentError) as e:
|
||||
yellow_print('WARNING: The exception {} was raised and we can\'t capture all your {} and '
|
||||
'hints on how to resolve errors can be not accurate.'.format(e, output_stream.name.strip('<>')))
|
||||
|
|
Ładowanie…
Reference in New Issue