diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/config.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/config.py index 548dd44b38025..8f45432193434 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/config.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/config.py @@ -67,7 +67,9 @@ def config(ctx, check, sync, verbose): spec_file_path = manifest.get_config_spec() if not file_exists(spec_file_path): check_display_queue.append( - lambda: echo_warning(f"Did not find spec file {spec_file_path} for check {check}") + lambda spec_file_path=spec_file_path, check=check: echo_warning( + f"Did not find spec file {spec_file_path} for check {check}" + ) ) validate_config_legacy(check, check_display_queue, files_failed, files_warned, file_counter) @@ -98,7 +100,7 @@ def config(ctx, check, sync, verbose): if not default_temp: message = "Missing default template in init_config or instances section" - check_display_queue.append(lambda **kwargs: echo_failure(message)) + check_display_queue.append(lambda message=message: echo_failure(message)) annotate_error(spec_file_path, message) if spec.errors: @@ -109,7 +111,7 @@ def config(ctx, check, sync, verbose): if spec.data['name'] != display_name: files_failed[spec_file_path] = True message = f"Spec name `{spec.data['name']}` should be `{display_name}`" - check_display_queue.append(lambda **kwargs: echo_failure(message, **kwargs)) + check_display_queue.append(lambda message=message, **kwargs: echo_failure(message, **kwargs)) annotate_error(spec_file_path, message) example_location = get_data_directory(check) @@ -136,7 +138,7 @@ def config(ctx, check, sync, verbose): ): message += f'\n{diff_line}' check_display_queue.append( - lambda example_file=example_file, **kwargs: echo_failure(message, **kwargs) + lambda message=message, **kwargs: echo_failure(message, **kwargs) ) annotate_error(example_file_path, message) @@ -203,9 +205,9 @@ def validate_config_legacy(check, check_display_queue, files_failed, files_warne # We must convert to text here to free Exception object before it goes out of scope error = str(e) - check_display_queue.append(lambda: echo_info(f'{file_name}:', indent=True)) + check_display_queue.append(lambda file_name=file_name: echo_info(f'{file_name}:', indent=True)) check_display_queue.append(lambda: echo_failure('Invalid YAML -', indent=FILE_INDENT)) - check_display_queue.append(lambda: echo_info(error, indent=FILE_INDENT * 2)) + check_display_queue.append(lambda error=error: echo_info(error, indent=FILE_INDENT * 2)) continue file_display_queue = [] @@ -225,7 +227,7 @@ def validate_config_legacy(check, check_display_queue, files_failed, files_warne if 'instances' not in config_data: files_failed[config_file] = True message = 'Missing `instances` section' - file_display_queue.append(lambda: echo_failure(message, indent=FILE_INDENT)) + file_display_queue.append(lambda message=message: echo_failure(message, indent=FILE_INDENT)) annotate_error(file_name, message) # Verify there is a default instance else: @@ -233,7 +235,7 @@ def validate_config_legacy(check, check_display_queue, files_failed, files_warne if check not in IGNORE_DEFAULT_INSTANCE and not isinstance(instances, list): files_failed[config_file] = True message = 'No default instance' - file_display_queue.append(lambda: echo_failure(message, indent=FILE_INDENT)) + file_display_queue.append(lambda message=message: echo_failure(message, indent=FILE_INDENT)) annotate_error(file_name, message) if file_display_queue: diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/config_block.py b/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/config_block.py index 933e58d4217b9..65ffdd00c8edb 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/config_block.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/config_block.py @@ -183,9 +183,9 @@ def parse_from_strings(cls, start, config_lines, indent, errors): def _get_end_of_param_declaration_block(start, end, config_lines, indent, errors, is_list=False): - """Here we suppose the config block is correctly formatted (@param, description, empty comment then the actual content) - and try to return the line of any data coming after. In case of a object we point to its first member. In case - of a list or a simple variable we point to the next element. + """Here we suppose the config block is correctly formatted (@param, description, empty comment then the + actual content) and try to return the line of any data coming after. In case of an object we point to its first + member. In case of a list or a simple variable we point to the next element. """ if not is_exactly_indented(config_lines[start], indent): diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/validator.py b/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/validator.py index b77493ec3883d..947805aff292d 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/validator.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/config_validator/validator.py @@ -79,9 +79,9 @@ def _parse_init_config(config_lines, init_config_start_line, errors): def _parse_for_config_blocks(config_lines, start, end, errors): - """The function basically do all the work. It reads the config from start, removes blank lines first then when it first - sees data, it sets the 'indent' variable once for all. All blocks read in a given function call must have the same - indentation. Sub-blocks are parsed recursively and thus the 'indent' variable is given a new value. + """The function basically do all the work. It reads the config from start, removes blank lines first then when + it first sees data, it sets the 'indent' variable once for all. All blocks read in a given function call must + have the same indentation. Sub-blocks are parsed recursively and thus the 'indent' variable is given a new value. Once a block is parsed the function will either recurse if the block requires it (see ConfigBlock), or it will go to the next block and iterate. """