Skip to content

Commit

Permalink
Detect if we are installed in dev mode, and modify template search pa…
Browse files Browse the repository at this point in the history
…ths accordingly
  • Loading branch information
maartenbreddels committed May 14, 2019
1 parent 9f9fb15 commit 538346c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions voila/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ def setup_template_dirs(self):
self.template_paths,
self.template)
self.log.debug('using template: %s', self.template)
self.log.debug('nbconvert template paths: %s', self.nbconvert_template_paths)
self.log.debug('template paths: %s', self.template_paths)
self.log.debug('static paths: %s', self.static_paths)
self.log.debug('nbconvert template paths:\n\t%s', '\n\t'.join(self.nbconvert_template_paths))
self.log.debug('template paths:\n\t%s', '\n\t'.join(self.template_paths))
self.log.debug('static paths:\n\t%s', '\n\t'.join(self.static_paths))
if self.notebook_path and not os.path.exists(self.notebook_path):
raise ValueError('Notebook not found: %s' % self.notebook_path)

Expand Down
13 changes: 8 additions & 5 deletions voila/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(ROOT, 'static')
# if the directory above us contains the following paths, it means we are installed in dev mode (pip install -e .)
DEV_MODE = os.path.exists(os.path.join(ROOT, '../setup.py')) and os.path.exists(os.path.join(ROOT, '../share'))


def collect_template_paths(
Expand All @@ -35,10 +37,11 @@ def collect_template_paths(
"""

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

found_at_least_one = False
for search_directory in search_directories:
Expand Down Expand Up @@ -75,4 +78,4 @@ def collect_template_paths(
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))
raise ValueError('No template sub-directory with name %r found in the following paths:\n\t%s' % (template_name, paths))

0 comments on commit 538346c

Please sign in to comment.