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

Detect unmatched skip begin/end commands #1309

Merged
merged 4 commits into from
Oct 18, 2024
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
2 changes: 1 addition & 1 deletion .ci/scripts/run-docs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

if [ "$1" == "readme" ]; then
echo "::group::Create script to run README"
python3 torchchat/utils/scripts/updown.py --create-sections --file README.md --replace 'llama3:stories15M,-l 3:-l 2' --suppress huggingface-cli,HF_TOKEN > ./run-readme.sh
python3 torchchat/utils/scripts/updown.py --create-sections --file README.md --replace 'llama3.1:stories15M,-l 3:-l 2' --suppress huggingface-cli,HF_TOKEN > ./run-readme.sh
# for good measure, if something happened to updown processor,
# and it did not error out, fail with an exit 1
echo "exit 1" >> ./run-readme.sh
Expand Down
28 changes: 25 additions & 3 deletions torchchat/utils/scripts/updown.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import re

skip_nesting_level = 0

###############################################################################################
###
Expand Down Expand Up @@ -115,7 +116,7 @@ def updown_process_line(
return
if len(options) > 1:
output(
"echo 'cross product of options not yet supported anot line {line} of {filename}'\nexit 1",
"echo 'cross product of options not yet supported in line {line} of {filename}'\nexit 1",
suppress_list=None,
replace_list=None,
)
Expand All @@ -137,7 +138,8 @@ def updown_process_line(
def process_command(
line, lineno, filename, predicate_list, replace_list, suppress_list, create_sections
) -> bool:


global skip_nesting_level
command = r"^\[\s*(\w+)\s+(\w+)\s*\]\s*:\s*(.*)"
match = re.search(command, line)

Expand Down Expand Up @@ -168,12 +170,26 @@ def process_command(
)
elif keyword == "skip":
if trailing_command == "begin":
skip_nesting_level += 1
if skip_nesting_level > 1:
output(
"echo 'nested skips are discouraged in line {lineno} of {filename} and may be prohibited in the future'",
replace_list=replace_list,
suppress_list=suppress_list,
)
output(
"if false; then",
replace_list=replace_list,
suppress_list=suppress_list,
)
elif trailing_command == "end":
skip_nesting_level -= 1
if skip_nesting_level < 0:
output(
"echo 'skip end without matching skip begin in line {lineno} of {filename}'\nexit 1;",
replace_list=replace_list,
suppress_list=suppress_list,
)
output(
"fi",
replace_list=replace_list,
Expand All @@ -187,6 +203,12 @@ def process_command(
)
exit(1)
elif keyword == "end":
if skip_nesting_level > 0:
output(
"echo 'skip begin without matching skip end in line {lineno} of {filename}'\nexit 1;",
replace_list=replace_list,
suppress_list=suppress_list,
)
if create_sections:
output(
"echo '::endgroup::'",
Expand Down Expand Up @@ -303,7 +325,7 @@ def updown_processor(
)

output(
"echo 'reached end of file without exit command'\nexit 1;",
"echo 'reached end of file without `end` command'\nexit 1;",
suppress_list=None,
replace_list=None,
)
Expand Down
Loading