Skip to content

Commit

Permalink
Merge pull request #44 from ccordoba12/nb-4.3
Browse files Browse the repository at this point in the history
PR: Fixes to work with Notebook 4.3+
  • Loading branch information
ccordoba12 authored Mar 22, 2017
2 parents 0a963ec + f139707 commit 08bad92
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
40 changes: 19 additions & 21 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@
from setuptools import find_packages, setup
from spyder_notebook import __version__

REQUIREMENTS = ['spyder>=3', 'notebook']
REQUIREMENTS = ['spyder>=3', 'notebook>=4.3']

setup(
name='spyder-notebook',
version=__version__,
keywords='spyder jupyter notebook',
url='https://github.com/spyder-ide/spyder-notebook',
license='MIT',
author='Spyder Development Team',
description='Jupyter notebook integration with Spyder',
long_description="This is a initial implementation of "
"the notebook running inside Spyder "
"as a plugin.",
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
install_requires=REQUIREMENTS,
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python 2.7',
'Programming Language :: Python 3'
])
name='spyder-notebook',
version=__version__,
keywords='spyder jupyter notebook',
url='https://github.com/spyder-ide/spyder-notebook',
license='MIT',
author='Spyder Development Team',
description='Jupyter notebook integration with Spyder',
long_description="This package allows the Jupyter notebook "
"to run inside Spyder as a plugin.",
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
install_requires=REQUIREMENTS,
classifiers=['Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python 2.7',
'Programming Language :: Python 3']
)
3 changes: 2 additions & 1 deletion spyder_notebook/utils/nbopen.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def nbopen(filename):

print("Starting new server")
command = ['jupyter', 'notebook', '--no-browser',
'--notebook-dir={}'.format(nbdir)]
'--notebook-dir={}'.format(nbdir),
'--NotebookApp.password=']
proc = subprocess.Popen(command)
atexit.register(proc.terminate)

Expand Down
36 changes: 26 additions & 10 deletions spyder_notebook/widgets/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def show_loading_page(self):
self.setHtml(page)



class NotebookClient(QWidget):
"""
Notebook client for Spyder.
Expand All @@ -124,7 +123,7 @@ def __init__(self, plugin, name):

self.plugin_actions = plugin.get_plugin_actions()
self.notebookwidget = NotebookWidget(self)
self.notebookwidget.show_loading_page()
self.notebookwidget.show_blank()

self.find_widget = FindReplace(self)
self.find_widget.set_editor(self.notebookwidget)
Expand All @@ -136,20 +135,33 @@ def __init__(self, plugin, name):
layout.addWidget(self.find_widget)
self.setLayout(layout)

def add_token(self, url):
"""Add notebook token to a given url."""
token_url = url + '?token={}'.format(self.token)
return token_url

def register(self, server_info):
"""Register attributes that can be computed with the server info."""
# Path relative to the server directory
self.path = os.path.relpath(self.name,
start=server_info['notebook_dir'])

# Full url used to render the notebook as a web page
self.file_url = url_path_join(server_info['url'],
'notebooks',
url_escape(self.path.replace('\\','/')))
# Replace backslashes on Windows
if os.name == 'nt':
self.path = self.path.replace('\\','/')

# Server url to send requests to
self.server_url = server_info['url']

# Server token
self.token = server_info['token']

url = url_path_join(self.server_url, 'notebooks',
url_escape(self.path))

# Set file url to load this notebook
self.file_url = self.add_token(url)

def go_to(self, url_or_text):
"""Go to page *address*"""
if is_text_string(url_or_text):
Expand Down Expand Up @@ -177,22 +189,26 @@ def save(self):

def shutdown_kernel(self):
"""Shutdown the kernel of the client."""
sessions_url = url_path_join(self.server_url, 'api/sessions')
sessions_url = self.add_token(url_path_join(self.server_url,
'api/sessions'))
sessions_req = requests.get(sessions_url).content.decode()
sessions = json.loads(sessions_req)
kernel_id = None

if os.name == 'nt':
path = self.path.replace('\\', '/')
else:
path = self.path

for session in sessions:
if session['notebook']['path'] == path:
kernel_id = session['kernel']['id']
break

if kernel_id:
delete_url = url_path_join(self.server_url,
'api/kernels/',
kernel_id)
delete_url = self.add_token(url_path_join(self.server_url,
'api/kernels/',
kernel_id))
delete_req = requests.delete(delete_url)
if delete_req.status_code != 204:
QMessageBox.warning(
Expand Down

0 comments on commit 08bad92

Please sign in to comment.