I am using mybinder.org for a jupyter kernel in executable cells enabled by thebe(lab) in a website.
The option to start the kernel for a notebook in a selected folder given in the thebe config file as kernelOptions: { path: “src/code” } doesn’t seem to work, because the kernel starts in the root directory of the repo. Since this is a known issue in the executablebooks project, but it hasn’t been solved (thebe always starts in the repository root, instead of the current subdirectory ), I would like to discuss a potential solution using the postBuild or start file.
I tried various attempts using shell or bash syntax in postBuild and/or start file to add a subdirectory containing some python modules to PATH, so they can be imported in any cell on the website, but it seems that I am missing how mybinder’s jupyter kernel is deployed, because those scripts are ineffective:
Folder structure
The folder structure in the repo is: (in short repo’s_root/src/code)
repo
|_ src
|_ code
|_ sharedlib1.py
|_ sharedlib2.py
if I use the following in any cell, sharedlib modules are imported correctly:
cd src/code
the output of pwd inside the cell is then
/home/jovyan/src/code
Attempts to add to PATH
So I thought the most promising approach would be a start script for the repo2docker deployment of mybinder using bash to simply add this folder to PATH:
#!/bin/bash
set - e
echo "export PATH=$PATH:${HOME}/src/code" >> /etc/profile
e exec "$@"
It went through but was ineffective.
I also made an attempt with an ipython_config.py but I couldn’t figure out where to place this file either or how to inject it using start file:
c.InteractiveShellApp.exec_lines = [
'import sys; sys.path.append("/home/jovyan/src/code")'
]
A working but an impractical solution (too many cells to modify)
I could of course have the following in each cell, it works:
import sys
sys.path.append(‘/home/jovyan/src/code’)
from sharedlib1 import function1
Ideas?
What would be the best practice to make sharedlibs.py available for each cell by default in this situation?