Skip to content

Commit

Permalink
feature/bundle kernel package (#302)
Browse files Browse the repository at this point in the history
* Copy the Streamlit wheel to stlite-kernel/dist

* Add wheel files to the package of @stlite/stlite-kernel

* Create a phony make target stlite-kernel

* Add build-stlite-kernel CI job

* Add streamilt_wheel to the dep list of stlite_kernel

* Add streamlit_proto to the deps of streamlit_wheel
  • Loading branch information
whitphx authored Oct 1, 2022
1 parent 16a3295 commit 19dad24
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 6 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,97 @@ jobs:
- run: yarn typecheck
- run: yarn test

build-stlite-kernel:
if: ${{ ! failure() }} # This job should run even if the depending jobs are skipped, but not when those jobs failed: https://qiita.com/abetomo/items/d9ede7dbeeb24f723fc5#%E8%A8%AD%E5%AE%9A%E4%BE%8B4
needs: [test-stlite-kernel, test-tornado-e2e]

env:
python-version: "3.10.2"
node-version: "16.x"
# To avoid an error like "FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory".
# See https://github.com/actions/virtual-environments/issues/70#issuecomment-653886422
# The Linux VM has 7GB RAM (https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources),
# so we set the max memory size as 6.5 GiB like https://nodejs.org/api/cli.html#--max-old-space-sizesize-in-megabytes
NODE_OPTIONS: "--max-old-space-size=6656"

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

## Set up Python and Poetry environment
- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ env.python-version }}

# Ref: https://github.com/python-poetry/poetry/blob/f51a2c7427a046bcb71434e8ff29f6ce137301f7/.github/workflows/main.yml#L51-L79
- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Bootstrap poetry
run: |
curl -sL https://install.python-poetry.org | python - -y
- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v3
id: cache
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Ensure cache is healthy
if: steps.cache.outputs.cache-hit == 'true'
run: timeout 10s pip --version || rm -rf .venv

## Set up Node environment
- name: Use Node.js ${{ env.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'
scope: '@stlite'

## Set up apt packages. Ref: https://github.com/streamlit/streamlit/wiki/Contributing#ubuntu
- name: Install Streamlit build dependencies
run: sudo apt install protobuf-compiler

- name: Set up
run: make init

## Build and deploy @stlite/mountable
# PUBLIC_URL here is set as a relative path, which is possible to the trick introduced at https://github.com/whitphx/stlite/pull/143.
- name: Set PUBLIC_URL
run: echo "PUBLIC_URL=." >> $GITHUB_ENV
- name: Build @stlite/stlite-kernel
run: make stlite-kernel

- name: Package
working-directory: packages/stlite-kernel
run: yarn pack

- name: Upload the built tar ball as an artifact
uses: actions/upload-artifact@v2
if: ${{ ! startsWith(github.ref, 'refs/tags/v') }}
with:
path: packages/stlite-kernel/stlite-stlite-kernel-v*.tgz
name: stlite-stlite-kernel-${{ github.sha }}.tgz

- name: Upload the built tar ball as an artifact (when pushed with a version tag)
uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
path: packages/stlite-kernel/stlite-stlite-kernel-v*.tgz
name: stlite-stlite-kernel-${{ github.ref_name }}.tgz

build-mountable:
if: ${{ ! failure() }} # This job should run even if the depending jobs are skipped, but not when those jobs failed: https://qiita.com/abetomo/items/d9ede7dbeeb24f723fc5#%E8%A8%AD%E5%AE%9A%E4%BE%8B4
needs: [test-stlite-kernel, test-tornado-e2e, test-mountable]
Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stlite_kernel := packages/stlite-kernel/dist/*
pyarrow_wheel := packages/stlite-kernel/py/stlite-pyarrow/dist/stlite_pyarrow-0.1.0-py3-none-any.whl
tornado_wheel := packages/stlite-kernel/py/tornado/dist/tornado-6.2-py3-none-any.whl
streamlit_proto := streamlit/frontend/src/autogen
streamlit_wheel := streamlit/lib/dist/streamlit-1.12.0-py2.py3-none-any.whl
streamlit_wheel := packages/stlite-kernel/py/streamlit/lib/dist/streamlit-1.12.0-py2.py3-none-any.whl

.PHONY: all
all: init mountable playground sharing sharing-editor
Expand Down Expand Up @@ -76,7 +76,9 @@ $(playground): packages/playground/src/*.ts packages/playground/src/*.tsx packag
yarn build
@touch $@

$(stlite_kernel): packages/stlite-kernel/src/*.ts $(pyarrow_wheel) $(tornado_wheel) $(streamlit_proto)
.PHONY: stlite-kernel
stlite-kernel: $(stlite_kernel)
$(stlite_kernel): packages/stlite-kernel/src/*.ts $(pyarrow_wheel) $(tornado_wheel) $(streamlit_wheel) $(streamlit_proto)
cd packages/stlite-kernel; \
yarn build
@touch $@
Expand All @@ -98,11 +100,12 @@ $(streamlit_proto): $(VENV) streamlit/proto/streamlit/proto/*.proto
$(MAKE) mini-init
@touch $@

$(streamlit_wheel): $(VENV) streamlit/lib/streamlit/**/*.py streamlit/lib/Pipfile streamlit/lib/setup.py streamlit/lib/bin/* streamlit/lib/MANIFEST.in
$(streamlit_wheel): $(VENV) $(streamlit_proto) streamlit/lib/streamlit/**/*.py streamlit/lib/Pipfile streamlit/lib/setup.py streamlit/lib/bin/* streamlit/lib/MANIFEST.in
. $(VENV)/bin/activate && \
cd streamlit && \
make distribution
@touch $@
mkdir -p `dirname $(streamlit_wheel)`
cp streamlit/lib/dist/streamlit-1.12.0-py2.py3-none-any.whl $(streamlit_wheel)


.PHONY: serve
Expand Down
3 changes: 2 additions & 1 deletion packages/stlite-kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"private": true,
"main": "dist/index.js",
"files": [
"dist/"
"dist/",
"py/**/*.whl"
],
"scripts": {
"start": "tsc -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/stlite-kernel/src/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { makeAbsoluteWheelURL } from "./url";
// https://pyodide.org/en/stable/project/changelog.html#micropip
import TORNADO_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/tornado/dist/tornado-6.2-py3-none-any.whl"; // TODO: Extract the import statement to an auto-generated file like `_pypi.ts` in JupyterLite: https://github.com/jupyterlite/jupyterlite/blob/f2ecc9cf7189cb19722bec2f0fc7ff5dfd233d47/packages/pyolite-kernel/src/_pypi.ts
import PYARROW_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/stlite-pyarrow/dist/stlite_pyarrow-0.1.0-py3-none-any.whl";
import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../../../streamlit/lib/dist/streamlit-1.12.0-py2.py3-none-any.whl";
import STREAMLIT_WHEEL from "!!file-loader?name=pypi/[name].[ext]&context=.!../py/streamlit/lib/dist/streamlit-1.12.0-py2.py3-none-any.whl";

import Worker from "!!worker-loader?inline=no-fallback!./worker";

Expand Down

0 comments on commit 19dad24

Please sign in to comment.