Skip to content

WayScience/demo-vs-code-notebook-root

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-vs-code-notebook-root

This repository demonstrates how to set a notebook root for VS Code through a repository.

VS Code Jupyter notebooks will by default treat their local directory as the root. This creates challenges when attempting to load local data or code within the notebook because the kernal and Python won't have visibility of those files without customization. A common workaround is to use sys.path manipulation to add paths. This leads to an anti-pattern of extra code in all notebooks where you must use outside-of-local-path files.

This repository demonstrates how to use a simple file and related configuration found within .vscode/settings.json to configure VS Code Jupyter notebooks so that they use the root of the repository as their root. This enables notebooks to open and automatically use the root of the repository as their root and avoids the addition of sys.path manipulation within each notebook.

installation

This work requires uv to install the environment. Any environment manager can be used to reproduce the results (uv was just used to build a quick example).

  1. Run uv sync to synchronize the uv environment locally.
  2. Explore the local Python package cow and module say to better understand how they're structured in context with the notebook found within src/notebooks/.
  3. Open the notebook under src/notebooks/example.ipynb within VS Code.
  4. Within the VS Code notebook window, select kernal: demo-vs-code-notebook-root found under .venv/bin/python.
  5. Run the notebook to reproduce the local pathing result.

About

Demonstrating how to set a notebook root for vs code through a repository.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published