Skip to content

Commit 978912f

Browse files
authored
Merge pull request #7 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 3a3db47 + b321029 commit 978912f

File tree

6 files changed

+130
-101
lines changed

6 files changed

+130
-101
lines changed

.github/workflows/build.yml

+1-1
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_lis2mdl.py

+30-19
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,22 @@
6060
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS2MDL.git"
6161

6262
# pylint: disable=bad-whitespace
63-
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x
63+
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x
6464

6565

6666
MAG_DEVICE_ID = 0b01000000
6767

68-
class DataRate: # pylint: disable=too-few-public-methods
68+
69+
class DataRate: # pylint: disable=too-few-public-methods
6970
"""Data rate choices to set using `data_rate`"""
70-
Rate_10_HZ = const(0x00)
71+
72+
Rate_10_HZ = const(0x00)
7173
"""10 Hz"""
72-
Rate_20_HZ = const(0x01)
74+
Rate_20_HZ = const(0x01)
7375
"""20 Hz"""
74-
Rate_50_HZ = const(0x02)
76+
Rate_50_HZ = const(0x02)
7577
"""50 Hz"""
76-
Rate_100_HZ = const(0x03)
78+
Rate_100_HZ = const(0x03)
7779
"""100 Hz"""
7880

7981

@@ -88,7 +90,7 @@ class DataRate: # pylint: disable=too-few-public-methods
8890
CFG_REG_A = 0x60
8991
CFG_REG_B = 0x61
9092
CFG_REG_C = 0x62
91-
INT_CRTL_REG = 0x63
93+
INT_CRTL_REG = 0x63
9294
INT_SOURCE_REG = 0x64
9395
INT_THS_L_REG = 0x65
9496
STATUS_REG = 0x67
@@ -101,15 +103,17 @@ class DataRate: # pylint: disable=too-few-public-methods
101103

102104
# pylint: enable=bad-whitespace
103105

104-
_MAG_SCALE = 0.15 # 1.5 milligauss/LSB * 0.1 microtesla/milligauss
106+
_MAG_SCALE = 0.15 # 1.5 milligauss/LSB * 0.1 microtesla/milligauss
107+
105108

106-
class LIS2MDL:# pylint: disable=too-many-instance-attributes
109+
class LIS2MDL: # pylint: disable=too-many-instance-attributes
107110
"""
108111
Driver for the LIS2MDL 3-axis magnetometer.
109112
110113
:param busio.I2C i2c_bus: The I2C bus the LIS2MDL is connected to.
111114
112115
"""
116+
113117
_BUFFER = bytearray(6)
114118

115119
_device_id = ROUnaryStruct(WHO_AM_I, "B")
@@ -139,7 +143,6 @@ class LIS2MDL:# pylint: disable=too-many-instance-attributes
139143

140144
_int_source = ROUnaryStruct(INT_SOURCE_REG, "B")
141145

142-
143146
low_power = RWBit(CFG_REG_A, 4, 1)
144147

145148
"""Enables and disables low power mode"""
@@ -167,22 +170,26 @@ def reset(self):
167170
self._reboot = True
168171
sleep(0.100)
169172
self._mode = 0x00
170-
self._bdu = True # Make sure high and low bytes are set together
173+
self._bdu = True # Make sure high and low bytes are set together
171174
self._int_latched = True
172175
self._int_reg_polarity = True
173176
self._int_iron_off = False
174177
self._interrupt_pin_putput = True
175178
self._temp_comp = True
176179

177-
sleep(0.030) # sleep 20ms to allow measurements to stabilize
180+
sleep(0.030) # sleep 20ms to allow measurements to stabilize
178181

179182
@property
180183
def magnetic(self):
181184
"""The processed magnetometer sensor values.
182185
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
183186
"""
184187

185-
return (self._raw_x * _MAG_SCALE, self._raw_y * _MAG_SCALE, self._raw_z * _MAG_SCALE)
188+
return (
189+
self._raw_x * _MAG_SCALE,
190+
self._raw_y * _MAG_SCALE,
191+
self._raw_z * _MAG_SCALE,
192+
)
186193

187194
@property
188195
def data_rate(self):
@@ -191,8 +198,12 @@ def data_rate(self):
191198

192199
@data_rate.setter
193200
def data_rate(self, value):
194-
if not value in (DataRate.Rate_10_HZ, DataRate.Rate_20_HZ,
195-
DataRate.Rate_50_HZ, DataRate.Rate_100_HZ):
201+
if not value in (
202+
DataRate.Rate_10_HZ,
203+
DataRate.Rate_20_HZ,
204+
DataRate.Rate_50_HZ,
205+
DataRate.Rate_100_HZ,
206+
):
196207
raise ValueError("data_rate must be a `DataRate`")
197208
self._data_rate = value
198209

@@ -206,7 +217,7 @@ def interrupt_threshold(self):
206217
def interrupt_threshold(self, value):
207218
if value < 0:
208219
value = -value
209-
self._interrupt_threshold = int(value/_MAG_SCALE)
220+
self._interrupt_threshold = int(value / _MAG_SCALE)
210221

211222
@property
212223
def interrupt_enabled(self):
@@ -243,7 +254,7 @@ def x_offset(self):
243254

244255
@x_offset.setter
245256
def x_offset(self, value):
246-
self._x_offset = int(value/_MAG_SCALE)
257+
self._x_offset = int(value / _MAG_SCALE)
247258

248259
@property
249260
def y_offset(self):
@@ -253,7 +264,7 @@ def y_offset(self):
253264

254265
@y_offset.setter
255266
def y_offset(self, value):
256-
self._y_offset = int(value/_MAG_SCALE)
267+
self._y_offset = int(value / _MAG_SCALE)
257268

258269
@property
259270
def z_offset(self):
@@ -263,4 +274,4 @@ def z_offset(self):
263274

264275
@z_offset.setter
265276
def z_offset(self, value):
266-
self._z_offset = int(value/_MAG_SCALE)
277+
self._z_offset = int(value / _MAG_SCALE)

docs/conf.py

+68-46
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.viewcode',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.viewcode",
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 = ["micropython", "adafruit_bus_device", "adafruit_register"]
2223

23-
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)}
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 LIS2MDL 3-axis Magnetometer Library'
35-
copyright = u'2019 Bryan Siepert'
36-
author = u'Bryan Siepert'
42+
project = u"Adafruit LIS2MDL 3-axis Magnetometer Library"
43+
copyright = u"2019 Bryan Siepert"
44+
author = u"Bryan Siepert"
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,68 +88,76 @@
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
# The name of an image file (relative to this directory) to use as a favicon of
102111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103112
# pixels large.
104113
#
105-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
106115

107116
# Output file base name for HTML help builder.
108-
htmlhelp_basename = 'AdafruitLIS2MDLLibrarydoc'
117+
htmlhelp_basename = "AdafruitLIS2MDLLibrarydoc"
109118

110119
# -- Options for LaTeX output ---------------------------------------------
111120

112121
latex_elements = {
113-
# The paper size ('letterpaper' or 'a4paper').
114-
#
115-
# 'papersize': 'letterpaper',
116-
117-
# The font size ('10pt', '11pt' or '12pt').
118-
#
119-
# 'pointsize': '10pt',
120-
121-
# Additional stuff for the LaTeX preamble.
122-
#
123-
# 'preamble': '',
124-
125-
# Latex figure (float) alignment
126-
#
127-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
128134
}
129135

130136
# Grouping the document tree into LaTeX files. List of tuples
131137
# (source start file, target name, title,
132138
# author, documentclass [howto, manual, or own class]).
133139
latex_documents = [
134-
(master_doc, 'AdafruitLIS2MDLLibrary.tex', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
135-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitLIS2MDLLibrary.tex",
143+
u"Adafruit LIS2MDL 3-axis Magnetometer Library Documentation",
144+
author,
145+
"manual",
146+
),
136147
]
137148

138149
# -- Options for manual page output ---------------------------------------
139150

140151
# One entry per manual page. List of tuples
141152
# (source start file, name, description, authors, manual section).
142153
man_pages = [
143-
(master_doc, 'AdafruitLIS2MDLlibrary', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
144-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitLIS2MDLlibrary",
157+
u"Adafruit LIS2MDL 3-axis Magnetometer Library Documentation",
158+
[author],
159+
1,
160+
)
145161
]
146162

147163
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +166,13 @@
150166
# (source start file, target name, title, author,
151167
# dir menu entry, description, category)
152168
texinfo_documents = [
153-
(master_doc, 'AdafruitLIS2MDLLibrary', u'Adafruit LIS2MDL 3-axis Magnetometer Library Documentation',
154-
author, 'AdafruitLIS2MDLLibrary', 'One line description of project.',
155-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitLIS2MDLLibrary",
172+
u"Adafruit LIS2MDL 3-axis Magnetometer Library Documentation",
173+
author,
174+
"AdafruitLIS2MDLLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
156178
]

examples/lis2mdl_interrupt.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
x_hi, y_hi, z_hi, x_lo, y_lo, z_lo, int_triggered = lis.faults
1313

1414
print(lis.magnetic)
15-
print("Xhi:%s\tYhi:%s\tZhi:%s"%(x_hi, y_hi, z_hi))
16-
print("Xlo:%s\tYlo:%s\tZlo:%s"%(x_lo, y_lo, z_lo))
17-
print("Int triggered: %s"%int_triggered)
15+
print("Xhi:%s\tYhi:%s\tZhi:%s" % (x_hi, y_hi, z_hi))
16+
print("Xlo:%s\tYlo:%s\tZlo:%s" % (x_lo, y_lo, z_lo))
17+
print("Int triggered: %s" % int_triggered)
1818
print()
1919

2020
time.sleep(1)

examples/lis2mdl_simpletest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
while True:
1212
mag_x, mag_y, mag_z = sensor.magnetic
1313

14-
print('X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT'.format(mag_x, mag_y, mag_z))
15-
print('')
14+
print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z))
15+
print("")
1616
time.sleep(1.0)

0 commit comments

Comments
 (0)