Skip to content

Commit

Permalink
Merge pull request #6 from minrk/config-arg
Browse files Browse the repository at this point in the history
allow specifying config file with `--config FILE`
  • Loading branch information
Carreau committed Apr 21, 2015
2 parents c0e8787 + 4925f20 commit 92698fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 11 additions & 5 deletions jupyter_core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

base_aliases = {
'log-level' : 'Application.log_level',
'config' : 'JupyterApp.config_file',
}

base_flags = {
Expand Down Expand Up @@ -98,15 +99,20 @@ def _runtime_dir_changed(self, new):

generate_config = Bool(False)

config_file_name = Unicode()
def _config_file_name_default(self):
config_file = Unicode(config=True,
help="Specify a config file to load."
)
def _config_file_default(self):
if not self.name:
return ''
return self.name.replace('-','_') + u'_config'

@property
def config_files(self):
return [self.config_file_name]
if self.config_file:
return [self.config_file]
else:
return []

def write_config_file(self):
"""Write our default config to a .py config file"""
Expand Down Expand Up @@ -159,7 +165,7 @@ def load_config_file(self, suppress_errors=True):
if not config_file_name or config_file_name == base_config:
continue
self.log.debug("Attempting to load config file: %s" %
self.config_file_name)
self.config_file)
try:
Application.load_config_file(
self,
Expand All @@ -173,7 +179,7 @@ def load_config_file(self, suppress_errors=True):
if not suppress_errors:
raise
self.log.warn("Error loading config file: %s" %
self.config_file_name, exc_info=True)
self.config_file, exc_info=True)
# subcommand-related
def _find_subcommand(self, name):
name = '{}-{}'.format(self.name, name)
Expand Down
26 changes: 23 additions & 3 deletions jupyter_core/tests/test_application.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
from jupyter_core import application
from tempfile import NamedTemporaryFile

from traitlets import Integer

from jupyter_core.application import JupyterApp

def test_basic():
app = application.JupyterApp()
app = JupyterApp()

def test_default_traits():
app = application.JupyterApp()
app = JupyterApp()
for trait_name in app.traits():
value = getattr(app, trait_name)

class DummyApp(JupyterApp):
n = Integer(0, config=True)

_dummy_config = """
c.DummyApp.n = 10
"""

def test_custom_config():
app = DummyApp()
with NamedTemporaryFile(suffix='.py', mode='w') as f:
f.write(_dummy_config)
f.flush()
app.initialize(['--config', f.name])
assert app.config_file == f.name
assert app.n == 10

0 comments on commit 92698fc

Please sign in to comment.