Skip to content

Commit 7c39b8e

Browse files
authored
Merge pull request #11 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 049b3b2 + 88e6c82 commit 7c39b8e

File tree

5 files changed

+174
-154
lines changed

5 files changed

+174
-154
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_mma8451.py

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,43 +42,43 @@
4242
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MMA8451.git"
4343

4444

45-
#pylint: disable=bad-whitespace
45+
# pylint: disable=bad-whitespace
4646
# Internal constants:
47-
_MMA8451_DEFAULT_ADDRESS = const(0x1D)
48-
_MMA8451_REG_OUT_X_MSB = const(0x01)
49-
_MMA8451_REG_SYSMOD = const(0x0B)
50-
_MMA8451_REG_WHOAMI = const(0x0D)
51-
_MMA8451_REG_XYZ_DATA_CFG = const(0x0E)
52-
_MMA8451_REG_PL_STATUS = const(0x10)
53-
_MMA8451_REG_PL_CFG = const(0x11)
54-
_MMA8451_REG_CTRL_REG1 = const(0x2A)
55-
_MMA8451_REG_CTRL_REG2 = const(0x2B)
56-
_MMA8451_REG_CTRL_REG4 = const(0x2D)
57-
_MMA8451_REG_CTRL_REG5 = const(0x2E)
58-
_MMA8451_DATARATE_MASK = const(0b111)
59-
_SENSORS_GRAVITY_EARTH = 9.80665
47+
_MMA8451_DEFAULT_ADDRESS = const(0x1D)
48+
_MMA8451_REG_OUT_X_MSB = const(0x01)
49+
_MMA8451_REG_SYSMOD = const(0x0B)
50+
_MMA8451_REG_WHOAMI = const(0x0D)
51+
_MMA8451_REG_XYZ_DATA_CFG = const(0x0E)
52+
_MMA8451_REG_PL_STATUS = const(0x10)
53+
_MMA8451_REG_PL_CFG = const(0x11)
54+
_MMA8451_REG_CTRL_REG1 = const(0x2A)
55+
_MMA8451_REG_CTRL_REG2 = const(0x2B)
56+
_MMA8451_REG_CTRL_REG4 = const(0x2D)
57+
_MMA8451_REG_CTRL_REG5 = const(0x2E)
58+
_MMA8451_DATARATE_MASK = const(0b111)
59+
_SENSORS_GRAVITY_EARTH = 9.80665
6060

6161
# External user-facing constants:
62-
PL_PUF = 0 # Portrait, up, front
63-
PL_PUB = 1 # Portrait, up, back
64-
PL_PDF = 2 # Portrait, down, front
65-
PL_PDB = 3 # Portrait, down, back
66-
PL_LRF = 4 # Landscape, right, front
67-
PL_LRB = 5 # Landscape, right, back
68-
PL_LLF = 6 # Landscape, left, front
69-
PL_LLB = 7 # Landscape, left, back
70-
RANGE_8G = 0b10 # +/- 8g
71-
RANGE_4G = 0b01 # +/- 4g (default value)
72-
RANGE_2G = 0b00 # +/- 2g
73-
DATARATE_800HZ = 0b000 # 800Hz
74-
DATARATE_400HZ = 0b001 # 400Hz
75-
DATARATE_200HZ = 0b010 # 200Hz
76-
DATARATE_100HZ = 0b011 # 100Hz
77-
DATARATE_50HZ = 0b100 # 50Hz
78-
DATARATE_12_5HZ = 0b101 # 12.5Hz
79-
DATARATE_6_25HZ = 0b110 # 6.25Hz
80-
DATARATE_1_56HZ = 0b111 # 1.56Hz
81-
#pylint: enable=bad-whitespace
62+
PL_PUF = 0 # Portrait, up, front
63+
PL_PUB = 1 # Portrait, up, back
64+
PL_PDF = 2 # Portrait, down, front
65+
PL_PDB = 3 # Portrait, down, back
66+
PL_LRF = 4 # Landscape, right, front
67+
PL_LRB = 5 # Landscape, right, back
68+
PL_LLF = 6 # Landscape, left, front
69+
PL_LLB = 7 # Landscape, left, back
70+
RANGE_8G = 0b10 # +/- 8g
71+
RANGE_4G = 0b01 # +/- 4g (default value)
72+
RANGE_2G = 0b00 # +/- 2g
73+
DATARATE_800HZ = 0b000 # 800Hz
74+
DATARATE_400HZ = 0b001 # 400Hz
75+
DATARATE_200HZ = 0b010 # 200Hz
76+
DATARATE_100HZ = 0b011 # 100Hz
77+
DATARATE_50HZ = 0b100 # 50Hz
78+
DATARATE_12_5HZ = 0b101 # 12.5Hz
79+
DATARATE_6_25HZ = 0b110 # 6.25Hz
80+
DATARATE_1_56HZ = 0b111 # 1.56Hz
81+
# pylint: enable=bad-whitespace
8282

8383

8484
class MMA8451:
@@ -97,7 +97,7 @@ def __init__(self, i2c, *, address=_MMA8451_DEFAULT_ADDRESS):
9797
self._device = i2c_device.I2CDevice(i2c, address)
9898
# Verify device ID.
9999
if self._read_u8(_MMA8451_REG_WHOAMI) != 0x1A:
100-
raise RuntimeError('Failed to find MMA8451, check wiring!')
100+
raise RuntimeError("Failed to find MMA8451, check wiring!")
101101
# Reset and wait for chip to be ready.
102102
self._write_u8(_MMA8451_REG_CTRL_REG2, 0x40)
103103
while self._read_u8(_MMA8451_REG_CTRL_REG2) & 0x40 > 0:
@@ -122,12 +122,11 @@ def _read_into(self, address, buf, count=None):
122122
# has at least 1 value. I don't trust the implicit true/false
123123
# recommendation as it was not designed for bytearrays which may not
124124
# follow that semantic. Ignore pylint's superfulous complaint.
125-
assert len(buf) > 0 #pylint: disable=len-as-condition
125+
assert len(buf) > 0 # pylint: disable=len-as-condition
126126
if count is None:
127127
count = len(buf)
128128
with self._device as i2c:
129-
i2c.write_then_readinto(bytes([address & 0xFF]), buf,
130-
in_end=count)
129+
i2c.write_then_readinto(bytes([address & 0xFF]), buf, in_end=count)
131130

132131
def _read_u8(self, address):
133132
# Read an 8-bit unsigned value from the specified 8-bit address.
@@ -154,9 +153,9 @@ def range(self):
154153
def range(self, val):
155154
assert 0 <= val <= 2
156155
reg1 = self._read_u8(_MMA8451_REG_CTRL_REG1)
157-
self._write_u8(_MMA8451_REG_CTRL_REG1, 0x00) # deactivate
156+
self._write_u8(_MMA8451_REG_CTRL_REG1, 0x00) # deactivate
158157
self._write_u8(_MMA8451_REG_XYZ_DATA_CFG, val)
159-
self._write_u8(_MMA8451_REG_CTRL_REG1, reg1 | 0x01) # activate
158+
self._write_u8(_MMA8451_REG_CTRL_REG1, reg1 | 0x01) # activate
160159

161160
@property
162161
def data_rate(self):
@@ -170,17 +169,16 @@ def data_rate(self):
170169
- DATARATE_6_25HZ: 6.25Hz
171170
- DATARATE_1_56HZ: 1.56Hz
172171
"""
173-
return (self._read_u8(_MMA8451_REG_CTRL_REG1) >> 3) & \
174-
_MMA8451_DATARATE_MASK
172+
return (self._read_u8(_MMA8451_REG_CTRL_REG1) >> 3) & _MMA8451_DATARATE_MASK
175173

176174
@data_rate.setter
177175
def data_rate(self, val):
178176
assert 0 <= val <= 7
179177
ctl1 = self._read_u8(_MMA8451_REG_CTRL_REG1)
180-
self._write_u8(_MMA8451_REG_CTRL_REG1, 0x00) # deactivate
181-
ctl1 &= ~(_MMA8451_DATARATE_MASK << 3) # mask off bits
182-
ctl1 |= (val << 3)
183-
self._write_u8(_MMA8451_REG_CTRL_REG1, ctl1 | 0x01) # activate
178+
self._write_u8(_MMA8451_REG_CTRL_REG1, 0x00) # deactivate
179+
ctl1 &= ~(_MMA8451_DATARATE_MASK << 3) # mask off bits
180+
ctl1 |= val << 3
181+
self._write_u8(_MMA8451_REG_CTRL_REG1, ctl1 | 0x01) # activate
184182

185183
@property
186184
def acceleration(self):
@@ -192,26 +190,32 @@ def acceleration(self):
192190
# Read 6 bytes for 16-bit X, Y, Z values.
193191
self._read_into(_MMA8451_REG_OUT_X_MSB, self._BUFFER, count=6)
194192
# Reconstruct signed 16-bit integers.
195-
x, y, z = struct.unpack('>hhh', self._BUFFER)
193+
x, y, z = struct.unpack(">hhh", self._BUFFER)
196194
x >>= 2
197195
y >>= 2
198196
z >>= 2
199197
# Scale values based on current sensor range to get proper units.
200198
_range = self.range
201199
if _range == RANGE_8G:
202-
return (x/1024.0*_SENSORS_GRAVITY_EARTH,
203-
y/1024.0*_SENSORS_GRAVITY_EARTH,
204-
z/1024.0*_SENSORS_GRAVITY_EARTH)
200+
return (
201+
x / 1024.0 * _SENSORS_GRAVITY_EARTH,
202+
y / 1024.0 * _SENSORS_GRAVITY_EARTH,
203+
z / 1024.0 * _SENSORS_GRAVITY_EARTH,
204+
)
205205
elif _range == RANGE_4G:
206-
return (x/2048.0*_SENSORS_GRAVITY_EARTH,
207-
y/2048.0*_SENSORS_GRAVITY_EARTH,
208-
z/2048.0*_SENSORS_GRAVITY_EARTH)
206+
return (
207+
x / 2048.0 * _SENSORS_GRAVITY_EARTH,
208+
y / 2048.0 * _SENSORS_GRAVITY_EARTH,
209+
z / 2048.0 * _SENSORS_GRAVITY_EARTH,
210+
)
209211
elif _range == RANGE_2G:
210-
return (x/4096.0*_SENSORS_GRAVITY_EARTH,
211-
y/4096.0*_SENSORS_GRAVITY_EARTH,
212-
z/4096.0*_SENSORS_GRAVITY_EARTH)
212+
return (
213+
x / 4096.0 * _SENSORS_GRAVITY_EARTH,
214+
y / 4096.0 * _SENSORS_GRAVITY_EARTH,
215+
z / 4096.0 * _SENSORS_GRAVITY_EARTH,
216+
)
213217
else:
214-
raise RuntimeError('Unexpected range!')
218+
raise RuntimeError("Unexpected range!")
215219

216220
@property
217221
def orientation(self):

docs/conf.py

Lines changed: 67 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,55 @@
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.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.todo",
1617
]
1718

1819
# Uncomment the below if you use native CircuitPython modules such as
1920
# digitalio, micropython and busio. List the modules you use. Without it, the
2021
# autodoc module docs will fail to generate with a warning.
2122
# autodoc_mock_imports = ["digitalio", "busio", "micropython", "adafruit_bus_device", "adafruit_bus_device.i2c_device"]
2223

23-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/bus_device/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
24+
intersphinx_mapping = {
25+
"python": ("https://docs.python.org/3.4", None),
26+
"BusDevice": (
27+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
28+
None,
29+
),
30+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
31+
}
2432

2533
# Add any paths that contain templates here, relative to this directory.
26-
templates_path = ['_templates']
34+
templates_path = ["_templates"]
2735

28-
source_suffix = '.rst'
36+
source_suffix = ".rst"
2937

3038
# The master toctree document.
31-
master_doc = 'index'
39+
master_doc = "index"
3240

3341
# General information about the project.
34-
project = u'Adafruit MMA8451 Library'
35-
copyright = u'2017 Tony DiCola'
36-
author = u'Tony DiCola'
42+
project = u"Adafruit MMA8451 Library"
43+
copyright = u"2017 Tony DiCola"
44+
author = u"Tony DiCola"
3745

3846
# The version info for the project you're documenting, acts as replacement for
3947
# |version| and |release|, also used in various other places throughout the
4048
# built documents.
4149
#
4250
# The short X.Y version.
43-
version = u'1.0'
51+
version = u"1.0"
4452
# The full version, including alpha/beta/rc tags.
45-
release = u'1.0'
53+
release = u"1.0"
4654

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

5967
# The reST default role (used for this markup: `text`) to use for all
6068
# documents.
@@ -66,7 +74,7 @@
6674
add_function_parentheses = True
6775

6876
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = 'sphinx'
77+
pygments_style = "sphinx"
7078

7179
# If true, `todo` and `todoList` produce output, else they produce nothing.
7280
todo_include_todos = False
@@ -80,62 +88,70 @@
8088
# The theme to use for HTML and HTML Help pages. See the documentation for
8189
# a list of builtin themes.
8290
#
83-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8492

8593
if not on_rtd: # only import and set the theme if we're building docs locally
8694
try:
8795
import sphinx_rtd_theme
88-
html_theme = 'sphinx_rtd_theme'
89-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9099
except:
91-
html_theme = 'default'
92-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
93102
else:
94-
html_theme_path = ['.']
103+
html_theme_path = ["."]
95104

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

101110
# Output file base name for HTML help builder.
102-
htmlhelp_basename = 'AdafruitMma8451Librarydoc'
111+
htmlhelp_basename = "AdafruitMma8451Librarydoc"
103112

104113
# -- Options for LaTeX output ---------------------------------------------
105114

106115
latex_elements = {
107-
# The paper size ('letterpaper' or 'a4paper').
108-
#
109-
# 'papersize': 'letterpaper',
110-
111-
# The font size ('10pt', '11pt' or '12pt').
112-
#
113-
# 'pointsize': '10pt',
114-
115-
# Additional stuff for the LaTeX preamble.
116-
#
117-
# 'preamble': '',
118-
119-
# Latex figure (float) alignment
120-
#
121-
# 'figure_align': 'htbp',
116+
# The paper size ('letterpaper' or 'a4paper').
117+
#
118+
# 'papersize': 'letterpaper',
119+
# The font size ('10pt', '11pt' or '12pt').
120+
#
121+
# 'pointsize': '10pt',
122+
# Additional stuff for the LaTeX preamble.
123+
#
124+
# 'preamble': '',
125+
# Latex figure (float) alignment
126+
#
127+
# 'figure_align': 'htbp',
122128
}
123129

124130
# Grouping the document tree into LaTeX files. List of tuples
125131
# (source start file, target name, title,
126132
# author, documentclass [howto, manual, or own class]).
127133
latex_documents = [
128-
(master_doc, 'AdafruitMMA8451Library.tex', u'AdafruitMMA8451 Library Documentation',
129-
author, 'manual'),
134+
(
135+
master_doc,
136+
"AdafruitMMA8451Library.tex",
137+
u"AdafruitMMA8451 Library Documentation",
138+
author,
139+
"manual",
140+
),
130141
]
131142

132143
# -- Options for manual page output ---------------------------------------
133144

134145
# One entry per manual page. List of tuples
135146
# (source start file, name, description, authors, manual section).
136147
man_pages = [
137-
(master_doc, 'AdafruitMMA8451library', u'Adafruit MMA8451 Library Documentation',
138-
[author], 1)
148+
(
149+
master_doc,
150+
"AdafruitMMA8451library",
151+
u"Adafruit MMA8451 Library Documentation",
152+
[author],
153+
1,
154+
)
139155
]
140156

141157
# -- Options for Texinfo output -------------------------------------------
@@ -144,7 +160,13 @@
144160
# (source start file, target name, title, author,
145161
# dir menu entry, description, category)
146162
texinfo_documents = [
147-
(master_doc, 'AdafruitMMA8451Library', u'Adafruit MMA8451 Library Documentation',
148-
author, 'AdafruitMMA8451Library', 'One line description of project.',
149-
'Miscellaneous'),
163+
(
164+
master_doc,
165+
"AdafruitMMA8451Library",
166+
u"Adafruit MMA8451 Library Documentation",
167+
author,
168+
"AdafruitMMA8451Library",
169+
"One line description of project.",
170+
"Miscellaneous",
171+
),
150172
]

0 commit comments

Comments
 (0)