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 15, 2019
1 parent 67221e6 commit 3e34e15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 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
11 changes: 7 additions & 4 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

0 comments on commit 3e34e15

Please sign in to comment.