kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.
MIT License
520 stars 15 forks source link

Troubles to use jupynium from a remot machine #82

Closed MathisClautrier closed 1 year ago

MathisClautrier commented 1 year ago

Hi,

Thanks for releasing jupynium,

I am trying to install jupynium for using it from a remote machine. Specifically, I would like to render the notebook from firefox in an interface machine (machine A) while running the kernel and nvim in a remote machine (machine B). To do so I am using the command-line usage of jupynium as suggested. While I can launch jupynium correctly (I see a jupynium widget in nvim saying that it is set and firefox opens a geckodriver window on my notebook dir), if I run :JupyniumStartSync it crashes due to window undefined in selenium (error messages paste below)

To Reproduce Steps to reproduce the behavior:

  1. From machine A : ssh -X machine B
  2. Launch jupyter notebook from the same dir as *.ju.py files
  3. Run nvim file.ju.py and get nvim address with :echo v:servername
  4. Launch jupynium : jupynium --nvim_listen_addr /tmp/your_socket_path --notebook_URL notebook_URL where notebook_URL is _http://machine_b_name:port_number/_
  5. Run :JupyniumStartSync in nvim

Expected behavior At step 4 jupynium should launch firefox as expected but at step 5 it will crash with the following error message:

jupynium.cmds.jupynium: 512 - ERROR - Uncaught exception occurred while processing events. Detaching nvim. Traceback (most recent call last): File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 138, in _w3c_window send_handle(window_name) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 134, in send_handle self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h}) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute self.error_handler.check_response(response) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchWindowException: Message: Unable to locate window: undefined Stacktrace: WebDriverError@chrome://marionette/content/error.js:175:5 NoSuchWindowError@chrome://marionette/content/error.js:409:5 GeckoDriver.prototype.switchToWindow@chrome://marionette/content/driver.js:1602:11 despatch@chrome://marionette/content/server.js:305:40 execute@chrome://marionette/content/server.js:275:16 onPacket/<@chrome://marionette/content/server.js:248:20 onPacket@chrome://marionette/content/server.js:249:9 _onJSONObjectReady/<@chrome://marionette/content/transport.js:501:20 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/cmds/jupynium.py", line 507, in main status, rpcrequest_event = process_events(nvim_info, driver) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 205, in process_events status, request_event = process_request_event(nvim_info, driver, event) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 429, in process_request_event start_sync_with_filename( File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 236, in start_sync_with_filename driver.switch_to.window(nvim_info.home_window) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 130, in window self._w3c_window(window_name) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 144, in _w3c_window send_handle(handle) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 134, in send_handle self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h}) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute self.error_handler.check_response(response) File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchWindowException: Message: Unable to locate window: undefined Stacktrace: WebDriverError@chrome://marionette/content/error.js:175:5 NoSuchWindowError@chrome://marionette/content/error.js:409:5 GeckoDriver.prototype.switchToWindow@chrome://marionette/content/driver.js:1602:11 despatch@chrome://marionette/content/server.js:305:40 execute@chrome://marionette/content/server.js:275:16 onPacket/<@chrome://marionette/content/server.js:248:20 onPacket@chrome://marionette/content/server.js:249:9 _onJSONObjectReady/<@chrome://marionette/content/transport.js:501:20

Output of jupynium --version

Jupynium v0.1.dev1+gaaa0e59

Output of nvim --version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by girolims@ldzls998i

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Despite my efforts to fix this, I couldn't find what I did wrong here, any help would be greatly appreciated thanks!

kiyoon commented 1 year ago

Hi, there's one thing you did it wrong. The socket path is used only for attaching local neovim (unless you share it in a network directory)

So if you opened neovim in a remove directory, you should run it with nvim --listen localhost:12345 file.ju.py and pass jupynium --nvim_listen_addr machine_b_name:12345 .... Instead of socket you'd want to use TCP.

Actually I don't really get the error message. You might be experiencing another issue.

MathisClautrier commented 1 year ago

Hi, thanks for this correction,

From your message I understand that the jupynium command must be launched from machine A. If so is there anything that I need to export? In fact when I run the exact same command that you did above (first nvim on machine B then jupynium on machine A) the jupynium query is failling with the following error message :

jupynium.cmds.jupynium: 440 - ERROR - Exception occurred Traceback (most recent call last): File "/lxhome/clautrim/Desktop/jupyenv/lib64/python3.8/site-packages/jupynium/cmds/jupynium.py", line 438, in main nvim = attach_and_init(args.nvim_listen_addr) File "/lxhome/clautrim/Desktop/jupyenv/lib64/python3.8/site-packages/jupynium/pynvim_helpers.py", line 28, in attach_and_init raise TimeoutError("Timeout while waiting for nvim to start") TimeoutError: Timeout while waiting for nvim to start

Running : jupynium --nvim_listen_addr localhost:12345 ... on machine B works for though

kiyoon commented 1 year ago

@MathisClautrier If your port is not open, you need to port-forward it through SSH. It's the same way you'd use Jupyter Notebook from a remote machine. You just need two ports open (one for nvim, the other for Jupyter Notebook).

You're correct that jupynium command should be launched locally (machine A)

MathisClautrier commented 1 year ago

Thanks @kiyoon, it sounds obvious now that you point it out. For the initial error, it is still occurring as you suggested previously. After checking my setting I think it comes from urllib3 being outdated due to old version of openSSL (I am using urrlib3 1.26.16 with openSSL 1.0.2)

MathisClautrier commented 1 year ago

Hi, my assumption about out-dated OpenSSL was not helpful. I tried to fix this by updating openSSL, but it raises another error about a different signature in selenium. I can see that your requirements.txt suggests openSSL 1.0.2 is supported (urllib3 1.26) so I went back to my previous setting. After playing a bit with jupynium, I found that the error is raised here : https://github.com/kiyoon/jupynium.nvim/blob/master/src/jupynium/events_control.py#L236 The value of nvim_info.home_window is 6. Do you have any idea what can be the issue here?

kiyoon commented 1 year ago

It used to crash because the window was undefined, but now it is 6 and still crashing?

MathisClautrier commented 1 year ago

Hi, sorry for being confusing, it is still crashing by looking for undefined windows when running driver.switch_to.window(nvim_info.home_window). However, logging nvim_info.home_window before this outputs 6.

MathisClautrier commented 1 year ago

Hi, apparently this issue was fixed by downgrading geckodriver to 0.30.0, to cope with my firefox version according to : https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

kiyoon commented 1 year ago

Thanks for letting me know! I'm glad it's finally working