Create notebook directory on first login

52 views
Skip to first unread message

Craig Ching

unread,
Aug 12, 2017, 12:20:21 PM8/12/17
to Project Jupyter
I want to create the notebook directory when my user logs in for the first time.  Looking through the issues, I found a couple of suggestions and am trying this:

from jupyterhub.spawner import LocalProcessSpawner
import os

class MySpawner(LocalProcessSpawner):
    def _notebook_dir_validate(self, value, trait):
        # Strip any trailing slashes
        # *except* if it's root
        _, path = os.path.splitdrive(value)
        if path == os.sep:
            return value

        value = value.rstrip(os.sep)

        if not os.path.isabs(value):
            # If we receive a non-absolute path, make it absolute.
            value = os.path.abspath(value)
        if not os.path.isdir(value):
            os.mkdir(value, mode=0o755)
        return value

c.JupyterHub.spawner_class = MySpawner

But I'm getting this when I start jupyterhub:

Traceback (most recent call last):                                     
  File "/usr/local/lib/python3.5/dist-packages/jupyterhub/app.py", line
    yield self.initialize(argv)                                        
  File "/usr/lib/python3.5/types.py", line 179, in throw               
    return self.__wrapped.throw(tp, *rest)                             
  File "/usr/local/lib/python3.5/dist-packages/jupyterhub/app.py", line
    yield self.init_spawners()                                         
  File "/usr/local/lib/python3.5/dist-packages/jupyterhub/app.py", line
    self.users[orm_user.id] = user = User(orm_user, self.tornado_settin
  File "/usr/local/lib/python3.5/dist-packages/jupyterhub/user.py", lin
    config=self.settings.get('config'),                                
  File "/usr/local/lib/python3.5/dist-packages/traitlets/traitlets.py",
    inst.setup_instance(*args, **kwargs)                               
  File "/usr/local/lib/python3.5/dist-packages/traitlets/traitlets.py",
    super(HasTraits, self).setup_instance(*args, **kwargs)             
  File "/usr/local/lib/python3.5/dist-packages/traitlets/traitlets.py",
    value.instance_init(self)                                          
  File "/usr/local/lib/python3.5/dist-packages/traitlets/traitlets.py",
    inst._register_validator(self, self.trait_names)                   
  File "/usr/local/lib/python3.5/dist-packages/traitlets/traitlets.py",
    _deprecated_method(class_value, self.__class, magic_name,          
AttributeError: 'MySpawner' object has no attribute '_HasTraits__class'

What am I doing wrong?  Thanks for any help!

Thomas Kluyver

unread,
Aug 14, 2017, 5:43:04 AM8/14/17
to Project Jupyter
Looks like a bug in traitlets, I think this should fix it:
https://github.com/ipython/traitlets/pull/440

In the meantime, you can probably work around it by doing:

from traitlets import validate

class MySpawner(LocalProcessSpawner):
    @validate('notebook_dir')
    def _notebook_dir_validate(self, value, trait):
    ...

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/3755a0c5-0dbd-46ee-a715-8f093f5dec98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Craig Ching

unread,
Aug 15, 2017, 10:50:41 AM8/15/17
to Project Jupyter
Hi takowl!

Thanks much for your help!

On Monday, August 14, 2017 at 4:43:04 AM UTC-5, takowl wrote:

from traitlets import validate

class MySpawner(LocalProcessSpawner):
    @validate('notebook_dir')
    def _notebook_dir_validate(self, value, trait):
    ...


I've done that, but now I'm getting:

TypeError: _notebook_dir_validate() missing 1 required positional argument: 'trait'

I've tried looking through the source code to see if I have the arguments defined correctly, but I'm afraid I'm not that strong at Python yet. 

Thomas Kluyver

unread,
Aug 15, 2017, 10:58:37 AM8/15/17
to Project Jupyter
Sorry, my mistake. The method should take just one argument like this:

@validate('notebook_dir')
def _validate_notebook_dir(self, proposal):
    value = proposal['value']
    ...

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages