diff --git a/.ci/scripts/run-docs b/.ci/scripts/run-docs index fb0eb53ec..a09944ad5 100755 --- a/.ci/scripts/run-docs +++ b/.ci/scripts/run-docs @@ -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 diff --git a/torchchat/utils/scripts/updown.py b/torchchat/utils/scripts/updown.py index 94cf52cc6..86ebf803f 100644 --- a/torchchat/utils/scripts/updown.py +++ b/torchchat/utils/scripts/updown.py @@ -9,6 +9,7 @@ import os import re +skip_nesting_level = 0 ############################################################################################### ### @@ -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, ) @@ -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) @@ -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, @@ -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::'", @@ -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, )