##// END OF EJS Templates
Added tests for IPython.config.application.Application
Added tests for IPython.config.application.Application

File last commit:

r3795:605614c3
r3795:605614c3
Show More
appconfig.py
61 lines | 1.6 KiB | text/x-python | PythonLexer
Brian Granger
Added tests for IPython.config.application.Application
r3795 """A simple example of how to use IPython.config.application.Application.
This should serve as a simple example that shows how the IPython config
system works. The main classes are:
* IPython.config.configurable.Configurable
* IPython.config.configurable.SingletonConfigurable
* IPython.config.loader.Config
* IPython.config.application.Application
"""
Brian Granger
Ongoing work on the config system....
r3789 import sys
from IPython.config.configurable import Configurable
Brian Granger
Created config.application and updated Configurable.
r3790 from IPython.config.application import Application
Brian Granger
Ongoing work on the config system....
r3789 from IPython.utils.traitlets import (
Bool, Unicode, Int, Float, List
)
class Foo(Configurable):
i = Int(0, config=True, shortname='i', help="The integer i.")
j = Int(1, config=True, shortname='j', help="The integer j.")
name = Unicode(u'Brian', config=True, shortname='name', help="First name.")
class Bar(Configurable):
Brian Granger
Added tests for IPython.config.application.Application
r3795 enabled = Bool(True, config=True, shortname="enabled", help="Enable bar.")
Brian Granger
Ongoing work on the config system....
r3789
Brian Granger
Created config.application and updated Configurable.
r3790 class MyApp(Application):
Brian Granger
Ongoing work on the config system....
r3789
Brian Granger
Created config.application and updated Configurable.
r3790 app_name = Unicode(u'myapp')
Brian Granger
Added tests for IPython.config.application.Application
r3795 running = Bool(False, config=True, shortname="running",
help="Is the app running?")
Brian Granger
Ongoing work on the config system....
r3789 classes = List([Bar, Foo])
Brian Granger
Added tests for IPython.config.application.Application
r3795 config_file = Unicode(u'', config=True, shortname="config_file",
help="Load this config file")
def init_foo(self):
self.foo = Foo(config=self.config)
def init_bar(self):
self.bar = Bar(config=self.config)
Brian Granger
Ongoing work on the config system....
r3789
def main():
app = MyApp()
app.parse_command_line()
Brian Granger
Created config.application and updated Configurable.
r3790 if app.config_file:
app.load_config_file(app.config_file)
Brian Granger
Added tests for IPython.config.application.Application
r3795 app.init_foo()
app.init_bar()
Brian Granger
Ongoing work on the config system....
r3789 print "app.config:"
print app.config
if __name__ == "__main__":
main()