19
19
from bpython .importcompletion import find_iterator
20
20
from bpython .curtsiesfrontend import events as bpythonevents
21
21
from bpython import inspection
22
+ from bpython .repl import extract_exit_value
22
23
23
24
logger = logging .getLogger (__name__ )
24
25
@@ -55,7 +56,7 @@ def main(args=None, locals_=None, banner=None):
55
56
if exec_args :
56
57
if not options :
57
58
raise ValueError ("don't pass in exec_args without options" )
58
- exit_value = 0
59
+ exit_value = ()
59
60
if options .paste :
60
61
paste = curtsies .events .PasteEvent ()
61
62
encoding = inspection .get_encoding_file (exec_args [0 ])
@@ -69,14 +70,18 @@ def main(args=None, locals_=None, banner=None):
69
70
except SystemExit as e :
70
71
exit_value = e .args
71
72
if not options .interactive :
72
- raise SystemExit (exit_value )
73
+ return extract_exit_value (exit_value )
73
74
else :
74
75
# expected for interactive sessions (vanilla python does it)
75
76
sys .path .insert (0 , '' )
76
77
77
78
print (bpargs .version_banner ())
78
- mainloop (config , locals_ , banner , interp , paste ,
79
- interactive = (not exec_args ))
79
+ try :
80
+ exit_value = mainloop (config , locals_ , banner , interp , paste ,
81
+ interactive = (not exec_args ))
82
+ except (SystemExitFromCodeGreenlet , SystemExit ) as e :
83
+ exit_value = e .args
84
+ return extract_exit_value (exit_value )
80
85
81
86
82
87
def mainloop (config , locals_ , banner , interp = None , paste = None ,
0 commit comments