Skip to content

Commit 94088a7

Browse files
authored
Merge pull request #24 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 73db026 + 83d9a09 commit 94088a7

14 files changed

+137
-115
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_mcp3xxx/analog_in.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,38 @@
3737

3838
from .mcp3xxx import MCP3xxx
3939

40-
class AnalogIn():
40+
41+
class AnalogIn:
4142
"""AnalogIn Mock Implementation for ADC Reads.
4243
4344
:param MCP3002,MCP3004,MCP3008 mcp: The mcp object.
4445
:param int positive_pin: Required pin for single-ended.
4546
:param int negative_pin: Optional pin for differential reads.
4647
"""
48+
4749
def __init__(self, mcp, positive_pin, negative_pin=None):
4850
if not isinstance(mcp, MCP3xxx):
4951
raise ValueError("mcp object is not a sibling of MCP3xxx class.")
5052
self._mcp = mcp
5153
self._pin_setting = positive_pin
5254
self.is_differential = negative_pin is not None
5355
if self.is_differential:
54-
self._pin_setting = self._mcp.DIFF_PINS.get((positive_pin, negative_pin), None)
56+
self._pin_setting = self._mcp.DIFF_PINS.get(
57+
(positive_pin, negative_pin), None
58+
)
5559
if self._pin_setting is None:
56-
raise ValueError("Differential pin mapping not defined. Please read the "
57-
"documentation for valid differential channel mappings.")
60+
raise ValueError(
61+
"Differential pin mapping not defined. Please read the "
62+
"documentation for valid differential channel mappings."
63+
)
5864

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

6573
@property
6674
def voltage(self):

adafruit_mcp3xxx/mcp3002.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
P0 = 0
4040
P1 = 1
4141

42+
4243
class MCP3002(MCP3xxx):
4344
"""
4445
MCP3002 Differential channel mapping. The following list of available differential readings
@@ -49,14 +50,12 @@ class MCP3002(MCP3xxx):
4950
5051
See also the warning in the `AnalogIn`_ class API.
5152
"""
52-
DIFF_PINS = {
53-
(0, 1) : P0,
54-
(1, 0) : P1
55-
}
53+
54+
DIFF_PINS = {(0, 1): P0, (1, 0): P1}
5655

5756
def read(self, pin, is_differential=False):
5857
self._out_buf[0] = 0x40 | ((not is_differential) << 5) | (pin << 4)
5958
with self._spi_device as spi:
60-
#pylint: disable=no-member
59+
# pylint: disable=no-member
6160
spi.write_readinto(self._out_buf, self._in_buf, out_end=2, in_end=2)
6261
return ((self._in_buf[0] & 0x03) << 8) | self._in_buf[1]

adafruit_mcp3xxx/mcp3004.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
P2 = 2
4242
P3 = 3
4343

44+
4445
class MCP3004(MCP3xxx):
4546
"""
4647
MCP3004 Differential channel mapping. The following list of available differential readings
@@ -53,12 +54,8 @@ class MCP3004(MCP3xxx):
5354
5455
See also the warning in the `AnalogIn`_ class API.
5556
"""
56-
DIFF_PINS = {
57-
(0, 1) : P0,
58-
(1, 0) : P1,
59-
(2, 3) : P2,
60-
(3, 2) : P3
61-
}
57+
58+
DIFF_PINS = {(0, 1): P0, (1, 0): P1, (2, 3): P2, (3, 2): P3}
6259

6360
def __init__(self, spi_bus, cs, ref_voltage=3.3):
6461
super(MCP3004, self).__init__(spi_bus, cs, ref_voltage=ref_voltage)

adafruit_mcp3xxx/mcp3008.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
P6 = 6
4646
P7 = 7
4747

48+
4849
class MCP3008(MCP3xxx):
4950
"""
5051
MCP3008 Differential channel mapping. The following list of available differential readings
@@ -61,15 +62,16 @@ class MCP3008(MCP3xxx):
6162
6263
See also the warning in the `AnalogIn`_ class API.
6364
"""
65+
6466
DIFF_PINS = {
65-
(0, 1) : P0,
66-
(1, 0) : P1,
67-
(2, 3) : P2,
68-
(3, 2) : P3,
69-
(4, 5) : P4,
70-
(5, 4) : P5,
71-
(6, 7) : P6,
72-
(7, 6) : P7
67+
(0, 1): P0,
68+
(1, 0): P1,
69+
(2, 3): P2,
70+
(3, 2): P3,
71+
(4, 5): P4,
72+
(5, 4): P5,
73+
(6, 7): P6,
74+
(7, 6): P7,
7375
}
7476

7577
def __init__(self, spi_bus, cs, ref_voltage=3.3):

adafruit_mcp3xxx/mcp3xxx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
from adafruit_bus_device.spi_device import SPIDevice
6161

62+
6263
class MCP3xxx:
6364
"""
6465
This abstract base class is meant to be inherited by `MCP3008`_, `MCP3004`_,
@@ -68,6 +69,7 @@ class MCP3xxx:
6869
:param ~digitalio.DigitalInOut cs: Chip Select Pin.
6970
:param float ref_voltage: Voltage into (Vin) the ADC.
7071
"""
72+
7173
def __init__(self, spi_bus, cs, ref_voltage=3.3):
7274
self._spi_device = SPIDevice(spi_bus, cs)
7375
self._out_buf = bytearray(3)
@@ -93,6 +95,6 @@ def read(self, pin, is_differential=False):
9395
"""
9496
self._out_buf[1] = ((not is_differential) << 7) | (pin << 4)
9597
with self._spi_device as spi:
96-
#pylint: disable=no-member
98+
# pylint: disable=no-member
9799
spi.write_readinto(self._out_buf, self._in_buf)
98100
return ((self._in_buf[1] & 0x03) << 8) | self._in_buf[2]

docs/conf.py

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,36 @@
2324
autodoc_mock_imports = ["busio"]
2425

2526

26-
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)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"BusDevice": (
30+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
31+
None,
32+
),
33+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
34+
}
2735

2836
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
37+
templates_path = ["_templates"]
3038

31-
source_suffix = '.rst'
39+
source_suffix = ".rst"
3240

3341
# The master toctree document.
34-
master_doc = 'index'
42+
master_doc = "index"
3543

3644
# General information about the project.
37-
project = u'Adafruit MCP3xxx Library'
38-
copyright = u'2018 ladyada'
39-
author = u'ladyada'
45+
project = u"Adafruit MCP3xxx Library"
46+
copyright = u"2018 ladyada"
47+
author = u"ladyada"
4048

4149
# The version info for the project you're documenting, acts as replacement for
4250
# |version| and |release|, also used in various other places throughout the
4351
# built documents.
4452
#
4553
# The short X.Y version.
46-
version = u'1.0'
54+
version = u"1.0"
4755
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
56+
release = u"1.0"
4957

5058
# The language for content autogenerated by Sphinx. Refer to documentation
5159
# for a list of supported languages.
@@ -57,7 +65,7 @@
5765
# List of patterns, relative to source directory, that match files and
5866
# directories to ignore when looking for source files.
5967
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
68+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6169

6270
# The reST default role (used for this markup: `text`) to use for all
6371
# documents.
@@ -69,7 +77,7 @@
6977
add_function_parentheses = True
7078

7179
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
7381

7482
# If true, `todo` and `todoList` produce output, else they produce nothing.
7583
todo_include_todos = False
@@ -84,68 +92,76 @@
8492
# The theme to use for HTML and HTML Help pages. See the documentation for
8593
# a list of builtin themes.
8694
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
95+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8896

8997
if not on_rtd: # only import and set the theme if we're building docs locally
9098
try:
9199
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
100+
101+
html_theme = "sphinx_rtd_theme"
102+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
94103
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
104+
html_theme = "default"
105+
html_theme_path = ["."]
97106
else:
98-
html_theme_path = ['.']
107+
html_theme_path = ["."]
99108

100109
# Add any paths that contain custom static files (such as style sheets) here,
101110
# relative to this directory. They are copied after the builtin static files,
102111
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
112+
html_static_path = ["_static"]
104113

105114
# The name of an image file (relative to this directory) to use as a favicon of
106115
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107116
# pixels large.
108117
#
109-
html_favicon = '_static/favicon.ico'
118+
html_favicon = "_static/favicon.ico"
110119

111120
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitMcp3xxxLibrarydoc'
121+
htmlhelp_basename = "AdafruitMcp3xxxLibrarydoc"
113122

114123
# -- Options for LaTeX output ---------------------------------------------
115124

116125
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
126+
# The paper size ('letterpaper' or 'a4paper').
127+
#
128+
# 'papersize': 'letterpaper',
129+
# The font size ('10pt', '11pt' or '12pt').
130+
#
131+
# 'pointsize': '10pt',
132+
# Additional stuff for the LaTeX preamble.
133+
#
134+
# 'preamble': '',
135+
# Latex figure (float) alignment
136+
#
137+
# 'figure_align': 'htbp',
132138
}
133139

134140
# Grouping the document tree into LaTeX files. List of tuples
135141
# (source start file, target name, title,
136142
# author, documentclass [howto, manual, or own class]).
137143
latex_documents = [
138-
(master_doc, 'AdafruitMCP3xxxLibrary.tex', u'AdafruitMCP3xxx Library Documentation',
139-
author, 'manual'),
144+
(
145+
master_doc,
146+
"AdafruitMCP3xxxLibrary.tex",
147+
u"AdafruitMCP3xxx Library Documentation",
148+
author,
149+
"manual",
150+
),
140151
]
141152

142153
# -- Options for manual page output ---------------------------------------
143154

144155
# One entry per manual page. List of tuples
145156
# (source start file, name, description, authors, manual section).
146157
man_pages = [
147-
(master_doc, 'AdafruitMCP3xxxlibrary', u'Adafruit MCP3xxx Library Documentation',
148-
[author], 1)
158+
(
159+
master_doc,
160+
"AdafruitMCP3xxxlibrary",
161+
u"Adafruit MCP3xxx Library Documentation",
162+
[author],
163+
1,
164+
)
149165
]
150166

151167
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +170,13 @@
154170
# (source start file, target name, title, author,
155171
# dir menu entry, description, category)
156172
texinfo_documents = [
157-
(master_doc, 'AdafruitMCP3xxxLibrary', u'Adafruit MCP3xxx Library Documentation',
158-
author, 'AdafruitMCP3xxxLibrary', 'One line description of project.',
159-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"AdafruitMCP3xxxLibrary",
176+
u"Adafruit MCP3xxx Library Documentation",
177+
author,
178+
"AdafruitMCP3xxxLibrary",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
160182
]

examples/mcp3xxx_mcp3002_differential_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
# create a differential ADC channel between Pin 0 and Pin 1
1717
chan = AnalogIn(mcp, MCP.P0, MCP.P1)
1818

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

examples/mcp3xxx_mcp3002_single_ended_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
# create an analog input channel on pin 0
1717
chan = AnalogIn(mcp, MCP.P0)
1818

19-
print('Raw ADC Value: ', chan.value)
20-
print('ADC Voltage: ' + str(chan.voltage) + 'V')
19+
print("Raw ADC Value: ", chan.value)
20+
print("ADC Voltage: " + str(chan.voltage) + "V")

examples/mcp3xxx_mcp3004_differential_simpletest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
# create a differential ADC channel between Pin 0 and Pin 1
1717
chan = AnalogIn(mcp, MCP.P0, MCP.P1)
1818

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

0 commit comments

Comments
 (0)