0

I am currently working on a JupyterLab extension, and I have been getting through the whole official documentation for days now. I want to make an extension that watches specific files for changes in JupyterLab's scope. For example, let's say my JupyterLab scope is /home/me/lab/ which then identifies as / in JupyterLab's tree view.

I should be somehow able to watch the state of, let's say, the /lib/index.js (which on my computer should be located at /home/me/lab/lib/index.js), but I cannot find how to do it.

I tried several solutions already:

  • using fs.watch, but it does not work in browser apps such as Jupyter so that's a no.

  • using the ContentsManager from @jupyterlab/services but I can only watch for changes saved by the ContentsManager instance that I create. I also tried to get the main one but in vain. I don't even know if it exists. Anyway, I would only be able to listen for changes made by the user in JupyterLab, while I would like to watch for any change on the watched files.

  • ChatGPT also told me about ChokidarSocketEmitter but this requires to have a watching service alongside the jupyter service, which I would like to avoid.

I want to know if there is something that exists and that would probably be more efficient than me "making a watchdog based on a repeated timer with a callback to fetch the file(s) every 0.5s or so and manually check for changes".

Does anybody have any clue/guidance to give me?

  • Did you see [Performing file accessing and modifying actions in jupyterlab extension](https://discourse.jupyter.org/t/performing-file-accessing-and-modifying-actions-in-jupyterlab-extension/10925/3?u=fomightez) or [here](https://discourse.jupyter.org/t/get-current-open-file-content/18630/2?u=fomightez)? Or maybe see how extension [here](https://discourse.jupyter.org/t/jupyter-not-finding-folders/1116/20?u=fomightez) accesses files? [Here](https://discourse.jupyter.org/t/automatically-refresh-notebook-on-changes/16912/4?u=fomightez) says, ... – Wayne May 14 '23 at 00:20
  • "The notebook server doesn’t watch the filesystem for changes...So a lot would have to be implemented (by an extension)." However, that was for Jupyter Notebook server, I believe and not JupyterLab. [This now-old post](https://discourse.jupyter.org/t/extension-development-how-to-save-a-file-to-some-absolute-path/8889/3?u=fomightez) makes me think maybe the code for `jupyterlab-starters` (or [jupyterlab_templates](https://github.com/timkpaine/jupyterlab_templates#templates-for-libraries)) could provide guidance in dealing with files in JupyterLab? – Wayne May 14 '23 at 00:27
  • 1
    @Wayne I have in fact checked the first link, that's what I meant by me going through the whole documentation. I know that I can access the files and watch for some of the actions done in the jupyter UI but not if the file has been changed by another program. Your last link confirms that I will probably need to do a watchdog by myself. Thanks for this. – Diamondemon May 14 '23 at 00:33

0 Answers0