-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from jitseniesen/jupyterlab
PR: Use JupyterLab to render notebooks
- Loading branch information
Showing
27 changed files
with
1,184 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Contributing to the Spyder notebook plugin | ||
|
||
:+1::tada: | ||
First off, thanks for taking the time to contribute to the Spyder notebook | ||
plugin! | ||
:tada::+1: | ||
|
||
## General guidelines for contributing | ||
|
||
The Spyder notebook plugin is developed as part of the wider Spyder project. | ||
In general, the guidelines for contributing to Spyder also apply here. | ||
Specifically, all contributors are expected to abide by | ||
[Spyder's Code of Conduct](https://github.com/spyder-ide/spyder/blob/master/CODE_OF_CONDUCT.md). | ||
|
||
There are many ways to contribute and all are valued and welcome. | ||
You can help other users, write documentation, spread the word, submit | ||
helpful issues on the | ||
[issue tracker](https://github.com/spyder-ide/spyder-notebook/issues) | ||
with problems you encounter or ways to improve the plugin, test the development | ||
version, or submit a pull request on GitHub. | ||
|
||
The rest of this document explains how to set up a development environment. | ||
|
||
## Setting up a development environment | ||
|
||
This section explains how to set up a conda environment to run and work on the | ||
development version of the Spyder notebook plugin. | ||
|
||
### Creating a conda environment | ||
|
||
This creates a new conda environment with the name `spydernb-dev`. | ||
|
||
```bash | ||
$ conda create -n spydernb-dev python=3.7 | ||
$ conda activate spydernb-dev | ||
``` | ||
|
||
### Cloning the repository | ||
|
||
This creates a new directory `spyder-notebook` with the source code of the | ||
Spyder notebook plugin. | ||
|
||
```bash | ||
$ git clone https://github.com/spyder-ide/spyder-notebook.git | ||
$ cd spyder-notebook | ||
``` | ||
|
||
### Installing dependencies | ||
|
||
This installs Spyder, JupyterLab and all other dependencies of the plugin into | ||
the conda environment. | ||
|
||
```bash | ||
$ conda install --file requirements/conda.txt | ||
``` | ||
|
||
### Building the notebook server | ||
|
||
The Spyder notebook plugin includes a server which serves notebooks as HTML | ||
pages. The following commands install the JavaScript dependencies of the | ||
notebook server and build the server. | ||
|
||
```bash | ||
$ cd spyder_notebook/server | ||
$ jlpm install | ||
$ jlpm build | ||
$ cd ../.. | ||
``` | ||
|
||
### Installing the plugin | ||
|
||
This installs the Spyder notebook plugin so that Spyder will use it. | ||
|
||
```bash | ||
$ pip install --no-deps -e . | ||
``` | ||
|
||
### Running Spyder | ||
|
||
You are done! You can run Spyder as normal and it should load the notebook | ||
plugin. | ||
|
||
```bash | ||
$ spyder | ||
``` | ||
|
||
### Running Tests | ||
|
||
This command installs the test dependencies in the conda environment. | ||
|
||
```bash | ||
$ conda install -c spyder-ide --file requirements/tests.txt | ||
``` | ||
|
||
You can now run the tests with a simple | ||
|
||
```bash | ||
$ pytest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
notebook | ||
jupyterlab | ||
spyder >=4.0.0b5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
The files in this directory and its subdirectories are licensed under the | ||
modified BSD license, as detailed below. They are adapted from the directory | ||
examples/notebook in the JupyterLab repository at | ||
https://github.com/jupyterlab/jupyterlab | ||
|
||
|
||
Copyright (c) 2015 Project Jupyter Contributors | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*----------------------------------------------------------------------------- | ||
| Copyright (c) Jupyter Development Team. | ||
| Distributed under the terms of the Modified BSD License. | ||
|----------------------------------------------------------------------------*/ | ||
|
||
body { | ||
background: white; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
#main { | ||
position: absolute; | ||
top: 4px; | ||
left: 4px; | ||
right: 4px; | ||
bottom: 4px; | ||
} | ||
|
||
.jp-NotebookPanel { | ||
border-bottom: 1px solid #e0e0e0; | ||
} | ||
|
||
.notebookCommandPalette { | ||
min-width: 225px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Notebook Demo</title> | ||
</head> | ||
<body> | ||
<script id='jupyter-config-data' type="application/json"> | ||
{{ config_data|tojson }} | ||
</script> | ||
<script src="{{config_data['frontendUrl'] | e}}bundle.js"></script> | ||
|
||
<script type="text/javascript"> | ||
/* Remove token from URL. */ | ||
(function () { | ||
var parsedUrl = new URL(window.location.href); | ||
if (parsedUrl.searchParams.get('token')) { | ||
parsedUrl.searchParams.delete('token'); | ||
window.history.replaceState({ }, '', parsedUrl.href); | ||
} | ||
})(); | ||
</script> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
An example demonstrating a stand-alone "notebook". | ||
Copyright (c) Jupyter Development Team. | ||
Distributed under the terms of the Modified BSD License. | ||
Example | ||
------- | ||
To run the example, see the instructions in the README to build it. Then | ||
run ``python main.py``. | ||
""" | ||
import os | ||
from jinja2 import FileSystemLoader | ||
from notebook.base.handlers import IPythonHandler, FileFindHandler | ||
from notebook.notebookapp import NotebookApp | ||
from notebook.utils import url_path_join as ujoin | ||
|
||
HERE = os.path.dirname(__file__) | ||
|
||
|
||
class NotebookHandler(IPythonHandler): | ||
""" | ||
Serve a notebook file from the filesystem in the notebook interface | ||
""" | ||
|
||
def get(self, filename): | ||
"""Get the main page for the application's interface.""" | ||
# Options set here can be read with PageConfig.getOption | ||
config_data = { | ||
# Use camelCase here, since that's what the lab components expect | ||
'baseUrl': self.base_url, | ||
'token': self.settings['token'], | ||
'notebookPath': filename, | ||
'frontendUrl': ujoin(self.base_url, 'static/'), | ||
# FIXME: Don't use a CDN here | ||
'mathjaxUrl': 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/' | ||
'2.7.5/MathJax.js', | ||
'mathjaxConfig': "TeX-AMS_CHTML-full,Safe" | ||
} | ||
return self.write( | ||
self.render_template( | ||
'index.html', | ||
static=self.static_url, | ||
base_url=self.base_url, | ||
config_data=config_data | ||
) | ||
) | ||
|
||
def get_template(self, name): | ||
loader = FileSystemLoader(HERE) | ||
return loader.load(self.settings['jinja2_env'], name) | ||
|
||
|
||
class SpyderNotebookServer(NotebookApp): | ||
def init_webapp(self): | ||
"""initialize tornado webapp and httpserver. | ||
""" | ||
super(SpyderNotebookServer, self).init_webapp() | ||
|
||
default_handlers = [ | ||
(ujoin(self.base_url, r'/notebook/(.*)'), NotebookHandler), | ||
(ujoin(self.base_url, r"/static/(.*)"), FileFindHandler, | ||
{'path': os.path.join(HERE, 'build')}) | ||
] | ||
self.web_app.add_handlers('.*$', default_handlers) | ||
|
||
|
||
if __name__ == '__main__': | ||
SpyderNotebookServer.launch_instance() |
Oops, something went wrong.