Skip to content

Commit c3159a1

Browse files
author
Bob Farrell
committed
pyparsing import cleaned up
An ImportError was being raised for pyparsing even if it was being partly successfully imported which may have caused problems in other places. committer: Bob Farrell <bob@keys.(none)>
1 parent d657028 commit c3159a1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎bpython.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# bpython 0.5.3::fancy curses interface to the Python repl::Bob Farrell 2008
2+
# bpython 0.5.4::fancy curses interface to the Python repl::Bob Farrell 2008
33
#
44
# The MIT License
55
#
@@ -65,6 +65,11 @@ class Dummy( object ):
6565
alphas, alphanums, printables, ParseException
6666
except ImportError:
6767
OPTS.arg_spec = False
68+
# XXX: This is for later, as the loadrc function checks that it got imported okay.
69+
# pyparsing will still be in sys.modules even if only part of the import works, so
70+
# this makes sure only a clean import happens or no import.
71+
if 'pyparsing' in sys.modules:
72+
del sys.modules['pyparsing']
6873
else:
6974
OPTS.arg_spec = True
7075

@@ -218,7 +223,6 @@ def __init__( self, scr, interp, statusbar=None, idle=None):
218223
self.s = ''
219224
self.list_win_visible = False
220225

221-
222226
if not OPTS.arg_spec:
223227
return
224228

@@ -502,6 +506,8 @@ def lsize():
502506
self.scr.touchwin()
503507
self.scr.cursyncup()
504508
self.scr.noutrefresh()
509+
# This looks a little odd, but I can't figure a better way to stick the cursor
510+
# back where it belongs (refreshing the window hides the list_win)
505511
self.scr.move( *self.scr.getyx() )
506512
self.list_win.refresh()
507513

@@ -1399,10 +1405,15 @@ def loadrc():
13991405
leaves them as strings and handles hopefully all the sane ways of
14001406
representing a boolean."""
14011407

1402-
if not os.path.isfile( os.path.expanduser( '~/.bpythonrc' ) ):
1408+
if len(sys.argv) > 2:
1409+
path = sys.argv[2]
1410+
else:
1411+
path = os.path.expanduser( '~/.bpythonrc' )
1412+
1413+
if not os.path.isfile( path ):
14031414
return
14041415

1405-
f = open( os.path.expanduser( '~/.bpythonrc' ) )
1416+
f = open( path )
14061417
parser = shlex.shlex( f )
14071418

14081419
bools = {

0 commit comments

Comments
 (0)