Skip to content

Pylint update #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ jobs:
with:
repository: adafruit/actions-ci-circuitpython-libs
path: actions-ci
- name: Install deps
- name: Install dependencies
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
run: |
source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx
run: |
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ confidence=
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
57 changes: 41 additions & 16 deletions adafruit_led_animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

from . import NANOS_PER_SECOND
from .color import BLACK, RAINBOW

try:
from time import monotonic_ns
except ImportError:
Expand All @@ -68,6 +69,7 @@ class Animation:
"""
Base class for animations.
"""

# pylint: disable=too-many-arguments
def __init__(self, pixel_object, speed, color, peers=None, paused=False):
self.pixel_object = pixel_object
Expand Down Expand Up @@ -152,7 +154,7 @@ def color(self, color):
if self._color == color:
return
if isinstance(color, int):
color = (color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff)
color = (color >> 16 & 0xFF, color >> 8 & 0xFF, color & 0xFF)
self._color = color
self._recompute_color(color)

Expand Down Expand Up @@ -183,6 +185,7 @@ class ColorCycle(Animation):
:param colors: A list of colors to cycle through in ``(r, g, b)`` tuple, or ``0x000000`` hex
format. Defaults to a rainbow color cycle.
"""

def __init__(self, pixel_object, speed, colors=RAINBOW):
self.colors = colors
super(ColorCycle, self).__init__(pixel_object, speed, colors[0])
Expand All @@ -209,6 +212,7 @@ class Blink(ColorCycle):
:param int speed: Animation speed in seconds, e.g. ``0.1``.
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
"""

def __init__(self, pixel_object, speed, color):
super(Blink, self).__init__(pixel_object, speed, [color, BLACK])

Expand All @@ -223,6 +227,7 @@ class Solid(ColorCycle):
:param pixel_object: The initialised LED object.
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
"""

def __init__(self, pixel_object, color):
super(Solid, self).__init__(pixel_object, speed=1, colors=[color])

Expand All @@ -243,8 +248,11 @@ class Comet(Animation):
:param bool reverse: Animates the comet in the reverse order. Defaults to ``False``.
:param bool bounce: Comet will bounce back and forth. Defaults to ``True``.
"""

# pylint: disable=too-many-arguments
def __init__(self, pixel_object, speed, color, tail_length=10, reverse=False, bounce=False):
def __init__(
self, pixel_object, speed, color, tail_length=10, reverse=False, bounce=False
):
self._tail_length = tail_length + 1
self._color_step = 0.9 / tail_length
self._color_offset = 0.1
Expand All @@ -260,9 +268,11 @@ def __init__(self, pixel_object, speed, color, tail_length=10, reverse=False, bo

def _recompute_color(self, color):
self._comet_colors = [BLACK] + [
[int(color[rgb] * ((n * self._color_step) + self._color_offset))
for rgb in range(len(color))
] for n in range(self._tail_length - 1)
[
int(color[rgb] * ((n * self._color_step) + self._color_offset))
for rgb in range(len(color))
]
for n in range(self._tail_length - 1)
]
self._reverse_comet_colors = list(reversed(self._comet_colors))

Expand All @@ -283,9 +293,11 @@ def _comet_generator(self):
end = num_pixels - start
if start <= 0:
num_visible = self._tail_length + start
self.pixel_object[0:num_visible] = colors[self._tail_length - num_visible:]
self.pixel_object[0:num_visible] = colors[
self._tail_length - num_visible :
]
else:
self.pixel_object[start:start + end] = colors[0:end]
self.pixel_object[start : start + end] = colors[0:end]
self.show()
yield
if self.bounce:
Expand All @@ -303,6 +315,7 @@ class Sparkle(Animation):
:param int speed: Animation speed in seconds, e.g. ``0.1``.
:param color: Animation color in ``(r, g, b)`` tuple, or ``0x000000`` hex format.
"""

def __init__(self, pixel_object, speed, color):
if len(pixel_object) < 2:
raise ValueError("Sparkle needs at least 2 pixels")
Expand Down Expand Up @@ -343,7 +356,9 @@ class Pulse(Animation):
"""

# pylint: disable=too-many-arguments
def __init__(self, pixel_object, speed, color, period=5, max_intensity=1, min_intensity=0):
def __init__(
self, pixel_object, speed, color, period=5, max_intensity=1, min_intensity=0
):
self.max_intensity = max_intensity
self.min_intensity = min_intensity
self._period = period
Expand All @@ -359,10 +374,14 @@ def draw(self):
now = monotonic_ns()
time_since_last_draw = (now - self._last_update) / NANOS_PER_SECOND
self._last_update = now
pos = self._cycle_position = (self._cycle_position + time_since_last_draw) % self._period
pos = self._cycle_position = (
self._cycle_position + time_since_last_draw
) % self._period
if pos > self._half_period:
pos = self._period - pos
intensity = self.min_intensity + (pos * self._intensity_delta * self._position_factor)
intensity = self.min_intensity + (
pos * self._intensity_delta * self._position_factor
)
color = [int(self.color[n] * intensity) for n in range(self._bpp)]
self.fill(color)
self.show()
Expand Down Expand Up @@ -408,8 +427,10 @@ def draw(self):
self.pixel_object.fill((0, 0, 0))
for i in range(self._size):
n = (self._n + i) % self._repeat_width
num = len(self.pixel_object[n::self._repeat_width])
self.pixel_object[n::self._repeat_width] = [self.group_color(n) for n in range(num)]
num = len(self.pixel_object[n :: self._repeat_width])
self.pixel_object[n :: self._repeat_width] = [
self.group_color(n) for n in range(num)
]
self._n = (self._n + self._direction) % self._repeat_width
self.show()

Expand Down Expand Up @@ -449,9 +470,12 @@ class AnimationSequence:
while True:
animations.animate()
"""

def __init__(self, *members, advance_interval=None, auto_clear=False):
self._members = members
self._advance_interval = advance_interval * NANOS_PER_SECOND if advance_interval else None
self._advance_interval = (
advance_interval * NANOS_PER_SECOND if advance_interval else None
)
self._last_advance = monotonic_ns()
self._current = 0
self._auto_clear = auto_clear
Expand Down Expand Up @@ -545,6 +569,7 @@ class AnimationGroup:
first member of the group. Defaults to ``False``.

"""

def __init__(self, *members, sync=False):
self._members = members
self._sync = sync
Expand Down Expand Up @@ -584,16 +609,16 @@ def fill(self, color):
"""
Fills all pixel objects in the group with a color.
"""
self._for_all('fill', color)
self._for_all("fill", color)

def freeze(self):
"""
Freeze all animations in the group.
"""
self._for_all('freeze')
self._for_all("freeze")

def resume(self):
"""
Resume all animations in the group.
"""
self._for_all('resume')
self._for_all("resume")
Loading