From 6fa4c3f8ed9a90704d75ef503d7cbff871e5dac9 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 25 May 2011 12:57:56 -0700 Subject: [PATCH] use BaseIPythonApp.load_config, not Application.load_config --- IPython/parallel/apps/clusterdir.py | 46 +++++++++++------------- IPython/parallel/apps/ipclusterapp.py | 8 ++--- IPython/parallel/apps/ipcontrollerapp.py | 3 +- IPython/parallel/apps/ipengineapp.py | 2 +- IPython/parallel/apps/iploggerapp.py | 4 +-- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/IPython/parallel/apps/clusterdir.py b/IPython/parallel/apps/clusterdir.py index 3766d26dfb7..5c5a8ec00eb 100755 --- a/IPython/parallel/apps/clusterdir.py +++ b/IPython/parallel/apps/clusterdir.py @@ -36,7 +36,7 @@ get_ipython_dir, expand_path ) -from IPython.utils.traitlets import Unicode, Bool, Instance, Dict +from IPython.utils.traitlets import Unicode, Bool, Instance, Dict, List #----------------------------------------------------------------------------- # Module errors @@ -303,12 +303,12 @@ def __init__(self, app): base_aliases = { 'profile' : "ClusterDir.profile", 'cluster_dir' : 'ClusterDir.location', - 'auto_create' : 'ClusterDirApplication.auto_create', 'log_level' : 'ClusterApplication.log_level', 'work_dir' : 'ClusterApplication.work_dir', 'log_to_file' : 'ClusterApplication.log_to_file', 'clean_logs' : 'ClusterApplication.clean_logs', 'log_url' : 'ClusterApplication.log_url', + 'config' : 'ClusterApplication.config_file', } base_flags = { @@ -329,7 +329,7 @@ class ClusterApplication(BaseIPythonApplication): The cluster directory is resolved as follows: * If the ``cluster_dir`` option is given, it is used. - * If ``cluster_dir`` is not given, the application directory is + * If ``cluster_dir`` is not given, the application directory is resolve using the profile name as ``cluster_``. The search path for this directory is then i) cwd if it is found there and ii) in ipython_dir otherwise. @@ -357,16 +357,27 @@ def _work_dir_changed(self, name, old, new): log_to_file = Bool(config=True, help="whether to log to a file") - clean_logs = Bool(False, shortname='--clean-logs', config=True, + clean_logs = Bool(False, config=True, help="whether to cleanup old logfiles before starting") - log_url = Unicode('', shortname='--log-url', config=True, + log_url = Unicode('', config=True, help="The ZMQ URL of the iplogger to aggregate logging.") config_file = Unicode(u'', config=True, - help="""Path to ipcontroller configuration file. The default is to use + help="""Path to ip configuration file. The default is to use _config.py, as found by cluster-dir.""" ) + def _config_file_paths_default(self): + # don't include profile dir + return [ os.getcwdu(), self.ipython_dir ] + + def _config_file_changed(self, name, old, new): + if os.pathsep in new: + path, new = new.rsplit(os.pathsep) + self.config_file_paths.insert(0, path) + self.config_file_name = new + + config_file_name = Unicode('') loop = Instance('zmq.eventloop.ioloop.IOLoop') def _loop_default(self): @@ -409,6 +420,9 @@ def init_clusterdir(self): else: self.log.info('Using existing cluster dir: %s' % \ self.cluster_dir.location) + + # insert after cwd: + self.config_file_paths.insert(1, self.cluster_dir.location) def initialize(self, argv=None): """initialize the app""" @@ -416,14 +430,7 @@ def initialize(self, argv=None): self.parse_command_line(argv) cl_config = self.config self.init_clusterdir() - if self.config_file: - self.load_config_file(self.config_file) - elif self.default_config_file_name: - try: - self.load_config_file(self.default_config_file_name, - path=self.cluster_dir.location) - except IOError: - self.log.warn("Warning: Default config file not found") + self.load_config_file() # command-line should *override* config file, but command-line is necessary # to determine clusterdir, etc. self.update_config(cl_config) @@ -438,17 +445,6 @@ def to_work_dir(self): # This is the working dir by now. sys.path.insert(0, '') - def load_config_file(self, filename, path=None): - """Load a .py based config file by filename and path.""" - # use config.application.Application.load_config - # instead of inflexible core.newapplication.BaseIPythonApplication.load_config - return Application.load_config_file(self, filename, path=path) - # - # def load_default_config_file(self): - # """Load a .py based config file by filename and path.""" - # return BaseIPythonApplication.load_config_file(self) - - # disable URL-logging def reinit_logging(self): # Remove old log files log_dir = self.cluster_dir.log_dir diff --git a/IPython/parallel/apps/ipclusterapp.py b/IPython/parallel/apps/ipclusterapp.py index 35a4cbd2c11..8ef7221d478 100755 --- a/IPython/parallel/apps/ipclusterapp.py +++ b/IPython/parallel/apps/ipclusterapp.py @@ -178,7 +178,7 @@ class IPClusterCreate(ClusterApplication): description = create_help auto_create_cluster_dir = Bool(True, help="whether to create the cluster_dir if it doesn't exist") - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) reset = Bool(False, config=True, help="Whether to reset config files as part of 'create'." @@ -210,7 +210,7 @@ class IPClusterStop(ClusterApplication): name = u'ipcluster' description = stop_help auto_create_cluster_dir = Bool(False) - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) signal = Int(signal.SIGINT, config=True, help="signal to use for stopping processes.") @@ -277,7 +277,7 @@ class IPClusterEngines(ClusterApplication): name = u'ipcluster' description = engines_help usage = None - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) default_log_level = logging.INFO auto_create_cluster_dir = Bool(False) classes = List() @@ -409,8 +409,6 @@ class IPClusterStart(IPClusterEngines): name = u'ipcluster' description = start_help - usage = None - default_config_file_name = default_config_file_name default_log_level = logging.INFO auto_create_cluster_dir = Bool(True, config=True, help="whether to create the cluster_dir if it doesn't exist") diff --git a/IPython/parallel/apps/ipcontrollerapp.py b/IPython/parallel/apps/ipcontrollerapp.py index 94951015b60..40bb50d5269 100755 --- a/IPython/parallel/apps/ipcontrollerapp.py +++ b/IPython/parallel/apps/ipcontrollerapp.py @@ -110,8 +110,7 @@ class IPControllerApp(ClusterApplication): name = u'ipcontroller' description = _description - # command_line_loader = IPControllerAppConfigLoader - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) classes = [ClusterDir, StreamSession, HubFactory, TaskScheduler, HeartMonitor, SQLiteDB] + maybe_mongo auto_create_cluster_dir = Bool(True, config=True, diff --git a/IPython/parallel/apps/ipengineapp.py b/IPython/parallel/apps/ipengineapp.py index e04274a3326..fdd4b68b35e 100755 --- a/IPython/parallel/apps/ipengineapp.py +++ b/IPython/parallel/apps/ipengineapp.py @@ -102,7 +102,7 @@ class IPEngineApp(ClusterApplication): app_name = Unicode(u'ipengine') description = Unicode(_description) - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) classes = List([ClusterDir, StreamSession, EngineFactory, Kernel, MPI]) auto_create_cluster_dir = Bool(False, diff --git a/IPython/parallel/apps/iploggerapp.py b/IPython/parallel/apps/iploggerapp.py index 8c9869263a3..5b1cf738a29 100755 --- a/IPython/parallel/apps/iploggerapp.py +++ b/IPython/parallel/apps/iploggerapp.py @@ -20,7 +20,7 @@ import zmq -from IPython.utils.traitlets import Bool, Dict +from IPython.utils.traitlets import Bool, Dict, Unicode from IPython.parallel.apps.clusterdir import ( ClusterApplication, @@ -58,7 +58,7 @@ class IPLoggerApp(ClusterApplication): name = u'iploggerz' description = _description - default_config_file_name = default_config_file_name + config_file_name = Unicode(default_config_file_name) auto_create_cluster_dir = Bool(False) classes = [LogWatcher, ClusterDir]