Skip to content

Commit 9e9da49

Browse files
authored
Merge pull request #20 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents e817b57 + b5b6299 commit 9e9da49

File tree

6 files changed

+135
-113
lines changed

6 files changed

+135
-113
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_tlc5947.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@
4848
# Globally disable protected access. Ppylint can't figure out the
4949
# context for using internal decorate classes below. In these cases protectected
5050
# access is by design for the internal class.
51-
#pylint: disable=protected-access
51+
# pylint: disable=protected-access
5252

5353
_CHANNELS = 24
54-
_STOREBYTES = _CHANNELS + _CHANNELS//2
54+
_STOREBYTES = _CHANNELS + _CHANNELS // 2
55+
5556

5657
class TLC5947:
5758
"""TLC5947 12-bit 24 channel LED PWM driver. Create an instance of this by
@@ -105,7 +106,9 @@ def duty_cycle(self):
105106
@duty_cycle.setter
106107
def duty_cycle(self, val):
107108
if val < 0 or val > 65535:
108-
raise ValueError("PWM intensity {0} outside supported range [0;65535]".format(val))
109+
raise ValueError(
110+
"PWM intensity {0} outside supported range [0;65535]".format(val)
111+
)
109112
# Convert to 12-bit value (quantization error will occur!).
110113
val = (val >> 4) & 0xFFF
111114
self._tlc5947._set_gs_value(self._channel, val)
@@ -121,16 +124,18 @@ def frequency(self):
121124
# pylint bug misidentifies the following as a regular function instead
122125
# of the associated setter: https://github.com/PyCQA/pylint/issues/870
123126
# Must disable a few checks to make pylint happy (ugh).
124-
#pylint: disable=no-self-use,unused-argument
127+
# pylint: disable=no-self-use,unused-argument
125128
@frequency.setter
126129
def frequency(self, val):
127-
raise RuntimeError('Cannot set TLC5947 PWM frequency!')
128-
#pylint: enable=no-self-use,unused-argument
130+
raise RuntimeError("Cannot set TLC5947 PWM frequency!")
129131

132+
# pylint: enable=no-self-use,unused-argument
130133

131134
def __init__(self, spi, latch, *, auto_write=True, num_drivers=1):
132135
if num_drivers < 1:
133-
raise ValueError("Need at least one driver; {0} is not supported.".format(num_drivers))
136+
raise ValueError(
137+
"Need at least one driver; {0} is not supported.".format(num_drivers)
138+
)
134139
self._spi = spi
135140
self._latch = latch
136141
self._latch.switch_to_output(value=False)
@@ -157,7 +162,7 @@ def write(self):
157162
# First ensure latch is low.
158163
self._latch.value = False
159164
# Write out the bits.
160-
self._spi.write(self._shift_reg, start=0, end=_STOREBYTES*self._n +1)
165+
self._spi.write(self._shift_reg, start=0, end=_STOREBYTES * self._n + 1)
161166
# Then toggle latch high and low to set the value.
162167
self._latch.value = True
163168
self._latch.value = False
@@ -170,7 +175,8 @@ def _get_gs_value(self, channel):
170175
# Disable should be removed when refactor can be tested
171176
if channel < 0 or channel >= _CHANNELS * self._n:
172177
raise ValueError(
173-
"Channel {0} not available with {1} board(s).".format(channel, self._n))
178+
"Channel {0} not available with {1} board(s).".format(channel, self._n)
179+
)
174180
# Invert channel position as the last channel needs to be written first.
175181
# I.e. is in the first position of the shift registr.
176182
channel = _CHANNELS * self._n - 1 - channel
@@ -182,7 +188,7 @@ def _get_gs_value(self, channel):
182188
start_offset = bit_offset % 8
183189
# Grab the high and low bytes.
184190
high_byte = self._shift_reg[byte_start]
185-
low_byte = self._shift_reg[byte_start+1]
191+
low_byte = self._shift_reg[byte_start + 1]
186192
if start_offset == 4:
187193
# Value starts in the lower 4 bits of the high bit so you can
188194
# just concat high with low byte and return the 12-bit value.
@@ -192,14 +198,17 @@ def _get_gs_value(self, channel):
192198
# 4 bits of low byte. Shift low byte and concat values.
193199
return ((high_byte << 4) | (low_byte >> 4)) & 0xFFF
194200
else:
195-
raise RuntimeError('Unsupported bit offset!')
201+
raise RuntimeError("Unsupported bit offset!")
196202

197203
def _set_gs_value(self, channel, val):
198204
if channel < 0 or channel >= _CHANNELS * self._n:
199205
raise ValueError(
200-
"Channel {0} not available with {1} board(s).".format(channel, self._n))
206+
"Channel {0} not available with {1} board(s).".format(channel, self._n)
207+
)
201208
if val < 0 or val > 4095:
202-
raise ValueError("PWM intensity {0} outside supported range [0;4095]".format(val))
209+
raise ValueError(
210+
"PWM intensity {0} outside supported range [0;4095]".format(val)
211+
)
203212

204213
# Invert channel position as the last channel needs to be written first.
205214
# I.e. is in the first position of the shift registr.
@@ -212,11 +221,11 @@ def _set_gs_value(self, channel, val):
212221
start_offset = bit_offset % 8
213222
# Grab the high and low bytes.
214223
high_byte = self._shift_reg[byte_start]
215-
low_byte = self._shift_reg[byte_start+1]
224+
low_byte = self._shift_reg[byte_start + 1]
216225
if start_offset == 4:
217226
# Value starts in the lower 4 bits of the high bit.
218227
high_byte &= 0b11110000
219-
high_byte |= (val >> 8)
228+
high_byte |= val >> 8
220229
low_byte = val & 0xFF
221230
elif start_offset == 0:
222231
# Value starts in the entire high byte and spills into upper
@@ -225,9 +234,9 @@ def _set_gs_value(self, channel, val):
225234
low_byte &= 0b00001111
226235
low_byte |= (val << 4) & 0xFF
227236
else:
228-
raise RuntimeError('Unsupported bit offset!')
237+
raise RuntimeError("Unsupported bit offset!")
229238
self._shift_reg[byte_start] = high_byte
230-
self._shift_reg[byte_start+1] = low_byte
239+
self._shift_reg[byte_start + 1] = low_byte
231240
# Write the updated shift register values if required.
232241
if self.auto_write:
233242
self.write()
@@ -256,7 +265,7 @@ def __getitem__(self, key):
256265
"""
257266
if key < 0: # allow reverse adressing with negative index
258267
key = key + _CHANNELS * self._n
259-
return self._get_gs_value(key) # does parameter checking
268+
return self._get_gs_value(key) # does parameter checking
260269

261270
def __setitem__(self, key, val):
262271
"""Set the 12-bit PWM value (0-4095) for the specified channel (0-max).
@@ -267,4 +276,4 @@ def __setitem__(self, key, val):
267276
"""
268277
if key < 0: # allow reverse adressing with negative index
269278
key = key + _CHANNELS * self._n
270-
self._set_gs_value(key, val) # does parameter checking
279+
self._set_gs_value(key, val) # does parameter checking

docs/conf.py

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,51 @@
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.viewcode',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.viewcode",
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 = ["digitalio", "busio"]
2223

23-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
24+
intersphinx_mapping = {
25+
"python": ("https://docs.python.org/3.4", None),
26+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
27+
}
2428

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

28-
source_suffix = '.rst'
32+
source_suffix = ".rst"
2933

3034
# The master toctree document.
31-
master_doc = 'index'
35+
master_doc = "index"
3236

3337
# General information about the project.
34-
project = u'Adafruit TLC5947 Library'
35-
copyright = u'2017 Tony DiCola'
36-
author = u'Tony DiCola'
38+
project = u"Adafruit TLC5947 Library"
39+
copyright = u"2017 Tony DiCola"
40+
author = u"Tony DiCola"
3741

3842
# The version info for the project you're documenting, acts as replacement for
3943
# |version| and |release|, also used in various other places throughout the
4044
# built documents.
4145
#
4246
# The short X.Y version.
43-
version = u'1.0'
47+
version = u"1.0"
4448
# The full version, including alpha/beta/rc tags.
45-
release = u'1.0'
49+
release = u"1.0"
4650

4751
# The language for content autogenerated by Sphinx. Refer to documentation
4852
# for a list of supported languages.
@@ -54,7 +58,7 @@
5458
# List of patterns, relative to source directory, that match files and
5559
# directories to ignore when looking for source files.
5660
# 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']
61+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5862

5963
# The reST default role (used for this markup: `text`) to use for all
6064
# documents.
@@ -66,7 +70,7 @@
6670
add_function_parentheses = True
6771

6872
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = 'sphinx'
73+
pygments_style = "sphinx"
7074

7175
# If true, `todo` and `todoList` produce output, else they produce nothing.
7276
todo_include_todos = False
@@ -80,68 +84,76 @@
8084
# The theme to use for HTML and HTML Help pages. See the documentation for
8185
# a list of builtin themes.
8286
#
83-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
87+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8488

8589
if not on_rtd: # only import and set the theme if we're building docs locally
8690
try:
8791
import sphinx_rtd_theme
88-
html_theme = 'sphinx_rtd_theme'
89-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
92+
93+
html_theme = "sphinx_rtd_theme"
94+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9095
except:
91-
html_theme = 'default'
92-
html_theme_path = ['.']
96+
html_theme = "default"
97+
html_theme_path = ["."]
9398
else:
94-
html_theme_path = ['.']
99+
html_theme_path = ["."]
95100

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

101106
# The name of an image file (relative to this directory) to use as a favicon of
102107
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103108
# pixels large.
104109
#
105-
html_favicon = '_static/favicon.ico'
110+
html_favicon = "_static/favicon.ico"
106111

107112
# Output file base name for HTML help builder.
108-
htmlhelp_basename = 'AdafruitTlc5947Librarydoc'
113+
htmlhelp_basename = "AdafruitTlc5947Librarydoc"
109114

110115
# -- Options for LaTeX output ---------------------------------------------
111116

112117
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',
118+
# The paper size ('letterpaper' or 'a4paper').
119+
#
120+
# 'papersize': 'letterpaper',
121+
# The font size ('10pt', '11pt' or '12pt').
122+
#
123+
# 'pointsize': '10pt',
124+
# Additional stuff for the LaTeX preamble.
125+
#
126+
# 'preamble': '',
127+
# Latex figure (float) alignment
128+
#
129+
# 'figure_align': 'htbp',
128130
}
129131

130132
# Grouping the document tree into LaTeX files. List of tuples
131133
# (source start file, target name, title,
132134
# author, documentclass [howto, manual, or own class]).
133135
latex_documents = [
134-
(master_doc, 'AdafruitTLC5947Library.tex', u'AdafruitTLC5947 Library Documentation',
135-
author, 'manual'),
136+
(
137+
master_doc,
138+
"AdafruitTLC5947Library.tex",
139+
u"AdafruitTLC5947 Library Documentation",
140+
author,
141+
"manual",
142+
),
136143
]
137144

138145
# -- Options for manual page output ---------------------------------------
139146

140147
# One entry per manual page. List of tuples
141148
# (source start file, name, description, authors, manual section).
142149
man_pages = [
143-
(master_doc, 'AdafruitTLC5947library', u'Adafruit TLC5947 Library Documentation',
144-
[author], 1)
150+
(
151+
master_doc,
152+
"AdafruitTLC5947library",
153+
u"Adafruit TLC5947 Library Documentation",
154+
[author],
155+
1,
156+
)
145157
]
146158

147159
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +162,13 @@
150162
# (source start file, target name, title, author,
151163
# dir menu entry, description, category)
152164
texinfo_documents = [
153-
(master_doc, 'AdafruitTLC5947Library', u'Adafruit TLC5947 Library Documentation',
154-
author, 'AdafruitTLC5947Library', 'One line description of project.',
155-
'Miscellaneous'),
165+
(
166+
master_doc,
167+
"AdafruitTLC5947Library",
168+
u"Adafruit TLC5947 Library Documentation",
169+
author,
170+
"AdafruitTLC5947Library",
171+
"One line description of project.",
172+
"Miscellaneous",
173+
),
156174
]

0 commit comments

Comments
 (0)