Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Xeus python build addon #10

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 130 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
pull_request:
branches: '*'

defaults:
run:
shell: bash -l {0}

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -64,14 +68,14 @@ jobs:

pip install build
python -m build --sdist
cp dist/*.tar.gz myextension.tar.gz
pip uninstall -y myextension jupyterlab
rm -rf myextension
cp dist/*.tar.gz jupyterlite-xeus-python.tar.gz
pip uninstall -y jupyterlite-xeus-python jupyterlab
rm -rf jupyterlite-xeus-python

- uses: actions/upload-artifact@v2
with:
name: myextension-sdist
path: myextension.tar.gz
name: jupyterlite-xeus-python-sdist
path: jupyterlite-xeus-python.tar.gz

test_isolated:
needs: build
Expand All @@ -87,16 +91,135 @@ jobs:
architecture: 'x64'
- uses: actions/download-artifact@v2
with:
name: myextension-sdist
name: jupyterlite-xeus-python-sdist
- name: Install and Test
run: |
set -eux
# Remove NodeJS, twice to take care of system and locally installed node versions.
sudo rm -rf $(which node)
sudo rm -rf $(which node)
pip install myextension.tar.gz
pip install jupyterlite-xeus-python.tar.gz
pip install jupyterlab
jupyter labextension list 2>&1 | grep -ie "@jupyterlite/xeus-python-kernel.*OK"

# TODO: add JupyterLite browser check
# python -m jupyterlab.browser_check --no-chrome-test

python-tests-mamba-python:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: jupyterlite-xeus-python-sdist

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"
mamba-version: "*"

- name: Make sure the Mamba Python API is available
run: |
mamba install mamba
python -c "from mamba.api import create"

- name: Install
run: |
emsdk install 3.1.2
emsdk activate 3.1.2
pip install jupyterlite-xeus-python.tar.gz

- name: Run tests
run: pytest -rP tests/test_xeus_python_env.py

python-tests-mamba:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: jupyterlite-xeus-python-sdist

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"
mamba-version: "*"

- name: Install
run: |
emsdk install 3.1.2
emsdk activate 3.1.2
pip install jupyterlite-xeus-python.tar.gz

- name: Run tests
run: pytest -rP tests/test_xeus_python_env.py

python-tests-micromamba:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: jupyterlite-xeus-python-sdist

- name: Install mamba
uses: mamba-org/provision-with-micromamba@main
with:
micromamba-version: "0.22.0"
environment-file: environment.yml
environment-name: xeus-python-kernel

- name: Install
run: |
emsdk install 3.1.2
emsdk activate 3.1.2
pip install jupyterlite-xeus-python.tar.gz

- name: Run tests
run: pytest -rP tests/test_xeus_python_env.py

python-tests-conda:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- uses: actions/download-artifact@v2
with:
name: jupyterlite-xeus-python-sdist

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: xeus-python-kernel
environment-file: environment.yml
python-version: "3.10"

- name: Install
run: |
emsdk install 3.1.2
emsdk activate 3.1.2
pip install jupyterlite-xeus-python.tar.gz

- name: Run tests
run: pytest -rP tests/test_xeus_python_env.py
29 changes: 11 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
# TODO Try to combine micromamba and emsdk
# FROM emscripten/emsdk:2.0.32
FROM mambaorg/micromamba:0.22.0
FROM mambaorg/micromamba:0.23.1

ARG MAMBA_DOCKERFILE_ACTIVATE=1
ARG PYTHON_VERSION=3.10

RUN micromamba install --yes -c https://repo.mamba.pm/conda-forge \
git pip python=$PYTHON_VERSION click typer
RUN micromamba install --yes -c conda-forge \
git pip python=$PYTHON_VERSION click typer emsdk

##################################################################
# Install emboa
# Install empack
##################################################################

RUN pip install git+https://github.com/emscripten-forge/emboa
RUN pip install empack

##################################################################
# Setup emsdk
##################################################################

RUN git clone https://github.com/emscripten-core/emsdk.git && \
pushd emsdk && \
./emsdk install 3.1.2 && \
popd
RUN emsdk install 3.1.2 && emsdk activate 3.1.2

##################################################################
# Create emscripten env and pack it
##################################################################

RUN micromamba create -n xeus-python-kernel \
--platform=emscripten-32 \
--root-prefix=/tmp/xeus-python-kernel \
-c https://repo.mamba.pm/emscripten-forge \
-c https://repo.mamba.pm/conda-forge \
--yes \
python=$PYTHON_VERSION xeus-python \
numpy matplotlib
python=$PYTHON_VERSION xeus-python

RUN mkdir -p xeus-python-kernel && cd xeus-python-kernel && \
export FILE_PACKAGER=/tmp/emsdk/upstream/emscripten/tools/file_packager.py && \
/tmp/emsdk/emsdk activate 3.1.2 3.1.2 && \
cp $MAMBA_ROOT_PREFIX/envs/xeus-python-kernel/bin/xpython_wasm.js . && \
cp $MAMBA_ROOT_PREFIX/envs/xeus-python-kernel/bin/xpython_wasm.wasm . && \
emboa pack python core $MAMBA_ROOT_PREFIX/envs/xeus-python-kernel --version=$PYTHON_VERSION
cp /tmp/xeus-python-kernel/envs/xeus-python-kernel/bin/xpython_wasm.js . && \
cp /tmp/xeus-python-kernel/envs/xeus-python-kernel/bin/xpython_wasm.wasm . && \
empack pack python core /tmp/xeus-python-kernel/envs/xeus-python-kernel --version=$PYTHON_VERSION

COPY copy_output.sh .

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
include LICENSE
include *.md
include *.yml
include pyproject.toml
include package.json
include install.json
include ts*.json
include yarn.lock
include webpack.config.js
recursive-include tests *.py

graft jupyterlite_xeus_python/labextension

Expand Down
11 changes: 11 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: xeus-python-kernel
channels:
- conda-forge
dependencies:
- python
- pip
- pytest
- emsdk
- pip:
- jupyterlite
- empack
6 changes: 1 addition & 5 deletions jupyterlite_xeus_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import json
from pathlib import Path

Expand All @@ -11,7 +10,4 @@


def _jupyter_labextension_paths():
return [{
"src": "labextension",
"dest": data["name"]
}]
return [{"src": "labextension", "dest": data["name"]}]
2 changes: 2 additions & 0 deletions jupyterlite_xeus_python/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

__all__ = ["__version__"]


def _fetchVersion():
HERE = Path(__file__).parent.resolve()

Expand All @@ -20,4 +21,5 @@ def _fetchVersion():

raise FileNotFoundError(f"Could not find package.json under dir {HERE!s}")


__version__ = _fetchVersion()
Loading