Skip to content

Commit

Permalink
use BaseIPythonApp.load_config, not Application.load_config
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Jun 10, 2011
1 parent 3776732 commit 6fa4c3f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
46 changes: 21 additions & 25 deletions IPython/parallel/apps/clusterdir.py
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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_<profile>``. The search
path for this directory is then i) cwd if it is found there
and ii) in ipython_dir otherwise.
Expand Down Expand Up @@ -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<appname> configuration file. The default is to use
<appname>_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):
Expand Down Expand Up @@ -409,21 +420,17 @@ 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"""
self.init_crash_handler()
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)
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions IPython/parallel/apps/ipclusterapp.py
Expand Up @@ -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'."
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions IPython/parallel/apps/ipcontrollerapp.py
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion IPython/parallel/apps/ipengineapp.py
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions IPython/parallel/apps/iploggerapp.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 6fa4c3f

Please sign in to comment.