Sage-Bionetworks / sage-monorepo

Where OpenChallenges, Schematic, and other Sage open source apps are built
https://sage-bionetworks.github.io/sage-monorepo/
Apache License 2.0
21 stars 12 forks source link

[Task] Explore the development of Python notebooks in VS Code #2260

Open tschaffter opened 8 months ago

tschaffter commented 8 months ago

What product(s) is this story for?

Sage Monorepo

As a user, I want

As a Sage Monorepo User, I want to be able to develop Python notebook directly in VS Code, so that I can keep contributing using a single UI.

Description

No response

Acceptance criteria

No response

Tasks

No response

Anything else?

No response

Have you linked this story to a GitHub Project?

tschaffter commented 8 months ago

First exploration

I opened an OC notebook in VS Code and it looks good. Upon executing the first block, I'm invited to install extensions, which could be added to Sage Monorepo dev container if we decide to use them.

image

After selecting a Python interpreter, there is a Python package that needs to be installed.

image

It also looks like VS Code could connect to a Jupyter server, which we already have using Docker.

image

tschaffter commented 8 months ago

I can execute the first block after selecting the Python interpreter returned by nx prepare openchallenges-notebook (see top-right in the screenshot). However, it seems that I need to recreate this interpreter/environment from scratch (delete it then run nx prepare ...) whenever I update the API client (openchallenges-api-client-python). We can do better!

image
tschaffter commented 8 months ago

Build OC API client

The build folder is generated in the client project folder (libs/openchallenges/api-client-python) when running nx prepare openchallenges-notebook. I should probably add a build command to the client project to regenerate the build folder after the client is updated (e.g. after updating the API description).

image
tschaffter commented 8 months ago

Slow detection of Python kernel

JupyterLab logs:

Visual Studio Code (1.83.1, dev-container, desktop)
Jupyter Extension Version: 2023.9.1102792234.
Python Extension Version: 2023.18.0.
Platform: linux (x64).
Workspace folder /workspaces/sage-monorepo, Home = /home/vscode
16:46:56.433 [info] User belongs to experiment group 'NewJupyterSession'
16:46:57.344 [info] Start refreshing Kernel Picker (1698770817344)
16:46:57.362 [info] Using Pylance
16:46:59.649 [info] Process Execution: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python -m pip list
16:47:00.011 [info] End refreshing Kernel Picker (1698770817344)
16:55:57.781 [info] Start refreshing Interpreter Kernel Picker
16:55:57.781 [info] Start refreshing Kernel Picker (1698771357781)
16:55:57.897 [info] Starting Kernel startUsingPythonInterpreter, .jvsc74a57bd0d21d50ec23609e73fcd97cf736f2753ab831c4c019c54aac7b21be8162f74855./workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/python./workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/python.-m#ipykernel_launcher  (Python Path: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python, Poetry, .venv, 3.10.12) for '/workspaces/sage-monorepo/apps/openchallenges/notebook/notebooks/openai-challenge-headline.ipynb' (disableUI=true)
16:55:57.938 [info] Process Execution: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python -m pip list
16:55:58.142 [info] Process Execution: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)"
16:55:58.617 [info] Process Execution: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python -m ipykernel_launcher --ip=127.0.0.1 --stdin=9003 --control=9001 --hb=9000 --Session.signature_scheme="hmac-sha256" --Session.key=b"b54f996a-94cf-4b8d-b23d-ab1797d92e36" --shell=9002 --transport="tcp" --iopub=9004 --f=~/.local/share/jupyter/runtime/kernel-v2-9570v1NpyLFdUXe.json
    > cwd: /workspaces/sage-monorepo/apps/openchallenges/notebook/notebooks
16:55:58.842 [info] ipykernel version & path 6.25.2, /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/lib/python3.10/site-packages/ipykernel/__init__.py for /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python
16:56:00.518 [info] Process Execution: /workspaces/sage-monorepo/apps/openchallenges/notebook/.venv/bin/python ~/.<username>-server/extensions/ms-toolsai.jupyter-2023.9.1102792234-linux-x64/pythonFiles/printJupyterDataDir.py
16:56:01.160 [info] End refreshing Kernel Picker (1698771357781)