Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give an error when a template is not found #137

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions voila/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ def collect_template_paths(

# We look at the usual jupyter locations, and for development purposes also
# relative to the package directory (with highest precedence)
template_directories = \
[os.path.abspath(os.path.join(ROOT, '..', 'share', 'jupyter', 'voila', 'template', template_name))] +\
jupyter_path('voila', 'template', template_name)
search_directories = \
[os.path.abspath(os.path.join(ROOT, '..', 'share', 'jupyter', 'voila', 'template'))] +\
jupyter_path('voila', 'template')

for dirname in template_directories:
if os.path.exists(dirname):
found_at_least_one = False
for search_directory in search_directories:
template_directory = os.path.join(search_directory, template_name)
if os.path.exists(template_directory):
found_at_least_one = True
conf = {}
conf_file = os.path.join(dirname, 'conf.json')
conf_file = os.path.join(template_directory, 'conf.json')
if os.path.exists(conf_file):
with open(conf_file) as f:
conf = json.load(f)
Expand All @@ -57,25 +60,19 @@ def collect_template_paths(
tornado_template_paths,
conf.get('base_template', 'default'))

extra_nbconvert_path = os.path.join(dirname, 'nbconvert_templates')
# if not os.path.exists(extra_nbconvert_path):
# log.warning('template named %s found at path %r, but %s does not exist', template_name,
# dirname, extra_nbconvert_path)
extra_nbconvert_path = os.path.join(template_directory, 'nbconvert_templates')
nbconvert_template_paths.insert(0, extra_nbconvert_path)

extra_static_path = os.path.join(dirname, 'static')
# if not os.path.exists(extra_static_path):
# log.warning('template named %s found at path %r, but %s does not exist', template_name,
# dirname, extra_static_path)
extra_static_path = os.path.join(template_directory, 'static')
static_paths.insert(0, extra_static_path)

extra_template_path = os.path.join(dirname, 'templates')
# if not os.path.exists(extra_template_path):
# log.warning('template named %s found at path %r, but %s does not exist', template_name,
# dirname, extra_template_path)
extra_template_path = os.path.join(template_directory, 'templates')
tornado_template_paths.insert(0, extra_template_path)

# We don't look at multiple directories, once a directory with a given name is found at a
# given level of precedence (for instance user directory), we don't look further (for instance
# in sys.prefix)
break
if not found_at_least_one:
paths = "\n\t".join(search_directories)
raise ValueError('No template sub-directory with name %r found in the following paths:\n\t%s' % (template_name, paths))