Ran black, updated to pylint 2.x

This commit is contained in:
dherrada 2020-03-16 15:41:23 -04:00
parent 566dbbd8ab
commit f334edadec
12 changed files with 183 additions and 162 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

@ -119,7 +119,8 @@ spelling-store-unknown-words=no
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,XXX,TODO
# notes=FIXME,XXX,TODO
notes=FIXME,XXX
[TYPECHECK]

View file

@ -28,6 +28,7 @@ CircuitPython driver for ADS1015 ADCs.
* Author(s): Carter Nelson
"""
import struct
# pylint: disable=unused-import
from .ads1x15 import ADS1x15, Mode
@ -39,7 +40,7 @@ _ADS1015_CONFIG_DR = {
920: 0x0060,
1600: 0x0080,
2400: 0x00A0,
3300: 0x00C0
3300: 0x00C0,
}
# Pins
@ -48,6 +49,7 @@ P1 = 1
P2 = 2
P3 = 3
class ADS1015(ADS1x15):
"""Class for the ADS1015 12 bit ADC."""

View file

@ -28,6 +28,7 @@ CircuitPython driver for 1115 ADCs.
* Author(s): Carter Nelson
"""
import struct
# pylint: disable=unused-import
from .ads1x15 import ADS1x15, Mode
@ -40,7 +41,7 @@ _ADS1115_CONFIG_DR = {
128: 0x0080,
250: 0x00A0,
475: 0x00C0,
860: 0x00E0
860: 0x00E0,
}
# Pins
@ -49,6 +50,7 @@ P1 = 1
P2 = 2
P3 = 3
class ADS1115(ADS1x15):
"""Class for the ADS1115 16 bit ADC."""

View file

@ -47,12 +47,14 @@ _ADS1X15_CONFIG_GAIN = {
2: 0x0400,
4: 0x0600,
8: 0x0800,
16: 0x0A00
16: 0x0A00,
}
# pylint: enable=bad-whitespace
class Mode:
"""An enum-like class representing possible ADC operating modes."""
# See datasheet "Operating Modes" section
# values here are masks for setting MODE bit in Config Register
# pylint: disable=too-few-public-methods
@ -60,11 +62,17 @@ class Mode:
SINGLE = 0x0100
class ADS1x15(object):
class ADS1x15:
"""Base functionality for ADS1x15 analog to digital converters."""
def __init__(self, i2c, gain=1, data_rate=None, mode=Mode.SINGLE,
address=_ADS1X15_DEFAULT_ADDRESS):
def __init__(
self,
i2c,
gain=1,
data_rate=None,
mode=Mode.SINGLE,
address=_ADS1X15_DEFAULT_ADDRESS,
):
# pylint: disable=too-many-arguments
self._last_pin_read = None
self.buf = bytearray(3)
@ -89,12 +97,12 @@ class ADS1x15(object):
@property
def rates(self):
"""Possible data rate settings."""
raise NotImplementedError('Subclass must implement rates property.')
raise NotImplementedError("Subclass must implement rates property.")
@property
def rate_config(self):
"""Rate configuration masks."""
raise NotImplementedError('Subclass must implement rate_config property.')
raise NotImplementedError("Subclass must implement rate_config property.")
@property
def gain(self):
@ -122,7 +130,7 @@ class ADS1x15(object):
@mode.setter
def mode(self, mode):
if mode != Mode.CONTINUOUS and mode != Mode.SINGLE:
if mode not in (Mode.CONTINUOUS, Mode.SINGLE):
raise ValueError("Unsupported mode.")
self._mode = mode
@ -140,19 +148,18 @@ class ADS1x15(object):
"""Retrieve the default data rate for this ADC (in samples per second).
Should be implemented by subclasses.
"""
raise NotImplementedError('Subclasses must implement _data_rate_default!')
raise NotImplementedError("Subclasses must implement _data_rate_default!")
def _conversion_value(self, raw_adc):
"""Subclasses should override this function that takes the 16 raw ADC
values of a conversion result and returns a signed integer value.
"""
raise NotImplementedError('Subclass must implement _conversion_value function!')
raise NotImplementedError("Subclass must implement _conversion_value function!")
def _read(self, pin):
"""Perform an ADC read. Returns the signed integer result of the read."""
if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin:
return self._conversion_value(self.get_last_result(True))
else:
self._last_pin_read = pin
config = _ADS1X15_CONFIG_OS_SINGLE
config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET

View file

@ -29,23 +29,12 @@ differential ADC readings.
"""
# pylint: disable=bad-whitespace
_ADS1X15_DIFF_CHANNELS = {
(0, 1): 0,
(0, 3): 1,
(1, 3): 2,
(2, 3): 3
}
_ADS1X15_PGA_RANGE = {
2/3: 6.144,
1: 4.096,
2: 2.048,
4: 1.024,
8: 0.512,
16: 0.256
}
_ADS1X15_DIFF_CHANNELS = {(0, 1): 0, (0, 3): 1, (1, 3): 2, (2, 3): 3}
_ADS1X15_PGA_RANGE = {2 / 3: 6.144, 1: 4.096, 2: 2.048, 4: 1.024, 8: 0.512, 16: 0.256}
# pylint: enable=bad-whitespace
class AnalogIn():
class AnalogIn:
"""AnalogIn Mock Implementation for ADC Reads."""
def __init__(self, ads, positive_pin, negative_pin=None):
@ -62,16 +51,20 @@ class AnalogIn():
if negative_pin is not None:
pins = (self._pin_setting, self._negative_pin)
if pins not in _ADS1X15_DIFF_CHANNELS:
raise ValueError("Differential channels must be one of: {}"
.format(list(_ADS1X15_DIFF_CHANNELS.keys())))
raise ValueError(
"Differential channels must be one of: {}".format(
list(_ADS1X15_DIFF_CHANNELS.keys())
)
)
self._pin_setting = _ADS1X15_DIFF_CHANNELS[pins]
self.is_differential = True
@property
def value(self):
"""Returns the value of an ADC pin as an integer."""
return self._ads.read(self._pin_setting,
is_differential=self.is_differential) << (16 - self._ads.bits)
return self._ads.read(
self._pin_setting, is_differential=self.is_differential
) << (16 - self._ads.bits)
@property
def voltage(self):

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,34 +11,45 @@ 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.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]
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 CIRCUITPYTHON_ADS1X15 Library'
copyright = u'2017 Carter Nelson'
author = u'Carter Nelson'
project = u"Adafruit CIRCUITPYTHON_ADS1X15 Library"
copyright = u"2017 Carter Nelson"
author = u"Carter Nelson"
# 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.
@ -49,7 +61,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.
@ -61,7 +73,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
@ -75,32 +87,33 @@ 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"]
# 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 = 'AdafruitCIRCUITPYTHON_ADS1X15Librarydoc'
htmlhelp_basename = "AdafruitCIRCUITPYTHON_ADS1X15Librarydoc"
# -- Options for LaTeX output ---------------------------------------------
@ -108,15 +121,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',
@ -126,8 +136,13 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'AdafruitCIRCUITPYTHON_ADS1X15Library.tex', u'Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitCIRCUITPYTHON_ADS1X15Library.tex",
u"Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation",
author,
"manual",
),
]
# -- Options for manual page output ---------------------------------------
@ -135,8 +150,13 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'adafruitCIRCUITPYTHON_ADS1X15library', u'Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation',
[author], 1)
(
master_doc,
"adafruitCIRCUITPYTHON_ADS1X15library",
u"Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation",
[author],
1,
)
]
# -- Options for Texinfo output -------------------------------------------
@ -145,7 +165,13 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitCIRCUITPYTHON_ADS1X15Library', u'Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation',
author, 'AdafruitCIRCUITPYTHON_ADS1X15Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitCIRCUITPYTHON_ADS1X15Library",
u"Adafruit CIRCUITPYTHON_ADS1X15 Library Documentation",
author,
"AdafruitCIRCUITPYTHON_ADS1X15Library",
"One line description of project.",
"Miscellaneous",
),
]

View file

@ -18,7 +18,7 @@ chan = AnalogIn(ads, ADS.P0)
# Create differential input between channel 0 and 1
# chan = AnalogIn(ads, ADS.P0, ADS.P1)
print("{:>5}\t{:>5}".format('raw', 'v'))
print("{:>5}\t{:>5}".format("raw", "v"))
while True:
print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))

View file

@ -1,6 +1,7 @@
import time
import board
import busio
# import adafruit_ads1x15.ads1015 as ADS
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
@ -32,9 +33,9 @@ gains = (2/3, 1, 2, 4, 8, 16)
while True:
ads.gain = gains[0]
print('{:5} {:5.3f}'.format(chan.value, chan.voltage), end='')
print("{:5} {:5.3f}".format(chan.value, chan.voltage), end="")
for gain in gains[1:]:
ads.gain = gain
print(' | {:5} {:5.3f}'.format(chan.value, chan.voltage), end='')
print(" | {:5} {:5.3f}".format(chan.value, chan.voltage), end="")
print()
time.sleep(0.5)

View file

@ -16,7 +16,7 @@ chan = AnalogIn(ads, ADS.P0)
# Create differential input between channel 0 and 1
# chan = AnalogIn(ads, ADS.P0, ADS.P1)
print("{:>5}\t{:>5}".format('raw', 'v'))
print("{:>5}\t{:>5}".format("raw", "v"))
while True:
print("{:>5}\t{:>5.3f}".format(chan.value, chan.voltage))

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,50 +14,38 @@ 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-ads1x15',
name="adafruit-circuitpython-ads1x15",
use_scm_version=True,
setup_requires=['setuptools_scm'],
description='CircuitPython library for controlling an ADS1x15 ADC.',
setup_requires=["setuptools_scm"],
description="CircuitPython library for controlling an ADS1x15 ADC.",
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_ADS1x15',
url="https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15",
# Author details
author='Adafruit Industries',
author_email='circuitpython@adafruit.com',
install_requires=[
'Adafruit-Blinka',
'adafruit-circuitpython-busdevice'
],
author="Adafruit Industries",
author_email="circuitpython@adafruit.com",
install_requires=["Adafruit-Blinka", "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 ads1x115 adc hardware micropython circuitpython',
keywords="adafruit ads1x115 adc hardware micropython circuitpython",
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=['adafruit_ads1x15'],
packages=["adafruit_ads1x15"],
)