Skip to content

Commit f15e523

Browse files
committed
Merge branch 'master' into example
2 parents 505fafc + 08473f0 commit f15e523

20 files changed

+498
-4325
lines changed

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
11+
## [0.2.0] - 2019-12-19
12+
13+
### Added
14+
- `extension` submodule ([#48](https://github.com/jupyter/jupyter_server/pull/48))
15+
- ExtensionApp - configurable JupyterApp-subclass for server extensions
16+
- Most useful for Jupyter frontends, like Notebook, JupyterLab, nteract, voila etc.
17+
- Launch with entrypoints
18+
- Configure from file or CLI
19+
- Add custom templates, static assets, handlers, etc.
20+
- Static assets are served behind a `/static/<extension_name>` endpoint.
21+
- Run server extensions in "standalone mode" ([#70](https://github.com/jupyter/jupyter_server/pull/70) and [#76](https://github.com/jupyter/jupyter_server/pull/76))
22+
- ExtensionHandler - tornado handlers for extensions.
23+
- Finds static assets at `/static/<extension_name>`
24+
25+
### Changed
26+
- `jupyter serverextension <command>` entrypoint has been changed to `jupyter server extension <command>`.
27+
- `toggle_jupyter_server` and `validate_jupyter_server` function no longer take a Logger object as an argument.
28+
- Changed testing framework from nosetests to pytest ([#152](https://github.com/jupyter/jupyter_server/pull/152))
29+
- Depend on pytest-tornasync extension for handling tornado/asyncio eventloop
30+
- Depend on pytest-console-scripts for testing CLI entrypoints
31+
- Added Github actions as a testing framework along side Travis and Azure ([#146](https://github.com/jupyter/jupyter_server/pull/146))
32+
33+
### Removed
34+
- Removed the option to update `root_dir` trait in FileContentsManager and MappingKernelManager in ServerApp ([#135](https://github.com/jupyter/jupyter_server/pull/135))
35+
36+
### Fixed
37+
- Synced Jupyter Server with Notebook PRs in batches (ended on 2019-09-27)
38+
- [Batch 1](https://github.com/jupyter/jupyter_server/pull/95)
39+
- [Batch 2](https://github.com/jupyter/jupyter_server/pull/97)
40+
- [Batch 3](https://github.com/jupyter/jupyter_server/pull/98)
41+
- [Batch 4](https://github.com/jupyter/jupyter_server/pull/99)
42+
- [Batch 5](https://github.com/jupyter/jupyter_server/pull/103)
43+
- [Batch 6](https://github.com/jupyter/jupyter_server/pull/104)
44+
- [Batch 7](https://github.com/jupyter/jupyter_server/pull/105)
45+
- [Batch 8](https://github.com/jupyter/jupyter_server/pull/106)
46+
47+
### Security
48+
- Added a "secure_write to function for cookie/token saves ([#77](https://github.com/jupyter/jupyter_server/pull/77))

CONTRIBUTING.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To run the Python tests, use::
6969

7070
If you want coverage statistics as well, you can run::
7171

72-
py.test --cov notebook -v --pyargs jupyter_server
72+
py.test --cov notebook -v
7373

7474
Building the Documentation
7575
--------------------------
@@ -82,7 +82,7 @@ containing all the necessary packages (except pandoc), use::
8282

8383
conda env create -f docs/environment.yml
8484
source activate server_docs # Linux and OS X
85-
activate notebook_docs # Windows
85+
activate server_docs # Windows
8686

8787
.. _conda environment:
8888
https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file

jupyter_server/extension/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from .application import ExtensionApp
2-
from .handler import ExtensionHandler

jupyter_server/extension/application.py

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
import re
33

4+
from jinja2 import Environment, FileSystemLoader
5+
46
from traitlets import (
57
Unicode,
68
List,
@@ -25,6 +27,9 @@
2527
except KeyError:
2628
pass
2729

30+
#-----------------------------------------------------------------------------
31+
# Util functions and classes.
32+
#-----------------------------------------------------------------------------
2833

2934
def _preparse_for_subcommand(Application, argv):
3035
"""Preparse command line to look for subcommands.
@@ -81,11 +86,52 @@ def _preparse_for_stopping_flags(Application, argv):
8186
app.exit(0)
8287

8388

89+
class ExtensionAppJinjaMixin:
90+
"""Use Jinja templates for HTML templates on top of an ExtensionApp."""
91+
92+
jinja2_options = Dict(
93+
help=_("""Options to pass to the jinja2 environment for this
94+
extension.
95+
""")
96+
).tag(config=True)
97+
98+
def _prepare_templates(self):
99+
# Add templates to web app settings if extension has templates.
100+
if len(self.template_paths) > 0:
101+
self.settings.update({
102+
"{}_template_paths".format(self.extension_name): self.template_paths
103+
})
104+
105+
# Create a jinja environment for logging html templates.
106+
self.jinja2_env = Environment(
107+
loader=FileSystemLoader(self.template_paths),
108+
extensions=['jinja2.ext.i18n'],
109+
autoescape=True,
110+
**self.jinja2_options
111+
)
112+
113+
# Get templates defined in a subclass.
114+
self.initialize_templates()
115+
116+
# Add the jinja2 environment for this extension to the tornado settings.
117+
self.settings.update(
118+
{
119+
"{}_jinja2_env".format(self.extension_name): self.jinja2_env
120+
}
121+
)
122+
123+
#-----------------------------------------------------------------------------
124+
# Aliases and Flags
125+
#-----------------------------------------------------------------------------
126+
84127
flags['no-browser']=(
85128
{'ExtensionApp' : {'open_browser' : True}},
86129
_("Prevent the opening of the default url in the browser.")
87130
)
88131

132+
#-----------------------------------------------------------------------------
133+
# ExtensionApp
134+
#-----------------------------------------------------------------------------
89135

90136
class ExtensionApp(JupyterApp):
91137
"""Base class for configurable Jupyter Server Extension Applications.
@@ -98,6 +144,9 @@ class ExtensionApp(JupyterApp):
98144
class method. This method can be set as a entry_point in
99145
the extensions setup.py
100146
"""
147+
# Subclasses should override this trait. Tells the server if
148+
# this extension allows other other extensions to be loaded
149+
# side-by-side when launched directly.
101150
load_other_extensions = True
102151

103152
# Name of the extension
@@ -302,7 +351,6 @@ def _prepare_templates(self):
302351
self.settings.update({
303352
"{}_template_paths".format(self.extension_name): self.template_paths
304353
})
305-
self.initialize_templates()
306354

307355
@staticmethod
308356
def initialize_server(argv=[], load_other_extensions=True, **kwargs):
@@ -370,7 +418,6 @@ def load_jupyter_server_extension(cls, serverapp, argv=[], **kwargs):
370418
extension.initialize(serverapp, argv=argv)
371419
return extension
372420

373-
374421
@classmethod
375422
def launch_instance(cls, argv=None, **kwargs):
376423
"""Launch the extension like an application. Initializes+configs a stock server
@@ -405,5 +452,4 @@ def launch_instance(cls, argv=None, **kwargs):
405452

406453
extension = cls.load_jupyter_server_extension(serverapp, argv=args, **kwargs)
407454
# Start the ioloop.
408-
extension.start()
409-
455+
extension.start()

jupyter_server/extension/handler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
from traitlets import Unicode, default
33

44

5+
class ExtensionHandlerJinjaMixin:
6+
"""Mixin class for ExtensionApp handlers that use jinja templating for
7+
template rendering.
8+
"""
9+
def get_template(self, name):
10+
"""Return the jinja template object for a given name"""
11+
env = '{}_jinja2_env'.format(self.extension_name)
12+
return self.settings[env].get_template(name)
13+
14+
515
class ExtensionHandler(JupyterHandler):
616
"""Base class for Jupyter server extension handlers.
717

0 commit comments

Comments
 (0)