chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
748 stars 127 forks source link

Add support for passing environment variables when installing pip packages #1183

Open IsakTheHacker opened 1 week ago

IsakTheHacker commented 1 week ago

Many pip packages support passing environment variables at install time. For example, to use the slower multidict Python implementation:

MULTIDICT_NO_EXTENSIONS=1 pip install multidict

I haven't tested this yet, I'm sorry. Maybe Chaquopy's pip already reads from the local environment variables? Regardless, I think it would be easier to have this be an explicit option in the gradle plugin. That would also lead to more reproducible builds across machines

mhsmith commented 1 week ago

If all you want is a newer version of multidict, you may be able to do that by moving to a newer version of Python. See the repository for the available version combinations – the newest versions are currently multidict 5.1.0 for Python 3.8-3.11, and multidict 6.0.4 for Python 3.12.

Most packages that support pure-Python fallbacks will either use them automatically if the native compilation fails, or have a pure-Python wheel on PyPI. I see multidict 6.0.4 doesn't do either of those things, so the environment variable would be necessary to install it on Python 3.11 or older.

However, the current multidict version 6.0.5 does have a pure-Python wheel on PyPI, so that should solve your immediate problem if you need a newer version of multidict on an older version of Python.

Maybe Chaquopy's pip already reads from the local environment variables?

Yes, it does, so you can pass the environment variable through Gradle on the command line, like this:

MULTIDICT_NO_EXTENSIONS=1 ./gradlew assembleDebug

After you've done this once, the wheel will be cached locally so you won't need to set the variable again.

But I agree it would be better to put it in a Gradle file so it's more reproducible, and I haven't managed to find an easy way of doing that:

So I'll leave this issue open and see if anyone else has a similar problem.