From 737ab7f6b621f66a79e1197889b83c4b38f66d9b Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 20 Mar 2020 21:01:56 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_display_shapes/circle.py | 5 +- adafruit_display_shapes/line.py | 2 + adafruit_display_shapes/polygon.py | 17 +++- adafruit_display_shapes/rect.py | 5 +- adafruit_display_shapes/roundrect.py | 79 ++++++++++++------ adafruit_display_shapes/triangle.py | 20 +++-- docs/conf.py | 112 +++++++++++++++----------- examples/display_shapes_simpletest.py | 22 +++-- setup.py | 54 +++++-------- 10 files changed, 194 insertions(+), 124 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + 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/adafruit_display_shapes/circle.py b/adafruit_display_shapes/circle.py index 998e74a..8bdaa95 100644 --- a/adafruit_display_shapes/circle.py +++ b/adafruit_display_shapes/circle.py @@ -56,5 +56,8 @@ class Circle(RoundRect): ``None`` for no outline. """ + def __init__(self, x0, y0, r, *, fill=None, outline=None): - super().__init__(x0-r, y0-r, 2*r+1, 2*r+1, r, fill=fill, outline=outline) + super().__init__( + x0 - r, y0 - r, 2 * r + 1, 2 * r + 1, r, fill=fill, outline=outline + ) diff --git a/adafruit_display_shapes/line.py b/adafruit_display_shapes/line.py index d138aff..3945695 100755 --- a/adafruit_display_shapes/line.py +++ b/adafruit_display_shapes/line.py @@ -43,6 +43,7 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes.git" + class Line(Polygon): # pylint: disable=too-many-arguments,invalid-name """A line. @@ -53,5 +54,6 @@ class Line(Polygon): :param y1: The y-position of the second vertex. :param color: The color of the line. """ + def __init__(self, x0, y0, x1, y1, color): super().__init__([(x0, y0), (x1, y1)], outline=color) diff --git a/adafruit_display_shapes/polygon.py b/adafruit_display_shapes/polygon.py index d11df3e..111e7f3 100755 --- a/adafruit_display_shapes/polygon.py +++ b/adafruit_display_shapes/polygon.py @@ -54,6 +54,7 @@ class Polygon(displayio.TileGrid): :param outline: The outline of the polygon. Can be a hex value for a color or ``None`` for no outline. """ + def __init__(self, points, *, outline=None): xs = [] ys = [] @@ -82,10 +83,17 @@ def __init__(self, points, *, outline=None): point_b = points[0] else: point_b = points[index + 1] - self._line(point_a[0] - x_offset, point_a[1] - y_offset, - point_b[0] - x_offset, point_b[1] - y_offset, 1) - - super().__init__(self._bitmap, pixel_shader=self._palette, x=x_offset, y=y_offset) + self._line( + point_a[0] - x_offset, + point_a[1] - y_offset, + point_b[0] - x_offset, + point_b[1] - y_offset, + 1, + ) + + super().__init__( + self._bitmap, pixel_shader=self._palette, x=x_offset, y=y_offset + ) # pylint: disable=invalid-name, too-many-locals, too-many-branches def _line(self, x0, y0, x1, y1, color): @@ -128,6 +136,7 @@ def _line(self, x0, y0, x1, y1, color): if err < 0: y0 += ystep err += dx + # pylint: enable=invalid-name, too-many-locals, too-many-branches @property diff --git a/adafruit_display_shapes/rect.py b/adafruit_display_shapes/rect.py index 4eecacc..5e6caf1 100755 --- a/adafruit_display_shapes/rect.py +++ b/adafruit_display_shapes/rect.py @@ -59,6 +59,7 @@ class Rect(displayio.TileGrid): ``height``. """ + def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1): self._bitmap = displayio.Bitmap(width, height, 2) self._palette = displayio.Palette(2) @@ -68,11 +69,11 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1): for w in range(width): for line in range(stroke): self._bitmap[w, line] = 1 - self._bitmap[w, height-1-line] = 1 + self._bitmap[w, height - 1 - line] = 1 for _h in range(height): for line in range(stroke): self._bitmap[line, _h] = 1 - self._bitmap[width-1-line, _h] = 1 + self._bitmap[width - 1 - line, _h] = 1 if fill is not None: self._palette[0] = fill diff --git a/adafruit_display_shapes/roundrect.py b/adafruit_display_shapes/roundrect.py index 8f923e2..48e09b2 100755 --- a/adafruit_display_shapes/roundrect.py +++ b/adafruit_display_shapes/roundrect.py @@ -51,15 +51,23 @@ class RoundRect(displayio.TileGrid): ``height``. """ + def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1): self._palette = displayio.Palette(3) self._palette.make_transparent(0) self._bitmap = displayio.Bitmap(width, height, 3) - for i in range(0, width): # draw the center chunk - for j in range(r, height - r): # draw the center chunk + for i in range(0, width): # draw the center chunk + for j in range(r, height - r): # draw the center chunk self._bitmap[i, j] = 2 - self._helper(r, r, r, color=2, fill=True, - x_offset=width-2*r-1, y_offset=height-2*r-1) + self._helper( + r, + r, + r, + color=2, + fill=True, + x_offset=width - 2 * r - 1, + y_offset=height - 2 * r - 1, + ) if fill is not None: self._palette[2] = fill @@ -74,19 +82,37 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1) for w in range(r, width - r): for line in range(stroke): self._bitmap[w, line] = 1 - self._bitmap[w, height-line-1] = 1 + self._bitmap[w, height - line - 1] = 1 for _h in range(r, height - r): for line in range(stroke): self._bitmap[line, _h] = 1 - self._bitmap[width-line-1, _h] = 1 + self._bitmap[width - line - 1, _h] = 1 # draw round corners - self._helper(r, r, r, color=1, stroke=stroke, - x_offset=width-2*r-1, y_offset=height-2*r-1) + self._helper( + r, + r, + r, + color=1, + stroke=stroke, + x_offset=width - 2 * r - 1, + y_offset=height - 2 * r - 1, + ) super().__init__(self._bitmap, pixel_shader=self._palette, x=x, y=y) # pylint: disable=invalid-name, too-many-locals, too-many-branches - def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0, - stroke=1, corner_flags=0xF, fill=False): + def _helper( + self, + x0, + y0, + r, + *, + color, + x_offset=0, + y_offset=0, + stroke=1, + corner_flags=0xF, + fill=False + ): f = 1 - r ddF_x = 1 ddF_y = -2 * r @@ -103,32 +129,33 @@ def _helper(self, x0, y0, r, *, color, x_offset=0, y_offset=0, f += ddF_x if corner_flags & 0x8: if fill: - for w in range(x0-y, x0+y+x_offset): - self._bitmap[w, y0+x+y_offset] = color - for w in range(x0-x, x0+x+x_offset): - self._bitmap[w, y0+y+y_offset] = color + for w in range(x0 - y, x0 + y + x_offset): + self._bitmap[w, y0 + x + y_offset] = color + for w in range(x0 - x, x0 + x + x_offset): + self._bitmap[w, y0 + y + y_offset] = color else: for line in range(stroke): - self._bitmap[x0-y+line, y0+x+y_offset] = color - self._bitmap[x0-x, y0+y+y_offset-line] = color + self._bitmap[x0 - y + line, y0 + x + y_offset] = color + self._bitmap[x0 - x, y0 + y + y_offset - line] = color if corner_flags & 0x1: if fill: - for w in range(x0-y, x0+y+x_offset): - self._bitmap[w, y0-x] = color - for w in range(x0-x, x0+x+x_offset): - self._bitmap[w, y0-y] = color + for w in range(x0 - y, x0 + y + x_offset): + self._bitmap[w, y0 - x] = color + for w in range(x0 - x, x0 + x + x_offset): + self._bitmap[w, y0 - y] = color else: for line in range(stroke): - self._bitmap[x0-y+line, y0-x] = color - self._bitmap[x0-x, y0-y+line] = color + self._bitmap[x0 - y + line, y0 - x] = color + self._bitmap[x0 - x, y0 - y + line] = color if corner_flags & 0x4: for line in range(stroke): - self._bitmap[x0+x+x_offset, y0+y+y_offset-line] = color - self._bitmap[x0+y+x_offset-line, y0+x+y_offset] = color + self._bitmap[x0 + x + x_offset, y0 + y + y_offset - line] = color + self._bitmap[x0 + y + x_offset - line, y0 + x + y_offset] = color if corner_flags & 0x2: for line in range(stroke): - self._bitmap[x0+x+x_offset, y0-y+line] = color - self._bitmap[x0+y+x_offset-line, y0-x] = color + self._bitmap[x0 + x + x_offset, y0 - y + line] = color + self._bitmap[x0 + y + x_offset - line, y0 - x] = color + # pylint: enable=invalid-name, too-many-locals, too-many-branches @property diff --git a/adafruit_display_shapes/triangle.py b/adafruit_display_shapes/triangle.py index 1036a8e..222285d 100755 --- a/adafruit_display_shapes/triangle.py +++ b/adafruit_display_shapes/triangle.py @@ -82,7 +82,9 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None): super().__init__(points) if fill is not None: - self._draw_filled(x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0) + self._draw_filled( + x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0 + ) self.fill = fill else: self.fill = None @@ -95,12 +97,17 @@ def __init__(self, x0, y0, x1, y1, x2, y2, *, fill=None, outline=None): point_b = points[0] else: point_b = points[index + 1] - self._line(point_a[0] - min(xs), point_a[1] - y0, - point_b[0] - min(xs), point_b[1] - y0, 1) + self._line( + point_a[0] - min(xs), + point_a[1] - y0, + point_b[0] - min(xs), + point_b[1] - y0, + 1, + ) # pylint: disable=invalid-name, too-many-branches def _draw_filled(self, x0, y0, x1, y1, x2, y2): - if y0 == y2: # Handle awkward all-on-same-line case as its own thing + if y0 == y2: # Handle awkward all-on-same-line case as its own thing a = x0 b = x0 if x1 < a: @@ -116,9 +123,9 @@ def _draw_filled(self, x0, y0, x1, y1, x2, y2): return if y1 == y2: - last = y1 # Include y1 scanline + last = y1 # Include y1 scanline else: - last = y1 - 1 # Skip it + last = y1 - 1 # Skip it # Upper Triangle for y in range(y0, last + 1): @@ -135,6 +142,7 @@ def _draw_filled(self, x0, y0, x1, y1, x2, y2): if a > b: a, b = b, a self._line(a, y, b, y, 2) + # pylint: enable=invalid-name, too-many-locals, too-many-branches @property diff --git a/docs/conf.py b/docs/conf.py index 670451e..fa08a9a 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 = ["displayio"] -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'Adafruit Display_Shapes Library' -copyright = u'2019 Limor Fried' -author = u'Limor Fried' +project = u"Adafruit Display_Shapes Library" +copyright = u"2019 Limor Fried" +author = u"Limor Fried" # 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 = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"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 = 'AdafruitDisplay_shapesLibrarydoc' +htmlhelp_basename = "AdafruitDisplay_shapesLibrarydoc" # -- 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, 'AdafruitDisplay_ShapesLibrary.tex', u'AdafruitDisplay_Shapes Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitDisplay_ShapesLibrary.tex", + u"AdafruitDisplay_Shapes 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, 'AdafruitDisplay_Shapeslibrary', u'Adafruit Display_Shapes Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitDisplay_Shapeslibrary", + u"Adafruit Display_Shapes 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, 'AdafruitDisplay_ShapesLibrary', u'Adafruit Display_Shapes Library Documentation', - author, 'AdafruitDisplay_ShapesLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitDisplay_ShapesLibrary", + u"Adafruit Display_Shapes Library Documentation", + author, + "AdafruitDisplay_ShapesLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/display_shapes_simpletest.py b/examples/display_shapes_simpletest.py index 35eeef6..d74f9dc 100644 --- a/examples/display_shapes_simpletest.py +++ b/examples/display_shapes_simpletest.py @@ -15,8 +15,7 @@ color_bitmap = displayio.Bitmap(320, 240, 1) color_palette = displayio.Palette(1) color_palette[0] = 0xFFFFFF -bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, - pixel_shader=color_palette) +bg_sprite = displayio.TileGrid(color_bitmap, x=0, y=0, pixel_shader=color_palette) splash.append(bg_sprite) ########################################################################## @@ -25,9 +24,22 @@ splash.append(Line(220, 210, 270, 130, 0xFF0000)) splash.append(Line(270, 130, 220, 130, 0xFF0000)) -#Draw a blue star -polygon = Polygon([(255, 40), (262, 62), (285, 62), (265, 76), (275, 100), - (255, 84), (235, 100), (245, 76), (225, 62), (248, 62)], outline=0x0000FF) +# Draw a blue star +polygon = Polygon( + [ + (255, 40), + (262, 62), + (285, 62), + (265, 76), + (275, 100), + (255, 84), + (235, 100), + (245, 76), + (225, 62), + (248, 62), + ], + outline=0x0000FF, +) splash.append(polygon) triangle = Triangle(170, 50, 120, 140, 210, 160, fill=0x00FF00, outline=0xFF00FF) diff --git a/setup.py b/setup.py index 16ba40f..c75add8 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,52 +14,41 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-display_shapes', - + name="adafruit-circuitpython-display_shapes", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Various common shapes for use with displayio', + setup_requires=["setuptools_scm"], + description="Various common shapes for use with displayio", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes', - + url="https://github.com/adafruit/Adafruit_CircuitPython_Display_Shapes", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=[ - 'Adafruit-Blinka' - ], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit blinka circuitpython micropython display_shapes shapes displayio ' - 'drawing', - + keywords="adafruit blinka circuitpython micropython display_shapes shapes displayio " + "drawing", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - packages=['adafruit_display_shapes'], + packages=["adafruit_display_shapes"], )