Skip to content

Commit

Permalink
fix: update R kernel logic for Pixi >= 0.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
renan-r-santos committed Jul 25, 2024
1 parent 0a2bc28 commit 2ca7a18
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/pixi_kernel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ipykernel.ipkernel import IPythonKernel
from ipykernel.kernelapp import IPKernelApp

from .pixi import PixiDiscoveryError, find_project_manifest
from .pixi import PixiDiscoveryError, find_pixi_version, find_project_manifest

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,6 +43,7 @@ def main() -> None:
kernel_display_name = sys.argv[2]

try:
pixi_version = find_pixi_version(kernel_display_name)
manifest_path = find_project_manifest(
cwd=Path.cwd(),
package_name=package_name,
Expand All @@ -63,6 +64,10 @@ def main() -> None:
env["R_LIBS_SITE"] = r_libs_path
env["R_LIBS_USER"] = r_libs_path

if pixi_version >= (0, 26, 0):
# Remove single quotes from R kernel spec arguments: https://github.com/prefix-dev/pixi/pull/1582
args = [arg.replace("'", "") for arg in args]

logger.info(f"launching {kernel_display_name} kernel with {args}")

if sys.platform == "win32":
Expand Down
7 changes: 5 additions & 2 deletions src/pixi_kernel/pixi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import shutil
import subprocess
from pathlib import Path
from typing import List, Optional
from typing import List, Optional, Tuple

import msgspec

Expand Down Expand Up @@ -40,7 +40,7 @@ class ProjectInfo(msgspec.Struct, frozen=True, kw_only=True):
manifest_path: str


def find_project_manifest(*, cwd: Path, package_name: str, kernel_display_name: str) -> Path:
def find_pixi_version(kernel_display_name: str) -> Tuple[str, str, str]:
# Ensure Pixi is in PATH
if shutil.which("pixi") is None:
raise PixiDiscoveryError(PIXI_NOT_FOUND.format(kernel_display_name=kernel_display_name))
Expand All @@ -63,7 +63,10 @@ def find_project_manifest(*, cwd: Path, package_name: str, kernel_display_name:
)
)
logger.info(f"found Pixi {pixi_version}")
return (major, minor, patch)


def find_project_manifest(*, cwd: Path, package_name: str, kernel_display_name: str) -> Path:
# Find project's manifest file
candidate_dirs = [cwd, *cwd.parents]
for dir in candidate_dirs:
Expand Down

0 comments on commit 2ca7a18

Please sign in to comment.