Skip to content

Commit

Permalink
fix(wheels): use extism_sys binary distribution wheels (#5)
Browse files Browse the repository at this point in the history
Make use of pre-built extism_sys wheels built from `extism/extism` using
maturin. The default configuration uses the latest release from extism
to pull down the wheels -- this ensures we turn up breaking changes
early.

Future work: add a release workflow. The release workflow should pull
the specific latest tag (e.g., 0.5.2) from `extism/extism`, update
pyproject.toml and the lock file, then release the `extism` package on
PyPI.

Fixes #4.
  • Loading branch information
chrisdickinson authored Sep 29, 2023
1 parent 7b2e49e commit df61134
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 107 deletions.
18 changes: 1 addition & 17 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
rust:
- stable
steps:
Expand All @@ -31,22 +31,6 @@ jobs:

- run: poetry install

- name: download extism development release
run: |
set -eou pipefail
arch="$(<<<'${{ runner.arch }}' sed -e 's/ARM64/aarch64/g')"
arch="${arch/X64/x86_64}"
os="$(<<<'${{ runner.os }}' tr '[:upper:]' '[:lower:]')"
os="${os/macos/darwin}"
echo "attempting to download 'libextism-${arch}-${os}-*.tar.gz'"
gh release -R extism/extism download latest -p "libextism-${arch}-*${os}-*.tar.gz"
tar zxfv *.tar.gz
sudo mv libextism.* /usr/local/lib/
sudo mv extism.h /usr/local/include/
env:
GH_TOKEN: ${{ github.token }}

- name: Run Python lint
run: |
just lint
Expand Down
19 changes: 7 additions & 12 deletions extism/extism.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@
from typing import Union
from enum import Enum
from uuid import UUID
from .utils import _locate, Error

# Initialize the C library
_ffi = FFI()
_header, _lib = _locate()
with open(_header) as f:
lines = []
for line in f.readlines():
if line[0] != "#":
lines.append(line)
_ffi.cdef("".join(lines))
_lib = _ffi.dlopen(_lib)
from extism_sys import lib as _lib, ffi as _ffi


class Error(Exception):
"""Extism error type"""

pass


class _Base64Encoder(json.JSONEncoder):
Expand Down
61 changes: 0 additions & 61 deletions extism/utils.py

This file was deleted.

29 changes: 14 additions & 15 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
export PATH := env_var("PATH") + ":" + env_var("HOME") + "/.local/bin"
export PATH := env_var("PATH") + ":" + env_var_or_default("HOME", env_var_or_default("APPDATA", "")) + "/.local/bin"

help:
just --list
# Make just arguments available as env vars; useful for preserving
# quotes.
set export

_help:
@just --list

prepare:
#!/bin/bash
if ! &>/dev/null which poetry; then
curl -sSL https://install.python-poetry.org | sed -e 's|symlinks=False|symlinks=True|' | python3 -
fi

if ! &>/dev/null poetry env list; then
poetry install
fi

# check for presence of the extism shared library and headers, installing
# then if necessary
if ! &>/dev/null poetry run python3 -m extism.utils; then
if ! &>/dev/null which extism; then
pip3 install git+https://github.com/extism/cli
fi

extism install git
envs="$(poetry env list || true)"
if [ ! $? ] || [ -z "$envs" ]; then
poetry install --no-cache
fi

test: prepare
poetry run python -m unittest discover

poetry *args: prepare
#!/bin/bash
poetry $args

clean:
rm -rf dist/*

Expand Down
87 changes: 86 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.7"
cffi = "^1.10.0"
extism-sys = [
{platform = "darwin", markers="sys_platform == 'darwin' and platform_machine!='x86_64'", url = "https://github.com/extism/extism/releases/download/latest/extism_sys-0.0.0.dev0-py3-none-macosx_11_0_arm64.whl"},
{platform = "darwin", markers="sys_platform == 'darwin' and platform_machine=='x86_64'", url = "https://github.com/extism/extism/releases/download/latest/extism_sys-0.0.0.dev0-py3-none-macosx_10_7_x86_64.whl"},
{platform = "linux", markers="sys_platform == 'linux' and platform_machine!='x86_64'", url = "https://github.com/extism/extism/releases/download/latest/extism_sys-0.0.0.dev0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl"},
{platform = "linux", markers="sys_platform == 'linux' and platform_machine=='x86_64'", url = "https://github.com/extism/extism/releases/download/latest/extism_sys-0.0.0.dev0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"},
{platform = "win32", markers="sys_platform == 'win32'", url = "https://github.com/extism/extism/releases/download/latest/extism_sys-0.0.0.dev0-py3-none-win_amd64.whl"},
]

[tool.poetry.dev-dependencies]
black = "^23.1.0"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extism.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_extism_plugin_timeout(self):
end = datetime.now()
self.assertLess(
end,
start + timedelta(seconds=1.01),
start + timedelta(seconds=1.1),
"plugin timeout exceeded 1000ms expectation",
)

Expand Down

0 comments on commit df61134

Please sign in to comment.