Ran black, updated to pylint 2.x

This commit is contained in:
dherrada 2020-03-15 14:45:42 -04:00
parent 6919489a53
commit 7ac2b297ed
5 changed files with 128 additions and 106 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

@ -49,7 +49,7 @@ _AS726X_INT_T = const(0x05)
_AS726X_DEVICE_TEMP = const(0x06)
_AS726X_LED_CONTROL = const(0x07)
#for reading sensor data
# for reading sensor data
_AS7262_V_HIGH = const(0x08)
_AS7262_V_LOW = const(0x09)
_AS7262_B_HIGH = const(0x0A)
@ -70,7 +70,7 @@ _AS7262_Y_CAL = const(0x20)
_AS7262_O_CAL = const(0x24)
_AS7262_R_CAL = const(0x28)
#hardware registers
# hardware registers
_AS726X_SLAVE_STATUS_REG = const(0x00)
_AS726X_SLAVE_WRITE_REG = const(0x01)
_AS726X_SLAVE_READ_REG = const(0x02)
@ -92,9 +92,9 @@ _AS7262_RED_CALIBRATED = const(0x28)
_AS726X_NUM_CHANNELS = const(6)
#pylint: disable=too-many-instance-attributes
#pylint: disable=too-many-public-methods
class Adafruit_AS726x(object):
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-public-methods
class Adafruit_AS726x():
"""AS726x spectral sensor.
:param ~busio.I2C i2c_bus: The I2C bus connected to the sensor
@ -108,7 +108,7 @@ class Adafruit_AS726x(object):
"""Continuously gather samples of green, yellow, orange and red. Violet and blue are skipped
and read zero."""
MODE_2 = 0b10 #default
MODE_2 = 0b10 # default
"""Continuously gather samples of all colors"""
ONE_SHOT = 0b11
@ -132,18 +132,20 @@ class Adafruit_AS726x(object):
self.i2c_device = I2CDevice(i2c_bus, _AS726X_ADDRESS)
#reset device
# reset device
self._virtual_write(_AS726X_CONTROL_SETUP, 0x80)
#wait for it to boot up
# wait for it to boot up
time.sleep(1)
#try to read the version reg to make sure we can connect
# try to read the version reg to make sure we can connect
version = self._virtual_read(_AS726X_HW_VERSION)
#TODO: add support for other devices
# TODO: add support for other devices
if version != 0x40:
raise ValueError("device could not be reached or this device is not supported!")
raise ValueError(
"device could not be reached or this device is not supported!"
)
self.integration_time = 140
self.conversion_mode = Adafruit_AS726x.MODE_2
@ -258,7 +260,7 @@ class Adafruit_AS726x(object):
self._gain = val
state = self._virtual_read(_AS726X_CONTROL_SETUP)
state &= ~(0x3 << 4)
state |= (Adafruit_AS726x.GAIN.index(val) << 4)
state |= Adafruit_AS726x.GAIN.index(val) << 4
self._virtual_write(_AS726X_CONTROL_SETUP, state)
@property
@ -274,7 +276,7 @@ class Adafruit_AS726x(object):
if self._integration_time == val:
return
self._integration_time = val
self._virtual_write(_AS726X_INT_T, int(val/2.8))
self._virtual_write(_AS726X_INT_T, int(val / 2.8))
def start_measurement(self):
"""Begin a measurement.
@ -298,7 +300,7 @@ class Adafruit_AS726x(object):
val[1] = self._virtual_read(channel + 1)
val[2] = self._virtual_read(channel + 2)
val[3] = self._virtual_read(channel + 3)
return struct.unpack('!f', val)[0]
return struct.unpack("!f", val)[0]
@property
def data_ready(self):
@ -426,5 +428,5 @@ class Adafruit_AS726x(object):
self.__write_u8(_AS726X_SLAVE_WRITE_REG, value)
#pylint: enable=too-many-instance-attributes
#pylint: enable=too-many-public-methods
# pylint: enable=too-many-instance-attributes
# pylint: enable=too-many-public-methods

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,36 +11,47 @@ 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.todo',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
]
autodoc_member_order = 'bysource'
autodoc_member_order = "bysource"
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/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,
),
"Register": (
"https://circuitpython.readthedocs.io/projects/register/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 AS726x Library'
copyright = u'2017 Dean Miller'
author = u'Dean Miller'
project = u"Adafruit AS726x Library"
copyright = u"2017 Dean Miller"
author = u"Dean Miller"
# 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.
@ -51,7 +63,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.
@ -63,7 +75,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
@ -77,26 +89,27 @@ todo_emit_warnings = True
# 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"]
# Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitAs726xLibrarydoc'
htmlhelp_basename = "AdafruitAs726xLibrarydoc"
# -- Options for LaTeX output ---------------------------------------------
@ -104,15 +117,12 @@ 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',
@ -122,8 +132,13 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'AdafruitAS726xLibrary.tex', u'AdafruitAS726x Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitAS726xLibrary.tex",
u"AdafruitAS726x Library Documentation",
author,
"manual",
),
]
# -- Options for manual page output ---------------------------------------
@ -131,8 +146,13 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitAS726xlibrary', u'Adafruit AS726x Library Documentation',
[author], 1)
(
master_doc,
"AdafruitAS726xlibrary",
u"Adafruit AS726x Library Documentation",
[author],
1,
)
]
# -- Options for Texinfo output -------------------------------------------
@ -141,7 +161,13 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitAS726xLibrary', u'Adafruit AS726x Library Documentation',
author, 'AdafruitAS726xLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitAS726xLibrary",
u"Adafruit AS726x Library Documentation",
author,
"AdafruitAS726xLibrary",
"One line description of project.",
"Miscellaneous",
),
]

View file

@ -5,15 +5,17 @@ import busio
from adafruit_as726x import Adafruit_AS726x
#maximum value for sensor reading
# maximum value for sensor reading
max_val = 16000
#max number of characters in each graph
# max number of characters in each graph
max_graph = 80
def graph_map(x):
return min(int(x * max_graph / max_val), max_graph)
# Initialize I2C bus and sensor.
i2c = busio.I2C(board.SCL, board.SDA)
sensor = Adafruit_AS726x(i2c)
@ -23,15 +25,15 @@ sensor.conversion_mode = sensor.MODE_2
while True:
# Wait for data to be ready
while not sensor.data_ready:
time.sleep(.1)
time.sleep(0.1)
#plot plot the data
# plot plot the data
print("\n")
print("V: " + graph_map(sensor.violet)*'=')
print("B: " + graph_map(sensor.blue)*'=')
print("G: " + graph_map(sensor.green)*'=')
print("Y: " + graph_map(sensor.yellow)*'=')
print("O: " + graph_map(sensor.orange)*'=')
print("R: " + graph_map(sensor.red)*'=')
print("V: " + graph_map(sensor.violet) * "=")
print("B: " + graph_map(sensor.blue) * "=")
print("G: " + graph_map(sensor.green) * "=")
print("Y: " + graph_map(sensor.yellow) * "=")
print("O: " + graph_map(sensor.orange) * "=")
print("R: " + graph_map(sensor.red) * "=")
time.sleep(1)

View file

@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from os import path
@ -14,51 +15,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-as726x',
name="adafruit-circuitpython-as726x",
use_scm_version=True,
setup_requires=['setuptools_scm'],
description='CircuitPython driver for AS726x spectral sensor.',
setup_requires=["setuptools_scm"],
description="CircuitPython driver for AS726x spectral sensor.",
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_AS726x',
url="https://github.com/adafruit/Adafruit_CircuitPython_AS726x",
# Author details
author='Adafruit Industries',
author_email='circuitpython@adafruit.com',
author="Adafruit Industries",
author_email="circuitpython@adafruit.com",
install_requires=[
'Adafruit-Blinka',
'adafruit-circuitpython-register',
'adafruit-circuitpython-busdevice'
"Adafruit-Blinka",
"adafruit-circuitpython-register",
"adafruit-circuitpython-busdevice",
],
# 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 as726x light sensor hardware micropython circuitpython',
keywords="adafruit as726x light sensor hardware micropython circuitpython",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
py_modules=['adafruit_as726x'],
py_modules=["adafruit_as726x"],
)