jupyter-book / thebe

Turn static HTML pages into live documents with Jupyter kernels.
https://thebe.readthedocs.io
BSD 3-Clause "New" or "Revised" License
395 stars 68 forks source link

kernelOptions path does not seem to change the current working directory of the launched kernel #583

Closed lesteve closed 6 months ago

lesteve commented 1 year ago

Describe the bug

context In the JupyterBook thebe integration, the kernel is not started from the same folder as the notebook, as was reported in https://github.com/executablebooks/jupyter-book/issues/1304. I think I have managed to confirm this is an issue in thebe. JupyterBook does set the kernelOptions path as mentioned in https://github.com/executablebooks/jupyter-book/issues/107#issuecomment-520007658 and I have double-checked this.

expectation kernelOptions path should be taken into account as mentioned in https://thebe.readthedocs.io/en/latest/configure.html#configure-the-working-directory-of-the-launched-kernel

bug kernelOptions path is not taken into account

problem This is an issue since the current folder will not be the same whether in Binder or in thebe, which causes issues when loading local files with relative paths https://github.com/INRIA/scikit-learn-mooc/issues/669 or importing local modules https://github.com/executablebooks/jupyter-book/issues/1304

Reproduce the bug

git fetch https://github.com/lesteve/thebe reproduce-path-issue:reproduce-path-issue
git checkout reproduce-path-issue
yarn run develop

you also need to start a local notebook server

jupyter notebook --no-browser \
              --NotebookApp.token=thebe-test-secret \
              --NotebookApp.allow_origin='http://127.0.0.1:8080'

and open a browser at http://127.0.0.1:8080/development/local.html

I modified options['kernelOptions']['path'] to be development:

    <script type="text/x-thebe-config">
      { .
        .
        .
        kernelOptions: {
          name: "python3",
          path: "development"
        .
        .
        .
      }

but running the code in thebe shows that the current working directory is still the root of the repo: image

With the browser debugger I can confirm that path gets passed to the KernelManager.startNew call: image

but I have no idea to debug further ...

List your environment

❯ jupyter-book --version
Jupyter Book      : 0.13.1
External ToC      : 0.2.4
MyST-Parser       : 0.15.2
MyST-NB           : 0.13.2
Sphinx Book Theme : 0.3.3
Jupyter-Cache     : 0.4.3
NbClient          : 0.5.13

Python 3.11 OS: Ubuntu 22.04

welcome[bot] commented 1 year ago

Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:

e-dong commented 6 months ago

Fyi this is where the path is being set for starting a connection with the jupyter server. https://github.com/executablebooks/thebe/blob/main/packages/core/src/server.ts#L123

agoose77 commented 6 months ago

The latest version of thebe (0.9.x) supports this. I'm going to close this issue for now, though I can imagine we'd want to re-open it if other clients of thebe are unable to upgrade for some reason.