Skip to content

Commit

Permalink
Merge pull request #24 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni committed Mar 17, 2020
2 parents 73db026 + 83d9a09 commit 94088a7
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions adafruit_mcp3xxx/analog_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,38 @@

from .mcp3xxx import MCP3xxx

class AnalogIn():

class AnalogIn:
"""AnalogIn Mock Implementation for ADC Reads.
:param MCP3002,MCP3004,MCP3008 mcp: The mcp object.
:param int positive_pin: Required pin for single-ended.
:param int negative_pin: Optional pin for differential reads.
"""

def __init__(self, mcp, positive_pin, negative_pin=None):
if not isinstance(mcp, MCP3xxx):
raise ValueError("mcp object is not a sibling of MCP3xxx class.")
self._mcp = mcp
self._pin_setting = positive_pin
self.is_differential = negative_pin is not None
if self.is_differential:
self._pin_setting = self._mcp.DIFF_PINS.get((positive_pin, negative_pin), None)
self._pin_setting = self._mcp.DIFF_PINS.get(
(positive_pin, negative_pin), None
)
if self._pin_setting is None:
raise ValueError("Differential pin mapping not defined. Please read the "
"documentation for valid differential channel mappings.")
raise ValueError(
"Differential pin mapping not defined. Please read the "
"documentation for valid differential channel mappings."
)

@property
def value(self):
"""Returns the value of an ADC pin as an integer. Due to 10-bit accuracy of the chip, the
returned values range [0, 65472]."""
return self._mcp.read(self._pin_setting, is_differential=self.is_differential) << 6
return (
self._mcp.read(self._pin_setting, is_differential=self.is_differential) << 6
)

@property
def voltage(self):
Expand Down
9 changes: 4 additions & 5 deletions adafruit_mcp3xxx/mcp3002.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
P0 = 0
P1 = 1


class MCP3002(MCP3xxx):
"""
MCP3002 Differential channel mapping. The following list of available differential readings
Expand All @@ -49,14 +50,12 @@ class MCP3002(MCP3xxx):
See also the warning in the `AnalogIn`_ class API.
"""
DIFF_PINS = {
(0, 1) : P0,
(1, 0) : P1
}

DIFF_PINS = {(0, 1): P0, (1, 0): P1}

def read(self, pin, is_differential=False):
self._out_buf[0] = 0x40 | ((not is_differential) << 5) | (pin << 4)
with self._spi_device as spi:
#pylint: disable=no-member
# pylint: disable=no-member
spi.write_readinto(self._out_buf, self._in_buf, out_end=2, in_end=2)
return ((self._in_buf[0] & 0x03) << 8) | self._in_buf[1]
9 changes: 3 additions & 6 deletions adafruit_mcp3xxx/mcp3004.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
P2 = 2
P3 = 3


class MCP3004(MCP3xxx):
"""
MCP3004 Differential channel mapping. The following list of available differential readings
Expand All @@ -53,12 +54,8 @@ class MCP3004(MCP3xxx):
See also the warning in the `AnalogIn`_ class API.
"""
DIFF_PINS = {
(0, 1) : P0,
(1, 0) : P1,
(2, 3) : P2,
(3, 2) : P3
}

DIFF_PINS = {(0, 1): P0, (1, 0): P1, (2, 3): P2, (3, 2): P3}

def __init__(self, spi_bus, cs, ref_voltage=3.3):
super(MCP3004, self).__init__(spi_bus, cs, ref_voltage=ref_voltage)
Expand Down
18 changes: 10 additions & 8 deletions adafruit_mcp3xxx/mcp3008.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
P6 = 6
P7 = 7


class MCP3008(MCP3xxx):
"""
MCP3008 Differential channel mapping. The following list of available differential readings
Expand All @@ -61,15 +62,16 @@ class MCP3008(MCP3xxx):
See also the warning in the `AnalogIn`_ class API.
"""

DIFF_PINS = {
(0, 1) : P0,
(1, 0) : P1,
(2, 3) : P2,
(3, 2) : P3,
(4, 5) : P4,
(5, 4) : P5,
(6, 7) : P6,
(7, 6) : P7
(0, 1): P0,
(1, 0): P1,
(2, 3): P2,
(3, 2): P3,
(4, 5): P4,
(5, 4): P5,
(6, 7): P6,
(7, 6): P7,
}

def __init__(self, spi_bus, cs, ref_voltage=3.3):
Expand Down
4 changes: 3 additions & 1 deletion adafruit_mcp3xxx/mcp3xxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

from adafruit_bus_device.spi_device import SPIDevice


class MCP3xxx:
"""
This abstract base class is meant to be inherited by `MCP3008`_, `MCP3004`_,
Expand All @@ -68,6 +69,7 @@ class MCP3xxx:
:param ~digitalio.DigitalInOut cs: Chip Select Pin.
:param float ref_voltage: Voltage into (Vin) the ADC.
"""

def __init__(self, spi_bus, cs, ref_voltage=3.3):
self._spi_device = SPIDevice(spi_bus, cs)
self._out_buf = bytearray(3)
Expand All @@ -93,6 +95,6 @@ def read(self, pin, is_differential=False):
"""
self._out_buf[1] = ((not is_differential) << 7) | (pin << 4)
with self._spi_device as spi:
#pylint: disable=no-member
# pylint: disable=no-member
spi.write_readinto(self._out_buf, self._in_buf)
return ((self._in_buf[1] & 0x03) << 8) | self._in_buf[2]
116 changes: 69 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# 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!
Expand All @@ -23,29 +24,36 @@
autodoc_mock_imports = ["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 MCP3xxx Library'
copyright = u'2018 ladyada'
author = u'ladyada'
project = u"Adafruit MCP3xxx Library"
copyright = u"2018 ladyada"
author = u"ladyada"

# 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.
Expand All @@ -57,7 +65,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.
Expand All @@ -69,7 +77,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
Expand All @@ -84,68 +92,76 @@
# 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 = 'AdafruitMcp3xxxLibrarydoc'
htmlhelp_basename = "AdafruitMcp3xxxLibrarydoc"

# -- 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, 'AdafruitMCP3xxxLibrary.tex', u'AdafruitMCP3xxx Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitMCP3xxxLibrary.tex",
u"AdafruitMCP3xxx Library Documentation",
author,
"manual",
),
]

# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitMCP3xxxlibrary', u'Adafruit MCP3xxx Library Documentation',
[author], 1)
(
master_doc,
"AdafruitMCP3xxxlibrary",
u"Adafruit MCP3xxx Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +170,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitMCP3xxxLibrary', u'Adafruit MCP3xxx Library Documentation',
author, 'AdafruitMCP3xxxLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitMCP3xxxLibrary",
u"Adafruit MCP3xxx Library Documentation",
author,
"AdafruitMCP3xxxLibrary",
"One line description of project.",
"Miscellaneous",
),
]
4 changes: 2 additions & 2 deletions examples/mcp3xxx_mcp3002_differential_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# create a differential ADC channel between Pin 0 and Pin 1
chan = AnalogIn(mcp, MCP.P0, MCP.P1)

print('Differential ADC Value: ', chan.value)
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')
print("Differential ADC Value: ", chan.value)
print("Differential ADC Voltage: " + str(chan.voltage) + "V")
4 changes: 2 additions & 2 deletions examples/mcp3xxx_mcp3002_single_ended_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)

print('Raw ADC Value: ', chan.value)
print('ADC Voltage: ' + str(chan.voltage) + 'V')
print("Raw ADC Value: ", chan.value)
print("ADC Voltage: " + str(chan.voltage) + "V")
4 changes: 2 additions & 2 deletions examples/mcp3xxx_mcp3004_differential_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
# create a differential ADC channel between Pin 0 and Pin 1
chan = AnalogIn(mcp, MCP.P0, MCP.P1)

print('Differential ADC Value: ', chan.value)
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')
print("Differential ADC Value: ", chan.value)
print("Differential ADC Voltage: " + str(chan.voltage) + "V")

0 comments on commit 94088a7

Please sign in to comment.