PiSupply / PaPiRus

Resources for PaPiRus ePaper eInk displays
https://www.pi-supply.com/product/papirus-epaper-eink-screen-hat-for-raspberry-pi/
Other
346 stars 88 forks source link

Python3 compatibility #137

Closed RTiK closed 6 years ago

RTiK commented 7 years ago

In order to use the package in python3 I had to change a print() and make file open() handle text as strings and not binary. Also I fixed some mixed indents. I may be missing something but the code seems to be compatible with both python versions now.

francesco-vannini commented 7 years ago

'Thanks @RTiK we'll have a look as soon as possible. Could you confirm if all aspects mentioned by @tvoverbeek in #122 have been addressed?

RTiK commented 7 years ago

It is true that python 2 and 3 handle unicode differently:

python 2

type(u'foo') 
<type 'unicode'>

python 3

type(u'foo')
<class 'str'>

From what I understand PIL is used to draw on the display. Right now it is already using unicode strings as input. However, it can handle str as input if interpreted by python 3. I have tested the unicode example code and it produces black and white stars as expected. Other unicode characters that are implemented in FreeMono are displayable as well.

francesco-vannini commented 7 years ago

That's great, thanks. We'll test the whole Python 3 thing and merge if nothing obviously wrong comes up. Really appreciate you spending time on this. Do we need to write anything in the main Readme file about how maybe to use PaPiRus with Python 3 i.e. using the right interpreter or needing to change the interpreter path on the demo scripts. It would be nice to make it as simple as possible to people to switch and something isn't working "out of the box" maybe we should just point them to a set of manual steps. If you could summarise this in this thread I'll make sure to integrate it in the readme after merge.

RTiK commented 7 years ago

The only thing I can point out is to use

sudo python3 setup.py install

instead of

sudo python setup.py install

to install the API for python 3. The install script must be changed accordingly.

tvoverbeek commented 7 years ago

Correct, but not before all examples in bin and other modules are python 3 compatible.

On Thu, Jul 20, 2017 at 1:17 PM, RTiK notifications@github.com wrote:

The only thing I can point out is to use

sudo python3 setup.py install

instead of

sudo python setup.py install

to install the API for python 3. The install script must be changed accordingly.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/137#issuecomment-316673550, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7ljz3uenEdfv6eAlnTyOBrTXLq0Oks5sPzdWgaJpZM4Ockpi .

RTiK commented 7 years ago

Also the __init__.py file seems a bit off. In order to be able to import the classes correctly I had to prepend the package name to each import to make it work:

from papirus.lm75b import LM75B

instead of

from lm75b import LM75B

and so on... But I guess this is another issue.

tvoverbeek commented 7 years ago

The init.py issue is one of the differences between python 2 and python 3. Tried to run papirus-clock after 'sudo python3 setup.py install', but ran into python 3 incompatiblity problems (no execfile(), difference between str in 2 and 3, etc.) Propose to merge this as is without python3 install instructions. It is a good first step toward python3 compatibility.

On a side-note, does anyone know if python3 will be the default in Debian Stretch. Raspbian will go to Stretch in the near future.

shawaj commented 7 years ago

Is there any merit in trying to maintain python 2.7 compatibility whilst giving python 3 compatibility too?

Not sure if it'll be easy but just a thought

On 20 Jul 2017 1:02 pm, "tvoverbeek" notifications@github.com wrote:

The init.py issue is one of the differences between python 2 and python 3. Tried to run papirus-clock after 'sudo python3 setup.py install', but ran into python 3 incompatiblity problems (no execfile(), difference between str in 2 and 3, etc.) Propose to merge this as is without python3 install instructions. It is a good first step toward python3 compatibility.

On a side-note, does anyone know if python3 will be the default in Debian Stretch. Raspbian will go to Stretch in the near future.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/137#issuecomment-316682154, or mute the thread https://github.com/notifications/unsubscribe-auth/ADNCuupq-PcWIXkMC3IDDotJSbErj5jTks5sP0GFgaJpZM4Ockpi .

tvoverbeek commented 7 years ago

Certainly possible to support python 2.7 and 3.x simultaneously (which should be our goal according to me). See e.g. https://docs.python.org/3/howto/pyporting.html

On Fri, Jul 21, 2017 at 7:28 AM, Aaron Shaw notifications@github.com wrote:

Is there any merit in trying to maintain python 2.7 compatibility whilst giving python 3 compatibility too?

Not sure if it'll be easy but just a thought

On 20 Jul 2017 1:02 pm, "tvoverbeek" notifications@github.com wrote:

The init.py issue is one of the differences between python 2 and python 3. Tried to run papirus-clock after 'sudo python3 setup.py install', but ran into python 3 incompatiblity problems (no execfile(), difference between str in 2 and 3, etc.) Propose to merge this as is without python3 install instructions. It is a good first step toward python3 compatibility.

On a side-note, does anyone know if python3 will be the default in Debian Stretch. Raspbian will go to Stretch in the near future.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/137#issuecomment-316682154, or mute the thread https://github.com/notifications/unsubscribe-auth/ADNCuupq- PcWIXkMC3IDDotJSbErj5jTks5sP0GFgaJpZM4Ockpi .

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/137#issuecomment-316906969, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7iEsU_1adpPuqPScQ3qZ2fVhsEBsks5sQDcUgaJpZM4Ockpi .

RTiK commented 7 years ago

the missing execfile() method can be substituted by exec(open(<filepath>).read())

some rounding issues in papirus-gol resulting from division result being a float and not an int can be fixed by explicitly calling floor division with // instead of a single /

tvoverbeek commented 7 years ago

Yes, I know about the execfile replacement and the division changes. More serious the python imaging library for python3 is missing in a standard Raspbian installation. The install (when using python3) installs all examples in /usr/local/bin requiring python3 to run. As it is now all examples will fail because of the missing python3-pil package.

On Fri, Jul 21, 2017 at 1:40 PM, RTiK notifications@github.com wrote:

the missing execfile() method can be substituted by exec(open().read())

some rounding issues in papirus-gol resulting from division result being a float and not an int can be fixed by explicitly calling floor division with // instead of a single /

— You are receiving this because your review was requested. Reply to this email directly, view it on GitHub https://github.com/PiSupply/PaPiRus/pull/137#issuecomment-316979407, or mute the thread https://github.com/notifications/unsubscribe-auth/ABJE7q6hCDoY2UnS4VXfPCkwIMzmEIL6ks5sQI46gaJpZM4Ockpi .

tvoverbeek commented 6 years ago

Python 3 support for library and all examples/demos now available since merge of PR #160. Closing this PR.