Skip to content

Commit 0208302

Browse files
authored
Merge pull request #3 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 5701452 + eb4922c commit 0208302

File tree

5 files changed

+130
-109
lines changed

5 files changed

+130
-109
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_tlv493d.py

+32-28
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646

4747
import struct
4848
import adafruit_bus_device.i2c_device as i2cdevice
49+
4950
__version__ = "0.0.0-auto.0"
5051
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TLV493D.git"
5152

53+
5254
class TLV493D:
5355
"""Driver for the TLV493D 3-axis Magnetometer.
5456
@@ -70,21 +72,21 @@ class TLV493D:
7072
"POWERDOWNFLAG": (5, 0x10, 4),
7173
"RES1": (7, 0x18, 3),
7274
"RES2": (8, 0xFF, 0),
73-
"RES3": (9, 0x1F, 0)
75+
"RES3": (9, 0x1F, 0),
7476
}
7577

7678
write_masks = {
77-
"PARITY":(1, 0x80, 7),
78-
"ADDR":(1, 0x60, 5),
79-
"INT":(1, 0x04, 2),
80-
"FAST":(1, 0x02, 1),
81-
"LOWPOWER":(1, 0x01, 0),
82-
"TEMP_DISABLE":(3, 0x80, 7),
83-
"LP_PERIOD":(3, 0x40, 6),
84-
"POWERDOWN":(3, 0x20, 5),
85-
"RES1":(1, 0x18, 3),
86-
"RES2":(2, 0xFF, 0),
87-
"RES3":(3, 0x1F, 0)
79+
"PARITY": (1, 0x80, 7),
80+
"ADDR": (1, 0x60, 5),
81+
"INT": (1, 0x04, 2),
82+
"FAST": (1, 0x02, 1),
83+
"LOWPOWER": (1, 0x01, 0),
84+
"TEMP_DISABLE": (3, 0x80, 7),
85+
"LP_PERIOD": (3, 0x40, 6),
86+
"POWERDOWN": (3, 0x20, 5),
87+
"RES1": (1, 0x18, 3),
88+
"RES2": (2, 0xFF, 0),
89+
"RES3": (3, 0x1F, 0),
8890
}
8991

9092
def __init__(self, i2c_bus):
@@ -96,10 +98,10 @@ def __init__(self, i2c_bus):
9698
self._setup_write_buffer()
9799

98100
# setup MASTERCONTROLLEDMODE which takes a measurement for every read
99-
self._set_write_key('PARITY', 1)
100-
self._set_write_key('PARITY', 1)
101-
self._set_write_key('LOWPOWER', 1)
102-
self._set_write_key('LP_PERIOD', 1)
101+
self._set_write_key("PARITY", 1)
102+
self._set_write_key("PARITY", 1)
103+
self._set_write_key("LOWPOWER", 1)
104+
self._set_write_key("LP_PERIOD", 1)
103105
self._write_i2c()
104106

105107
def _read_i2c(self):
@@ -113,41 +115,43 @@ def _write_i2c(self):
113115

114116
def _setup_write_buffer(self):
115117
self._read_i2c()
116-
for key in ['RES1', 'RES2', 'RES3']:
118+
for key in ["RES1", "RES2", "RES3"]:
117119
write_value = self._get_read_key(key)
118120
self._set_write_key(key, write_value)
119121

120122
def _get_read_key(self, key):
121123
read_byte_num, read_mask, read_shift = self.read_masks[key]
122124
raw_read_value = self.read_buffer[read_byte_num]
123-
write_value = (raw_read_value & read_mask)>>read_shift
125+
write_value = (raw_read_value & read_mask) >> read_shift
124126
return write_value
125127

126128
def _set_write_key(self, key, value):
127129
write_byte_num, write_mask, write_shift = self.write_masks[key]
128130
current_write_byte = self.write_buffer[write_byte_num]
129131
current_write_byte &= ~write_mask
130-
current_write_byte |= value<<write_shift
132+
current_write_byte |= value << write_shift
131133
self.write_buffer[write_byte_num] = current_write_byte
132134

133135
@property
134136
def magnetic(self):
135137
"""The processed magnetometer sensor values.
136138
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
137139
"""
138-
self._read_i2c() # update read registers
140+
self._read_i2c() # update read registers
139141
x_top = self._get_read_key("BX1")
140-
x_bot = ((self._get_read_key("BX2") << 4) & 0xFF)
142+
x_bot = (self._get_read_key("BX2") << 4) & 0xFF
141143
y_top = self._get_read_key("BY1")
142-
y_bot = ((self._get_read_key("BY2") << 4) & 0xFF)
144+
y_bot = (self._get_read_key("BY2") << 4) & 0xFF
143145
z_top = self._get_read_key("BZ1")
144-
z_bot = ((self._get_read_key("BZ2") << 4) & 0xFF)
146+
z_bot = (self._get_read_key("BZ2") << 4) & 0xFF
145147

146-
return (self._unpack_and_scale(x_top, x_bot),
147-
self._unpack_and_scale(y_top, y_bot),
148-
self._unpack_and_scale(z_top, z_bot))
148+
return (
149+
self._unpack_and_scale(x_top, x_bot),
150+
self._unpack_and_scale(y_top, y_bot),
151+
self._unpack_and_scale(z_top, z_bot),
152+
)
149153

150-
def _unpack_and_scale(self, top, bottom): #pylint: disable=no-self-use
154+
def _unpack_and_scale(self, top, bottom): # pylint: disable=no-self-use
151155
binval = struct.unpack_from(">h", bytearray([top, bottom]))[0]
152-
binval = binval >>4
156+
binval = binval >> 4
153157
return binval * 0.098

docs/conf.py

+73-47
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,40 @@
2324
autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/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+
"Register": (
34+
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
35+
None,
36+
),
37+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
38+
}
2739

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

31-
source_suffix = '.rst'
43+
source_suffix = ".rst"
3244

3345
# The master toctree document.
34-
master_doc = 'index'
46+
master_doc = "index"
3547

3648
# General information about the project.
37-
project = u'Adafruit TLV493D Library'
38-
copyright = u'2019 Bryan Siepert'
39-
author = u'Bryan Siepert'
49+
project = "Adafruit TLV493D Library"
50+
copyright = "2019 Bryan Siepert"
51+
author = "Bryan Siepert"
4052

4153
# The version info for the project you're documenting, acts as replacement for
4254
# |version| and |release|, also used in various other places throughout the
4355
# built documents.
4456
#
4557
# The short X.Y version.
46-
version = u'1.0'
58+
version = "1.0"
4759
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
60+
release = "1.0"
4961

5062
# The language for content autogenerated by Sphinx. Refer to documentation
5163
# for a list of supported languages.
@@ -57,7 +69,7 @@
5769
# List of patterns, relative to source directory, that match files and
5870
# directories to ignore when looking for source files.
5971
# 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']
72+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6173

6274
# The reST default role (used for this markup: `text`) to use for all
6375
# documents.
@@ -69,7 +81,7 @@
6981
add_function_parentheses = True
7082

7183
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
84+
pygments_style = "sphinx"
7385

7486
# If true, `todo` and `todoList` produce output, else they produce nothing.
7587
todo_include_todos = False
@@ -84,68 +96,76 @@
8496
# The theme to use for HTML and HTML Help pages. See the documentation for
8597
# a list of builtin themes.
8698
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
99+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
88100

89101
if not on_rtd: # only import and set the theme if we're building docs locally
90102
try:
91103
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
104+
105+
html_theme = "sphinx_rtd_theme"
106+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
94107
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
108+
html_theme = "default"
109+
html_theme_path = ["."]
97110
else:
98-
html_theme_path = ['.']
111+
html_theme_path = ["."]
99112

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

105118
# The name of an image file (relative to this directory) to use as a favicon of
106119
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107120
# pixels large.
108121
#
109-
html_favicon = '_static/favicon.ico'
122+
html_favicon = "_static/favicon.ico"
110123

111124
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitTlv493dLibrarydoc'
125+
htmlhelp_basename = "AdafruitTlv493dLibrarydoc"
113126

114127
# -- Options for LaTeX output ---------------------------------------------
115128

116129
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',
130+
# The paper size ('letterpaper' or 'a4paper').
131+
#
132+
# 'papersize': 'letterpaper',
133+
# The font size ('10pt', '11pt' or '12pt').
134+
#
135+
# 'pointsize': '10pt',
136+
# Additional stuff for the LaTeX preamble.
137+
#
138+
# 'preamble': '',
139+
# Latex figure (float) alignment
140+
#
141+
# 'figure_align': 'htbp',
132142
}
133143

134144
# Grouping the document tree into LaTeX files. List of tuples
135145
# (source start file, target name, title,
136146
# author, documentclass [howto, manual, or own class]).
137147
latex_documents = [
138-
(master_doc, 'AdafruitTLV493DLibrary.tex', u'AdafruitTLV493D Library Documentation',
139-
author, 'manual'),
148+
(
149+
master_doc,
150+
"AdafruitTLV493DLibrary.tex",
151+
"AdafruitTLV493D Library Documentation",
152+
author,
153+
"manual",
154+
),
140155
]
141156

142157
# -- Options for manual page output ---------------------------------------
143158

144159
# One entry per manual page. List of tuples
145160
# (source start file, name, description, authors, manual section).
146161
man_pages = [
147-
(master_doc, 'AdafruitTLV493Dlibrary', u'Adafruit TLV493D Library Documentation',
148-
[author], 1)
162+
(
163+
master_doc,
164+
"AdafruitTLV493Dlibrary",
165+
"Adafruit TLV493D Library Documentation",
166+
[author],
167+
1,
168+
)
149169
]
150170

151171
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +174,13 @@
154174
# (source start file, target name, title, author,
155175
# dir menu entry, description, category)
156176
texinfo_documents = [
157-
(master_doc, 'AdafruitTLV493DLibrary', u'Adafruit TLV493D Library Documentation',
158-
author, 'AdafruitTLV493DLibrary', 'One line description of project.',
159-
'Miscellaneous'),
177+
(
178+
master_doc,
179+
"AdafruitTLV493DLibrary",
180+
"Adafruit TLV493D Library Documentation",
181+
author,
182+
"AdafruitTLV493DLibrary",
183+
"One line description of project.",
184+
"Miscellaneous",
185+
),
160186
]

examples/tlv493d_simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
tlv = adafruit_tlv493d.TLV493D(i2c)
88

99
while True:
10-
print("X: %s, Y: %s, Z: %s mT"%tlv.magnetic)
10+
print("X: %s, Y: %s, Z: %s mT" % tlv.magnetic)
1111
time.sleep(1)

0 commit comments

Comments
 (0)