Skip to content

Commit c26e6bb

Browse files
Make sure the kernel spec uses the path to Pixi
Cache the Pixi path after a successful call to has_compatible_pixi
1 parent b768a44 commit c26e6bb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

pixi_kernel/compatibility.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
"""
4444

4545

46+
# Cache for the Pixi path
47+
_pixi_path_cache: str | None = None
48+
49+
4650
def get_config_file() -> Path:
4751
return Path.home() / ".config" / "pixi-kernel" / "config.toml"
4852

@@ -55,6 +59,10 @@ def get_default_pixi_path() -> Path:
5559

5660

5761
def find_pixi_binary() -> Result[str, None]:
62+
# Return cached result if available
63+
if _pixi_path_cache is not None:
64+
return Success(_pixi_path_cache)
65+
5866
# 1. Check if the Pixi binary is available in the system PATH
5967
pixi_path = shutil.which("pixi")
6068
if pixi_path is not None:
@@ -82,6 +90,11 @@ def find_pixi_binary() -> Result[str, None]:
8290

8391

8492
async def has_compatible_pixi() -> Result[None, str]:
93+
global _pixi_path_cache
94+
95+
if _pixi_path_cache is not None:
96+
return Success(None)
97+
8598
result = find_pixi_binary()
8699

87100
if isinstance(result, Failure):
@@ -100,6 +113,8 @@ async def has_compatible_pixi() -> Result[None, str]:
100113
minimum_version = ".".join(map(str, MINIMUM_PIXI_VERSION))
101114
return Failure(PIXI_OUTDATED.format(minimum_version=minimum_version))
102115

116+
# We found a compatible Pixi binary, cache it
117+
_pixi_path_cache = pixi_path
103118
return Success(None)
104119

105120

pixi_kernel/provisioner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from jupyter_client.provisioning.local_provisioner import LocalProvisioner
99
from returns.result import Failure
1010

11+
from .compatibility import find_pixi_binary
1112
from .readiness import verify_env_readiness
1213

1314

@@ -80,8 +81,9 @@ async def pre_launch(self, **kwargs: Any) -> dict[str, Any]:
8081
pixi_environment = result.unwrap()
8182

8283
# Update kernel spec command line arguments: `argv[:2] = ["pixi", "run"]`
84+
pixi_path = find_pixi_binary().unwrap()
8385
argv = kernel_spec.argv
84-
kernel_spec.argv = [*argv[:2], "--environment", environment_name, *argv[2:]]
86+
kernel_spec.argv = [pixi_path, argv[1], "--environment", environment_name, *argv[2:]]
8587

8688
# R kernel needs special treatment
8789
# https://github.com/renan-r-santos/pixi-kernel/issues/15

0 commit comments

Comments
 (0)