Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse all lines in app file looking for shebangs to run commands. #15714

Merged
merged 2 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/lightning_app/utilities/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_app/utilities/test_app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# !echo "foo"
import lighting
# !echo "bar"