From f5df2b16c9ff24f06a81ed1988705508c2c43b22 2010-01-31 19:26:59 From: Brian Granger Date: 2010-01-31 19:26:59 Subject: [PATCH] Various fixes to ipapp/ipcluster/ipengine/ipcontroller. * Fixed bugs in handling of ``reuse_furls`` and ``secure``. * Fixed ``--no-sep`` option. * Refactored how the :attr:`Application.config_file_name` is handled to make it clearer and more robust. * Tested all the apps. --- diff --git a/IPython/core/application.py b/IPython/core/application.py index 8ee1f07..d53fc6d 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -97,11 +97,11 @@ class Application(object): usage = None #: The command line config loader. Subclass of ArgParseConfigLoader. command_line_loader = BaseAppConfigLoader - #: The name of the config file to load. - config_file_name = u'ipython_config.py' + #: The name of the config file to load, determined at runtime + config_file_name = None #: The name of the default config file. Track separately from the actual #: name because some logic happens only if we aren't using the default. - default_config_file_name = config_file_name + default_config_file_name = u'ipython_config.py' default_log_level = logging.WARN #: Set by --profile option profile_name = None @@ -315,18 +315,22 @@ class Application(object): If a profile has been set at the command line, this will resolve it. """ - try: self.config_file_name = self.command_line_config.Global.config_file except AttributeError: pass + else: + return try: self.profile_name = self.command_line_config.Global.profile except AttributeError: - pass + # Just use the default as there is no profile + self.config_file_name = self.default_config_file_name else: - name_parts = self.config_file_name.split('.') + # Use the default config file name and profile name if set + # to determine the used config file name. + name_parts = self.default_config_file_name.split('.') name_parts.insert(1, u'_' + self.profile_name + u'.') self.config_file_name = ''.join(name_parts) diff --git a/IPython/core/ipapp.py b/IPython/core/ipapp.py index 213afa3..efd42f9 100755 --- a/IPython/core/ipapp.py +++ b/IPython/core/ipapp.py @@ -252,7 +252,7 @@ class IPAppConfigLoader(BaseAppConfigLoader): type=str, dest='InteractiveShell.separate_out2', help="Separator after output prompts. Default 0 (nonight).", metavar='InteractiveShell.separate_out2') - paa('-no-sep', + paa('--no-sep', action='store_true', dest='Global.nosep', help="Eliminate all spacing between prompts.") paa('--term-title', @@ -389,7 +389,7 @@ class IPythonApp(Application): description = None usage = usage.cl_usage command_line_loader = IPAppConfigLoader - config_file_name = default_config_file_name + default_config_file_name = default_config_file_name crash_handler_class = IPAppCrashHandler def create_default_config(self): @@ -486,7 +486,6 @@ class IPythonApp(Application): # based app, because we call shell.show_banner() by hand below # so the banner shows *before* all extension loading stuff. self.shell.display_banner = False - if config.Global.display_banner and \ config.Global.interact: self.shell.show_banner() diff --git a/IPython/kernel/clusterdir.py b/IPython/kernel/clusterdir.py index 84b10e0..63174eb 100755 --- a/IPython/kernel/clusterdir.py +++ b/IPython/kernel/clusterdir.py @@ -441,8 +441,10 @@ class ApplicationWithClusterDir(Application): def find_config_file_name(self): """Find the config file name for this application.""" # For this type of Application it should be set as a class attribute. - if not hasattr(self, 'config_file_name'): + if not hasattr(self, 'default_config_file_name'): self.log.critical("No config filename found") + else: + self.config_file_name = self.default_config_file_name def find_config_file_paths(self): # Set the search path to to the cluster directory. We should NOT diff --git a/IPython/kernel/fcutil.py b/IPython/kernel/fcutil.py index 4de4e89..a222401 100644 --- a/IPython/kernel/fcutil.py +++ b/IPython/kernel/fcutil.py @@ -265,9 +265,13 @@ class FCServiceFactory(AdaptedConfiguredObjectFactory): """Register the reference with the FURL file. The FURL file is created and then moved to make sure that when the - file appears, the buffer has been flushed and the file closed. + file appears, the buffer has been flushed and the file closed. This + is not done if we are re-using FURLS however. """ - temp_furl_file = get_temp_furlfile(furl_file) - self.tub.registerReference(ref, furlFile=temp_furl_file) - os.rename(temp_furl_file, furl_file) + if self.reuse_furls: + self.tub.registerReference(ref, furlFile=furl_file) + else: + temp_furl_file = get_temp_furlfile(furl_file) + self.tub.registerReference(ref, furlFile=temp_furl_file) + os.rename(temp_furl_file, furl_file) diff --git a/IPython/kernel/ipclusterapp.py b/IPython/kernel/ipclusterapp.py index a19b415..57b7675 100755 --- a/IPython/kernel/ipclusterapp.py +++ b/IPython/kernel/ipclusterapp.py @@ -218,7 +218,7 @@ class IPClusterApp(ApplicationWithClusterDir): description = _description usage = None command_line_loader = IPClusterAppConfigLoader - config_file_name = default_config_file_name + default_config_file_name = default_config_file_name default_log_level = logging.INFO auto_create_cluster_dir = False diff --git a/IPython/kernel/ipcontrollerapp.py b/IPython/kernel/ipcontrollerapp.py index 2468710..37cf583 100755 --- a/IPython/kernel/ipcontrollerapp.py +++ b/IPython/kernel/ipcontrollerapp.py @@ -30,7 +30,7 @@ from IPython.kernel.clusterdir import ( ApplicationWithClusterDir, ClusterDirConfigLoader ) -from IPython.kernel.fcutil import FCServiceFactory +from IPython.kernel.fcutil import FCServiceFactory, FURLError from IPython.utils.traitlets import Instance, Unicode @@ -186,19 +186,22 @@ class IPControllerApp(ApplicationWithClusterDir): name = u'ipcontroller' description = _description command_line_loader = IPControllerAppConfigLoader - config_file_name = default_config_file_name + default_config_file_name = default_config_file_name auto_create_cluster_dir = True def create_default_config(self): super(IPControllerApp, self).create_default_config() - self.default_config.Global.reuse_furls = False - self.default_config.Global.secure = True + # Don't set defaults for Global.secure or Global.reuse_furls + # as those are set in a component. self.default_config.Global.import_statements = [] self.default_config.Global.clean_logs = True - def post_load_command_line_config(self): - # Now setup reuse_furls - c = self.command_line_config + def pre_construct(self): + super(IPControllerApp, self).pre_construct() + c = self.master_config + # The defaults for these are set in FCClientServiceFactory and + # FCEngineServiceFactory, so we only set them here if the global + # options have be set to override the class level defaults. if hasattr(c.Global, 'reuse_furls'): c.FCClientServiceFactory.reuse_furls = c.Global.reuse_furls c.FCEngineServiceFactory.reuse_furls = c.Global.reuse_furls @@ -221,11 +224,19 @@ class IPControllerApp(ApplicationWithClusterDir): controller_service = controllerservice.ControllerService() controller_service.setServiceParent(self.main_service) # The client tub and all its refereceables - csfactory = FCClientServiceFactory(self.master_config, controller_service) + try: + csfactory = FCClientServiceFactory(self.master_config, controller_service) + except FURLError, e: + log.err(e) + self.exit(0) client_service = csfactory.create() client_service.setServiceParent(self.main_service) # The engine tub - esfactory = FCEngineServiceFactory(self.master_config, controller_service) + try: + esfactory = FCEngineServiceFactory(self.master_config, controller_service) + except FURLError, e: + log.err(e) + self.exit(0) engine_service = esfactory.create() engine_service.setServiceParent(self.main_service) diff --git a/IPython/kernel/ipengineapp.py b/IPython/kernel/ipengineapp.py index 129af6b..61f010a 100755 --- a/IPython/kernel/ipengineapp.py +++ b/IPython/kernel/ipengineapp.py @@ -103,7 +103,7 @@ class IPEngineApp(ApplicationWithClusterDir): name = u'ipengine' description = _description command_line_loader = IPEngineAppConfigLoader - config_file_name = default_config_file_name + default_config_file_name = default_config_file_name auto_create_cluster_dir = True def create_default_config(self):