Skip to content

Commit 91dae41

Browse files
committed
use pipenv for third-party packages
The tricky thing about this is finding the `site-packages` directory where `pipenv` has installed our packages and mounting it where Python can find it during Wizer initialization. Signed-off-by: Joel Dice <[email protected]>
1 parent 6a391f5 commit 91dae41

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ build: target/config.txt target/lib
44
env -i wasi-vfs/target/release/wasi-vfs pack target/wasm32-wasi/release/python_wasi.wasm \
55
--mapdir lib::$$(pwd)/target/lib \
66
-o target/wasm32-wasi/release/python-wasi-vfs.wasm
7-
env -i PYTHONUNBUFFERED=1 PYTHONPATH=/py $$(which wizer) target/wasm32-wasi/release/python-wasi-vfs.wasm \
7+
env -i PYTHONUNBUFFERED=1 PYTHONPATH=/py:/site-packages \
8+
$$(which wizer) target/wasm32-wasi/release/python-wasi-vfs.wasm \
89
--inherit-env true --wasm-bulk-memory true --allow-wasi --dir py \
10+
--mapdir site-packages::$$(cd py && find $$(pipenv --venv)/lib -name site-packages | head -1) \
911
-o target/wasm32-wasi/release/python-wasi-vfs-wizer.wasm
1012

1113
target/config.txt:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This is an experiment to build a Spin Python SDK using CPython, wasi-vfs, and Py
1010
- [Wizer](https://github.com/bytecodealliance/wizer) v1.6.0 or later
1111
- [Spin](https://github.com/fermyon/spin)
1212
- [rsync](https://rsync.samba.org/) -- used at build time for copying files around; we could replace this with something more portable, if desired
13+
- [pipenv](https://pypi.org/project/pipenv/) for installing Python project dependencies
1314

1415
## Building and Running
1516

@@ -40,6 +41,7 @@ Then, build the wasi-vfs CLI:
4041
Finally, build and run this app:
4142

4243
```
44+
(cd py && pipenv install)
4345
spin build
4446
spin up
4547
```

py/Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
toml = "*"
8+
9+
[dev-packages]
10+
11+
[requires]
12+
python_version = "3.10"

py/Pipfile.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/app.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
from spin_redis import redis_get, redis_set
33
from spin_config import config_get
44
from os import environ
5+
import toml
56

67
def handle_request(request):
78
print(f"Got request URI: {request.uri}")
89

910
print(f"Here's my environment: {environ}")
1011

12+
some_toml = """
13+
title = "foo"
14+
15+
[bar]
16+
baz = "wow"
17+
such = "toml"
18+
"""
19+
20+
print(f"And here's some TOML: {toml.loads(some_toml)}")
21+
1122
response = http_send(Request("GET", "https://some-random-api.ml/facts/dog", [], None))
1223
print(f"Got dog fact: {str(response.body, 'utf-8')}")
1324

0 commit comments

Comments
 (0)