-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Remove string decoding in _android.pyx for Python3 compatibility #1748
Conversation
0377062
to
dc2b7df
Compare
i'm thinking now maybe it would be better to make them explicitely unicode (by adding edit: though i'm not sure why the pygame ones are defined as explicitely bytes. |
In Python3 strings are unicode by default. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be the right approach to this issue since it is still compatible with python 2.
Fixed the issues I was having while trying to compile my apk with buildozer/kivy/python3.
I also second what @tshirtman says regarding explicitly forcing unicode so it would behave the same for python2 and python3. The thing is we already have the future unicode literal import. That's why I was suspecting initial issue from @tshirtman was with pygame because indeed it's the only path I could see where the type may differ. See #1747 (comment) comment. |
Yes. It seems that (with Python3) the error occurs when trying to ask runtime permissions (I got it with ZbarCam). |
@darosior i know python strings are unicode by default in python3, that's also why i was suprised by this issue, because i did build targetting python3, and it failed at runtime for me, but since this is a cython file (.pyx), it generated code for python2, (as tito suggested in the PR i did), that could explain why people get different results, i was pretty sure i had built everything in python3, but seems edit: ideally, p4a should be able to check that the cython it calls corresponds to the python version it targets, and raise a warning when it's not the case, one hacky way to do that could be
that's a bit hacky, but i don't know of a better one yet. re-edit: but also, just adding python-for-android/pythonforandroid/recipes/android/__init__.py Lines 48 to 49 in 7bb8c8d
|
The proposal in the re edit seems great, would you like me to edit the commit to make this change instead of modifying the cython file ? |
the thing that puzzle me is why is it marked as bytes for the pygame alternative, but otherwise yeah, i think that's the best route. |
dc2b7df
to
a74847c
Compare
Indeed, that's weird. To my understanding (limited, first time going through the code) there is no need for that, the difference would be handled with, I think, python-for-android/pythonforandroid/recipes/android/__init__.py Lines 60 to 67 in 7bb8c8d
But it is not handled in any of these files : $ grep -ri "is_pygame" pythonforandroid/recipes/android/src/
pythonforandroid/recipes/android/src/android/_android_jni.c:#if IS_PYGAME
pythonforandroid/recipes/android/src/android/_android_jni.c:#endif // IS_PYGAME
pythonforandroid/recipes/android/src/android/_android.pyx:IF IS_PYGAME:
pythonforandroid/recipes/android/src/setup.py:if int(os.environ['IS_PYGAME']): The other thing I found is that there does not seem to be any error in other files where $ grep -ri "JAVA_NAMESPACE" pythonforandroid/recipes/android/src/
pythonforandroid/recipes/android/src/android/runnable.py:from android.config import JAVA_NAMESPACE
pythonforandroid/recipes/android/src/android/runnable.py:_PythonActivity = autoclass(JAVA_NAMESPACE + '.PythonActivity')
pythonforandroid/recipes/android/src/android/broadcast.py:from android.config import JAVA_NAMESPACE, JNI_NAMESPACE
pythonforandroid/recipes/android/src/android/broadcast.py: GenericBroadcastReceiver = autoclass(JAVA_NAMESPACE + '.GenericBroadcastReceiver')
pythonforandroid/recipes/android/src/android/broadcast.py: PythonService = autoclass(JAVA_NAMESPACE + '.PythonService')
pythonforandroid/recipes/android/src/android/broadcast.py: PythonActivity = autoclass(JAVA_NAMESPACE + '.PythonActivity')
pythonforandroid/recipes/android/src/android/activity.py:from android.config import JAVA_NAMESPACE, JNI_NAMESPACE
pythonforandroid/recipes/android/src/android/activity.py:_activity = autoclass(JAVA_NAMESPACE + '.PythonActivity').mActivity
pythonforandroid/recipes/android/src/android/_android.pyx:python_act = autoclass(JAVA_NAMESPACE + u'.PythonActivity') |
I would not care too much about pygame guys since it's pretty legacy right? I would just make it behave the same as sdl2 |
Thus removing this condition ? python-for-android/pythonforandroid/recipes/android/__init__.py Lines 50 to 51 in 7bb8c8d
|
Yes I would be really tempted to remove that condition indeed |
It seems reasonnable to me as well. Should we just change the |
a74847c
to
9a8d321
Compare
in that case i would remove the condition and put them both as unicode (by adding |
Yes @tshirtman I would explicitly force it to be the same on both with a comment explaining why. |
Ok I did it in the last commit, we are good then. |
Why ? Other string to which it is concatenated don't have it and it seems to work well (cf above) |
this code is compiled to C by cython, which might (and in my case, was), be interpreting it differently than python itself. hinting it to make sure it's not ambigious can only help, no? |
9a8d321
to
20f486e
Compare
As you want, did it :) |
thanks, let's see what happens with that 👍 |
But wait guys, then the call on |
🤦♂️ indeed we do need to remove this part too, i somehow though it had been done, although it's not in the diff. my bad. |
I just forgot to |
#1747 broke Python3 compatibility by decoding a string. Here is a fix.