Skip to content

Commit b674ff5

Browse files
committed
Set up sys.path properly. Also don't read PYTHONSTARTUP when executed with -i.
The latter to be consistent with Python. This closes issue #88.
1 parent b70c809 commit b674ff5

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

bpython/args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,6 @@ def exec_code(interpreter, args):
101101
with open(args[0], 'r') as sourcefile:
102102
code_obj = compile(sourcefile.read(), args[0], 'exec')
103103
old_argv, sys.argv = sys.argv, args
104+
sys.path.insert(0, os.path.abspath(os.path.dirname(args[0])))
104105
interpreter.runcode(code_obj)
105106
sys.argv = old_argv

bpython/cli.py

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

1551-
repl.startup()
1552-
15531551
if args:
15541552
bpython.args.exec_code(interpreter, args)
15551553
if not interactive:
15561554
curses.raw(False)
15571555
return repl.getstdout()
1556+
else:
1557+
sys.path.insert(0, '')
1558+
repl.startup()
15581559

15591560
if banner is not None:
15601561
repl.write(banner)

bpython/gtk_.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,10 @@ def main(args=None):
637637
sys.stdout = repl_widget
638638

639639
gobject.idle_add(init_import_completion)
640-
gobject.idle_add(repl_widget.startup)
640+
641+
if not args:
642+
sys.path.insert(0, '')
643+
gobject.idle_add(repl_widget.startup)
641644

642645
if not options.socket_id:
643646
parent = gtk.Window()

bpython/repl.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ def __init__(self, interp, config, idle=None):
296296
self.list_win_visible = False
297297
self._C = {}
298298
self.prev_block_finished = 0
299-
sys.path.insert(0, '.')
300299

301300
pythonhist = os.path.expanduser(self.config.hist_file)
302301
if os.path.exists(pythonhist):

doc/bpython.1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Show the help message and exit.
7070
.IP "\fB\-\-interactive\fR" 4
7171
.PD
7272
Drop to bpython shell after running \fIfile\fR instead of exiting.
73+
The PYTHONSTARTUP file is not read.
7374
.IP "\fB\-q\fR" 4
7475
.PD 0
7576
.IP "\fB\-\-quiet\fR" 4

0 commit comments

Comments
 (0)