Skip to content

added pylint to project and update code #10

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

Merged
merged 12 commits into from
Jan 3, 2018
Merged

Conversation

mrmcwethy
Copy link
Collaborator

Lint all the libraries! #475

Not tested

@mrmcwethy mrmcwethy changed the title added pylint to project and udpate code added pylint to project and update code Dec 12, 2017
@mrmcwethy
Copy link
Collaborator Author

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Started testing library. ST7735R fails.

def __init__(self, spi, dc, cs, rst=None, width=128, height=128):
super().__init__(spi, dc, cs, rst, width, height)
# def __init__(self, spi, dc, cs, rst=None, width=1, height=1, baudrate=1000000,
# polarity=0, phase=0)


class ST7735R(ST7735):
Copy link
Contributor

@kattni kattni Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with ST7735R display, shows bars and multicolored pixellation across the display. Tried with example code included at beginning of file, as well as other code. Both of my examples run with the current version (if I change the last line to self.write in the current version as well) - using PR version of rgb.py.

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSD1351 testing failed.

@@ -1,5 +1,6 @@
"""A simple driver for the SSD1351-based displays."""
Copy link
Contributor

@kattni kattni Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing with SSD1351 display fails - results in static looking pixellation using example in code.. Tested successfully with current version of this file with same example - using PR version of rgb.py.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kattni thanks for testing this. I trusted pylint too much and deleted some important __init__ code. put it back in the two you have identified and several others.

Copy link
Collaborator Author

@mrmcwethy mrmcwethy Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also notice the internal identifiers were only in the rgb.py file but also should be in all .py files. So I added those required lines.

Since travis checks were failing, i fixed some more error that my pylint did not find.

@mrmcwethy
Copy link
Collaborator Author

Ready to re-review.


>>> import busio
>>> import digitalio
>>> import board
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.hx8353 as hx8353
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = hx8353.HX8383(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15))
>>> display = hx8353.HX8383(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing "..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -1,10 +1,15 @@
"""A simple driver for the ILI9341/ILI9340-based displays."""

try:
import struct
except ImportError:
import ustruct as struct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed, CircuitPython always has "struct".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, sorry, old CircuitPython still uses ustruct.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got ya, ignored

@@ -16,7 +21,8 @@ class ILI9341(DisplaySPI):
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.ili9341 as ili9341
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15))
>>> display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


def scroll(self, dy=None):
if dy is None:
def scroll(self, delta_y=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is "dy" not "delta y" or "δy". It's a common notation in math.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted to dy

pass

def high(self):
"""Dummy high Pin method"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole class needs to be rewritten for CircuitPython, as it has a completely different gpio pin API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am inclined to remove dummy pin for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should move it to simpleio, but that would be a separate pull request. Please ignore this comment for now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


>>> import busio
>>> import digitalio
>>> import board
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.s6d02a1 as s6d02a1
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = s6d02a1.S6D02A1(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
>>> display = s6d02a1.S6D02A1(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "..."

@@ -43,7 +48,8 @@ class SSD1331(DisplaySPI):
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.ssd1331 as ssd1331
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
>>> display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "...".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

# (_CONTRASTA, b'\x91'), #//0xEF - 0x91
# (_CONTRASTB, b'\x50'), #;//0x11 - 0x50
# (_CONTRASTC, b'\x7d'), #;//0x48 - 0x7D
# (_DISPLAYON, b''),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DISPLAYON is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added _DISPLAYON

@@ -44,7 +48,8 @@ class SSD1351(DisplaySPI):
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.ssd1351 as ssd1351
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = ssd1351.SSD1351(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
>>> display = ssd1351.SSD1351(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -62,7 +67,8 @@ class ST7735(DisplaySPI):
>>> from adafruit_rgb_display import color565
>>> import adafruit_rgb_display.st7735 as st7735
>>> spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
>>> display = st7735.ST7735(spi, cs=digitalio.DigitalInOut(board.GPIO0), dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
>>> display = st7735.ST7735(spi, cs=digitalio.DigitalInOut(board.GPIO0),
dc=digitalio.DigitalInOut(board.GPIO15), rst=digitalio.DigitalInOut(board.GPIO16))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing "..."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@mrmcwethy
Copy link
Collaborator Author

ok, i am done with the 2nd round of testing. does the _DISPLAYON missing explain @kattni problem with drivers?

@@ -70,9 +70,9 @@ def _block(self, xpos0, ypos0, xpos1, ypos1, data=None):
return None
#pylint: enable-msg=too-many-arguments

def _encode_pos(self, avalue, bvalue):
def _encode_pos(self, x, y): #pylint: disable-msg=invalid-name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the impression that pylint has those names added to exceptions in its configuration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change got made after i created my template project from cookiecutter. I have updated the .pylintrc and remove the redundant #pylint lines

@@ -1 +1,2 @@
"""import class color565"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string here is a bit confusing. First, it's a module-level docstring, so it should be describing the module, rather than commenting the code. Second, color565 is a function, not a class. And finally I'm not sure we need to explain what the "import" statement does.


def read(self, command, count):
"""Derived class must implement this"""
raise NotImplementedError
Copy link
Contributor

@deshipu deshipu Dec 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advise against dummy methods raising NotImplementedError. Not only they waste memory, but they also make it very hard to use super() properly. I think that AttributeError in case something tries to call this is good enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe pylint has smarts around recognizing unimplemented methods like this and validating that suubclasses define them. The memory hit won't be so large that it isn't worth it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real problem is when you use this class in any multiple inheritance scenario, where you have to use super() to make sure all the methods are properly called, but this will also call this method and raise a NotImplementedError. That's why this is an anti-pattern. I understand that with CircuitPython we run a much lower risk for this, but it's still a bad habit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting! What would you recommend in this case? Would you mind opening an issue for us to make the drivers consistent on how to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way to do this in normal Python is to use @abc.abstractmethod, but CircuitPython doesn't have the abc module. Personally I'm inclined to just leaving this out completely, and just mentioning in the comments that the subclasses need to implement those methods. This is not something the user of the library should ever see or need anyways.

@deshipu
Copy link
Contributor

deshipu commented Dec 23, 2017

Does the _DISPLAYON missing explain @kattni problem with drivers?

I think so.

Copy link
Contributor

@kattni kattni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSD1331 test fails.

@@ -1,4 +1,9 @@
"""A simple driver for the SSD1331-based displays."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing with SSD1331 failed. However I get the same results with the current version of the driver as well. Multicolor pixellation and a single vertical line that turns the color that the code attempts to fill the entire display. That 1-pixel-wide line will change color if I change the fill color in the code. The line is close to the left side, if that matters.

@mrmcwethy
Copy link
Collaborator Author

@kattni what does your main.py look like?

@kattni
Copy link
Contributor

kattni commented Dec 23, 2017

@mrmcwethy The following:

import busio
import digitalio
import board
from adafruit_rgb_display import color565
import adafruit_rgb_display.ssd1331 as ssd1331
spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO)
display = ssd1331.SSD1331(spi, cs=digitalio.DigitalInOut(board.D5),
                               dc=digitalio.DigitalInOut(board.D11), rst=digitalio.DigitalInOut(board.D9))

while True:
    display.fill(0x7521)
    display.pixel(32, 32, 0)

@deshipu
Copy link
Contributor

deshipu commented Dec 23, 2017

I got the SSD1331 display to work after this library was forked from mine. If you look at the MicroPython library, you will see the fixed setup code there: https://github.com/adafruit/micropython-adafruit-rgb-display/blob/master/ssd1331.py#L52-L75

However, I believe that this would be a separate issue and a separate pull request.

@kattni
Copy link
Contributor

kattni commented Dec 24, 2017

I have the SSD1331 working. I'm going to make a separate PR to resolve it since it's an issue with the current version of the driver as well.

@mrmcwethy
Copy link
Collaborator Author

mrmcwethy commented Dec 29, 2017

Now that i have removed the "abstract functions" can this be merged?

Also resolved conflicts to SSD1331.py

@mrmcwethy
Copy link
Collaborator Author

I am happy to commit resolved conflicts. If someone else does it, take the "lint" changes over master.

@kattni
Copy link
Contributor

kattni commented Jan 2, 2018

Current testing status: the ILI9341 and the ST7735 (non-R version) still need to be tested.

All other displays have been successfully tested.

@kattni
Copy link
Contributor

kattni commented Jan 3, 2018

Adafruit does not carry the ST7735, only the ST7735R. ILI9341 tested successfully. That's everything! Great job!

@kattni kattni merged commit 7e3ae1d into adafruit:master Jan 3, 2018
tannewt pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants