X Tutup
Skip to content

Commit 917471c

Browse files
committed
make traceback line number frobbing smarter and make PYTHONSTARTUP execution happen after initialisation of repl to allow the repl to deal with any exceptions that may be raised in the file
1 parent 5697d6f commit 917471c

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

bpython/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@ def main_curses(scr, args, config, interactive=True, locals_=None):
15481548
sys.stdout = repl
15491549
sys.stderr = repl
15501550

1551+
repl.startup()
1552+
15511553
if args:
15521554
with open(args[0], 'r') as sourcefile:
15531555
code_obj = compile(sourcefile.read(), args[0], 'exec')

bpython/gtk_.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ def main(args=None):
629629
sys.stderr = repl_widget
630630
sys.stdout = repl_widget
631631

632+
# repl.startup()
633+
632634
gobject.idle_add(init_import_completion)
633635

634636
window = gtk.Window()
@@ -642,6 +644,7 @@ def main(args=None):
642644
window.add(sw)
643645
window.show_all()
644646
window.connect('delete-event', lambda widget, event: gtk.main_quit())
647+
645648
gtk.main()
646649

647650

bpython/repl.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ def showtraceback(self):
112112
tblist = traceback.extract_tb(tb)
113113
del tblist[:1]
114114
# Set the right lineno (encoding header adds an extra line)
115-
lineno = tblist[0][1]
116115
if not py3:
117-
lineno -= 1
118-
tblist[0] = (tblist[0][0], lineno) + tblist[0][2:]
116+
for i, (filename, lineno, module, something) in enumerate(tblist):
117+
if filename == '<input>':
118+
tblist[i] = (filename, lineno - 1, module, something)
119119

120120
l = traceback.format_list(tblist)
121121
if l:
@@ -301,9 +301,11 @@ def __init__(self, interp, config, idle=None):
301301
if os.path.exists(pythonhist):
302302
self.rl_history.load(pythonhist, getpreferredencoding())
303303

304-
# This was a feature request to have the PYTHONSTARTUP
305-
# file executed on startup - I personally don't use this
306-
# feature so please notify me of any breakage.
304+
def startup(self):
305+
"""
306+
Execute PYTHONSTARTUP file if it exits. Call this after front
307+
end-specific initialisation.
308+
"""
307309
filename = os.environ.get('PYTHONSTARTUP')
308310
if filename and os.path.isfile(filename):
309311
with open(filename, 'r') as f:

0 commit comments

Comments
 (0)
X Tutup