Skip to content
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

Ran black, updated to pylint 2.x #73

Merged
merged 3 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
6 changes: 3 additions & 3 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spelling-store-unknown-words=no
[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
#notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
notes=FIXME,XXX


Expand Down Expand Up @@ -301,7 +301,7 @@ function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$

# Good variable names which should always be accepted, separated by a comma
# good-names=i,j,k,ex,Run,_
good-names=r,g,b,i,j,k,n,x,y,z,ex,Run,_
good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_

# Include a hint for the correct naming format with invalid-name
include-naming-hint=no
Expand Down Expand Up @@ -423,7 +423,7 @@ max-returns=6
max-statements=50

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
min-public-methods=1


[EXCEPTIONS]
Expand Down
5 changes: 3 additions & 2 deletions adafruit_ht16k33/bargraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"


class Bicolor24(HT16K33):
"""Bi-color 24-bar bargraph display."""

Expand All @@ -46,7 +47,7 @@ def __getitem__(self, key):
x = key % 4 + 4 * (key // 12)
y = key // 4 - 3 * (key // 12)
# construct the color value and return it
return self._pixel(x, y) | self._pixel(x+8, y) << 1
return self._pixel(x, y) | self._pixel(x + 8, y) << 1

def __setitem__(self, key, value):
# map to HT16K33 row (x) and column (y), see schematic
Expand All @@ -55,7 +56,7 @@ def __setitem__(self, key, value):
# conditionally turn on red LED
self._pixel(x, y, value & 0x01)
# conditionally turn on green LED
self._pixel(x+8, y, value >> 1)
self._pixel(x + 8, y, value >> 1)

def fill(self, color):
"""Fill the whole display with the given color."""
Expand Down
22 changes: 12 additions & 10 deletions adafruit_ht16k33/ht16k33.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class HT16K33:
set. If False, `show` must be called explicitly.
:param float brightness: 0.0 - 1.0 default brightness level.
"""

def __init__(self, i2c, address=0x70, auto_write=True, brightness=1.0):
self.i2c_device = i2c_device.I2CDevice(i2c, address)
self._temp = bytearray(1)
Expand All @@ -74,11 +75,10 @@ def blink_rate(self):
@blink_rate.setter
def blink_rate(self, rate=None):
if not 0 <= rate <= 3:
raise ValueError('Blink rate must be an integer in the range: 0-3')
raise ValueError("Blink rate must be an integer in the range: 0-3")
rate = rate & 0x03
self._blink_rate = rate
self._write_cmd(_HT16K33_BLINK_CMD |
_HT16K33_BLINK_DISPLAYON | rate << 1)
self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1)

@property
def brightness(self):
Expand All @@ -88,7 +88,9 @@ def brightness(self):
@brightness.setter
def brightness(self, brightness):
if not 0.0 <= brightness <= 1.0:
raise ValueError('Brightness must be a decimal number in the range: 0.0-1.0')
raise ValueError(
"Brightness must be a decimal number in the range: 0.0-1.0"
)

self._brightness = brightness
xbright = round(15 * brightness)
Expand All @@ -105,7 +107,7 @@ def auto_write(self, auto_write):
if isinstance(auto_write, bool):
self._auto_write = auto_write
else:
raise ValueError('Must set to either True or False.')
raise ValueError("Must set to either True or False.")

def show(self):
"""Refresh the display and show the changes."""
Expand All @@ -116,14 +118,14 @@ def show(self):

def fill(self, color):
"""Fill the whole display with the given color."""
fill = 0xff if color else 0x00
fill = 0xFF if color else 0x00
for i in range(16):
self._buffer[i+1] = fill
self._buffer[i + 1] = fill
if self._auto_write:
self.show()

def _pixel(self, x, y, color=None):
addr = 2*y + x // 8
addr = 2 * y + x // 8
mask = 1 << x % 8
if color is None:
return bool(self._buffer[addr + 1] & mask)
Expand All @@ -138,7 +140,7 @@ def _pixel(self, x, y, color=None):
return None

def _set_buffer(self, i, value):
self._buffer[i+1] = value # Offset by 1 to move past register address.
self._buffer[i + 1] = value # Offset by 1 to move past register address.

def _get_buffer(self, i):
return self._buffer[i+1] # Offset by 1 to move past register address.
return self._buffer[i + 1] # Offset by 1 to move past register address.
48 changes: 31 additions & 17 deletions adafruit_ht16k33/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"


class Matrix8x8(HT16K33):
"""A single matrix."""

_columns = 8
_rows = 8

Expand All @@ -52,7 +54,7 @@ def __setitem__(self, key, value):
x, y = key
self.pixel(x, y, value)

#pylint: disable=too-many-branches
# pylint: disable=too-many-branches
def shift(self, x, y, rotate=False):
"""
Shift pixels by x and y
Expand All @@ -61,28 +63,28 @@ def shift(self, x, y, rotate=False):
"""
auto_write = self.auto_write
self._auto_write = False
if x > 0: # Shift Right
if x > 0: # Shift Right
for _ in range(x):
for row in range(0, self.rows):
last_pixel = self[self.columns - 1, row] if rotate else 0
for col in range(self.columns - 1, 0, -1):
self[col, row] = self[col - 1, row]
self[0, row] = last_pixel
elif x < 0: # Shift Left
elif x < 0: # Shift Left
for _ in range(-x):
for row in range(0, self.rows):
last_pixel = self[0, row] if rotate else 0
for col in range(0, self.columns - 1):
self[col, row] = self[col + 1, row]
self[self.columns - 1, row] = last_pixel
if y > 0: # Shift Up
if y > 0: # Shift Up
for _ in range(y):
for col in range(0, self.columns):
last_pixel = self[col, self.rows - 1] if rotate else 0
for row in range(self.rows - 1, 0, -1):
self[col, row] = self[col, row - 1]
self[col, 0] = last_pixel
elif y < 0: # Shift Down
elif y < 0: # Shift Down
for _ in range(-y):
for col in range(0, self.columns):
last_pixel = self[col, 0] if rotate else 0
Expand All @@ -92,7 +94,8 @@ def shift(self, x, y, rotate=False):
self._auto_write = auto_write
if auto_write:
self.show()
#pylint: enable=too-many-branches

# pylint: enable=too-many-branches

def shift_right(self, rotate=False):
"""
Expand Down Expand Up @@ -131,12 +134,15 @@ def image(self, img):
be in 1 bit mode and a size equal to the display size."""
imwidth, imheight = img.size
if imwidth != self.columns or imheight != self.rows:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
.format(self.columns, self.rows))
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.columns, self.rows
)
)
# Grab all the pixels from the image, faster than getpixel.
pixels = img.convert('1').load()
pixels = img.convert("1").load()
# Iterate through the pixels
for x in range(self.columns): # yes this double loop is slow,
for x in range(self.columns): # yes this double loop is slow,
for y in range(self.rows): # but these displays are small!
self.pixel(x, y, pixels[(x, y)])
if self._auto_write:
Expand All @@ -152,8 +158,10 @@ def rows(self):
"""Read-only property for number of rows"""
return self._rows


class Matrix16x8(Matrix8x8):
"""The matrix wing."""

_columns = 16

def pixel(self, x, y, color=None):
Expand All @@ -165,10 +173,12 @@ def pixel(self, x, y, color=None):
if x >= 8:
x -= 8
y += 8
return super()._pixel(y, x, color)
return super()._pixel(y, x, color) # pylint: disable=arguments-out-of-order


class MatrixBackpack16x8(Matrix16x8):
"""A double matrix backpack."""

def pixel(self, x, y, color=None):
"""Get or set the color of a given pixel."""
if not 0 <= x <= 15:
Expand All @@ -177,6 +187,7 @@ def pixel(self, x, y, color=None):
return None
return super()._pixel(x, y, color)


class Matrix8x8x2(Matrix8x8):
"""A bi-color matrix."""

Expand All @@ -200,8 +211,8 @@ def pixel(self, x, y, color=None):

def fill(self, color):
"""Fill the whole display with the given color."""
fill1 = 0xff if color & 0x01 else 0x00
fill2 = 0xff if color & 0x02 else 0x00
fill1 = 0xFF if color & 0x01 else 0x00
fill2 = 0xFF if color & 0x02 else 0x00
for i in range(8):
self._set_buffer(i * 2, fill1)
self._set_buffer(i * 2 + 1, fill2)
Expand All @@ -213,12 +224,15 @@ def image(self, img):
be a size equal to the display size."""
imwidth, imheight = img.size
if imwidth != self.columns or imheight != self.rows:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
.format(self.columns, self.rows))
raise ValueError(
"Image must be same dimensions as display ({0}x{1}).".format(
self.columns, self.rows
)
)
# Grab all the pixels from the image, faster than getpixel.
pixels = img.convert('RGB').load()
pixels = img.convert("RGB").load()
# Iterate through the pixels
for x in range(self.columns): # yes this double loop is slow,
for x in range(self.columns): # yes this double loop is slow,
for y in range(self.rows): # but these displays are small!
if pixels[(x, y)] == (255, 0, 0):
self.pixel(x, y, self.LED_RED)
Expand Down
Loading