Edit spacing in singleuser.py

This commit is contained in:
Carol Willing
2017-02-08 21:38:23 -08:00
parent cf02f3133a
commit 4688348020

View File

@@ -39,22 +39,26 @@ from jupyterhub import __version__
from .services.auth import HubAuth, HubAuthenticated from .services.auth import HubAuth, HubAuthenticated
from .utils import url_path_join from .utils import url_path_join
# Authenticate requests with the Hub # Authenticate requests with the Hub
class HubAuthenticatedHandler(HubAuthenticated): class HubAuthenticatedHandler(HubAuthenticated):
"""Class we are going to patch-in for authentication with the Hub""" """Class we are going to patch-in for authentication with the Hub"""
@property @property
def hub_auth(self): def hub_auth(self):
return self.settings['hub_auth'] return self.settings['hub_auth']
@property @property
def hub_users(self): def hub_users(self):
return { self.settings['user'] } return { self.settings['user'] }
@property @property
def hub_groups(self): def hub_groups(self):
if self.settings['group']: if self.settings['group']:
return { self.settings['group'] } return { self.settings['group'] }
return set() return set()
class JupyterHubLoginHandler(LoginHandler): class JupyterHubLoginHandler(LoginHandler):
"""LoginHandler that hooks up Hub authentication""" """LoginHandler that hooks up Hub authentication"""
@@ -90,7 +94,7 @@ class JupyterHubLogoutHandler(LogoutHandler):
# register new hub related command-line aliases # register new hub related command-line aliases
aliases = dict(notebook_aliases) aliases = dict(notebook_aliases)
aliases.update({ aliases.update({
'user' : 'SingleUserNotebookApp.user', 'user': 'SingleUserNotebookApp.user',
'group': 'SingleUserNotebookApp.group', 'group': 'SingleUserNotebookApp.group',
'cookie-name': 'HubAuth.cookie_name', 'cookie-name': 'HubAuth.cookie_name',
'hub-prefix': 'SingleUserNotebookApp.hub_prefix', 'hub-prefix': 'SingleUserNotebookApp.hub_prefix',
@@ -124,6 +128,7 @@ Control Panel</a>
{% endblock logo %} {% endblock logo %}
""" """
def _exclude_home(path_list): def _exclude_home(path_list):
"""Filter out any entries in a path list that are in my home directory. """Filter out any entries in a path list that are in my home directory.
@@ -139,10 +144,10 @@ class SingleUserNotebookApp(NotebookApp):
"""A Subclass of the regular NotebookApp that is aware of the parent multiuser context.""" """A Subclass of the regular NotebookApp that is aware of the parent multiuser context."""
description = dedent(""" description = dedent("""
Single-user server for JupyterHub. Extends the Jupyter Notebook server. Single-user server for JupyterHub. Extends the Jupyter Notebook server.
Meant to be invoked by JupyterHub Spawners, and not directly. Meant to be invoked by JupyterHub Spawners, and not directly.
""") """)
examples = "" examples = ""
subcommands = {} subcommands = {}
version = __version__ version = __version__
@@ -150,6 +155,7 @@ class SingleUserNotebookApp(NotebookApp):
user = CUnicode().tag(config=True) user = CUnicode().tag(config=True)
group = CUnicode().tag(config=True) group = CUnicode().tag(config=True)
@observe('user') @observe('user')
def _user_changed(self, change): def _user_changed(self, change):
self.log.name = change.new self.log.name = change.new
@@ -157,12 +163,14 @@ class SingleUserNotebookApp(NotebookApp):
hub_host = Unicode().tag(config=True) hub_host = Unicode().tag(config=True)
hub_prefix = Unicode('/hub/').tag(config=True) hub_prefix = Unicode('/hub/').tag(config=True)
@default('hub_prefix') @default('hub_prefix')
def _hub_prefix_default(self): def _hub_prefix_default(self):
base_url = os.environ.get('JUPYTERHUB_BASE_URL') or '/' base_url = os.environ.get('JUPYTERHUB_BASE_URL') or '/'
return base_url + 'hub/' return base_url + 'hub/'
hub_api_url = Unicode().tag(config=True) hub_api_url = Unicode().tag(config=True)
@default('hub_api_url') @default('hub_api_url')
def _hub_api_url_default(self): def _hub_api_url_default(self):
return os.environ.get('JUPYTERHUB_API_URL') or 'http://127.0.0.1:8081/hub/api' return os.environ.get('JUPYTERHUB_API_URL') or 'http://127.0.0.1:8081/hub/api'
@@ -199,7 +207,7 @@ class SingleUserNotebookApp(NotebookApp):
trust_xheaders = True trust_xheaders = True
login_handler_class = JupyterHubLoginHandler login_handler_class = JupyterHubLoginHandler
logout_handler_class = JupyterHubLogoutHandler logout_handler_class = JupyterHubLogoutHandler
port_retries = 0 # disable port-retries, since the Spawner will tell us what port to use port_retries = 0 # disable port-retries, since the Spawner will tell us what port to use
disable_user_config = Bool(False, disable_user_config = Bool(False,
help="""Disable user configuration of single-user server. help="""Disable user configuration of single-user server.
@@ -280,7 +288,7 @@ class SingleUserNotebookApp(NotebookApp):
api_token = os.environ['JPY_API_TOKEN'] api_token = os.environ['JPY_API_TOKEN']
if os.getenv('JUPYTERHUB_API_TOKEN'): if os.getenv('JUPYTERHUB_API_TOKEN'):
api_token = os.environ['JUPYTERHUB_API_TOKEN'] api_token = os.environ['JUPYTERHUB_API_TOKEN']
if not api_token: if not api_token:
self.exit("JUPYTERHUB_API_TOKEN env is required to run jupyterhub-singleuser. Did you launch it manually?") self.exit("JUPYTERHUB_API_TOKEN env is required to run jupyterhub-singleuser. Did you launch it manually?")
self.hub_auth = HubAuth( self.hub_auth = HubAuth(