ZeroPhone / ZPUI

Official ZeroPhone UI framework, based on pyLCI
http://zpui.rtfd.org/
Apache License 2.0
78 stars 19 forks source link

Python 3 #136

Open CRImier opened 5 years ago

CRImier commented 5 years ago

We need to ensure Python 3 compatibility - soon, Python 2 will no longer be the default Python interpreter, and we don't yet support Python 3. There are problems associated with switching, of course - a lot of our code doesn't support Python 3, and some of it (mainly low-level oriented) doesn't support it in a major way. We could migrate with 2to3, but it's nasty in the way that it's an one-way switch, and it's certain we'll have a Python 2 userbase for a long time.

LouisPi commented 5 years ago

Smspdu doesn't list support for Python3, jsonrpclib doesn't support Python3 although work has been done here towards Python3 compatibility (https://github.com/joshmarshall/jsonrpclib/pull/59) and unpaddedbase64 does not support Python 3.2. All other libraries in requirements.txt list support for Python 3.

LouisPi commented 5 years ago

The first task looks easy enough for me to do tomorrow and maybe the second one too.

CRImier commented 5 years ago

Thank you! Rr: unpaddedbase64 - we're not aiming for Python 3.2 compatibility, then =D jsonrpclib is mainly used by the pomodoro app (though it is supposed to be usable by user-written apps, too, I just never got around to writing a tutorial). smspdu is used by the current "Phone" app, which we'll deprecate really soon.

CRImier commented 5 years ago

The problem with relative imports that I discovered today - Python 2 doesn't handle all of them as well as it should, complaining like "Attempted relative import in non-package". If that doesn't happen normally, it might still happen when you, say, run tests in ui/tests (i.e. python test_menu.py).

LouisPi commented 5 years ago

Ah okay.

LouisPi commented 5 years ago

Are we supporting versions older than Python 2.7 as well? The Python docs state

While you can make Python 2.5 work with Python 3, it is much easier if you only have to work with Python 2.7

and also

you should aim for only supporting Python 2.7. Python 2.6 is no longer freely supported and thus is not receiving bugfixes. This means you will have to work around any issues you come across with Python 2.6

I think there is a clear message in the Python docs there. To put it into context Raspbian has Python 2.7.13 installed and has supported Python 2.7 since it first existed AFAIK considering Python 2.7 was released almost 2 years before the first Raspberry Pi was released. I see no reason why other operating systems for the Pi won't have Python 2.7 installed. If we did go down the course of supporting Python 2.7 and Python 3, it would save the need for using six and as the Python docs suggest, make it easier to port the code to Python 3. Of course the choice is yours and this is just my opinion after doing some research.

Thanks, Louis P

Edit - source for the quotes is here - https://docs.python.org/3/howto/pyporting.html

CRImier commented 5 years ago

I haven't aimed for Python 2.6/2.5 compatibility in the past, and I'm not sure it makes sense to do so now - our targets (Raspbian Stretch) have long abandoned 2.6/2.5. So, let's stick to 2.7 =) However, I don't see how it'd save the need for using six, since six is a 2-to-3 compatibility library and doesn't really concern 2.6 as such. I see it mentioned in the docs where 2.6 is involved, but the relationship is not clear to me.

LouisPi commented 5 years ago

Not really my speciality subject (I just did some searching) but it seems that there are supposedly 'easier' ways to keep code working with Python 2.7 and Python 3. That is according to the official docs. However, many other websites seem to recommend using six as well. Maybe I concentrated too much on the official docs. Maybe this link could be a useful reference - http://python-future.org/compatible_idioms.html .

CRImier commented 6 months ago

Port started in devel branch with https://github.com/ZeroPhone/ZPUI/commit/ae12f2c3b9fddc5a63fd6f17abc54ec846ce3dc7