Skip to content

Commit

Permalink
Use plural for template(s) data dir
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainCorlay committed May 27, 2019
1 parent 9908824 commit 7be3903
Show file tree
Hide file tree
Showing 19 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Expand Up @@ -28,10 +28,10 @@ config.rst

package-lock.json

share/jupyter/voila/template/nbconvert/static/index.css
share/jupyter/voila/template/nbconvert/static/theme-light.css
share/jupyter/voila/template/nbconvert/static/theme-dark.css
share/jupyter/voila/template/default/static/*voila.js
share/jupyter/voila/template/default/static/*[woff|woff2|eot|svg]
share/jupyter/voila/templates/nbconvert/static/index.css
share/jupyter/voila/templates/nbconvert/static/theme-light.css
share/jupyter/voila/templates/nbconvert/static/theme-dark.css
share/jupyter/voila/templates/default/static/*voila.js
share/jupyter/voila/templates/default/static/*[woff|woff2|eot|svg]

js/lib/
22 changes: 11 additions & 11 deletions docs/source/customize.rst
Expand Up @@ -48,15 +48,15 @@ Where are Voila templates located?
----------------------------------

All voila templates are stored as folders with particular configuration/template files inside.
These folders can exist in the standard Jupyter configuration locations, in a folder called ``voila/template``.
These folders can exist in the standard Jupyter configuration locations, in a folder called ``voila/templates``.
For example:

.. code-block:: bash
~/.local/share/jupyter/voila/template
~/path/to/env/dev/share/jupyter/voila/template
/usr/local/share/jupyter/voila/template
/usr/share/jupyter/voila/template
~/.local/share/jupyter/voila/templates
~/path/to/env/dev/share/jupyter/voila/templates
/usr/local/share/jupyter/voila/templates
/usr/share/jupyter/voila/templates
Voila will search these locations for a folder, one per template, where
the folder name defines the template name.
Expand All @@ -70,7 +70,7 @@ the folder structure of the base Voila template (called "default"):

.. code-block:: bash
tree path/to/env/share/jupyter/voila/template/default/
tree path/to/env/share/jupyter/voila/templates/default/
├── nbconvert_templates
│   ├── base.tpl
│   └── voila.tpl
Expand Down Expand Up @@ -104,15 +104,15 @@ We'll have two goals:
1. Add an ``<h1>>`` header displaying "Our awesome template" to the voila dashboard.
2. Add a custom 404.html page that displays an image.

First, we'll create a folder in ``~/.local/share/jupyter/voila/template`` called ``mytemplate``::
First, we'll create a folder in ``~/.local/share/jupyter/voila/templates`` called ``mytemplate``::

mkdir ~/.local/share/jupyter/voila/template/mytemplate
cd ~/.local/share/jupyter/voila/template/mytemplate
mkdir ~/.local/share/jupyter/voila/templates/mytemplate
cd ~/.local/share/jupyter/voila/templates/mytemplate

Next, we'll copy over the base template files for voila, which we'll modify::

cp -r path/to/env/share/jupyter/voila/template/default/nbconvert_templates ./
cp -r path/to/env/share/jupyter/voila/template/default/templates ./
cp -r path/to/env/share/jupyter/voila/templates/default/nbconvert_templates ./
cp -r path/to/env/share/jupyter/voila/templates/default/templates ./

We should now have a folder structure like this::

Expand Down
2 changes: 1 addition & 1 deletion js/webpack.config.js
Expand Up @@ -14,7 +14,7 @@ var rules = [
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, use: 'url-loader?limit=10000&mimetype=image/svg+xml' }
]

var distRoot = path.resolve(__dirname, '..', 'share', 'jupyter', 'voila', 'template', 'default', 'static')
var distRoot = path.resolve(__dirname, '..', 'share', 'jupyter', 'voila', 'templates', 'default', 'static')

module.exports = [
{
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Expand Up @@ -75,7 +75,7 @@ class NPM(Command):

node_modules = os.path.join(node_root, 'node_modules')

template_root = os.path.join(here, 'share', 'jupyter', 'voila', 'template', 'default', 'static')
template_root = os.path.join(here, 'share', 'jupyter', 'voila', 'templates', 'default', 'static')
targets = [
os.path.join(template_root, 'voila.js')
]
Expand Down Expand Up @@ -177,9 +177,9 @@ def _download_pycurl(self, url):
return buf.getvalue()

def run(self):
css_dest = os.path.join('share', 'jupyter', 'voila', 'template', 'default', 'static', 'index.css')
theme_light_dest = os.path.join('share', 'jupyter', 'voila', 'template', 'default', 'static', 'theme-light.css')
theme_dark_dest = os.path.join('share', 'jupyter', 'voila', 'template', 'default', 'static', 'theme-dark.css')
css_dest = os.path.join('share', 'jupyter', 'voila', 'templates', 'default', 'static', 'index.css')
theme_light_dest = os.path.join('share', 'jupyter', 'voila', 'templates', 'default', 'static', 'theme-light.css')
theme_dark_dest = os.path.join('share', 'jupyter', 'voila', 'templates', 'default', 'static', 'theme-dark.css')

try:
css = self._download(css_url)
Expand All @@ -194,7 +194,7 @@ def run(self):
return

try:
os.mkdir(os.path.join('share', 'jupyter', 'voila', 'template', 'default', 'static'))
os.mkdir(os.path.join('share', 'jupyter', 'voila', 'templates', 'default', 'static'))
except OSError: # Use FileExistsError from python 3.3 onward.
pass
with open(css_dest, 'wb+') as f:
Expand Down Expand Up @@ -241,7 +241,7 @@ def run(self):
]

# Add all the templates
for (dirpath, dirnames, filenames) in os.walk('share/jupyter/voila/template/'):
for (dirpath, dirnames, filenames) in os.walk('share/jupyter/voila/templates/'):
if filenames:
data_files.append((dirpath, [os.path.join(dirpath, filename) for filename in filenames]))

Expand Down
4 changes: 2 additions & 2 deletions tests/app/template_cli_test.py
Expand Up @@ -7,8 +7,8 @@

@pytest.fixture
def voila_args_extra():
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/default/nbconvert_templates'))
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default/nbconvert_templates'))
return ['--template=None', '--Voila.nbconvert_template_paths=[%r, %r]' % (path_gridstack, path_default)]


Expand Down
6 changes: 3 additions & 3 deletions tests/app/template_custom_test.py
Expand Up @@ -13,10 +13,10 @@ def voila_args_extra():
@pytest.fixture
def voila_config():
def config(app):
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/default/nbconvert_templates'))
path_gridstack = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/gridstack/nbconvert_templates'))
path_default = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default/nbconvert_templates'))
app.nbconvert_template_paths = [path_gridstack, path_default]
path = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/template/default/templates'))
path = os.path.abspath(os.path.join(BASE_DIR, '../../share/jupyter/voila/templates/default/templates'))
app.template_paths = [path]

return config
Expand Down
6 changes: 3 additions & 3 deletions voila/paths.py
Expand Up @@ -28,7 +28,7 @@ def collect_template_paths(
- nbconvert template paths,
- static paths,
- tornado template paths,
by looking in the standard Jupyter data directories (PREFIX/share/jupyter/voila/template)
by looking in the standard Jupyter data directories (PREFIX/share/jupyter/voila/templates)
with different prefix values (user directory, sys prefix, and then system prefix) which
allows users to override templates locally.
Expand All @@ -40,8 +40,8 @@ def collect_template_paths(
# 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'))
search_directories.append(os.path.abspath(os.path.join(ROOT, '..', 'share', 'jupyter', 'voila', 'templates')))
search_directories.extend(jupyter_path('voila', 'templates'))

found_at_least_one = False
for search_directory in search_directories:
Expand Down

0 comments on commit 7be3903

Please sign in to comment.