def start_shell(self, msg = ""): status_msg = [] status_msg.append(msg) #load convenient modules self.user_ns['time'] = time #find the available devices items = self.config._device_cache.items() items.sort() status_msg.append("Available devices:") for name, device in items: status_msg.append("\t%s" % name) #add device name to the user name space self.user_ns[name] = device #find the available controllers items = self.config._controller_cache.items() items.sort() status_msg.append("Available controllers:") for name, controller in items: status_msg.append("\t%s" % name) #add controller name to the user name space self.user_ns[name] = controller #add all the special commands to the namespace self.user_ns.update(self.commands) #complete the status message status_msg.append('') status_msg.append("-- Hit Ctrl-D to exit. --") status_msg = '\n'.join(status_msg) #start the shell ipshell = None # try: ipshell = IPYTHON_SHELL(user_ns = self.user_ns, banner1 = status_msg) #FIXME change made for ipython >= 0.13 #set up hooks ipshell.set_hook('shutdown_hook',self.shutdown_hook) ipshell.mainloop() #FIXME change made for ipython >= 0.13
logger.warning('import bpython error; trying ipython...') else: try: import IPython if IPython.__version__ >= '0.11': from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(user_ns=_env) shell() return else: # following 2 lines fix a problem with # IPython; thanks Michael Toomim if '__builtins__' in _env: del _env['__builtins__'] shell = IPython.Shell.IPShell(argv=[], user_ns=_env) shell.mainloop() return except: logger.warning( 'import IPython error; use default python shell') try: import readline import rlcompleter except ImportError: pass else: readline.set_completer(rlcompleter.Completer(_env).complete) readline.parse_and_bind('tab:complete') code.interact(local=_env)
'import bpython error; trying ipython...') else: try: import IPython if IPython.__version__ >= '0.11': from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(user_ns=_env) shell() return else: # following 2 lines fix a problem with # IPython; thanks Michael Toomim if '__builtins__' in _env: del _env['__builtins__'] shell = IPython.Shell.IPShell(argv=[], user_ns=_env) shell.mainloop() return except: logger.warning( 'import IPython error; use default python shell') enable_autocomplete_and_history(adir,_env) code.interact(local=_env) def parse_path_info(path_info, av=False): """ Parse path info formatted like a/c/f where c and f are optional and a leading / accepted. Return tuple (a, c, f). If invalid path_info a is set to None. If c or f are omitted they are set to None. If av=True, parse args and vars
def process_argv(argv): """ Process command-line arguments (minus argv[0]!), rearrange and execute. """ # Initial preparation import __main__ for (k,v) in global_constants.items(): exec '%s = %s' % (k,v) in __main__.__dict__ exec_startup_files() # Repeatedly process options, if any, followed by filenames, if any, until nothing is left topo_parser.disable_interspersed_args() args=argv option=None global something_executed while True: # Process options up until the first filename (option,args) = topo_parser.parse_args(args,option) # Handle filename if args: filename=args.pop(0) #print "Executing %s" % (filename) filedir = os.path.dirname(os.path.abspath(filename)) sys.path.insert(0,filedir) # Allow imports relative to this file's path sim_name_from_filename(filename) # Default value of topo.sim.name execfile(filename,__main__.__dict__) something_executed=True if not args: break global_params.check_for_unused_names() # OpenMP settings and defaults openmp_threads = __main__.__dict__.get('openmp_threads') if (openmp_threads is None): openmp_threads=-1 openmp_min_threads = __main__.__dict__.get('openmp_min_threads') if (openmp_min_threads is None): openmp_min_threads=2 openmp_max_threads = __main__.__dict__.get('openmp_max_threads') if (openmp_threads != 1): # OpenMP is disabled if openmp_threads == 1 (num_threads, total_cores) = get_omp_num_threads(openmp_threads, openmp_min_threads, openmp_max_threads) if num_threads is None: print "OpenMP: Using OMP_NUM_THREADS environment variable if set. Otherwise, all cores in use." elif num_threads == 'NSLOTS': os.environ['OMP_NUM_THREADS'] = os.environ['NSLOTS'] print "NSLOTS environment variable found; overriding any other thread settings and using N=%s threads" % os.environ['NSLOTS'] elif total_cores is None: print "OpenMP: Using %d threads" % num_threads os.environ['OMP_NUM_THREADS'] = str(num_threads) else: print "OpenMP: Using %d threads on a machine with %d detected CPUs" % (num_threads, total_cores) os.environ['OMP_NUM_THREADS'] = str(num_threads) # If no scripts and no commands were given, pretend -i was given. if not something_executed: interactive() if option.gui: topo.guimain.title(topo.sim.name) ## INTERACTIVE SESSION BEGINS HERE (i.e. can't have anything but ## some kind of cleanup code afterwards) if os.environ.get('PYTHONINSPECT'): print "Output path: %s" % param.normalize_path.prefix print BANNER # CBALERT: should probably allow a way for users to pass # things to IPython? Or at least set up some kind of # topographica ipython config file. Right now, a topo_parser # option has to be added for every ipython option we want to # support (e.g. see --pdb) if ipython_shell_interface == "IPython.Shell": # IPython 0.10 and earlier # Stop IPython namespace hack? # http://www.nabble.com/__main__-vs-__main__-td14606612.html __main__.__name__="__mynamespace__" ipython_args = ['-noconfirm_exit','-nobanner', '-pi1',CommandPrompt.get_format(), '-pi2',CommandPrompt2.get_format(), '-po',OutputPrompt.get_format()] if option.pdb: ipython_args.append('-pdb') ipshell = IPShell(ipython_args,user_ns=__main__.__dict__) ipshell.mainloop(sys_exit=1) elif ipython_shell_interface == "InteractiveShellEmbed": # IPython 0.11 and later config = Config() if ipython_prompt_interface == "PromptManager": config.PromptManager.in_template = CommandPrompt.get_format() config.PromptManager.in2_template = CommandPrompt2.get_format() config.PromptManager.out_template = OutputPrompt.get_format() else: config.InteractiveShell.prompt_in1 = CommandPrompt.get_format() config.InteractiveShell.prompt_in2 = CommandPrompt2.get_format() config.InteractiveShell.prompt_out = OutputPrompt.get_format() config.InteractiveShell.confirm_exit = False ipshell = IPShell(config=config,user_ns=__main__.__dict__, banner1="",exit_msg="") if option.pdb: ipshell.call_pdb = True ipshell() sys.exit()
on Windows platforms (only IPython v0.10 is fully supported). """ __ipythonshell__ = InteractiveShellEmbed(banner2=banner2)#, # display_banner=False) # __ipythonshell__.shell.show_banner() # __ipythonshell__.enable_pylab(gui='qt') #TODO: parse command line options using the two lines commented # above (banner has to be shown afterwards) #FIXME: Windows platforms: pylab/GUI loop support is not working __ipythonshell__.stdin_encoding = os.environ['SPYDER_ENCODING'] del banner2 except ImportError: # IPython v0.10 import IPython.Shell __ipythonshell__ = IPython.Shell.start() __ipythonshell__.IP.stdin_encoding = os.environ['SPYDER_ENCODING'] __ipythonshell__.IP.autoindent = 0 # Workaround #2 to make the HDF5 I/O variable explorer plugin work: # we import h5py only after initializing IPython in order to avoid # a premature import of IPython *and* to enable the h5py/IPython # completer (which wouldn't be enabled if we used the same approach # as workaround #1) # (see sitecustomize.py for the Workaround #1) try: import h5py #analysis:ignore except ImportError: pass __ipythonshell__.mainloop()
def process_argv(argv): """ Process command-line arguments (minus argv[0]!), rearrange and execute. """ # Initial preparation import __main__ for (k,v) in global_constants.items(): exec '%s = %s' % (k,v) in __main__.__dict__ exec_startup_files() # Repeatedly process options, if any, followed by filenames, if any, until nothing is left topo_parser.disable_interspersed_args() args=argv option=None global something_executed while True: # Process options up until the first filename (option,args) = topo_parser.parse_args(args,option) # Handle filename if args: filename=args.pop(0) #print "Executing %s" % (filename) filedir = os.path.dirname(os.path.abspath(filename)) sys.path.insert(0,filedir) # Allow imports relative to this file's path sim_name_from_filename(filename) # Default value of topo.sim.name execfile(filename,__main__.__dict__) something_executed=True if not args: break global_params.check_for_unused_names() # If no scripts and no commands were given, pretend -i was given. if not something_executed: interactive() if option.gui: topo.guimain.title(topo.sim.name) ## INTERACTIVE SESSION BEGINS HERE (i.e. can't have anything but ## some kind of cleanup code afterwards) if os.environ.get('PYTHONINSPECT'): print BANNER # CBALERT: should probably allow a way for users to pass # things to IPython? Or at least set up some kind of # topographica ipython config file. Right now, a topo_parser # option has to be added for every ipython option we want to # support (e.g. see --pdb) if ipython: if ipython == "0.10": # Stop IPython namespace hack? # http://www.nabble.com/__main__-vs-__main__-td14606612.html __main__.__name__="__mynamespace__" ipython_args = ['-noconfirm_exit','-nobanner', '-pi1',CommandPrompt.get_format(), '-pi2',CommandPrompt2.get_format(), '-po',OutputPrompt.get_format()] if option.pdb: ipython_args.append('-pdb') ipshell = IPShell( ipython_args, user_ns=__main__.__dict__, ) ipshell.mainloop(sys_exit=1) elif ipython == "0.11": config = Config() config.InteractiveShell.prompt_in1 = CommandPrompt.get_format() config.InteractiveShell.prompt_in2 = CommandPrompt2.get_format() config.InteractiveShell.prompt_out = OutputPrompt.get_format() config.InteractiveShell.confirm_exit = False ipshell = IPShell( config=config, user_ns=__main__.__dict__, banner1="", exit_msg="", ) ipshell() sys.exit()
def process_argv(argv): """ Process command-line arguments (minus argv[0]!), rearrange and execute. """ # Initial preparation import __main__ for (k, v) in global_constants.items(): exec '%s = %s' % (k, v) in __main__.__dict__ exec_startup_files() # Repeatedly process options, if any, followed by filenames, if any, until nothing is left topo_parser.disable_interspersed_args() args = argv option = None global something_executed while True: # Process options up until the first filename (option, args) = topo_parser.parse_args(args, option) # Handle filename if args: filename = args.pop(0) #print "Executing %s" % (filename) filedir = os.path.dirname(os.path.abspath(filename)) sys.path.insert( 0, filedir) # Allow imports relative to this file's path sim_name_from_filename(filename) # Default value of topo.sim.name execfile(filename, __main__.__dict__) something_executed = True if not args: break global_params.check_for_unused_names() # OpenMP settings and defaults openmp_threads = __main__.__dict__.get('openmp_threads') if (openmp_threads is None): openmp_threads = -1 openmp_min_threads = __main__.__dict__.get('openmp_min_threads') if (openmp_min_threads is None): openmp_min_threads = 2 openmp_max_threads = __main__.__dict__.get('openmp_max_threads') if (openmp_threads != 1): # OpenMP is disabled if openmp_threads == 1 (num_threads, total_cores) = get_omp_num_threads(openmp_threads, openmp_min_threads, openmp_max_threads) if num_threads is None: print "OpenMP: Using OMP_NUM_THREADS environment variable if set. Otherwise, all cores in use." elif num_threads == 'NSLOTS': os.environ['OMP_NUM_THREADS'] = os.environ['NSLOTS'] print "NSLOTS environment variable found; overriding any other thread settings and using N=%s threads" % os.environ[ 'NSLOTS'] elif total_cores is None: print "OpenMP: Using %d threads" % num_threads os.environ['OMP_NUM_THREADS'] = str(num_threads) else: print "OpenMP: Using %d threads on a machine with %d detected CPUs" % ( num_threads, total_cores) os.environ['OMP_NUM_THREADS'] = str(num_threads) # If no scripts and no commands were given, pretend -i was given. if not something_executed: interactive() if option.gui: topo.guimain.title(topo.sim.name) ## INTERACTIVE SESSION BEGINS HERE (i.e. can't have anything but ## some kind of cleanup code afterwards) if os.environ.get('PYTHONINSPECT'): print "Output path: %s" % param.normalize_path.prefix print BANNER # CBALERT: should probably allow a way for users to pass # things to IPython? Or at least set up some kind of # topographica ipython config file. Right now, a topo_parser # option has to be added for every ipython option we want to # support (e.g. see --pdb) if ipython_shell_interface == "IPython.Shell": # IPython 0.10 and earlier # Stop IPython namespace hack? # http://www.nabble.com/__main__-vs-__main__-td14606612.html __main__.__name__ = "__mynamespace__" ipython_args = [ '-noconfirm_exit', '-nobanner', '-pi1', CommandPrompt.get_format(), '-pi2', CommandPrompt2.get_format(), '-po', OutputPrompt.get_format() ] if option.pdb: ipython_args.append('-pdb') ipshell = IPShell(ipython_args, user_ns=__main__.__dict__) ipshell.mainloop(sys_exit=1) elif ipython_shell_interface == "InteractiveShellEmbed": # IPython 0.11 and later config = Config() if ipython_prompt_interface == "PromptManager": config.PromptManager.in_template = CommandPrompt.get_format() config.PromptManager.in2_template = CommandPrompt2.get_format() config.PromptManager.out_template = OutputPrompt.get_format() else: config.InteractiveShell.prompt_in1 = CommandPrompt.get_format() config.InteractiveShell.prompt_in2 = CommandPrompt2.get_format( ) config.InteractiveShell.prompt_out = OutputPrompt.get_format() config.InteractiveShell.confirm_exit = False ipshell = IPShell(config=config, user_ns=__main__.__dict__, banner1="", exit_msg="") if option.pdb: ipshell.call_pdb = True ipshell() sys.exit()
pass if ip is not None: try: ip.magic( 'config PromptManager.in_template = "EMZED_DEVELOP\\nIn [\\#]: "' ) except: pass for name in ["e", "pi", "path"]: try: ip.ex("del %s" % name) except: pass try: __ipythonshell__.magic( 'config PromptManager.in_template = "EMZED_DEVELOP\\nIn [\\#]: "') except: pass __ipythonshell__.mainloop() ########################################################################### # end of modification ############################################## ########################################################################### else: # standard shell ########################################################################### install_emzed(locals()) ###########################################################################