Skip to content

Commit 0d4ae36

Browse files
authored
Merge pull request #7 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 00c0650 + 800f0a6 commit 0d4ae36

File tree

6 files changed

+163
-128
lines changed

6 files changed

+163
-128
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_lsm303dlh_mag.py

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -57,53 +57,51 @@
5757
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM303DHL_Mag.git"
5858

5959
# pylint: disable=bad-whitespace
60-
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x
61-
_ID = const(0xD4) # (0b11010100)
60+
_ADDRESS_MAG = const(0x1E) # (0x3C >> 1) // 0011110x
61+
_ID = const(0xD4) # (0b11010100)
6262

6363
# Magnetometer registers
64-
_REG_MAG_CRA_REG_M = const(0x00)
65-
_REG_MAG_CRB_REG_M = const(0x01)
66-
_REG_MAG_MR_REG_M = const(0x02)
67-
_REG_MAG_OUT_X_H_M = const(0x03)
68-
_REG_MAG_OUT_X_L_M = const(0x04)
69-
_REG_MAG_OUT_Z_H_M = const(0x05)
70-
_REG_MAG_OUT_Z_L_M = const(0x06)
71-
_REG_MAG_OUT_Y_H_M = const(0x07)
72-
_REG_MAG_OUT_Y_L_M = const(0x08)
73-
_REG_MAG_SR_REG_M = const(0x09)
74-
_REG_MAG_IRA_REG_M = const(0x0A)
75-
_REG_MAG_IRB_REG_M = const(0x0B)
76-
_REG_MAG_IRC_REG_M = const(0x0C)
77-
78-
_REG_MAG_TEMP_OUT_H_M = const(0x31)
79-
_REG_MAG_TEMP_OUT_L_M = const(0x32)
80-
81-
64+
_REG_MAG_CRA_REG_M = const(0x00)
65+
_REG_MAG_CRB_REG_M = const(0x01)
66+
_REG_MAG_MR_REG_M = const(0x02)
67+
_REG_MAG_OUT_X_H_M = const(0x03)
68+
_REG_MAG_OUT_X_L_M = const(0x04)
69+
_REG_MAG_OUT_Z_H_M = const(0x05)
70+
_REG_MAG_OUT_Z_L_M = const(0x06)
71+
_REG_MAG_OUT_Y_H_M = const(0x07)
72+
_REG_MAG_OUT_Y_L_M = const(0x08)
73+
_REG_MAG_SR_REG_M = const(0x09)
74+
_REG_MAG_IRA_REG_M = const(0x0A)
75+
_REG_MAG_IRB_REG_M = const(0x0B)
76+
_REG_MAG_IRC_REG_M = const(0x0C)
77+
78+
_REG_MAG_TEMP_OUT_H_M = const(0x31)
79+
_REG_MAG_TEMP_OUT_L_M = const(0x32)
8280

8381

8482
MAG_DEVICE_ID = 0b01000000
8583
# Magnetometer gains
86-
MAGGAIN_1_3 = const(0x20) # +/- 1.3
87-
MAGGAIN_1_9 = const(0x40) # +/- 1.9
88-
MAGGAIN_2_5 = const(0x60) # +/- 2.5
89-
MAGGAIN_4_0 = const(0x80) # +/- 4.0
90-
MAGGAIN_4_7 = const(0xA0) # +/- 4.7
91-
MAGGAIN_5_6 = const(0xC0) # +/- 5.6
92-
MAGGAIN_8_1 = const(0xE0) # +/- 8.1
84+
MAGGAIN_1_3 = const(0x20) # +/- 1.3
85+
MAGGAIN_1_9 = const(0x40) # +/- 1.9
86+
MAGGAIN_2_5 = const(0x60) # +/- 2.5
87+
MAGGAIN_4_0 = const(0x80) # +/- 4.0
88+
MAGGAIN_4_7 = const(0xA0) # +/- 4.7
89+
MAGGAIN_5_6 = const(0xC0) # +/- 5.6
90+
MAGGAIN_8_1 = const(0xE0) # +/- 8.1
9391

9492
# Magentometer rates
95-
MAGRATE_0_7 = const(0x00) # 0.75 Hz
96-
MAGRATE_1_5 = const(0x01) # 1.5 Hz
97-
MAGRATE_3_0 = const(0x02) # 3.0 Hz
98-
MAGRATE_7_5 = const(0x03) # 7.5 Hz
99-
MAGRATE_15 = const(0x04) # 15 Hz
100-
MAGRATE_30 = const(0x05) # 30 Hz
101-
MAGRATE_75 = const(0x06) # 75 Hz
102-
MAGRATE_220 = const(0x07) # 220 Hz
93+
MAGRATE_0_7 = const(0x00) # 0.75 Hz
94+
MAGRATE_1_5 = const(0x01) # 1.5 Hz
95+
MAGRATE_3_0 = const(0x02) # 3.0 Hz
96+
MAGRATE_7_5 = const(0x03) # 7.5 Hz
97+
MAGRATE_15 = const(0x04) # 15 Hz
98+
MAGRATE_30 = const(0x05) # 30 Hz
99+
MAGRATE_75 = const(0x06) # 75 Hz
100+
MAGRATE_220 = const(0x07) # 220 Hz
103101

104102
# Conversion constants
105-
_GRAVITY_STANDARD = 9.80665 # Earth's gravity in m/s^2
106-
_GAUSS_TO_MICROTESLA = 100.0 # Gauss to micro-Tesla multiplier
103+
_GRAVITY_STANDARD = 9.80665 # Earth's gravity in m/s^2
104+
_GAUSS_TO_MICROTESLA = 100.0 # Gauss to micro-Tesla multiplier
107105
# pylint: enable=bad-whitespace
108106

109107

@@ -113,14 +111,17 @@ class LSM303DLH_Mag:
113111
:param busio.I2C i2c_bus: The I2C bus the LSM303DLH is connected to.
114112
115113
"""
114+
116115
# Class-level buffer for reading and writing data with the sensor.
117116
# This reduces memory allocations but means the code is not re-entrant or
118117
# thread safe!
119118
_BUFFER = bytearray(6)
120119

121120
def __init__(self, i2c):
122121
self._mag_device = I2CDevice(i2c, _ADDRESS_MAG)
123-
self._write_u8(self._mag_device, _REG_MAG_MR_REG_M, 0x00) # Enable the magnetometer
122+
self._write_u8(
123+
self._mag_device, _REG_MAG_MR_REG_M, 0x00
124+
) # Enable the magnetometer
124125
self._lsm303mag_gauss_lsb_xy = 1100.0
125126
self._lsm303mag_gauss_lsb_z = 980.0
126127
self._mag_gain = MAGGAIN_1_3
@@ -132,7 +133,7 @@ def _raw_magnetic(self):
132133
A 3-tuple of X, Y, Z axis values that are 16-bit signed integers.
133134
"""
134135
self._read_bytes(self._mag_device, _REG_MAG_OUT_X_H_M, 6, self._BUFFER)
135-
raw_values = struct.unpack_from('>hhh', self._BUFFER[0:6])
136+
raw_values = struct.unpack_from(">hhh", self._BUFFER[0:6])
136137
return (raw_values[0], raw_values[2], raw_values[1])
137138

138139
@property
@@ -141,9 +142,11 @@ def magnetic(self):
141142
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
142143
"""
143144
mag_x, mag_y, mag_z = self._raw_magnetic
144-
return (mag_x / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
145-
mag_y / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
146-
mag_z / self._lsm303mag_gauss_lsb_z * _GAUSS_TO_MICROTESLA)
145+
return (
146+
mag_x / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
147+
mag_y / self._lsm303mag_gauss_lsb_xy * _GAUSS_TO_MICROTESLA,
148+
mag_z / self._lsm303mag_gauss_lsb_z * _GAUSS_TO_MICROTESLA,
149+
)
147150

148151
@property
149152
def mag_gain(self):
@@ -152,8 +155,15 @@ def mag_gain(self):
152155

153156
@mag_gain.setter
154157
def mag_gain(self, value):
155-
assert value in (MAGGAIN_1_3, MAGGAIN_1_9, MAGGAIN_2_5, MAGGAIN_4_0, MAGGAIN_4_7,
156-
MAGGAIN_5_6, MAGGAIN_8_1)
158+
assert value in (
159+
MAGGAIN_1_3,
160+
MAGGAIN_1_9,
161+
MAGGAIN_2_5,
162+
MAGGAIN_4_0,
163+
MAGGAIN_4_7,
164+
MAGGAIN_5_6,
165+
MAGGAIN_8_1,
166+
)
157167

158168
self._mag_gain = value
159169
self._write_u8(self._mag_device, _REG_MAG_CRB_REG_M, self._mag_gain)
@@ -186,8 +196,16 @@ def mag_rate(self):
186196

187197
@mag_rate.setter
188198
def mag_rate(self, value):
189-
assert value in (MAGRATE_0_7, MAGRATE_1_5, MAGRATE_3_0, MAGRATE_7_5, MAGRATE_15, MAGRATE_30,
190-
MAGRATE_75, MAGRATE_220)
199+
assert value in (
200+
MAGRATE_0_7,
201+
MAGRATE_1_5,
202+
MAGRATE_3_0,
203+
MAGRATE_7_5,
204+
MAGRATE_15,
205+
MAGRATE_30,
206+
MAGRATE_75,
207+
MAGRATE_220,
208+
)
191209

192210
self._mag_rate = value
193211
reg_m = ((value & 0x07) << 2) & 0xFF
@@ -196,8 +214,7 @@ def mag_rate(self, value):
196214
def _read_u8(self, device, address):
197215
with device as i2c:
198216
self._BUFFER[0] = address & 0xFF
199-
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
200-
out_end=1, in_end=1)
217+
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
201218
return self._BUFFER[0]
202219

203220
def _write_u8(self, device, address, val):

docs/conf.py

Lines changed: 68 additions & 46 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.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"]
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 LSM303DLH Magnetometer Library'
35-
copyright = u'2019 Bryan Siepert'
36-
author = u'Bryan Siepert'
42+
project = u"Adafruit LSM303DLH 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 = 'AdafruitLsm303DlhMagLibrarydoc'
117+
htmlhelp_basename = "AdafruitLsm303DlhMagLibrarydoc"
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, 'AdafruitLSM303DLHMagLibrary.tex', u'Adafruit LSM303DLH Magnetometer Library Documentation',
135-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitLSM303DLHMagLibrary.tex",
143+
u"Adafruit LSM303DLH 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, 'AdafruitLSM303DLHMaglibrary', u'Adafruit LSM303DLH Magnetometer Library Documentation',
144-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitLSM303DLHMaglibrary",
157+
u"Adafruit LSM303DLH 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, 'AdafruitLSM303DLHMagLibrary', u'Adafruit LSM303DLH Magnetometer Library Documentation',
154-
author, 'AdafruitLSM303DLHMAgLibrary', 'One line description of project.',
155-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitLSM303DLHMagLibrary",
172+
u"Adafruit LSM303DLH Magnetometer Library Documentation",
173+
author,
174+
"AdafruitLSM303DLHMAgLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
156178
]

0 commit comments

Comments
 (0)