0

I have been trying to upload a function that allows me to turn a CSV into a JSON file. The code works but when I try to deploy it to my instance of Appwrite, the build fails.

Here is my function:

from appwrite.client import Client
from appwrite.services.storage import Storage
import pandas as pd


def main(req, res):
    file_id = res.payload["fileId"]
    bucket_id = res.variables.BUCKET_ID
    api_key = res.variables.API_KEY
    client = Client().set_endpoint(res.variables.ENDPOINT).set_project(res.variables.PROJECT_ID).set_key(api_key)
    storage = Storage(client)
    binary_csv = storage.get_file_view(bucket_id, file_id)
    data = BytesIO(binary_csv)  # type: ignore
    df = pd.read_csv(data)
    value = df.to_json(orient="records")
    return res.json({
        "message": "Success <200>",
        "payload": value
})

My requirements.txt:

appwrite
numpy>=1.23.0
pandas>=1.5.0

On the build failure log, this is where it fails

Docker Error:   error: subprocess-exited-with-error
  
  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 
  ╰─> [ lines of output]
      Collecting setuptools>=.0
        Downloading setuptools-65.5.0-py3-none-any.whl ( MB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ /1.2 MB  MB/s eta :00:00
      Collecting wheel
        Downloading wheel-0.37.1-py2.py3-none-any.whl ( kB)
      Collecting Cython<,>=.32
        Using cached Cython-0.29.32-cp310-cp310-musllinux_1_1_x86_64.whl ( MB)
      Collecting oldest-supported-numpy>=
        Downloading oldest_supported_numpy-2022.8.16-py3-none-any.whl ( kB)
      Collecting numpy==.6
        Downloading numpy-1.21.6.zip ( MB)
           ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ /10.3 MB  MB/s eta :00:00
        Installing build dependencies: started
        Installing build dependencies: finished with status 'done'
        Getting requirements to build wheel: started
        Getting requirements to build wheel: finished with status 'done'
        Preparing metadata (pyproject.toml): started
        Preparing metadata (pyproject.toml): finished with status 'done'
      Building wheels for collected packages: numpy
        Building wheel for numpy (pyproject.toml): started
        Building wheel for numpy (pyproject.toml): finished with status 'error'
        error: subprocess-exited-with-error

It is using the wrong version of numpy too. Later in the response it shows the actual pip command which does use the right version.

Collecting appwrite
  Downloading appwrite-1.1.0.tar.gz (13 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting numpy>=1.23.0
  Downloading numpy-1.23.4.tar.gz (10.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.7/10.7 MB 18.8 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Collecting pandas>=1.5.0
  Downloading pandas-1.5.1.tar.gz (5.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.2/5.2 MB 115.3 MB/s eta 0:00:00
  Installing build dependencies: started
  Installing build dependencies: finished with status 'error'

Any help would be appreciated.

1 Answers1

0

Unfortunately, you can't use pandas in Appwrite Functions because installing numpy seems to require some OS packages not available in the open runtime. You can follow this issue for updates on this.

For your basic CSV to JSON task, how about you use the standard csv package instead of pandas?

Steven Nguyen
  • 452
  • 4
  • 4