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 3e7e0e8
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

env:
pixi-version: "0.23.0"
pixi-version: "0.26.1"

jobs:
test:
Expand All @@ -17,7 +17,7 @@ jobs:
# https://github.com/ipython/ipykernel/issues/713
# https://stackoverflow.com/questions/70841648/jupyter-reverts-signal-handler-to-default-when-running-next-cell
os: [ubuntu-latest, macos-latest]
pixi-version: ["0.18.0", "0.23.0"]
pixi-version: ["0.18.0", "0.25.0", "0.26.1"]
python-version: ["38", "39", "310", "311", "312"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pixi-kernel"
version = "0.3.0"
version = "0.3.1"
description = "Jupyter kernels using Pixi for reproducible notebooks"
authors = ["Renan Rodrigues dos Santos <renan.engmec@gmail.com>"]
channels = ["conda-forge"]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "pixi-kernel"
version = "0.3.0"
version = "0.3.1"
description = "Jupyter kernels using Pixi for reproducible notebooks"
license = { text = "MIT" }
authors = [
Expand Down
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 3e7e0e8

Please sign in to comment.