Skip to content

Commit 1d272b9

Browse files
authored
Merge pull request #14 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents f3e2394 + 2a3b5b7 commit 1d272b9

File tree

5 files changed

+178
-116
lines changed

5 files changed

+178
-116
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_trellis.py

Lines changed: 73 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,84 @@
5454

5555
# HT16K33 Command Contstants
5656
# pylint: disable=bad-whitespace, invalid-name
57-
_HT16K33_OSCILATOR_ON = const(0x21)
58-
_HT16K33_BLINK_CMD = const(0x80)
59-
_HT16K33_BLINK_DISPLAYON = const(0x01)
60-
_HT16K33_CMD_BRIGHTNESS = const(0xE0)
61-
_HT16K33_KEY_READ_CMD = const(0x40)
57+
_HT16K33_OSCILATOR_ON = const(0x21)
58+
_HT16K33_BLINK_CMD = const(0x80)
59+
_HT16K33_BLINK_DISPLAYON = const(0x01)
60+
_HT16K33_CMD_BRIGHTNESS = const(0xE0)
61+
_HT16K33_KEY_READ_CMD = const(0x40)
6262

6363
# LED Lookup Table
64-
ledLUT = (0x3A, 0x37, 0x35, 0x34,
65-
0x28, 0x29, 0x23, 0x24,
66-
0x16, 0x1B, 0x11, 0x10,
67-
0x0E, 0x0D, 0x0C, 0x02)
64+
ledLUT = (
65+
0x3A,
66+
0x37,
67+
0x35,
68+
0x34,
69+
0x28,
70+
0x29,
71+
0x23,
72+
0x24,
73+
0x16,
74+
0x1B,
75+
0x11,
76+
0x10,
77+
0x0E,
78+
0x0D,
79+
0x0C,
80+
0x02,
81+
)
6882

6983
# Button Loookup Table
70-
buttonLUT = (0x07, 0x04, 0x02, 0x22,
71-
0x05, 0x06, 0x00, 0x01,
72-
0x03, 0x10, 0x30, 0x21,
73-
0x13, 0x12, 0x11, 0x31)
84+
buttonLUT = (
85+
0x07,
86+
0x04,
87+
0x02,
88+
0x22,
89+
0x05,
90+
0x06,
91+
0x00,
92+
0x01,
93+
0x03,
94+
0x10,
95+
0x30,
96+
0x21,
97+
0x13,
98+
0x12,
99+
0x11,
100+
0x31,
101+
)
74102
# pylint: enable=bad-whitespace, invalid-name
75103
# pylint: disable=missing-docstring, protected-access
76-
class TrellisLEDs():
104+
class TrellisLEDs:
77105
def __init__(self, trellis_obj):
78106
self._parent = trellis_obj
79107

80108
def __getitem__(self, x):
81109
if 0 < x >= self._parent._num_leds:
82-
raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1))
110+
raise ValueError(
111+
("LED number must be between 0 -", self._parent._num_leds - 1)
112+
)
83113
led = ledLUT[x % 16] >> 4
84-
mask = 1 << (ledLUT[x % 16] & 0x0f)
85-
return bool(((self._parent._led_buffer[x // 16][(led * 2) + 1] | \
86-
self._parent._led_buffer[x // 16][(led * 2) + 2] << 8) & mask) > 0)
114+
mask = 1 << (ledLUT[x % 16] & 0x0F)
115+
return bool(
116+
(
117+
(
118+
self._parent._led_buffer[x // 16][(led * 2) + 1]
119+
| self._parent._led_buffer[x // 16][(led * 2) + 2] << 8
120+
)
121+
& mask
122+
)
123+
> 0
124+
)
87125

88126
def __setitem__(self, x, value):
89127
if 0 < x >= self._parent._num_leds:
90-
raise ValueError(('LED number must be between 0 -', self._parent._num_leds - 1))
128+
raise ValueError(
129+
("LED number must be between 0 -", self._parent._num_leds - 1)
130+
)
91131
led = ledLUT[x % 16] >> 4
92-
mask = 1 << (ledLUT[x % 16] & 0x0f)
132+
mask = 1 << (ledLUT[x % 16] & 0x0F)
93133
if value:
94-
self._parent._led_buffer[x // 16][(led * 2) + 1] |= (mask & 0xff)
134+
self._parent._led_buffer[x // 16][(led * 2) + 1] |= mask & 0xFF
95135
self._parent._led_buffer[x // 16][(led * 2) + 2] |= mask >> 8
96136
elif not value:
97137
self._parent._led_buffer[x // 16][(led * 2) + 1] &= ~mask
@@ -101,17 +141,21 @@ def __setitem__(self, x, value):
101141

102142
if self._parent._auto_show:
103143
self._parent.show()
144+
104145
# pylint: disable=invalid-name
105146
def fill(self, on):
106-
fill = 0xff if on else 0x00
147+
fill = 0xFF if on else 0x00
107148
for buff in range(len(self._parent._i2c_devices)):
108149
for i in range(1, 17):
109150
self._parent._led_buffer[buff][i] = fill
110151
if self._parent._auto_show:
111152
self._parent.show()
153+
154+
112155
# pylint: enable=missing-docstring, protected-access
113156

114-
class Trellis():
157+
158+
class Trellis:
115159
"""
116160
Driver base for a single Trellis Board
117161
@@ -128,6 +172,7 @@ class Trellis():
128172
:linenos:
129173
130174
"""
175+
131176
def __init__(self, i2c, addresses=None):
132177
if addresses is None:
133178
addresses = [0x70]
@@ -173,11 +218,10 @@ def blink_rate(self):
173218
@blink_rate.setter
174219
def blink_rate(self, rate):
175220
if not 0 <= rate <= 3:
176-
raise ValueError('Blink rate must be an integer in the range: 0-3')
221+
raise ValueError("Blink rate must be an integer in the range: 0-3")
177222
rate = rate & 0x03
178223
self._blink_rate = rate
179-
self._write_cmd(_HT16K33_BLINK_CMD |
180-
_HT16K33_BLINK_DISPLAYON | rate << 1)
224+
self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1)
181225

182226
@property
183227
def brightness(self):
@@ -189,7 +233,7 @@ def brightness(self):
189233
@brightness.setter
190234
def brightness(self, brightness):
191235
if not 0 <= brightness <= 15:
192-
raise ValueError('Brightness must be an integer in the range: 0-15')
236+
raise ValueError("Brightness must be an integer in the range: 0-15")
193237
brightness = brightness & 0x0F
194238
self._brightness = brightness
195239
self._write_cmd(_HT16K33_CMD_BRIGHTNESS | brightness)
@@ -241,11 +285,11 @@ def read_buttons(self):
241285
return pressed, released
242286

243287
def _is_pressed(self, button):
244-
mask = 1 << (buttonLUT[button % 16] & 0x0f)
288+
mask = 1 << (buttonLUT[button % 16] & 0x0F)
245289
return self._buttons[button // 16][1][(buttonLUT[button % 16] >> 4)] & mask
246290

247291
def _was_pressed(self, button):
248-
mask = 1 << (buttonLUT[button % 16] & 0x0f)
292+
mask = 1 << (buttonLUT[button % 16] & 0x0F)
249293
return self._buttons[button // 16][0][(buttonLUT[button % 16] >> 4)] & mask
250294

251295
def _just_pressed(self, button):

docs/conf.py

Lines changed: 72 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,59 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.todo",
1617
]
1718

1819
# Uncomment the below if you use native CircuitPython modules such as
1920
# digitalio, micropython and busio. List the modules you use. Without it, the
2021
# autodoc module docs will fail to generate with a warning.
2122
# autodoc_mock_imports = ["micropython", "adafruit_bus_device"]
2223

23-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
24+
intersphinx_mapping = {
25+
"python": ("https://docs.python.org/3.4", None),
26+
"BusDevice": (
27+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
28+
None,
29+
),
30+
"Register": (
31+
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
32+
None,
33+
),
34+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
35+
}
2436

2537
# Add any paths that contain templates here, relative to this directory.
26-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
2739

28-
source_suffix = '.rst'
40+
source_suffix = ".rst"
2941

3042
# The master toctree document.
31-
master_doc = 'index'
43+
master_doc = "index"
3244

3345
# General information about the project.
34-
project = u'Adafruit Trellis Library'
35-
copyright = u'2017 Michael Schroeder'
36-
author = u'Michael Schroeder'
46+
project = u"Adafruit Trellis Library"
47+
copyright = u"2017 Michael Schroeder"
48+
author = u"Michael Schroeder"
3749

3850
# The version info for the project you're documenting, acts as replacement for
3951
# |version| and |release|, also used in various other places throughout the
4052
# built documents.
4153
#
4254
# The short X.Y version.
43-
version = u'1.0'
55+
version = u"1.0"
4456
# The full version, including alpha/beta/rc tags.
45-
release = u'1.0'
57+
release = u"1.0"
4658

4759
# The language for content autogenerated by Sphinx. Refer to documentation
4860
# for a list of supported languages.
@@ -54,7 +66,7 @@
5466
# List of patterns, relative to source directory, that match files and
5567
# directories to ignore when looking for source files.
5668
# This patterns also effect to html_static_path and html_extra_path
57-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
69+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5870

5971
# The reST default role (used for this markup: `text`) to use for all
6072
# documents.
@@ -66,7 +78,7 @@
6678
add_function_parentheses = True
6779

6880
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = 'sphinx'
81+
pygments_style = "sphinx"
7082

7183
# If true, `todo` and `todoList` produce output, else they produce nothing.
7284
todo_include_todos = False
@@ -80,68 +92,76 @@
8092
# The theme to use for HTML and HTML Help pages. See the documentation for
8193
# a list of builtin themes.
8294
#
83-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
95+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8496

8597
if not on_rtd: # only import and set the theme if we're building docs locally
8698
try:
8799
import sphinx_rtd_theme
88-
html_theme = 'sphinx_rtd_theme'
89-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
100+
101+
html_theme = "sphinx_rtd_theme"
102+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
90103
except:
91-
html_theme = 'default'
92-
html_theme_path = ['.']
104+
html_theme = "default"
105+
html_theme_path = ["."]
93106
else:
94-
html_theme_path = ['.']
107+
html_theme_path = ["."]
95108

96109
# Add any paths that contain custom static files (such as style sheets) here,
97110
# relative to this directory. They are copied after the builtin static files,
98111
# so a file named "default.css" will overwrite the builtin "default.css".
99-
html_static_path = ['_static']
112+
html_static_path = ["_static"]
100113

101114
# The name of an image file (relative to this directory) to use as a favicon of
102115
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103116
# pixels large.
104117
#
105-
html_favicon = '_static/favicon.ico'
118+
html_favicon = "_static/favicon.ico"
106119

107120
# Output file base name for HTML help builder.
108-
htmlhelp_basename = 'AdafruitTrellisLibrarydoc'
121+
htmlhelp_basename = "AdafruitTrellisLibrarydoc"
109122

110123
# -- Options for LaTeX output ---------------------------------------------
111124

112125
latex_elements = {
113-
# The paper size ('letterpaper' or 'a4paper').
114-
#
115-
# 'papersize': 'letterpaper',
116-
117-
# The font size ('10pt', '11pt' or '12pt').
118-
#
119-
# 'pointsize': '10pt',
120-
121-
# Additional stuff for the LaTeX preamble.
122-
#
123-
# 'preamble': '',
124-
125-
# Latex figure (float) alignment
126-
#
127-
# 'figure_align': 'htbp',
126+
# The paper size ('letterpaper' or 'a4paper').
127+
#
128+
# 'papersize': 'letterpaper',
129+
# The font size ('10pt', '11pt' or '12pt').
130+
#
131+
# 'pointsize': '10pt',
132+
# Additional stuff for the LaTeX preamble.
133+
#
134+
# 'preamble': '',
135+
# Latex figure (float) alignment
136+
#
137+
# 'figure_align': 'htbp',
128138
}
129139

130140
# Grouping the document tree into LaTeX files. List of tuples
131141
# (source start file, target name, title,
132142
# author, documentclass [howto, manual, or own class]).
133143
latex_documents = [
134-
(master_doc, 'AdafruitTrellisLibrary.tex', u'AdafruitTrellis Library Documentation',
135-
author, 'manual'),
144+
(
145+
master_doc,
146+
"AdafruitTrellisLibrary.tex",
147+
u"AdafruitTrellis Library Documentation",
148+
author,
149+
"manual",
150+
),
136151
]
137152

138153
# -- Options for manual page output ---------------------------------------
139154

140155
# One entry per manual page. List of tuples
141156
# (source start file, name, description, authors, manual section).
142157
man_pages = [
143-
(master_doc, 'AdafruitTrellislibrary', u'Adafruit Trellis Library Documentation',
144-
[author], 1)
158+
(
159+
master_doc,
160+
"AdafruitTrellislibrary",
161+
u"Adafruit Trellis Library Documentation",
162+
[author],
163+
1,
164+
)
145165
]
146166

147167
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +170,13 @@
150170
# (source start file, target name, title, author,
151171
# dir menu entry, description, category)
152172
texinfo_documents = [
153-
(master_doc, 'AdafruitTrellisLibrary', u'Adafruit Trellis Library Documentation',
154-
author, 'AdafruitTrellisLibrary', 'One line description of project.',
155-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"AdafruitTrellisLibrary",
176+
u"Adafruit Trellis Library Documentation",
177+
author,
178+
"AdafruitTrellisLibrary",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
156182
]

0 commit comments

Comments
 (0)