Skip to content

Commit

Permalink
Merge b27ef8e into 5528590
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Jun 12, 2015
2 parents 5528590 + b27ef8e commit ed8c879
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
6 changes: 3 additions & 3 deletions jupyterhub/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from . import orm
from ._data import DATA_FILES_PATH
from .log import CoroutineLogFormatter, log_request
from .traitlets import URLPrefix
from .traitlets import URLPrefix, Command
from .utils import (
url_path_join,
ISO8601_ms, ISO8601_s,
Expand Down Expand Up @@ -237,7 +237,7 @@ def _template_paths_default(self):
help="Supply extra arguments that will be passed to Jinja environment."
)

proxy_cmd = Unicode('configurable-http-proxy', config=True,
proxy_cmd = Command('configurable-http-proxy', config=True,
help="""The command to start the http proxy.
Only override if configurable-http-proxy is not on your PATH
Expand Down Expand Up @@ -742,7 +742,7 @@ def start_proxy(self):

env = os.environ.copy()
env['CONFIGPROXY_AUTH_TOKEN'] = self.proxy.auth_token
cmd = [self.proxy_cmd,
cmd = self.proxy_cmd + [
'--ip', self.proxy.public_server.ip,
'--port', str(self.proxy.public_server.port),
'--api-ip', self.proxy.api_server.ip,
Expand Down
3 changes: 2 additions & 1 deletion jupyterhub/spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Any, Bool, Dict, Enum, Instance, Integer, Float, List, Unicode,
)

from .traitlets import Command
from .utils import random_port

NUM_PAT = re.compile(r'\d+')
Expand Down Expand Up @@ -93,7 +94,7 @@ def _env_default(self):
env['JPY_API_TOKEN'] = self.api_token
return env

cmd = List(Unicode, default_value=['jupyterhub-singleuser'], config=True,
cmd = Command(['jupyterhub-singleuser'], config=True,
help="""The command used for starting notebooks."""
)
args = List(Unicode, config=True,
Expand Down
4 changes: 2 additions & 2 deletions jupyterhub/tests/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fin():
request.addfinalizer(fin)
env = os.environ.copy()
env['CONFIGPROXY_AUTH_TOKEN'] = auth_token
cmd = [app.proxy_cmd,
cmd = app.proxy_cmd + [
'--ip', app.ip,
'--port', str(app.port),
'--api-ip', proxy_ip,
Expand Down Expand Up @@ -82,7 +82,7 @@ def wait_for_proxy():
new_auth_token = 'different!'
env['CONFIGPROXY_AUTH_TOKEN'] = new_auth_token
proxy_port = 55432
cmd = [app.proxy_cmd,
cmd = app.proxy_cmd + [
'--ip', app.ip,
'--port', str(app.port),
'--api-ip', app.proxy_api_ip,
Expand Down
30 changes: 30 additions & 0 deletions jupyterhub/tests/test_traitlets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
try:
from traitlets import HasTraits
except ImportError:
from IPython.utils.traitlets import HasTraits

from jupyterhub.traitlets import URLPrefix, Command

def test_url_prefix():
class C(HasTraits):
url = URLPrefix()

c = C()
c.url = '/a/b/c/'
assert c.url == '/a/b/c/'
c.url = '/a/b'
assert c.url == '/a/b/'
c.url = 'a/b/c/d'
assert c.url == '/a/b/c/d/'

def test_command():
class C(HasTraits):
cmd = Command('default command')
cmd2 = Command(['default_cmd'])

c = C()
assert c.cmd == ['default command']
assert c.cmd2 == ['default_cmd']
c.cmd = 'foo bar'
assert c.cmd == ['foo bar']

17 changes: 16 additions & 1 deletion jupyterhub/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from IPython.utils.traitlets import Unicode
from IPython.utils.traitlets import List, Unicode

class URLPrefix(Unicode):
def validate(self, obj, value):
Expand All @@ -12,3 +12,18 @@ def validate(self, obj, value):
if not u.endswith('/'):
u = u + '/'
return u

class Command(List):
"""Traitlet for a command that should be a list of strings,
but allows it to be specified as a single string.
"""
def __init__(self, default_value=None, **kwargs):
kwargs.setdefault('minlen', 1)
if isinstance(default_value, str):
default_value = [default_value]
super().__init__(Unicode, default_value, **kwargs)

def validate(self, obj, value):
if isinstance(value, str):
value = [value]
return super().validate(obj, value)

0 comments on commit ed8c879

Please sign in to comment.