Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydantic not working #96

Open
MominIqbal-1234 opened this issue Apr 10, 2024 · 3 comments
Open

pydantic not working #96

MominIqbal-1234 opened this issue Apr 10, 2024 · 3 comments

Comments

@MominIqbal-1234
Copy link

Caused by:
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'
Error: Build command for component spin-templete failed with status Exited(1)

@dicej
Copy link
Collaborator

dicej commented Apr 10, 2024

Thanks for reporting this, @MominIqbal-1234. Would you mind providing instructions for reproducing this issue?

@karthik2804
Copy link
Contributor

@dicej I have reproduced it. pydantic relies on pydantic_core which has native rust code, therefore we need to get a build from wasi-wheels.

@MominIqbal-1234, Since pypi does not have builds for wasi yet you will have build it manually. There is a list of python packages with the appropriate makefiles to build to wasi at https://github.com/dicej/wasi-wheels/

The steps should be something like

git clone https://github.com/dicej/wasi-wheels/
cd wasi-wheel
make

With that step, all the packages will be built. you can then extract the pydantic_core.tar.gz and place it in your app directory. Once that is done, the app should build.

The directory structure

tree .
$ tree -L 2
.
├── README.md
├── __pycache__
│   └── app.cpython-312.pyc
├── app.py
├── app.wasm
├── pydantic_core
│   ├── __init__.py
│   ├── __pycache__
│   ├── _pydantic_core.cpython-312-wasm32-wasi.so
│   ├── _pydantic_core.pyi
│   ├── core_schema.py
│   └── py.typed
├── requirements.txt
├── spin.toml
└── venv
    ├── bin
    ├── include
    ├── lib
    └── pyvenv.cfg

I did not test a complicated example but this example compiled and I was able to run it successfully.

import datetime
from typing import Tuple
from spin_sdk.http import IncomingHandler, Request, Response

from pydantic import BaseModel

class Delivery(BaseModel):
    timestamp: datetime.datetime


class IncomingHandler(IncomingHandler):
    def handle_request(self, request: Request) -> Response:

        timestamp = datetime.datetime(2020, 1, 2, 3, 4, 5)

        m = Delivery(timestamp=timestamp)
        print(repr(m.timestamp))

        return Response(
            200,
            {"content-type": "text/plain"},
            bytes("Hello from Python!", "utf-8")
        )

@dicej
Copy link
Collaborator

dicej commented Apr 10, 2024

Thanks for digging into this @karthik2804. This is a good reminder that we should start publishing pre-built artifacts for all supported packages in the wasi-wheels repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants