File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,30 @@ def build_run_args(args):
200200
201201 return run_args
202202
203+ def is_quoted (arg ):
204+ return (arg .startswith ("'" ) and arg .endswith ("'" )) or \
205+ (arg .startswith ('"' ) and arg .endswith ('"' ))
206+
207+ def check_raw_arguments_for_non_ascii ():
208+ bad_args = []
209+
210+ # Skip sys.argv[0] (script name)
211+ for arg in sys .argv [1 :]:
212+ if is_quoted (arg ):
213+ continue # allow non-ASCII inside quotes
214+ for ch in arg :
215+ if ord (ch ) > 127 : # non-ASCII
216+ bad_args .append ((arg , ch , unicodedata .name (ch , "UNKNOWN" )))
217+ break # report each arg once
218+
219+ if bad_args :
220+ print ("\n ⚠️ ERROR: Non-ASCII characters detected in command-line arguments!\n " )
221+ for arg , ch , name in bad_args :
222+ print (f" → Argument: { arg } " )
223+ print (f" Contains non-ASCII character: '{ ch } ' ({ name } )" )
224+ print ("\n This often happens due to copy-paste from PDFs or documents.\n "
225+ "Please retype the arguments using plain ASCII.\n " )
226+ sys .exit (1 )
203227
204228def main ():
205229 """
@@ -239,6 +263,9 @@ def main():
239263 mlc run script --help
240264 mlc pull repo -h
241265 """
266+
267+ check_raw_arguments_for_non_ascii ()
268+
242269 pre_parser = build_pre_parser ()
243270 pre_args , remaining_args = pre_parser .parse_known_args ()
244271
You can’t perform that action at this time.
0 commit comments