diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66ce4db..008e6db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/.pylintrc b/.pylintrc index 039eaec..d8f0ee8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -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 diff --git a/adafruit_led_animation/animation.py b/adafruit_led_animation/animation.py index 242bd8f..c0eda03 100644 --- a/adafruit_led_animation/animation.py +++ b/adafruit_led_animation/animation.py @@ -48,6 +48,7 @@ from . import NANOS_PER_SECOND from .color import BLACK, RAINBOW + try: from time import monotonic_ns except ImportError: @@ -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 @@ -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) @@ -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]) @@ -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]) @@ -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]) @@ -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 @@ -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)) @@ -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: @@ -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") @@ -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 @@ -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() @@ -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() @@ -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 @@ -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 @@ -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") diff --git a/docs/conf.py b/docs/conf.py index 290aa7e..ec64647 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # TODO: Please Read! @@ -23,29 +24,32 @@ autodoc_mock_imports = ["led_animation"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'LED_Animation Library' -copyright = u'2017 Adam Patt' -author = u'Adam Patt' +project = "LED_Animation Library" +copyright = "2017 Adam Patt" +author = "Adam Patt" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -57,7 +61,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -69,7 +73,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -84,59 +88,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'Led_animationLibrarydoc' +htmlhelp_basename = "Led_animationLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'LED_AnimationLibrary.tex', u'LED_Animation Library Documentation', - author, 'manual'), + ( + master_doc, + "LED_AnimationLibrary.tex", + "LED_Animation Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'LED_Animationlibrary', u'LED_Animation Library Documentation', - [author], 1) + ( + master_doc, + "LED_Animationlibrary", + "LED_Animation Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'LED_AnimationLibrary', u' LED_Animation Library Documentation', - author, 'LED_AnimationLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "LED_AnimationLibrary", + " LED_Animation Library Documentation", + author, + "LED_AnimationLibrary", + "One line description of project.", + "Miscellaneous", + ), ]