diff --git a/.travis.yml b/.travis.yml index c1c9f6dda..24ea9cd1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,11 @@ before_install: - conda config --set always_yes yes --set changeps1 no - conda update -q conda - conda info -a - - conda create -q -n test-environment -c conda-forge python=$PYTHON_VERSION jupyter_server pytest==3.10.1 pytest-cov nodejs + - conda create -q -n test-environment -c conda-forge python=$PYTHON_VERSION jupyter_server pytest==3.10.1 pytest-cov nodejs flake8 - source activate test-environment install: - pip install ".[test]" +before_script: + - flake8 voila script: - py.test tests/ diff --git a/setup.cfg b/setup.cfg index ed8a958e0..695dc1589 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,6 @@ universal = 1 [metadata] license_file = LICENSE + +[flake8] +max-line-length=200 \ No newline at end of file diff --git a/voila/__init__.py b/voila/__init__.py index d2d6d9683..774fbee55 100644 --- a/voila/__init__.py +++ b/voila/__init__.py @@ -6,6 +6,7 @@ # The full license is in the file LICENSE, distributed with this software. # ############################################################################# + def _jupyter_nbextension_paths(): return [dict( section="notebook", diff --git a/voila/app.py b/voila/app.py index c383a0497..9b0c1726d 100644 --- a/voila/app.py +++ b/voila/app.py @@ -7,13 +7,9 @@ ############################################################################# from zmq.eventloop import ioloop - -ioloop.install() - import os import shutil import tempfile -import json import logging import gettext @@ -41,6 +37,7 @@ from ._version import __version__ from .static_file_handler import MultiStaticFileHandler +ioloop.install() _kernel_id_regex = r"(?P\w+-\w+-\w+-\w+-\w+)" @@ -72,9 +69,7 @@ class Voila(Application): config=True, help='Will autoreload to server and the page when a template, js file or Python code changes' ) - root_dir = Unicode(config=True, - help="The directory to use for notebooks." - ) + root_dir = Unicode(config=True, help="The directory to use for notebooks.") static_root = Unicode( STATIC_ROOT, config=True, @@ -107,8 +102,7 @@ class Voila(Application): @default('connection_dir_root') def _default_connection_dir(self): - return tempfile.gettempdir() - connection_dir = tempfile.mkdtemp() + connection_dir = tempfile.gettempdir() self.log.info('Using %s to store connection files' % connection_dir) return connection_dir @@ -256,4 +250,5 @@ def listen(self): finally: shutil.rmtree(self.connection_dir) + main = Voila.launch_instance diff --git a/voila/handler.py b/voila/handler.py index 2dee8bb69..6509ff268 100644 --- a/voila/handler.py +++ b/voila/handler.py @@ -10,7 +10,7 @@ from jupyter_server.base.handlers import JupyterHandler -import nbformat +import nbformat # noqa: F401 from nbconvert.preprocessors.execute import executenb from nbconvert import HTMLExporter @@ -87,4 +87,3 @@ def filter_empty_code_cells(cell): # Compose reply self.set_header('Content-Type', 'text/html') self.write(html) - diff --git a/voila/paths.py b/voila/paths.py index 2ebb95e7a..8b14964c1 100644 --- a/voila/paths.py +++ b/voila/paths.py @@ -7,11 +7,13 @@ ############################################################################# import os +import json from jupyter_core.paths import jupyter_path ROOT = os.path.dirname(__file__) STATIC_ROOT = os.path.join(ROOT, 'static') + def collect_template_paths( nbconvert_template_paths, static_paths, @@ -41,19 +43,19 @@ def collect_template_paths( conf.get('base_template', 'default')) extra_nbconvert_path = os.path.join(dirname, 'nbconvert_templates') - #if not os.path.exists(extra_nbconvert_path): + # 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) nbconvert_template_paths.insert(0, extra_nbconvert_path) extra_static_path = os.path.join(dirname, 'static') - #if not os.path.exists(extra_static_path): + # 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) static_paths.insert(0, extra_static_path) extra_template_path = os.path.join(dirname, 'templates') - #if not os.path.exists(extra_template_path): + # 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) template_paths.insert(0, extra_template_path) @@ -62,5 +64,3 @@ def collect_template_paths( # given level of precedence (for instance user directory), we don't look further (for instance # in sys.prefix) break - - return nbconvert_template_paths, static_paths, template_paths diff --git a/voila/server_extension.py b/voila/server_extension.py index 517a33f1c..71123fb5e 100644 --- a/voila/server_extension.py +++ b/voila/server_extension.py @@ -11,8 +11,6 @@ from jinja2 import Environment, FileSystemLoader -from jupyter_core.paths import jupyter_path - from jupyter_server.utils import url_path_join from jupyter_server.base.handlers import path_regex from jupyter_server.base.handlers import FileFindHandler diff --git a/voila/static_file_handler.py b/voila/static_file_handler.py index 4726274f5..2ad58c6da 100644 --- a/voila/static_file_handler.py +++ b/voila/static_file_handler.py @@ -5,7 +5,7 @@ class MultiStaticFileHandler(tornado.web.StaticFileHandler): """A static file handler that 'merges' a list of directories - + If initialized like this:: application = web.Application([ diff --git a/voila/treehandler.py b/voila/treehandler.py index 79741b1b5..6cf96a48b 100644 --- a/voila/treehandler.py +++ b/voila/treehandler.py @@ -23,8 +23,8 @@ def generate_breadcrumbs(self, path): for i in range(len(parts)): if parts[i]: link = url_path_join(self.base_url, 'voila/tree', - url_escape(url_path_join(*parts[:i + 1])), - ) + url_escape(url_path_join(*parts[:i + 1])), + ) breadcrumbs.append((link, parts[i])) return breadcrumbs @@ -49,13 +49,12 @@ def get(self, path=''): page_title = self.generate_page_title(path) contents = cm.get(path) self.write(self.render_template('tree.html', - page_title=page_title, - notebook_path=path, - breadcrumbs=breadcrumbs, - contents=contents, - terminals_available=False, - server_root=self.settings['server_root_dir'], - )) + page_title=page_title, + notebook_path=path, + breadcrumbs=breadcrumbs, + contents=contents, + terminals_available=False, + server_root=self.settings['server_root_dir'])) elif cm.file_exists(path): # it's not a directory, we have redirecting to do model = cm.get(path, content=False)