File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ Things to notice:
3+ - `main()` can take `argv` as a `list[str]` and can return an `i32` exit code
4+ - the exit code is propagated to the OS
5+ - `argv` contains the script/executable name and the script arguments
6+ """
7+
18def main(argv: list[str]) -> i32:
29 print("argv:")
310 for arg in argv:
Original file line number Diff line number Diff line change 3232libspy .LIBSPY_WASM = str (URL .new ("./libspy.mjs" , document .baseURI ))
3333
3434
35- def spy_main (argv ):
36- try :
37- spy .cli .app (argv )
38- except SystemExit :
39- pass
40-
41-
4235# =========== GUI code ==========
4336
4437
@@ -152,7 +145,7 @@ def run_spy_file_with_args(argv: list[str]):
152145 with open (display_filename , "w" ) as f :
153146 f .write (text )
154147
155- spy_main (argv )
148+ spy . cli . app (argv )
156149
157150
158151def run_click (event ):
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ packages = [ "micropip"]
44[files ]
55"pyscript.toml" = " "
66"hello_add.spy" = " examples/1_high_level/"
7+ "exit_code.spy" = " examples/1_high_level/"
78"bluefunc_pi.spy" = " examples/2_metaprogramming/"
89"bluefunc_adder.spy" = " examples/2_metaprogramming/"
910"point.spy" = " examples/3_low_level/"
Original file line number Diff line number Diff line change 2929
3030async def _pyodide_main (user_func : Callable , args : "Base_Args" ) -> None :
3131 """
32- For some reasons, it seems that pyodide doesn't print exceptions
33- uncaught exceptions which escapes an asyncio task. This is a small wrapper
34- to ensure that we display a proper traceback in that case
32+ For some reasons, it seems that pyodide doesn't print uncaught exceptions
33+ which escapes an asyncio task. This is a small wrapper to ensure that we
34+ display a proper traceback in that case.
3535 """
3636 try :
3737 await _run_command (user_func , args )
38- except BaseException :
38+ except BaseException as exc :
39+ if isinstance (exc , SystemExit ):
40+ return
3941 traceback .print_exc ()
4042
4143
You can’t perform that action at this time.
0 commit comments