jupyter-book
jupyter-book copied to clipboard
thebe always starts in the repository root, instead of the current subdirectory
Describe the bug
When running interactive live code using thebe, I would expect that I am working in the directory of the active jupyter-notebook. Actually, the session is in the root directory of the repository hosting the book. This can be problematic for instance with import my_script
statements in code blocks.
My use case, is that I provide unit tests with each chapter, so that readers can validate their programming exercises online.
I believe this is a regression of #107 and https://github.com/executablebooks/thebe/issues/114.
To Reproduce
Steps to reproduce the behavior:
- Go to https://joergbrech.github.io/jb-bug-demo/subdirectory/notebook.html
- Click on "Live Code"
- Run the code cell, that tries to import from a python script within the current directory
subdirectory
. - See error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-25c7ec6228f8> in <module>
----> 1 import hello_world
ModuleNotFoundError: No module named 'hello_world'
If I replace the contents of the code cell with
import os
os.getcwd()
I get the output
'/home/jovyan'
Expected behavior
I would expect the current working directory to be /home/jovyan/subdirectory
.
@choldgraf, I can see you guys are very busy here, and jupyterbook is making awesome progress. But could you please give me a short update on this? Is this something that will be fixed or should I try and find a workaround for my site?
I tried looking into this and it would seem the requests sent through jupyterlab/services are not configured properly and do not contain the specified path to the notebook directory, even though it is properly set in kernelOptions in the HTML.
I'd like to give this a go but am unaware of any other efforts. Also, thebe has been inactive and so I'm not sure if it's worth pursuing. Could someone please point me in the right direction?
I recently solved this problem in an analogical context for thebe implementation in a mkdocs material template by using the start script with:
#!/bin/bash
set -e
cd /home/jovyan/folder/subfolder/subsubfolder
exec "$@"
I placed this script inside a "binder" directory that I had placed in the root of my repo: repo/binder/start
Look up mybinder.org reference for details (It is redundant to set chmod to exec by hand for this script at the moment, because mybinder's build procedure does that anyway)
For more info about how and why I solved it like that, look here: https://discourse.jupyter.org/t/adding-repos-subdirectories-to-path-for-mybinders-jupyter-kernel/16450
This issue is quite old, and the tools powering JB have since changed a fair bit. I'm going to close the issue, but please re-open it if the bug is still present in some context.