Skip to content

Commit 418ca98

Browse files
authored
Merge pull request #90 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 61adb7a + d62bbf9 commit 418ca98

16 files changed

+236
-134
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
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

adafruit_circuitplayground/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"""Verifies which board is being used and imports the appropriate module."""
2424

2525
import sys
26-
if sys.platform == 'nRF52840':
26+
27+
if sys.platform == "nRF52840":
2728
from .bluefruit import cpb as cp
28-
elif sys.platform == 'Atmel SAMD21':
29+
elif sys.platform == "Atmel SAMD21":
2930
from .express import cpx as cp

adafruit_circuitplayground/bluefruit.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,35 @@ class Bluefruit(CircuitPlaygroundBase):
5757

5858
def __init__(self):
5959
# Only create the cpb module member when we aren't being imported by Sphinx
60-
if ("__module__" in dir(digitalio.DigitalInOut) and
61-
digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"):
60+
if (
61+
"__module__" in dir(digitalio.DigitalInOut)
62+
and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"
63+
):
6264
return
6365

6466
super().__init__()
6567

6668
self._sample = None
6769

6870
# Define mic/sound sensor:
69-
self._mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA,
70-
sample_rate=16000, bit_depth=16)
71+
self._mic = audiobusio.PDMIn(
72+
board.MICROPHONE_CLOCK,
73+
board.MICROPHONE_DATA,
74+
sample_rate=16000,
75+
bit_depth=16,
76+
)
7177
self._samples = None
7278

7379
@staticmethod
7480
def _normalized_rms(values):
7581
mean_values = int(sum(values) / len(values))
76-
return math.sqrt(sum(float(sample - mean_values) * (sample - mean_values)
77-
for sample in values) / len(values))
82+
return math.sqrt(
83+
sum(
84+
float(sample - mean_values) * (sample - mean_values)
85+
for sample in values
86+
)
87+
/ len(values)
88+
)
7889

7990
@property
8091
def sound_level(self):
@@ -94,7 +105,7 @@ def sound_level(self):
94105
print(cpb.sound_level)
95106
"""
96107
if self._sample is None:
97-
self._samples = array.array('H', [0] * 160)
108+
self._samples = array.array("H", [0] * 160)
98109
self._mic.record(self._samples, len(self._samples))
99110
return self._normalized_rms(self._samples)
100111

adafruit_circuitplayground/circuit_playground_base.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@
3939
import math
4040
import array
4141
import time
42+
4243
try:
4344
import audiocore
4445
except ImportError:
4546
import audioio as audiocore
46-
import adafruit_lis3dh
47-
import adafruit_thermistor
4847
import analogio
4948
import board
5049
import busio
5150
import digitalio
51+
import adafruit_lis3dh
52+
import adafruit_thermistor
5253
import neopixel
5354
import touchio
5455
import gamepad
@@ -60,6 +61,7 @@
6061

6162
class Photocell:
6263
"""Simple driver for analog photocell on the Circuit Playground Express and Bluefruit."""
64+
6365
# pylint: disable=too-few-public-methods
6466
def __init__(self, pin):
6567
self._photocell = analogio.AnalogIn(pin)
@@ -71,7 +73,7 @@ def light(self):
7173
return self._photocell.value * 330 // (2 ** 16)
7274

7375

74-
class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
76+
class CircuitPlaygroundBase: # pylint: disable=too-many-public-methods
7577
"""Circuit Playground base class."""
7678

7779
_audio_out = None
@@ -93,7 +95,9 @@ def __init__(self):
9395
self._pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
9496

9597
# Define sensors:
96-
self._temp = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
98+
self._temp = adafruit_thermistor.Thermistor(
99+
board.TEMPERATURE, 10000, 10000, 25, 3950
100+
)
97101
self._light = Photocell(board.LIGHT)
98102

99103
# Define touch:
@@ -103,13 +107,24 @@ def __init__(self):
103107
# For example, after `cp.touch_A2`, self._touches is equivalent to:
104108
# [None, board.A1, touchio.TouchIn(board.A2), board.A3, ...]
105109
# Slot 0 is not used (A0 is not allowed as a touch pin).
106-
self._touches = [None, board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.TX]
110+
self._touches = [
111+
None,
112+
board.A1,
113+
board.A2,
114+
board.A3,
115+
board.A4,
116+
board.A5,
117+
board.A6,
118+
board.TX,
119+
]
107120
self._touch_threshold_adjustment = 0
108121

109122
# Define acceleration:
110123
self._i2c = busio.I2C(board.ACCELEROMETER_SCL, board.ACCELEROMETER_SDA)
111124
self._int1 = digitalio.DigitalInOut(board.ACCELEROMETER_INTERRUPT)
112-
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(self._i2c, address=0x19, int1=self._int1)
125+
self._lis3dh = adafruit_lis3dh.LIS3DH_I2C(
126+
self._i2c, address=0x19, int1=self._int1
127+
)
113128
self._lis3dh.range = adafruit_lis3dh.RANGE_8_G
114129

115130
# Define audio:
@@ -148,9 +163,13 @@ def detect_taps(self):
148163
def detect_taps(self, value):
149164
self._detect_taps = value
150165
if value == 1:
151-
self._lis3dh.set_tap(value, 90, time_limit=4, time_latency=50, time_window=255)
166+
self._lis3dh.set_tap(
167+
value, 90, time_limit=4, time_latency=50, time_window=255
168+
)
152169
if value == 2:
153-
self._lis3dh.set_tap(value, 60, time_limit=10, time_latency=50, time_window=255)
170+
self._lis3dh.set_tap(
171+
value, 60, time_limit=10, time_latency=50, time_window=255
172+
)
154173

155174
@property
156175
def tapped(self):
@@ -515,7 +534,7 @@ def were_pressed(self):
515534
"""
516535
ret = set()
517536
pressed = self.gamepad.get_pressed()
518-
for button, mask in (('A', 0x01), ('B', 0x02)):
537+
for button, mask in (("A", 0x01), ("B", 0x02)):
519538
if mask & pressed:
520539
ret.add(button)
521540
return ret
@@ -619,7 +638,7 @@ def _sine_sample(length):
619638
tone_volume = (2 ** 15) - 1
620639
shift = 2 ** 15
621640
for i in range(length):
622-
yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)
641+
yield int(tone_volume * math.sin(2 * math.pi * (i / length)) + shift)
623642

624643
def _generate_sample(self, length=100):
625644
if self._sample is not None:

adafruit_circuitplayground/express.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,20 @@
3535
"""
3636

3737
import sys
38-
import audioio
3938
import digitalio
40-
# pylint: disable=wrong-import-position
39+
import audioio
40+
4141
try:
42-
lib_index = sys.path.index("/lib") # pylint: disable=invalid-name
42+
lib_index = sys.path.index("/lib") # pylint: disable=invalid-name
4343
if lib_index < sys.path.index(".frozen"):
4444
# Prefer frozen modules over those in /lib.
4545
sys.path.insert(lib_index, ".frozen")
4646
except ValueError:
4747
# Don't change sys.path if it doesn't contain "lib" or ".frozen".
4848
pass
49-
from adafruit_circuitplayground.circuit_playground_base import CircuitPlaygroundBase
49+
from adafruit_circuitplayground.circuit_playground_base import ( # pylint: disable=wrong-import-position
50+
CircuitPlaygroundBase,
51+
)
5052

5153

5254
__version__ = "0.0.0-auto.0"
@@ -65,16 +67,20 @@ class Express(CircuitPlaygroundBase):
6567

6668
def __init__(self):
6769
# Only create the cpx module member when we aren't being imported by Sphinx
68-
if ("__module__" in dir(digitalio.DigitalInOut) and
69-
digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"):
70+
if (
71+
"__module__" in dir(digitalio.DigitalInOut)
72+
and digitalio.DigitalInOut.__module__ == "sphinx.ext.autodoc"
73+
):
7074
return
7175

7276
super().__init__()
7377

7478
@property
7579
def _unsupported(self):
7680
"""This feature is not supported on Circuit Playground Express."""
77-
raise NotImplementedError("This feature is not supported on Circuit Playground Express.")
81+
raise NotImplementedError(
82+
"This feature is not supported on Circuit Playground Express."
83+
)
7884

7985
# The following is a list of the features available in other Circuit Playground modules but
8086
# not available for Circuit Playground Express. If called while using a Circuit Playground

0 commit comments

Comments
 (0)