From 84dd2d0c904f591d9dac9983e6067ec2ea19277e Mon Sep 17 00:00:00 2001 From: Rick Izzo Date: Thu, 17 Nov 2022 18:26:45 +0100 Subject: [PATCH] fixed command parsing so that all lines in the file are parsed --- src/lightning_app/utilities/app_commands.py | 5 +++-- tests/tests_app/utilities/test_app_commands.py | 2 +- .../app_commands/command_after_first_non_comment_line.txt | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lightning_app/utilities/app_commands.py b/src/lightning_app/utilities/app_commands.py index 011cb071299a1..3ec4c6d67dc57 100644 --- a/src/lightning_app/utilities/app_commands.py +++ b/src/lightning_app/utilities/app_commands.py @@ -38,12 +38,13 @@ def _extract_commands_from_file(file_name: str) -> CommandLines: file_lines = f.readlines() for line_number, line in enumerate(file_lines): - if line.strip() in APP_COMMAND_LINES_TO_IGNORE: + line = line.strip() + if line in APP_COMMAND_LINES_TO_IGNORE: continue # stop parsing at first non-comment line at top of file if not line.startswith("#"): - break + continue # remove comment marker and any leading / trailing whitespaces line = line.lstrip("#").strip() diff --git a/tests/tests_app/utilities/test_app_commands.py b/tests/tests_app/utilities/test_app_commands.py index 35f08509dca62..7e3b9beed4104 100644 --- a/tests/tests_app/utilities/test_app_commands.py +++ b/tests/tests_app/utilities/test_app_commands.py @@ -14,7 +14,7 @@ ("multiple_commands.txt", ['echo "foo"', 'echo "bar"'], [1, 2]), ("commands_with_mixed_comments_1.txt", ['echo "foo"', 'echo "bar"'], [1, 3]), ("commands_with_mixed_comments_2.txt", ['echo "foo"', 'echo "bar"'], [2, 4]), - ("command_after_first_non_comment_line.txt", ['echo "foo"'], [1]), + ("command_after_first_non_comment_line.txt", ['echo "foo"', 'echo "bar"'], [2, 4]), ("bang_not_at_start_of_line.txt", ['echo "foo"'], [2]), ("space_between_bang_and_command.txt", ['echo "foo"'], [1]), ("multiple_spaces_between_band_and_command.txt", ['echo "foo"'], [1]), diff --git a/tests/tests_app/utilities/testdata/app_commands/command_after_first_non_comment_line.txt b/tests/tests_app/utilities/testdata/app_commands/command_after_first_non_comment_line.txt index c9d90d8eff892..1cd80f15779df 100644 --- a/tests/tests_app/utilities/testdata/app_commands/command_after_first_non_comment_line.txt +++ b/tests/tests_app/utilities/testdata/app_commands/command_after_first_non_comment_line.txt @@ -1,3 +1,4 @@ + # !echo "foo" import lighting # !echo "bar"