Skip to content

Commit

Permalink
Merge pull request #64 from timkpaine/linting
Browse files Browse the repository at this point in the history
Linting
  • Loading branch information
maartenbreddels authored Jan 30, 2019
2 parents 91d8064 + 716b8d5 commit 0e2ecac
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 29 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ universal = 1

[metadata]
license_file = LICENSE

[flake8]
max-line-length=200
1 change: 1 addition & 0 deletions voila/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# The full license is in the file LICENSE, distributed with this software. #
#############################################################################


def _jupyter_nbextension_paths():
return [dict(
section="notebook",
Expand Down
13 changes: 4 additions & 9 deletions voila/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
#############################################################################

from zmq.eventloop import ioloop

ioloop.install()

import os
import shutil
import tempfile
import json
import logging
import gettext

Expand Down Expand Up @@ -41,6 +37,7 @@
from ._version import __version__
from .static_file_handler import MultiStaticFileHandler

ioloop.install()
_kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -256,4 +250,5 @@ def listen(self):
finally:
shutil.rmtree(self.connection_dir)


main = Voila.launch_instance
3 changes: 1 addition & 2 deletions voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -87,4 +87,3 @@ def filter_empty_code_cells(cell):
# Compose reply
self.set_header('Content-Type', 'text/html')
self.write(html)

10 changes: 5 additions & 5 deletions voila/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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
2 changes: 0 additions & 2 deletions voila/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion voila/static_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
17 changes: 8 additions & 9 deletions voila/treehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 0e2ecac

Please sign in to comment.