Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setup_template_dirs(self):
if self.voila_configuration.template:
collect_template_paths(
self.nbconvert_template_paths,
self.static_paths,
self.template_paths,
self.voila_configuration.template)
# look for possible template-related config files
template_conf_dir = [os.path.join(k, '..') for k in self.nbconvert_template_paths]
conf_paths = [os.path.join(d, 'conf.json') for d in template_conf_dir]
for p in conf_paths:
# see if config file exists
if os.path.exists(p):
# load the template-related config
with open(p) as json_file:
conf = json.load(json_file)
# update the overall config with it, preserving CLI config priority
if 'traitlet_configuration' in conf:
recursive_update(conf['traitlet_configuration'], self.voila_configuration.config.VoilaConfiguration)
def load_jupyter_server_extension(server_app):
web_app = server_app.web_app
nbconvert_template_paths = []
static_paths = [STATIC_ROOT]
template_paths = []
# common configuration options between the server extension and the application
voila_configuration = VoilaConfiguration(parent=server_app)
collect_template_paths(
nbconvert_template_paths,
static_paths,
template_paths,
voila_configuration.template
)
jenv_opt = {"autoescape": True}
env = Environment(loader=FileSystemLoader(template_paths), extensions=['jinja2.ext.i18n'], **jenv_opt)
web_app.settings['voila_jinja2_env'] = env
nbui = gettext.translation('nbui', localedir=os.path.join(ROOT, 'i18n'), fallback=True)
env.install_gettext_translations(nbui, newstyle=False)
host_pattern = '.*$'
base_url = url_path_join(web_app.settings['base_url'])