Merge pull request #7 from adafruit/pylint-update

Ran black, updated to pylint 2.x
This commit is contained in:
Kattni 2020-03-16 18:42:01 -04:00 committed by GitHub
commit 81012cf7f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 217 additions and 145 deletions

View file

@ -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

View file

@ -52,6 +52,7 @@ import time
from micropython import const
from adafruit_bus_device import i2c_device, spi_device
try:
import framebuf
except ImportError:
@ -60,35 +61,36 @@ except ImportError:
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SSD1305.git"
#pylint: disable-msg=bad-whitespace
# pylint: disable-msg=bad-whitespace
# register definitions
SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xa4)
SET_NORM_INV = const(0xa6)
SET_DISP = const(0xae)
SET_MEM_ADDR = const(0x20)
SET_COL_ADDR = const(0x21)
SET_PAGE_ADDR = const(0x22)
SET_CONTRAST = const(0x81)
SET_ENTIRE_ON = const(0xA4)
SET_NORM_INV = const(0xA6)
SET_DISP = const(0xAE)
SET_MEM_ADDR = const(0x20)
SET_COL_ADDR = const(0x21)
SET_PAGE_ADDR = const(0x22)
SET_DISP_START_LINE = const(0x40)
SET_LUT = const(0x91)
SET_SEG_REMAP = const(0xa0)
SET_MUX_RATIO = const(0xa8)
SET_MASTER_CONFIG = const(0xad)
SET_COM_OUT_DIR = const(0xc0)
SET_COMSCAN_DEC = const(0xc8)
SET_DISP_OFFSET = const(0xd3)
SET_COM_PIN_CFG = const(0xda)
SET_DISP_CLK_DIV = const(0xd5)
SET_AREA_COLOR = const(0xd8)
SET_PRECHARGE = const(0xd9)
SET_VCOM_DESEL = const(0xdb)
SET_CHARGE_PUMP = const(0x8d)
#pylint: enable-msg=bad-whitespace
SET_LUT = const(0x91)
SET_SEG_REMAP = const(0xA0)
SET_MUX_RATIO = const(0xA8)
SET_MASTER_CONFIG = const(0xAD)
SET_COM_OUT_DIR = const(0xC0)
SET_COMSCAN_DEC = const(0xC8)
SET_DISP_OFFSET = const(0xD3)
SET_COM_PIN_CFG = const(0xDA)
SET_DISP_CLK_DIV = const(0xD5)
SET_AREA_COLOR = const(0xD8)
SET_PRECHARGE = const(0xD9)
SET_VCOM_DESEL = const(0xDB)
SET_CHARGE_PUMP = const(0x8D)
# pylint: enable-msg=bad-whitespace
class _SSD1305(framebuf.FrameBuffer):
"""Base class for SSD1305 display driver"""
#pylint: disable-msg=too-many-arguments
# pylint: disable-msg=too-many-arguments
def __init__(self, buffer, width, height, *, external_vcc, reset):
super().__init__(buffer, width, height)
self.width = width
@ -101,7 +103,7 @@ class _SSD1305(framebuf.FrameBuffer):
self.pages = self.height // 8
self._column_offset = 0
if self.height == 32:
self._column_offset = 4 # hardcoded for now...
self._column_offset = 4 # hardcoded for now...
# Note the subclass must initialize self.framebuf to a framebuffer.
# This is necessary because the underlying data buffer is different
# between I2C and SPI implementations (I2C needs an extra byte).
@ -111,26 +113,43 @@ class _SSD1305(framebuf.FrameBuffer):
def init_display(self):
"""Base class to initialize display"""
for cmd in (
SET_DISP | 0x00, # off
# timing and driving scheme
SET_DISP_CLK_DIV, 0x80, #SET_DISP_CLK_DIV
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP
SET_MUX_RATIO, self.height - 1, #SET_MUX_RATIO
SET_DISP_OFFSET, 0x00, #SET_DISP_OFFSET
SET_MASTER_CONFIG, 0x8e, #Set Master Configuration
SET_AREA_COLOR, 0x05, #Set Area Color Mode On/Off & Low Power Display Mode
SET_MEM_ADDR, 0x00, # horizontal SET_MEM_ADDR ADD
SET_DISP_START_LINE | 0x00, 0x2E, #SET_DISP_START_LINE ADD
SET_COMSCAN_DEC, #Set COM Output Scan Direction 64 to 1
SET_COM_PIN_CFG, 0x12, #SET_COM_PIN_CFG
SET_LUT, 0x3f, 0x3f, 0x3f, 0x3f,#Current drive pulse width of BANK0, Color A, B, C
SET_CONTRAST, 0xff, # maximum SET_CONTRAST to maximum
SET_PRECHARGE, 0xd2, #SET_PRECHARGE orig: 0xd9, 0x22 if self.external_vcc else 0xf1,
SET_VCOM_DESEL, 0x34, #SET_VCOM_DESEL 0xdb, 0x30, $ 0.83* Vcc
SET_NORM_INV, # not inverted SET_NORM_INV
SET_ENTIRE_ON, # output follows RAM contents SET_ENTIRE_ON
SET_CHARGE_PUMP, 0x10 if self.external_vcc else 0x14, #SET_CHARGE_PUMP
SET_DISP | 0x01): #//--turn on oled panel
SET_DISP | 0x00, # off
# timing and driving scheme
SET_DISP_CLK_DIV,
0x80, # SET_DISP_CLK_DIV
SET_SEG_REMAP | 0x01, # column addr 127 mapped to SEG0 SET_SEG_REMAP
SET_MUX_RATIO,
self.height - 1, # SET_MUX_RATIO
SET_DISP_OFFSET,
0x00, # SET_DISP_OFFSET
SET_MASTER_CONFIG,
0x8E, # Set Master Configuration
SET_AREA_COLOR,
0x05, # Set Area Color Mode On/Off & Low Power Display Mode
SET_MEM_ADDR,
0x00, # horizontal SET_MEM_ADDR ADD
SET_DISP_START_LINE | 0x00,
0x2E, # SET_DISP_START_LINE ADD
SET_COMSCAN_DEC, # Set COM Output Scan Direction 64 to 1
SET_COM_PIN_CFG,
0x12, # SET_COM_PIN_CFG
SET_LUT,
0x3F,
0x3F,
0x3F,
0x3F, # Current drive pulse width of BANK0, Color A, B, C
SET_CONTRAST,
0xFF, # maximum SET_CONTRAST to maximum
SET_PRECHARGE,
0xD2, # SET_PRECHARGE orig: 0xd9, 0x22 if self.external_vcc else 0xf1,
SET_VCOM_DESEL,
0x34, # SET_VCOM_DESEL 0xdb, 0x30, $ 0.83* Vcc
SET_NORM_INV, # not inverted SET_NORM_INV
SET_ENTIRE_ON, # output follows RAM contents SET_ENTIRE_ON
SET_CHARGE_PUMP,
0x10 if self.external_vcc else 0x14, # SET_CHARGE_PUMP
SET_DISP | 0x01,
): # //--turn on oled panel
self.write_cmd(cmd)
self.fill(0)
self.show()
@ -183,6 +202,7 @@ class _SSD1305(framebuf.FrameBuffer):
self.write_cmd(self.pages - 1)
self.write_framebuf()
class SSD1305_I2C(_SSD1305):
"""
I2C class for SSD1305
@ -195,7 +215,9 @@ class SSD1305_I2C(_SSD1305):
:param reset: if needed, DigitalInOut designating reset pin
"""
def __init__(self, width, height, i2c, *, addr=0x3c, external_vcc=False, reset=None):
def __init__(
self, width, height, i2c, *, addr=0x3C, external_vcc=False, reset=None
):
self.i2c_device = i2c_device.I2CDevice(i2c, addr)
self.addr = addr
self.temp = bytearray(2)
@ -206,12 +228,17 @@ class SSD1305_I2C(_SSD1305):
# buffer).
self.buffer = bytearray(((height // 8) * width) + 1)
self.buffer[0] = 0x40 # Set first byte of data buffer to Co=0, D/C=1
super().__init__(memoryview(self.buffer)[1:], width, height,
external_vcc=external_vcc, reset=reset)
super().__init__(
memoryview(self.buffer)[1:],
width,
height,
external_vcc=external_vcc,
reset=reset,
)
def write_cmd(self, cmd):
"""Send a command to the SPI device"""
self.temp[0] = 0x80 # Co=1, D/C#=0
self.temp[0] = 0x80 # Co=1, D/C#=0
self.temp[1] = cmd
with self.i2c_device:
self.i2c_device.write(self.temp)
@ -222,7 +249,8 @@ class SSD1305_I2C(_SSD1305):
with self.i2c_device:
self.i2c_device.write(self.buffer)
#pylint: disable-msg=too-many-arguments
# pylint: disable-msg=too-many-arguments
class SSD1305_SPI(_SSD1305):
"""
SPI class for SSD1305
@ -234,18 +262,37 @@ class SSD1305_SPI(_SSD1305):
:param reset: the reset pin to use,
:param cs: the chip-select pin to use (sometimes labeled "SS").
"""
# pylint: disable=no-member
# Disable should be reconsidered when refactor can be tested.
def __init__(self, width, height, spi, dc, reset, cs, *,
external_vcc=False, baudrate=8000000, polarity=0, phase=0):
def __init__(
self,
width,
height,
spi,
dc,
reset,
cs,
*,
external_vcc=False,
baudrate=8000000,
polarity=0,
phase=0
):
self.rate = 10 * 1024 * 1024
dc.switch_to_output(value=0)
self.spi_device = spi_device.SPIDevice(spi, cs, baudrate=baudrate,
polarity=polarity, phase=phase)
self.spi_device = spi_device.SPIDevice(
spi, cs, baudrate=baudrate, polarity=polarity, phase=phase
)
self.dc_pin = dc
self.buffer = bytearray((height // 8) * width)
super().__init__(memoryview(self.buffer), width, height,
external_vcc=external_vcc, reset=reset)
super().__init__(
memoryview(self.buffer),
width,
height,
external_vcc=external_vcc,
reset=reset,
)
def write_cmd(self, cmd):
"""Send a command to the SPI device"""

View file

@ -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,42 +11,54 @@ sys.path.insert(0, os.path.abspath('..'))
# 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!
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["micropython", "adafruit_bus_device", "adafruit_framebuf", "busio"]
autodoc_mock_imports = [
"micropython",
"adafruit_bus_device",
"adafruit_framebuf",
"busio",
]
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
intersphinx_mapping = {
"python": ("https://docs.python.org/3.4", None),
"BusDevice": (
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
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 SSD1305 Library'
copyright = u'2019 Bryan Siepert'
author = u'Bryan Siepert'
project = u"Adafruit SSD1305 Library"
copyright = u"2019 Bryan Siepert"
author = u"Bryan Siepert"
# 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 +70,7 @@ language = None
# 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 +82,7 @@ default_role = "any"
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 +97,62 @@ napoleon_numpy_docstring = False
# 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 = 'AdafruitSsd1305Librarydoc'
htmlhelp_basename = "AdafruitSsd1305Librarydoc"
# -- 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, 'AdafruitSSD1305Library.tex', u'AdafruitSSD1305 Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitSSD1305Library.tex",
u"AdafruitSSD1305 Library Documentation",
author,
"manual",
),
]
# -- Options for manual page output ---------------------------------------
@ -144,8 +160,13 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitSSD1305library', u'Adafruit SSD1305 Library Documentation',
[author], 1)
(
master_doc,
"AdafruitSSD1305library",
u"Adafruit SSD1305 Library Documentation",
[author],
1,
)
]
# -- Options for Texinfo output -------------------------------------------
@ -154,7 +175,13 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitSSD1305Library', u'Adafruit SSD1305 Library Documentation',
author, 'AdafruitSSD1305Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitSSD1305Library",
u"Adafruit SSD1305 Library Documentation",
author,
"AdafruitSSD1305Library",
"One line description of project.",
"Miscellaneous",
),
]

View file

@ -18,7 +18,7 @@ oled_reset = digitalio.DigitalInOut(board.D4)
# Change these
# to the right size for your display!
WIDTH = 128
HEIGHT = 64 # Change to 32 if needed
HEIGHT = 64 # Change to 32 if needed
BORDER = 8
# Use for SPI
@ -28,8 +28,8 @@ oled_dc = digitalio.DigitalInOut(board.D6)
oled = adafruit_ssd1305.SSD1305_SPI(WIDTH, HEIGHT, spi, oled_dc, oled_reset, oled_cs)
# Use for I2C.
#i2c = board.I2C()
#oled = adafruit_ssd1305.SSD1305_I2C(WIDTH, HEIGHT, i2c, addr=0x3c, reset=oled_reset)
# i2c = board.I2C()
# oled = adafruit_ssd1305.SSD1305_I2C(WIDTH, HEIGHT, i2c, addr=0x3c, reset=oled_reset)
# Clear display.
oled.fill(0)
@ -37,7 +37,7 @@ oled.show()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
image = Image.new('1', (oled.width, oled.height))
image = Image.new("1", (oled.width, oled.height))
# Get drawing object to draw on image.
draw = ImageDraw.Draw(image)
@ -46,8 +46,11 @@ draw = ImageDraw.Draw(image)
draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255)
# Draw a smaller inner rectangle
draw.rectangle((BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
outline=0, fill=0)
draw.rectangle(
(BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1),
outline=0,
fill=0,
)
# Load default font.
font = ImageFont.load_default()
@ -55,8 +58,12 @@ font = ImageFont.load_default()
# Draw Some Text
text = "Hello World!"
(font_width, font_height) = font.getsize(text)
draw.text((oled.width//2 - font_width//2, oled.height//2 - font_height//2),
text, font=font, fill=255)
draw.text(
(oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2),
text,
font=font,
fill=255,
)
# Display image
oled.image(image)

View file

@ -14,7 +14,7 @@ i2c = busio.I2C(SCL, SDA)
display = adafruit_ssd1305.SSD1305_I2C(128, 32, i2c)
# Alternatively you can change the I2C address of the device with an addr parameter:
#display = adafruit_ssd1305.SSD1305_I2C(128, 32, i2c, addr=0x31)
# display = adafruit_ssd1305.SSD1305_I2C(128, 32, i2c, addr=0x31)
# Clear the display. Always call show after changing pixels to make the display
# update visible!

View file

@ -6,6 +6,7 @@ https://github.com/pypa/sampleproject
"""
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
@ -13,52 +14,42 @@ from os import path
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-ssd1305',
name="adafruit-circuitpython-ssd1305",
use_scm_version=True,
setup_requires=['setuptools_scm'],
description='Framebuf (non-displayio) driver for SSD1305 displays',
setup_requires=["setuptools_scm"],
description="Framebuf (non-displayio) driver for SSD1305 displays",
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_SSD1305',
url="https://github.com/adafruit/Adafruit_CircuitPython_SSD1305",
# Author details
author='Adafruit Industries',
author_email='circuitpython@adafruit.com',
author="Adafruit Industries",
author_email="circuitpython@adafruit.com",
install_requires=[
'Adafruit-Blinka',
'adafruit-circuitpython-busdevice',
'adafruit-circuitpython-framebuf'
"Adafruit-Blinka",
"adafruit-circuitpython-busdevice",
"adafruit-circuitpython-framebuf",
],
# 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 ssd1305 framebuf rpi',
keywords="adafruit blinka circuitpython micropython ssd1305 framebuf rpi",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
py_modules=['adafruit_ssd1305'],
py_modules=["adafruit_ssd1305"],
)