-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
563 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: PHP CI | ||
|
||
on: | ||
push: | ||
branches: [ main 'chris/20230914-python-ci' ] | ||
pull_request: | ||
branches: [ main, 'chris/20230914-python-ci' ] | ||
|
||
jobs: | ||
prepare: | ||
name: Install Extism Runtime | ||
runs-on: ubuntu-latest | ||
steps: | ||
# for now, we lean on php-sdk's download. eventually we should | ||
# split this out | ||
- uses: extism/php-sdk/.github/actions/libextism | ||
python: | ||
name: Python Test | ||
runs-on: ${{ matrix.os }} | ||
needs: prepare | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, macos-latest] | ||
rust: | ||
- stable | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download libextism.so | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: libextism-so-artifact | ||
|
||
- name: Download libextism.h | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: libextism-h-artifact | ||
|
||
- uses: extractions/setup-just@v1 | ||
|
||
- name: Move the files because download can't sudo | ||
run: | | ||
sudo mv libextism.so /usr/local/lib/ | ||
sudo mv extism.h /usr/local/include/ | ||
- name: Run Python tests | ||
run: | | ||
just test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
html | ||
__pycache__ | ||
poetry-installer-error-*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
_search_dirs = ["/usr/local", "/usr", os.path.join(os.getenv("HOME"), ".local"), "."] | ||
|
||
|
||
class Error(Exception): | ||
"""Extism error type""" | ||
|
||
pass | ||
|
||
|
||
def _check_for_header_and_lib(p): | ||
def _exists(a, *b): | ||
return os.path.exists(os.path.join(a, *b)) | ||
|
||
if _exists(p, "extism.h"): | ||
if _exists(p, "libextism.so"): | ||
return os.path.join(p, "extism.h"), os.path.join(p, "libextism.so") | ||
|
||
if _exists(p, "libextism.dylib"): | ||
return os.path.join(p, "extism.h"), os.path.join(p, "libextism.dylib") | ||
|
||
if _exists(p, "include", "extism.h"): | ||
if _exists(p, "lib", "libextism.so"): | ||
return os.path.join(p, "include", "extism.h"), os.path.join( | ||
p, "lib", "libextism.so" | ||
) | ||
|
||
if _exists(p, "lib", "libextism.dylib"): | ||
return os.path.join(p, "include", "extism.h"), os.path.join( | ||
p, "lib", "libextism.dylib" | ||
) | ||
|
||
|
||
def _locate(): | ||
"""Locate extism library and header""" | ||
script_dir = os.path.dirname(__file__) | ||
env = os.getenv("EXTISM_PATH") | ||
if env is not None: | ||
r = _check_for_header_and_lib(env) | ||
if r is not None: | ||
return r | ||
|
||
r = _check_for_header_and_lib(script_dir) | ||
if r is not None: | ||
return r | ||
|
||
r = _check_for_header_and_lib(".") | ||
if r is not None: | ||
return r | ||
|
||
for d in _search_dirs: | ||
r = _check_for_header_and_lib(d) | ||
if r is not None: | ||
return r | ||
|
||
raise Error("Unable to locate the extism library and header file") | ||
|
||
|
||
if __name__ == '__main__': | ||
print(_locate()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
_check: | ||
#!/usr/bin/env bash | ||
if ! &>/dev/null which poetry; then | ||
curl -sSL https://install.python-poetry.org | sed -e 's|symlinks=False|symlinks=True|' | python3 - | ||
fi | ||
if ! echo $PATH | grep -q "$HOME/.local/bin" &>/dev/null && ! echo $PATH | grep -q "~/.local/bin" &>/dev/null; then | ||
>&2 echo -e 'Please add \x1b[31m"~/.local/bin"\x1b[0m to \x1b[31m"$PATH"\x1b[0m, then rerun this command.' | ||
exit 1 | ||
fi | ||
|
||
# check for presence of the extism shared library and headers, installing | ||
# then if necessary | ||
if ! &>/dev/null poetry run python -m extism.utils; then | ||
if ! &>/dev/null which extism; then | ||
pip3 install git+https://github.com/extism/cli | ||
fi | ||
|
||
extism install git | ||
fi | ||
|
||
prepare: _check | ||
poetry install | ||
|
||
test: prepare | ||
poetry run python -m unittest discover | ||
|
||
clean: | ||
rm -rf dist/* | ||
|
||
publish: clean prepare | ||
poetry build | ||
poetry run twine upload dist/extism-*.tar.gz | ||
|
||
format: | ||
poetry run black extism/ tests/ example.py | ||
|
||
lint: | ||
poetry run black --check extism/ tests/ example.py | ||
|
||
docs: | ||
poetry run pycco extism/*.py | ||
|
||
show-docs: docs | ||
open docs/extism.html |
Oops, something went wrong.