Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add juv venv to support exporting explicit notebook enviroments #80

Merged
merged 2 commits into from
Mar 6, 2025

Conversation

manzt
Copy link
Owner

@manzt manzt commented Mar 6, 2025

Alternative to #62

Some editors and enviroments are missing the benefits from juv standalone notebooks, simply because we don't make it easy to use the specified virutal enviroment outside of spawning a Jupyter runtime with juv run.

While we typically try to hide virtual environments, they remain crucial for ecosystem like language servers, autocomplete, and intellisense, and exposing some way to quickly make a notebok enviroment is the easiest way to bring juv standalone notebooks to unknown tools.

To improve compatibility with more editors and tools, this PR introduces:

juv venv --from=Untitled.ipynb

This command creates a virtual environment with the dependencies and locking behavior expected from juv, and adds ipykernel for running the notebook. The resulting environment can be selected in an editor like VS Code.

To create a venv with only the locked dependencies, add the --no-kernel flag:

juv venv --from=Untitled.ipynb --no-kernel

Alternatives

While editor-specific integrations for juv would be ideal (and still welcome!), they require significant effort. I anticipate there will be opportunities to piggyback on whatever editors do to support uv standalone scripts in the future.

In the meantime, this approach provides a decent escape hatch. I think it's a reasonable tradeoff for individuals that want to use their favorite editor with notebook support and also read/write standalone notebooks.

Note

It's worth noting that these commands are basically sugar for composing some lesser known juv and uv commands:

uv env
juv export Untitled.ipynb | uv pip install -r -

or, when including ipykernel:

uv env
(juv export Untitled.ipynb; echo ipykernel) | uv pip install -r -

However, I think having a simple high-level API is ideal. It also means one does not need to have uv installed (even though they should!)

@manzt manzt added the enhancement New feature or request label Mar 6, 2025
@manzt manzt merged commit 436c7f6 into main Mar 6, 2025
19 checks passed
manzt added a commit that referenced this pull request Mar 6, 2025
@manzt manzt deleted the manzt/venv branch March 6, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant