Skip to content

Commit 63a3203

Browse files
committed
Ran black, updated to pylint 2.x
1 parent 5905b0b commit 63a3203

File tree

2 files changed

+106
-63
lines changed

2 files changed

+106
-63
lines changed

adafruit_led_animation/animation.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
from . import NANOS_PER_SECOND
5050
from .color import BLACK, RAINBOW
51+
5152
try:
5253
from time import monotonic_ns
5354
except ImportError:
@@ -68,6 +69,7 @@ class Animation:
6869
"""
6970
Base class for animations.
7071
"""
72+
7173
# pylint: disable=too-many-arguments
7274
def __init__(self, pixel_object, speed, color, peers=None, paused=False):
7375
self.pixel_object = pixel_object
@@ -152,7 +154,7 @@ def color(self, color):
152154
if self._color == color:
153155
return
154156
if isinstance(color, int):
155-
color = (color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff)
157+
color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF)
156158
self._color = color
157159
self._recompute_color(color)
158160

@@ -183,6 +185,7 @@ class ColorCycle(Animation):
183185
:param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex
184186
format. Defaults to a rainbow color cycle.
185187
"""
188+
186189
def __init__(self, pixel_object, speed, colors=RAINBOW):
187190
self.colors = colors
188191
super(ColorCycle, self).__init__(pixel_object, speed, colors[0])
@@ -209,6 +212,7 @@ class Blink(ColorCycle):
209212
:param int speed: Animation speed in seconds, e.g. ``0.1``.
210213
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
211214
"""
215+
212216
def __init__(self, pixel_object, speed, color):
213217
super(Blink, self).__init__(pixel_object, speed, [color, BLACK])
214218

@@ -223,6 +227,7 @@ class Solid(ColorCycle):
223227
:param pixel_object: The initialised LED object.
224228
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
225229
"""
230+
226231
def __init__(self, pixel_object, color):
227232
super(Solid, self).__init__(pixel_object, speed=1, colors=[color])
228233

@@ -243,8 +248,11 @@ class Comet(Animation):
243248
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
244249
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
245250
"""
251+
246252
# pylint: disable=too-many-arguments
247-
def __init__(self, pixel_object, speed, color, tail_length=10, reverse=False, bounce=False):
253+
def __init__(
254+
self, pixel_object, speed, color, tail_length=10, reverse=False, bounce=False
255+
):
248256
self._tail_length = tail_length + 1
249257
self._color_step = 0.9 / tail_length
250258
self._color_offset = 0.1
@@ -260,9 +268,11 @@ def __init__(self, pixel_object, speed, color, tail_length=10, reverse=False, bo
260268

261269
def _recompute_color(self, color):
262270
self._comet_colors = [BLACK] + [
263-
[int(color[rgb] * ((n * self._color_step) + self._color_offset))
264-
for rgb in range(len(color))
265-
] for n in range(self._tail_length - 1)
271+
[
272+
int(color[rgb] * ((n * self._color_step) + self._color_offset))
273+
for rgb in range(len(color))
274+
]
275+
for n in range(self._tail_length - 1)
266276
]
267277
self._reverse_comet_colors = list(reversed(self._comet_colors))
268278

@@ -283,9 +293,11 @@ def _comet_generator(self):
283293
end = num_pixels - start
284294
if start <= 0:
285295
num_visible = self._tail_length + start
286-
self.pixel_object[0:num_visible] = colors[self._tail_length - num_visible:]
296+
self.pixel_object[0:num_visible] = colors[
297+
self._tail_length - num_visible :
298+
]
287299
else:
288-
self.pixel_object[start:start + end] = colors[0:end]
300+
self.pixel_object[start : start + end] = colors[0:end]
289301
self.show()
290302
yield
291303
if self.bounce:
@@ -303,6 +315,7 @@ class Sparkle(Animation):
303315
:param int speed: Animation speed in seconds, e.g. ``0.1``.
304316
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
305317
"""
318+
306319
def __init__(self, pixel_object, speed, color):
307320
if len(pixel_object) < 2:
308321
raise ValueError("Sparkle needs at least 2 pixels")
@@ -343,7 +356,9 @@ class Pulse(Animation):
343356
"""
344357

345358
# pylint: disable=too-many-arguments
346-
def __init__(self, pixel_object, speed, color, period=5, max_intensity=1, min_intensity=0):
359+
def __init__(
360+
self, pixel_object, speed, color, period=5, max_intensity=1, min_intensity=0
361+
):
347362
self.max_intensity = max_intensity
348363
self.min_intensity = min_intensity
349364
self._period = period
@@ -359,10 +374,14 @@ def draw(self):
359374
now = monotonic_ns()
360375
time_since_last_draw = (now - self._last_update) / NANOS_PER_SECOND
361376
self._last_update = now
362-
pos = self._cycle_position = (self._cycle_position + time_since_last_draw) % self._period
377+
pos = self._cycle_position = (
378+
self._cycle_position + time_since_last_draw
379+
) % self._period
363380
if pos > self._half_period:
364381
pos = self._period - pos
365-
intensity = self.min_intensity + (pos * self._intensity_delta * self._position_factor)
382+
intensity = self.min_intensity + (
383+
pos * self._intensity_delta * self._position_factor
384+
)
366385
color = [int(self.color[n] * intensity) for n in range(self._bpp)]
367386
self.fill(color)
368387
self.show()
@@ -408,8 +427,10 @@ def draw(self):
408427
self.pixel_object.fill((0, 0, 0))
409428
for i in range(self._size):
410429
n = (self._n + i) % self._repeat_width
411-
num = len(self.pixel_object[n::self._repeat_width])
412-
self.pixel_object[n::self._repeat_width] = [self.group_color(n) for n in range(num)]
430+
num = len(self.pixel_object[n :: self._repeat_width])
431+
self.pixel_object[n :: self._repeat_width] = [
432+
self.group_color(n) for n in range(num)
433+
]
413434
self._n = (self._n + self._direction) % self._repeat_width
414435
self.show()
415436

@@ -449,9 +470,12 @@ class AnimationSequence:
449470
while True:
450471
animations.animate()
451472
"""
473+
452474
def __init__(self, *members, advance_interval=None, auto_clear=False):
453475
self._members = members
454-
self._advance_interval = advance_interval * NANOS_PER_SECOND if advance_interval else None
476+
self._advance_interval = (
477+
advance_interval * NANOS_PER_SECOND if advance_interval else None
478+
)
455479
self._last_advance = monotonic_ns()
456480
self._current = 0
457481
self._auto_clear = auto_clear
@@ -545,6 +569,7 @@ class AnimationGroup:
545569
first member of the group. Defaults to ``False``.
546570
547571
"""
572+
548573
def __init__(self, *members, sync=False):
549574
self._members = members
550575
self._sync = sync
@@ -584,16 +609,16 @@ def fill(self, color):
584609
"""
585610
Fills all pixel objects in the group with a color.
586611
"""
587-
self._for_all('fill', color)
612+
self._for_all("fill", color)
588613

589614
def freeze(self):
590615
"""
591616
Freeze all animations in the group.
592617
"""
593-
self._for_all('freeze')
618+
self._for_all("freeze")
594619

595620
def resume(self):
596621
"""
597622
Resume all animations in the group.
598623
"""
599-
self._for_all('resume')
624+
self._for_all("resume")

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
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.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
autodoc_mock_imports = ["led_animation"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'LED_Animation Library'
38-
copyright = u'2017 Adam Patt'
39-
author = u'Adam Patt'
41+
project = "LED_Animation Library"
42+
copyright = "2017 Adam Patt"
43+
author = "Adam Patt"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

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

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'Led_animationLibrarydoc'
117+
htmlhelp_basename = "Led_animationLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'LED_AnimationLibrary.tex', u'LED_Animation Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"LED_AnimationLibrary.tex",
143+
"LED_Animation Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'LED_Animationlibrary', u'LED_Animation Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"LED_Animationlibrary",
157+
"LED_Animation Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'LED_AnimationLibrary', u' LED_Animation Library Documentation',
158-
author, 'LED_AnimationLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"LED_AnimationLibrary",
172+
" LED_Animation Library Documentation",
173+
author,
174+
"LED_AnimationLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

0 commit comments

Comments
 (0)