From b5f24287e4670e4d5358d7eb3a5ff765c8caa89c Mon Sep 17 00:00:00 2001 From: Bob Farrell Date: Tue, 24 Jun 2008 20:57:58 +0100 Subject: [PATCH] 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. --- bpython.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/bpython.py b/bpython.py index 5609599..bf0cbde 100644 --- a/bpython.py +++ b/bpython.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# bpython 0.5.3::fancy curses interface to the Python repl::Bob Farrell 2008 +# bpython 0.5.4::fancy curses interface to the Python repl::Bob Farrell 2008 # # The MIT License # @@ -65,6 +65,11 @@ try: alphas, alphanums, printables, ParseException except ImportError: OPTS.arg_spec = False +# XXX: This is for later, as the loadrc function checks that it got imported okay. +# pyparsing will still be in sys.modules even if only part of the import works, so +# this makes sure only a clean import happens or no import. + if 'pyparsing' in sys.modules: + del sys.modules['pyparsing'] else: OPTS.arg_spec = True @@ -218,7 +223,6 @@ class Repl( object ): self.s = '' self.list_win_visible = False - if not OPTS.arg_spec: return @@ -502,6 +506,8 @@ class Repl( object ): self.scr.touchwin() self.scr.cursyncup() self.scr.noutrefresh() +# This looks a little odd, but I can't figure a better way to stick the cursor +# back where it belongs (refreshing the window hides the list_win) self.scr.move( *self.scr.getyx() ) self.list_win.refresh() @@ -1399,10 +1405,15 @@ def loadrc(): leaves them as strings and handles hopefully all the sane ways of representing a boolean.""" - if not os.path.isfile( os.path.expanduser( '~/.bpythonrc' ) ): + if len(sys.argv) > 2: + path = sys.argv[2] + else: + path = os.path.expanduser( '~/.bpythonrc' ) + + if not os.path.isfile( path ): return - f = open( os.path.expanduser( '~/.bpythonrc' ) ) + f = open( path ) parser = shlex.shlex( f ) bools = {