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 experimental VS Code (code) runtime to juv run #62

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/juv/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run( # noqa: PLR0913
if mode == "dry":
print(f"uv {' '.join(args)}") # noqa: T201

elif mode == "managed":
elif mode == "managed" and runtime.name != "code":
from ._run_managed import run as run_managed

run_managed(script, args, str(path))
Expand Down
23 changes: 19 additions & 4 deletions src/juv/_run_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
if typing.TYPE_CHECKING:
import pathlib

RuntimeName = typing.Literal["notebook", "lab", "nbclassic"]
RuntimeName = typing.Literal["notebook", "lab", "nbclassic", "code"]


def is_notebook_kind(kind: str) -> typing.TypeGuard[RuntimeName]:
return kind in {"notebook", "lab", "nbclassic"}
return kind in {"notebook", "lab", "nbclassic", "code"}


@dataclass
Expand Down Expand Up @@ -45,12 +45,19 @@ def script_template(self) -> str:
return NOTEBOOK
if self.name == "nbclassic":
return NBCLASSIC
if self.name == "code":
return VSCODE
msg = f"Invalid self: {self.name}"
raise ValueError(msg)

def as_with_arg(self) -> str:
# lab is actually jupyterlab
with_ = "jupyterlab" if self.name == "lab" else self.name
with_ = {
"lab": "jupyterlab",
"notebook": "notebook",
"nbclassic": "nbclassic",
# vscode needs ipykernel to be in the environment
"code": "ipykernel",
}[self.name]

# append version if present
if self.version:
Expand Down Expand Up @@ -200,6 +207,14 @@ def handle_termination(signum, frame):
main()
"""

VSCODE = """
{meta}
import subprocess
import os

subprocess.run(["code", r"{notebook}"], check=True, env=os.environ)
"""


def prepare_run_script_and_uv_run_args( # noqa: PLR0913
*,
Expand Down
Loading