Skip to content

Commit 9e73ebb

Browse files
authored
Merge pull request #73 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 41be105 + a9ff0ff commit 9e73ebb

13 files changed

+312
-255
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

.pylintrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
#notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123123
notes=FIXME,XXX
124124

125125

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

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

306306
# Include a hint for the correct naming format with invalid-name
307307
include-naming-hint=no
@@ -423,7 +423,7 @@ max-returns=6
423423
max-statements=50
424424

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

428428

429429
[EXCEPTIONS]

adafruit_ht16k33/bargraph.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
__version__ = "0.0.0-auto.0"
3434
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
3535

36+
3637
class Bicolor24(HT16K33):
3738
"""Bi-color 24-bar bargraph display."""
3839

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

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

6061
def fill(self, color):
6162
"""Fill the whole display with the given color."""

adafruit_ht16k33/ht16k33.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class HT16K33:
4949
set. If False, `show` must be called explicitly.
5050
:param float brightness: 0.0 - 1.0 default brightness level.
5151
"""
52+
5253
def __init__(self, i2c, address=0x70, auto_write=True, brightness=1.0):
5354
self.i2c_device = i2c_device.I2CDevice(i2c, address)
5455
self._temp = bytearray(1)
@@ -74,11 +75,10 @@ def blink_rate(self):
7475
@blink_rate.setter
7576
def blink_rate(self, rate=None):
7677
if not 0 <= rate <= 3:
77-
raise ValueError('Blink rate must be an integer in the range: 0-3')
78+
raise ValueError("Blink rate must be an integer in the range: 0-3")
7879
rate = rate & 0x03
7980
self._blink_rate = rate
80-
self._write_cmd(_HT16K33_BLINK_CMD |
81-
_HT16K33_BLINK_DISPLAYON | rate << 1)
81+
self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1)
8282

8383
@property
8484
def brightness(self):
@@ -88,7 +88,9 @@ def brightness(self):
8888
@brightness.setter
8989
def brightness(self, brightness):
9090
if not 0.0 <= brightness <= 1.0:
91-
raise ValueError('Brightness must be a decimal number in the range: 0.0-1.0')
91+
raise ValueError(
92+
"Brightness must be a decimal number in the range: 0.0-1.0"
93+
)
9294

9395
self._brightness = brightness
9496
xbright = round(15 * brightness)
@@ -105,7 +107,7 @@ def auto_write(self, auto_write):
105107
if isinstance(auto_write, bool):
106108
self._auto_write = auto_write
107109
else:
108-
raise ValueError('Must set to either True or False.')
110+
raise ValueError("Must set to either True or False.")
109111

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

117119
def fill(self, color):
118120
"""Fill the whole display with the given color."""
119-
fill = 0xff if color else 0x00
121+
fill = 0xFF if color else 0x00
120122
for i in range(16):
121-
self._buffer[i+1] = fill
123+
self._buffer[i + 1] = fill
122124
if self._auto_write:
123125
self.show()
124126

125127
def _pixel(self, x, y, color=None):
126-
addr = 2*y + x // 8
128+
addr = 2 * y + x // 8
127129
mask = 1 << x % 8
128130
if color is None:
129131
return bool(self._buffer[addr + 1] & mask)
@@ -138,7 +140,7 @@ def _pixel(self, x, y, color=None):
138140
return None
139141

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

143145
def _get_buffer(self, i):
144-
return self._buffer[i+1] # Offset by 1 to move past register address.
146+
return self._buffer[i + 1] # Offset by 1 to move past register address.

adafruit_ht16k33/matrix.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
__version__ = "0.0.0-auto.0"
3131
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HT16K33.git"
3232

33+
3334
class Matrix8x8(HT16K33):
3435
"""A single matrix."""
36+
3537
_columns = 8
3638
_rows = 8
3739

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

55-
#pylint: disable=too-many-branches
57+
# pylint: disable=too-many-branches
5658
def shift(self, x, y, rotate=False):
5759
"""
5860
Shift pixels by x and y
@@ -61,28 +63,28 @@ def shift(self, x, y, rotate=False):
6163
"""
6264
auto_write = self.auto_write
6365
self._auto_write = False
64-
if x > 0: # Shift Right
66+
if x > 0: # Shift Right
6567
for _ in range(x):
6668
for row in range(0, self.rows):
6769
last_pixel = self[self.columns - 1, row] if rotate else 0
6870
for col in range(self.columns - 1, 0, -1):
6971
self[col, row] = self[col - 1, row]
7072
self[0, row] = last_pixel
71-
elif x < 0: # Shift Left
73+
elif x < 0: # Shift Left
7274
for _ in range(-x):
7375
for row in range(0, self.rows):
7476
last_pixel = self[0, row] if rotate else 0
7577
for col in range(0, self.columns - 1):
7678
self[col, row] = self[col + 1, row]
7779
self[self.columns - 1, row] = last_pixel
78-
if y > 0: # Shift Up
80+
if y > 0: # Shift Up
7981
for _ in range(y):
8082
for col in range(0, self.columns):
8183
last_pixel = self[col, self.rows - 1] if rotate else 0
8284
for row in range(self.rows - 1, 0, -1):
8385
self[col, row] = self[col, row - 1]
8486
self[col, 0] = last_pixel
85-
elif y < 0: # Shift Down
87+
elif y < 0: # Shift Down
8688
for _ in range(-y):
8789
for col in range(0, self.columns):
8890
last_pixel = self[col, 0] if rotate else 0
@@ -92,7 +94,8 @@ def shift(self, x, y, rotate=False):
9294
self._auto_write = auto_write
9395
if auto_write:
9496
self.show()
95-
#pylint: enable=too-many-branches
97+
98+
# pylint: enable=too-many-branches
9699

97100
def shift_right(self, rotate=False):
98101
"""
@@ -131,12 +134,15 @@ def image(self, img):
131134
be in 1 bit mode and a size equal to the display size."""
132135
imwidth, imheight = img.size
133136
if imwidth != self.columns or imheight != self.rows:
134-
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
135-
.format(self.columns, self.rows))
137+
raise ValueError(
138+
"Image must be same dimensions as display ({0}x{1}).".format(
139+
self.columns, self.rows
140+
)
141+
)
136142
# Grab all the pixels from the image, faster than getpixel.
137-
pixels = img.convert('1').load()
143+
pixels = img.convert("1").load()
138144
# Iterate through the pixels
139-
for x in range(self.columns): # yes this double loop is slow,
145+
for x in range(self.columns): # yes this double loop is slow,
140146
for y in range(self.rows): # but these displays are small!
141147
self.pixel(x, y, pixels[(x, y)])
142148
if self._auto_write:
@@ -152,8 +158,10 @@ def rows(self):
152158
"""Read-only property for number of rows"""
153159
return self._rows
154160

161+
155162
class Matrix16x8(Matrix8x8):
156163
"""The matrix wing."""
164+
157165
_columns = 16
158166

159167
def pixel(self, x, y, color=None):
@@ -165,10 +173,12 @@ def pixel(self, x, y, color=None):
165173
if x >= 8:
166174
x -= 8
167175
y += 8
168-
return super()._pixel(y, x, color)
176+
return super()._pixel(y, x, color) # pylint: disable=arguments-out-of-order
177+
169178

170179
class MatrixBackpack16x8(Matrix16x8):
171180
"""A double matrix backpack."""
181+
172182
def pixel(self, x, y, color=None):
173183
"""Get or set the color of a given pixel."""
174184
if not 0 <= x <= 15:
@@ -177,6 +187,7 @@ def pixel(self, x, y, color=None):
177187
return None
178188
return super()._pixel(x, y, color)
179189

190+
180191
class Matrix8x8x2(Matrix8x8):
181192
"""A bi-color matrix."""
182193

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

201212
def fill(self, color):
202213
"""Fill the whole display with the given color."""
203-
fill1 = 0xff if color & 0x01 else 0x00
204-
fill2 = 0xff if color & 0x02 else 0x00
214+
fill1 = 0xFF if color & 0x01 else 0x00
215+
fill2 = 0xFF if color & 0x02 else 0x00
205216
for i in range(8):
206217
self._set_buffer(i * 2, fill1)
207218
self._set_buffer(i * 2 + 1, fill2)
@@ -213,12 +224,15 @@ def image(self, img):
213224
be a size equal to the display size."""
214225
imwidth, imheight = img.size
215226
if imwidth != self.columns or imheight != self.rows:
216-
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
217-
.format(self.columns, self.rows))
227+
raise ValueError(
228+
"Image must be same dimensions as display ({0}x{1}).".format(
229+
self.columns, self.rows
230+
)
231+
)
218232
# Grab all the pixels from the image, faster than getpixel.
219-
pixels = img.convert('RGB').load()
233+
pixels = img.convert("RGB").load()
220234
# Iterate through the pixels
221-
for x in range(self.columns): # yes this double loop is slow,
235+
for x in range(self.columns): # yes this double loop is slow,
222236
for y in range(self.rows): # but these displays are small!
223237
if pixels[(x, y)] == (255, 0, 0):
224238
self.pixel(x, y, self.LED_RED)

0 commit comments

Comments
 (0)