Skip to content

Commit bef48e7

Browse files
Make sure the kernel spec uses the path to Pixi (#66)
* Make sure the kernel spec uses the path to Pixi Cache the Pixi path after a successful call to has_compatible_pixi * Bump version to 0.6.6 * Use Optional instead of | for Python 3.9 * Clear cache before each test
1 parent b768a44 commit bef48e7

File tree

7 files changed

+86
-16
lines changed

7 files changed

+86
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pixi-kernel",
3-
"version": "0.6.5",
3+
"version": "0.6.6",
44
"description": "Jupyter kernels using Pixi for reproducible notebooks.",
55
"keywords": [
66
"kernel",

pixi_kernel/compatibility.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import shutil
22
import sys
33
from pathlib import Path
4-
from typing import Any
4+
from typing import Any, Optional
55

66
from returns.result import Failure, Result, Success
77

@@ -43,6 +43,10 @@
4343
"""
4444

4545

46+
# Cache for the Pixi path
47+
_pixi_path_cache: Optional[str] = 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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pixi-kernel"
3-
version = "0.6.5"
3+
version = "0.6.6"
44
description = "Jupyter kernels using Pixi for reproducible notebooks"
55
license = { text = "MIT" }
66
authors = [

tests/unit/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def event_loop_policy(request: pytest.FixtureRequest):
2121
return request.param
2222

2323

24+
@pytest.fixture(autouse=True)
25+
def _clear_pixi_path_cache():
26+
pixi_kernel.compatibility._pixi_path_cache = None
27+
28+
2429
@pytest.fixture
2530
def _patch_find_pixi_binary(monkeypatch: pytest.MonkeyPatch):
2631
monkeypatch.setattr(pixi_kernel.compatibility, "find_pixi_binary", lambda: Failure(None))

uv.lock

Lines changed: 54 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,11 +1724,11 @@ __metadata:
17241724
linkType: hard
17251725

17261726
"@types/react@npm:*":
1727-
version: 19.1.8
1728-
resolution: "@types/react@npm:19.1.8"
1727+
version: 19.1.9
1728+
resolution: "@types/react@npm:19.1.9"
17291729
dependencies:
17301730
csstype: ^3.0.2
1731-
checksum: 17e0c74d9c01214938fa805aaa8b97925bf3c5514e88fdf94bec42c0a6d4abbc63d4e30255db176f46fd7f0aa89f8085b9b2b2fa5abaffbbf7e5009386ada892
1731+
checksum: 531b1f40e7f93aade4385a56b73e98846ec482ac695ccb0d4da1fc53fa398564f71383cd120cf8b8a9a1ea95f207c3e042d145fa8bc26e4fa57d863459e53b29
17321732
languageName: node
17331733
linkType: hard
17341734

@@ -2386,9 +2386,9 @@ __metadata:
23862386
linkType: hard
23872387

23882388
"caniuse-lite@npm:^1.0.30001726":
2389-
version: 1.0.30001727
2390-
resolution: "caniuse-lite@npm:1.0.30001727"
2391-
checksum: 2bc6112f242701198a99c17713d4409be9b404d09005f34f351ec29a4ea46c054e7aa4982bc16f06b81b7a375cbc61c937e89650170cbce84db772a376ed3963
2389+
version: 1.0.30001731
2390+
resolution: "caniuse-lite@npm:1.0.30001731"
2391+
checksum: ecd2ad779f31011bef657c0104a08a780d9bb38ff8ad7aeeeaf196151be22c492de87f4a9c89a30ea4aa9575c5a39c85bf6bd56e89a4bf8259f54a4fbfc24a0d
23922392
languageName: node
23932393
linkType: hard
23942394

0 commit comments

Comments
 (0)