Jupyter-book: thebelab always runs in home directory

Created on 12 Feb 2019  路  8Comments  路  Source: executablebooks/jupyter-book

Currently, thebelab always runs in the home directory. It would be really convenient, if it were started in the subdirectory of the current page, e.g. contents/chapter_X. This way I could add chapter-dependent code files in this subdirectory. This would also fit with the current behavior of the "interact" button.

I wonder if this would be possible by modifying this line using the current page's data?

https://github.com/jupyter/jupyter-book/blob/493b346d888ee7c863d93c73abb53f038a54a89c/jupyter_book/book_template/_includes/js/thebelab.html#L8

bug

Most helpful comment

I think it's been fixed in Thebelab, though I haven't had a chance to try it out. From looking at the issue there, it seems like we should be able to add a path variable to the kernelOptions configuration that should define the path (relative to the project root, I assume?) for the kernel. See the kernelOptions section here:

https://github.com/minrk/thebelab#configuring-thebelab

We can try giving this a whirl by editing the thebelab.js file in jupyter book and adding the path variable here: https://github.com/jupyter/jupyter-book/blob/master/jupyter_book/book_template/_includes/js/thebelab.html#L17

wanna give it a shot locally and see if that works? If so, we can build it into the page configuration and add docs to thebelab

All 8 comments

ah ha - good catch. let me see if I understand what you mean:

You'd expect Thebelab to run as if you ran the notebook on your own. The Jupyter Notebook runs with the directory in which it lives as the CWD. Thebelab, on the other hand, uses the repository root as the CWD. Thus the confusion.

You're proposing that the Thebelab CWD should always be the notebook's directory?

Exactly! If I use Thebelab on the notebook repo/content/mynotebook.ipynb, repo/content/mycode.py (resp. repo/_build/mycode.py) will not be available, since Thebelab runs in repo.

totally makes sense - think you have time for a PR? this sounds like a good addition :-)

Sure, I will see what I can do! I will probably not get to it within the next few days though...

good idea opening up an issue in the Thebelab repo, it could be that this is the only way we can resolve this on the jupyter-book side.

One other possibility would be to actually add a os.cwd command to the first cell of the markdown file so that this happens. It's a bit hacky but it could work!

Thanks for checking this out on thebelab!

Changing the directory from a cell would work, but as you say it is a bit ugly, since I have to make sure that it works for binder and thebelab. So (using octave) I would have to do something along the lines of:

subdir = 'my/subdir';
if (exist(subdir, 'dir') )
    chdir(subdir)
end

Also, I would have to have the students explicitly run the cell and explain why...so it would really be cool to get this to work automatically under the hood!

FYI: I want to use this feature to supply unit tests for the exercise assignments of each chapter, without the students having to know anything about unit testing.

+1 on this, had the same issue. Is is resolved? I can't tell as the issue seems closed, but I'm getting the same behaviour still.

I think it's been fixed in Thebelab, though I haven't had a chance to try it out. From looking at the issue there, it seems like we should be able to add a path variable to the kernelOptions configuration that should define the path (relative to the project root, I assume?) for the kernel. See the kernelOptions section here:

https://github.com/minrk/thebelab#configuring-thebelab

We can try giving this a whirl by editing the thebelab.js file in jupyter book and adding the path variable here: https://github.com/jupyter/jupyter-book/blob/master/jupyter_book/book_template/_includes/js/thebelab.html#L17

wanna give it a shot locally and see if that works? If so, we can build it into the page configuration and add docs to thebelab

Was this page helpful?
0 / 5 - 0 ratings