From 3e34e153c150cd0a5795d0e7919f0b3d2e0e3cac Mon Sep 17 00:00:00 2001 From: Maarten Breddels Date: Tue, 14 May 2019 19:47:39 +0200 Subject: [PATCH] Detect if we are installed in dev mode, and modify template search paths accordingly --- voila/app.py | 6 +++--- voila/paths.py | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/voila/app.py b/voila/app.py index 89ec5a369..db4b2ad97 100644 --- a/voila/app.py +++ b/voila/app.py @@ -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) diff --git a/voila/paths.py b/voila/paths.py index a40c031aa..7a81ce1b1 100644 --- a/voila/paths.py +++ b/voila/paths.py @@ -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( @@ -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: