def make_argument_parser(): """ Creates an ArgumentParser for the generic arguments supported by all kernel entry points. """ parser = ArgumentParser() parser.add_argument('--ip', type=str, default=LOCALHOST, help='set the kernel\'s IP address [default: local]') parser.add_argument('--xrep', type=int, metavar='PORT', default=0, help='set the XREP channel port [default: random]') parser.add_argument('--pub', type=int, metavar='PORT', default=0, help='set the PUB channel port [default: random]') parser.add_argument('--req', type=int, metavar='PORT', default=0, help='set the REQ channel port [default: random]') parser.add_argument('--hb', type=int, metavar='PORT', default=0, help='set the heartbeat port [default: random]') parser.add_argument('--no-stdout', action='store_true', help='redirect stdout to the null device') parser.add_argument('--no-stderr', action='store_true', help='redirect stderr to the null device') if sys.platform == 'win32': parser.add_argument('--interrupt', type=int, metavar='HANDLE', default=0, help='interrupt this process when ' 'HANDLE is signaled') parser.add_argument('--parent', type=int, metavar='HANDLE', default=0, help='kill this process if the process ' 'with HANDLE dies') else: parser.add_argument('--parent', action='store_true', help='kill this process if its parent dies') return parser
def _add_arguments(self): # Don't call ClusterDirConfigLoader._add_arguments as we don't want # its defaults on self.parser. Instead, we will put those on # default options on our subparsers. # This has all the common options that all subcommands use parent_parser1 = ArgumentParser(add_help=False, argument_default=SUPPRESS) self._add_ipython_dir(parent_parser1) self._add_log_level(parent_parser1) # This has all the common options that other subcommands use parent_parser2 = ArgumentParser(add_help=False, argument_default=SUPPRESS) self._add_cluster_profile(parent_parser2) self._add_cluster_dir(parent_parser2) self._add_work_dir(parent_parser2) paa = parent_parser2.add_argument paa('--log-to-file', action='store_true', dest='Global.log_to_file', help='Log to a file in the log directory (default is stdout)') # Create the object used to create the subparsers. subparsers = self.parser.add_subparsers( dest='Global.subcommand', title='ipcluster subcommands', description= """ipcluster has a variety of subcommands. The general way of running ipcluster is 'ipcluster <cmd> [options]'. To get help on a particular subcommand do 'ipcluster <cmd> -h'.""" # help="For more help, type 'ipcluster <cmd> -h'", ) # The "list" subcommand parser parser_list = subparsers.add_parser( 'list', parents=[parent_parser1], argument_default=SUPPRESS, help="List all clusters in cwd and ipython_dir.", description= """List all available clusters, by cluster directory, that can be found in the current working directly or in the ipython directory. Cluster directories are named using the convention 'cluster_<profile>'.""") # The "create" subcommand parser parser_create = subparsers.add_parser( 'create', parents=[parent_parser1, parent_parser2], argument_default=SUPPRESS, help="Create a new cluster directory.", description= """Create an ipython cluster directory by its profile name or cluster directory path. Cluster directories contain configuration, log and security related files and are named using the convention 'cluster_<profile>'. By default they are located in your ipython directory. Once created, you will probably need to edit the configuration files in the cluster directory to configure your cluster. Most users will create a cluster directory by profile name, 'ipcluster create -p mycluster', which will put the directory in '<ipython_dir>/cluster_mycluster'. """) paa = parser_create.add_argument paa('--reset-config', dest='Global.reset_config', action='store_true', help="""Recopy the default config files to the cluster directory. You will loose any modifications you have made to these files.""") # The "start" subcommand parser parser_start = subparsers.add_parser( 'start', parents=[parent_parser1, parent_parser2], argument_default=SUPPRESS, help="Start a cluster.", description= """Start an ipython cluster by its profile name or cluster directory. Cluster directories contain configuration, log and security related files and are named using the convention 'cluster_<profile>' and should be creating using the 'start' subcommand of 'ipcluster'. If your cluster directory is in the cwd or the ipython directory, you can simply refer to it using its profile name, 'ipcluster start -n 4 -p <profile>`, otherwise use the '--cluster-dir' option. """) paa = parser_start.add_argument paa('-n', '--number', type=int, dest='Global.n', help='The number of engines to start.', metavar='Global.n') paa('--clean-logs', dest='Global.clean_logs', action='store_true', help='Delete old log flies before starting.') paa('--no-clean-logs', dest='Global.clean_logs', action='store_false', help="Don't delete old log flies before starting.") paa('--daemon', dest='Global.daemonize', action='store_true', help='Daemonize the ipcluster program. This implies --log-to-file') paa('--no-daemon', dest='Global.daemonize', action='store_false', help="Dont't daemonize the ipcluster program.") # The "stop" subcommand parser parser_stop = subparsers.add_parser( 'stop', parents=[parent_parser1, parent_parser2], argument_default=SUPPRESS, help="Stop a running cluster.", description= """Stop a running ipython cluster by its profile name or cluster directory. Cluster directories are named using the convention 'cluster_<profile>'. If your cluster directory is in the cwd or the ipython directory, you can simply refer to it using its profile name, 'ipcluster stop -p <profile>`, otherwise use the '--cluster-dir' option. """) paa = parser_stop.add_argument paa('--signal', dest='Global.signal', type=int, help= "The signal number to use in stopping the cluster (default=2).", metavar="Global.signal")
def main(): """ Entry point for application. """ # Parse command line arguments. parser = ArgumentParser() kgroup = parser.add_argument_group('kernel options') kgroup.add_argument('-e', '--existing', action='store_true', help='connect to an existing kernel') kgroup.add_argument('--ip', type=str, default=LOCALHOST, help=\ "set the kernel\'s IP address [default localhost].\ If the IP address is something other than localhost, then \ Consoles on other machines will be able to connect\ to the Kernel, so be careful!") kgroup.add_argument('--xreq', type=int, metavar='PORT', default=0, help='set the XREQ channel port [default random]') kgroup.add_argument('--sub', type=int, metavar='PORT', default=0, help='set the SUB channel port [default random]') kgroup.add_argument('--rep', type=int, metavar='PORT', default=0, help='set the REP channel port [default random]') kgroup.add_argument('--hb', type=int, metavar='PORT', default=0, help='set the heartbeat port [default random]') egroup = kgroup.add_mutually_exclusive_group() egroup.add_argument('--pure', action='store_true', help = \ 'use a pure Python kernel instead of an IPython kernel') egroup.add_argument('--pylab', type=str, metavar='GUI', nargs='?', const='auto', help = \ "Pre-load matplotlib and numpy for interactive use. If GUI is not \ given, the GUI backend is matplotlib's, otherwise use one of: \ ['tk', 'gtk', 'qt', 'wx', 'inline'].") wgroup = parser.add_argument_group('widget options') wgroup.add_argument('--paging', type=str, default='inside', choices = ['inside', 'hsplit', 'vsplit', 'none'], help='set the paging style [default inside]') wgroup.add_argument('--plain', action='store_true', help='disable rich text support') wgroup.add_argument('--gui-completion', action='store_true', help='use a GUI widget for tab completion') wgroup.add_argument('--style', type=str, choices = list(get_all_styles()), help='specify a pygments style for by name') wgroup.add_argument('--stylesheet', type=str, help='path to a custom CSS stylesheet') wgroup.add_argument('--colors', type=str, help = \ "Set the color scheme (LightBG,Linux,NoColor). This is guessed \ based on the pygments style if not set.") args = parser.parse_args() # parse the colors arg down to current known labels if args.colors: colors=args.colors.lower() if colors in ('lightbg', 'light'): colors='lightbg' elif colors in ('dark', 'linux'): colors='linux' else: colors='nocolor' elif args.style: if args.style=='bw': colors='nocolor' elif styles.dark_style(args.style): colors='linux' else: colors='lightbg' else: colors=None # Don't let Qt or ZMQ swallow KeyboardInterupts. import signal signal.signal(signal.SIGINT, signal.SIG_DFL) # Create a KernelManager and start a kernel. kernel_manager = QtKernelManager(xreq_address=(args.ip, args.xreq), sub_address=(args.ip, args.sub), rep_address=(args.ip, args.rep), hb_address=(args.ip, args.hb)) if not args.existing: # if not args.ip in LOCAL_IPS+ALL_ALIAS: # raise ValueError("Must bind a local ip, such as: %s"%LOCAL_IPS) kwargs = dict(ip=args.ip) if args.pure: kwargs['ipython']=False else: kwargs['colors']=colors if args.pylab: kwargs['pylab']=args.pylab kernel_manager.start_kernel(**kwargs) kernel_manager.start_channels() # Create the widget. app = QtGui.QApplication([]) local_kernel = (not args.existing) or args.ip in LOCAL_IPS if args.pure: kind = 'plain' if args.plain else 'rich' widget = FrontendWidget(kind=kind, paging=args.paging, local_kernel=local_kernel) elif args.plain: widget = IPythonWidget(paging=args.paging, local_kernel=local_kernel) else: widget = RichIPythonWidget(paging=args.paging, local_kernel=local_kernel) widget.gui_completion = args.gui_completion widget.kernel_manager = kernel_manager # Configure the style. if not args.pure: # only IPythonWidget supports styles if args.style: widget.syntax_style = args.style widget.style_sheet = styles.sheet_from_template(args.style, colors) widget._syntax_style_changed() widget._style_sheet_changed() elif colors: # use a default style widget.set_default_style(colors=colors) else: # this is redundant for now, but allows the widget's # defaults to change widget.set_default_style() if args.stylesheet: # we got an expicit stylesheet if os.path.isfile(args.stylesheet): with open(args.stylesheet) as f: sheet = f.read() widget.style_sheet = sheet widget._style_sheet_changed() else: raise IOError("Stylesheet %r not found."%args.stylesheet) # Create the main window. window = MainWindow(app, widget, args.existing, may_close=local_kernel) window.setWindowTitle('Python' if args.pure else 'IPython') window.show() # Start the application main loop. app.exec_()
def main(): """ Entry point for application. """ # Parse command line arguments. parser = ArgumentParser() kgroup = parser.add_argument_group('kernel options') kgroup.add_argument('-e', '--existing', action='store_true', help='connect to an existing kernel') kgroup.add_argument( '--ip', type=str, default=LOCALHOST, help='set the kernel\'s IP address [default localhost]') kgroup.add_argument('--xreq', type=int, metavar='PORT', default=0, help='set the XREQ channel port [default random]') kgroup.add_argument('--sub', type=int, metavar='PORT', default=0, help='set the SUB channel port [default random]') kgroup.add_argument('--rep', type=int, metavar='PORT', default=0, help='set the REP channel port [default random]') kgroup.add_argument('--hb', type=int, metavar='PORT', default=0, help='set the heartbeat port [default: random]') egroup = kgroup.add_mutually_exclusive_group() egroup.add_argument('--pure', action='store_true', help = \ 'use a pure Python kernel instead of an IPython kernel') egroup.add_argument('--pylab', type=str, metavar='GUI', nargs='?', const='auto', help = \ "Pre-load matplotlib and numpy for interactive use. If GUI is not \ given, the GUI backend is matplotlib's, otherwise use one of: \ ['tk', 'gtk', 'qt', 'wx', 'inline']." ) wgroup = parser.add_argument_group('widget options') wgroup.add_argument('--paging', type=str, default='inside', choices=['inside', 'hsplit', 'vsplit', 'none'], help='set the paging style [default inside]') wgroup.add_argument('--rich', action='store_true', help='enable rich text support') wgroup.add_argument('--gui-completion', action='store_true', help='use a GUI widget for tab completion') args = parser.parse_args() # Don't let Qt or ZMQ swallow KeyboardInterupts. import signal signal.signal(signal.SIGINT, signal.SIG_DFL) # Create a KernelManager and start a kernel. kernel_manager = QtKernelManager(xreq_address=(args.ip, args.xreq), sub_address=(args.ip, args.sub), rep_address=(args.ip, args.rep), hb_address=(args.ip, args.hb)) if args.ip == LOCALHOST and not args.existing: if args.pure: kernel_manager.start_kernel(ipython=False) elif args.pylab: kernel_manager.start_kernel(pylab=args.pylab) else: kernel_manager.start_kernel() kernel_manager.start_channels() # Create the widget. app = QtGui.QApplication([]) if args.pure: kind = 'rich' if args.rich else 'plain' widget = FrontendWidget(kind=kind, paging=args.paging) elif args.rich or args.pylab: widget = RichIPythonWidget(paging=args.paging) else: widget = IPythonWidget(paging=args.paging) widget.gui_completion = args.gui_completion widget.kernel_manager = kernel_manager # Create the main window. window = MainWindow(app, widget, args.existing) window.setWindowTitle('Python' if args.pure else 'IPython') window.show() # Start the application main loop. app.exec_()