Skip to content

Commit f65c74e

Browse files
committed
more work on settings
1 parent 651e91c commit f65c74e

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

examples/simple/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jupyter server --ServerApp.jpserver_extensions="{'simple_ext1': True, 'simple_ex
2929
Optionally, you can copy `simple_ext1.json` and `simple_ext2.json` configuration to your env `etc` folder and start only Extension 1, which will also start Extension 2.
3030

3131
```bash
32-
pip uninstall -y simple_ext
32+
pip uninstall -y jupyter_simple_ext
3333
python setup.py install
3434
cp -r ./etc $(dirname $(which jupyter))/..
3535
# Start the jupyter server extension simple_ext1, it will also load simple_ext2 because of load_other_extensions = True..
@@ -100,9 +100,9 @@ Try with the above links to check that only Extension 2 is responding (Extension
100100

101101
## Extension 11 extending Extension 1
102102

103-
`Extension 11` extends `Extension 1`.
103+
`Extension 11` extends `Extension 1` and brings a few more configs.
104104

105-
It brings a few more configs. Run `jupyter simple-ext11 --generate-config && vi ~/.jupyter/jupyter_config.py`.
105+
Run `jupyter simple-ext11 --generate-config && vi ~/.jupyter/jupyter_config.py`.
106106

107107
The generated configuration should contains the following.
108108

examples/simple/jupyter_server_config.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@
66

77
## The date format used by logging formatters for %(asctime)s
88
c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S Simple_Extensions'
9-
10-
c.SimpleApp1.file = 'OK'
11-
c.SimpleApp2.file = 'OK'
12-
13-
c.SimpleApp11.ignore_js = True

examples/simple/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def add_data_files(path):
2323
return data_files
2424

2525
setuptools.setup(
26-
name = 'simple_ext',
26+
name = 'jupyter_simple_ext',
2727
version = VERSION,
2828
description = 'Jupyter Simple Extension',
2929
long_description = open('README.md').read(),

examples/simple/simple_ext1/application.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os, jinja2
2+
from traitlets import Unicode
23
from jupyter_server.extension.application import ExtensionApp
34
from .handlers import (DefaultHandler, RedirectHandler,
45
ParameterHandler, TemplateHandler, TypescriptHandler, ErrorHandler)
@@ -27,6 +28,21 @@ class SimpleApp1(ExtensionApp):
2728
DEFAULT_TEMPLATE_FILES_PATH
2829
]
2930

31+
file = Unicode('',
32+
config=True,
33+
help='File path'
34+
)
35+
36+
app = Unicode('',
37+
config=True,
38+
help='File path'
39+
)
40+
41+
cli = Unicode('',
42+
config=True,
43+
help='File path'
44+
)
45+
3046
def initialize_handlers(self):
3147
self.handlers.extend([
3248
(r'/{}/default'.format(self.extension_name), DefaultHandler),
@@ -48,14 +64,18 @@ def initialize_templates(self):
4864
self.settings.update(**template_settings)
4965

5066
def get_conf(self, key):
51-
return self.settings.get('config').get('SimpleApp1').get(key, None)
67+
c = self.settings.get('config').get(type(self).__name__)
68+
if c:
69+
return c.get(key, None)
70+
else:
71+
return None
5272

5373
def initialize_settings(self):
54-
self.log.info('SimpleApp1.app {}'.format(self.get_conf('app')))
55-
self.log.info('SimpleApp1.file {}'.format(self.get_conf('file')))
56-
self.log.info('SimpleApp1.cli {}'.format(self.get_conf('cli')))
57-
self.log.info('Complete Settings {}'.format(self.settings))
58-
# TODO Check this setting/config handling... Updating does not look to be fine here...
74+
self.log.info('333 {}'.format(self.config))
75+
# self.log.info('SimpleApp1.app {}'.format(self.get_conf('app')))
76+
# self.log.info('SimpleApp1.file {}'.format(self.get_conf('file')))
77+
# self.log.info('SimpleApp1.cli {}'.format(self.get_conf('cli')))
78+
# self.log.info('Complete Settings {}'.format(self.settings))
5979
# self.settings.get('config').get(self.extension_name).update({'app': 'OK'})
6080
# self.settings["{}_config".format(self.extension_name)].update(**self.settings.get('config').get('SimpleApp1'))
6181

examples/simple/simple_ext1/handlers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
class DefaultHandler(ExtensionHandler):
44
def get(self):
55
# The ExtensionApp’s config object.
6-
self.log.info("Settings: {}".format(self.settings))
7-
self.log.info("Config: {}".format(self.config))
8-
# TODO The ServerApp’s config object.
6+
# self.log.info("Settings in {} Default Handler: {}".format(self.extension_name, self.settings))
7+
self.log.info("Config in {} Default Handler: {}".format(self.extension_name, self.config))
98
# self.log.info(self.server_config)
109
# The name of the extension to which this handler is linked.
11-
self.log.info("Extension Name: {}".format(self.extension_name))
10+
self.log.info("Extension Name in {} Default Handler: {}".format(self.extension_name, self.extension_name))
1211
# A method for getting the url to static files (prefixed with /static/<extension_name>).
13-
self.log.info("Static URL for /:".format(self.static_url(path='/')))
12+
self.log.info("Static URL for / in simple_ext1 Default Handler:".format(self.static_url(path='/')))
1413
self.write('<h1>Hello Simple 1 - I am the default...</h1>')
1514

1615
class RedirectHandler(ExtensionHandler):

examples/simple/simple_ext11/application.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,18 @@ def _update_ignore_js(self, change):
5454
def simple11_dir_formatted(self):
5555
return "/" + self.simple11_dir
5656

57-
def get_conf(self, key):
58-
return self.settings.get('config').get('SimpleApp11').get(key, None)
59-
6057
def initialize_settings(self):
61-
self.log.info('SimpleApp11.hello: {}'.format(self.get_conf('hello')))
58+
self.log.info('SimpleApp11.hello: {}'.format(super().get_conf('hello')))
6259
self.log.info('hello: {}'.format(self.hello))
6360
if self.get_conf('hello') == True:
6461
self.log.info("Hello Simple11 - You have provided the --hello flag or defined 'c.SimpleApp1.hello == True' in jupyter_server_config.py")
6562
self.log.info('SimpleApp11.simple11_dir: {}'.format(self.get_conf('simple11_dir')))
6663
self.log.info('SimpleApp11.ignore_js: {}'.format(self.get_conf('ignore_js')))
6764
self.log.info('ignore_js: {}'.format(self.ignore_js))
68-
# TODO Check this setting/config handling... Updating does not look to be fine here...
69-
self.settings["{}_config".format(self.extension_name)].update(**self.settings.get('config').get('SimpleApp11'))
70-
super().initialize_settings()
65+
c = self.settings.get('config').get(type(self).__name__)
66+
if c:
67+
self.settings["{}_config".format(self.extension_name)].update(**c)
68+
# super().initialize_settings()
7169

7270
#-----------------------------------------------------------------------------
7371
# Main entry point

0 commit comments

Comments
 (0)