Skip to content

Commit 102ed40

Browse files
authored
Merge pull request #17 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 5643572 + f19543c commit 102ed40

File tree

5 files changed

+117
-97
lines changed

5 files changed

+117
-97
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_l3gd20.py

+24-18
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
from micropython import const
5656
from adafruit_register.i2c_struct import Struct
57+
5758
try:
5859
from struct import unpack
5960
except ImportError:
@@ -78,9 +79,9 @@
7879
_L3GD20_CHIP_ID = const(0xD4)
7980
_L3GD20H_CHIP_ID = const(0xD7)
8081

81-
_L3GD20_SENSITIVITY_250DPS = 0.00875 ## Roughly 22/256 for fixed point match
82-
_L3GD20_SENSITIVITY_500DPS = 0.0175 ## Roughly 45/256
83-
_L3GD20_SENSITIVITY_2000DPS = 0.070 ## Roughly 18/256
82+
_L3GD20_SENSITIVITY_250DPS = 0.00875 ## Roughly 22/256 for fixed point match
83+
_L3GD20_SENSITIVITY_500DPS = 0.0175 ## Roughly 45/256
84+
_L3GD20_SENSITIVITY_2000DPS = 0.070 ## Roughly 18/256
8485

8586

8687
# pylint: disable=no-member
@@ -94,15 +95,17 @@ class L3GD20:
9495

9596
def __init__(self, rng=L3DS20_RANGE_250DPS):
9697
chip_id = self.read_register(_ID_REGISTER)
97-
if chip_id != _L3GD20_CHIP_ID and chip_id != _L3GD20H_CHIP_ID:
98-
raise RuntimeError("bad chip id (%x != %x or %x)" %
99-
(chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID))
100-
101-
if rng != L3DS20_RANGE_250DPS and \
102-
rng != L3DS20_RANGE_500DPS and \
103-
rng != L3DS20_RANGE_2000DPS:
104-
raise ValueError("Range value must be one of L3DS20_RANGE_250DPS, "
105-
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS")
98+
if chip_id not in (_L3GD20_CHIP_ID, _L3GD20H_CHIP_ID):
99+
raise RuntimeError(
100+
"bad chip id (%x != %x or %x)"
101+
% (chip_id, _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID)
102+
)
103+
104+
if rng not in (L3DS20_RANGE_250DPS, L3DS20_RANGE_500DPS, L3DS20_RANGE_2000DPS):
105+
raise ValueError(
106+
"Range value must be one of L3DS20_RANGE_250DPS, "
107+
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS"
108+
)
106109

107110
# Set CTRL_REG1 (0x20)
108111
# ====================================================================
@@ -186,15 +189,14 @@ def __init__(self, rng=L3DS20_RANGE_250DPS):
186189
# Nothing to do ... keep default values
187190
# ------------------------------------------------------------------
188191

189-
190192
@property
191193
def gyro(self):
192194
"""
193195
x, y, z angular momentum tuple floats, rescaled appropriately for
194196
range selected
195197
"""
196198
raw = self.gyro_raw
197-
return tuple(self.scale*v for v in raw)
199+
return tuple(self.scale * v for v in raw)
198200

199201

200202
class L3GD20_I2C(L3GD20):
@@ -207,11 +209,12 @@ class L3GD20_I2C(L3GD20):
207209
:param address: the optional device address, 0x68 is the default address
208210
"""
209211

210-
gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, '<hhh')
212+
gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, "<hhh")
211213
"""Gives the raw gyro readings, in units of rad/s."""
212214

213215
def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
214-
import adafruit_bus_device.i2c_device as i2c_device
216+
import adafruit_bus_device.i2c_device as i2c_device # pylint: disable=import-outside-toplevel
217+
215218
self.i2c_device = i2c_device.I2CDevice(i2c, address)
216219
self.buffer = bytearray(2)
217220
super().__init__(rng)
@@ -239,6 +242,7 @@ def read_register(self, register):
239242
i2c.write_then_readinto(self.buffer, self.buffer, out_end=1, in_start=1)
240243
return self.buffer[1]
241244

245+
242246
class L3GD20_SPI(L3GD20):
243247
"""
244248
Driver for L3GD20 Gyroscope using SPI communications
@@ -249,8 +253,10 @@ class L3GD20_SPI(L3GD20):
249253
L3DS20_RANGE_2000DPS
250254
:param baudrate: spi baud rate default is 100000
251255
"""
256+
252257
def __init__(self, spi_busio, cs, rng=L3DS20_RANGE_250DPS, baudrate=100000):
253-
import adafruit_bus_device.spi_device as spi_device
258+
import adafruit_bus_device.spi_device as spi_device # pylint: disable=import-outside-toplevel
259+
254260
self._spi = spi_device.SPIDevice(spi_busio, cs, baudrate=baudrate)
255261
self._spi_bytearray1 = bytearray(1)
256262
self._spi_bytearray6 = bytearray(6)
@@ -300,4 +306,4 @@ def gyro_raw(self):
300306
"""Gives the raw gyro readings, in units of rad/s."""
301307
buffer = self._spi_bytearray6
302308
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
303-
return unpack('<hhh', buffer)
309+
return unpack("<hhh", buffer)

docs/conf.py

+69-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,36 @@
2324
# autodoc_mock_imports = ["micropython", "adafruit_register"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', 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+
"Register": (
30+
"https://circuitpython.readthedocs.io/projects/register/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 l3gd20 Library'
38-
copyright = u'2018 Michael McWethy'
39-
author = u'Michael McWethy'
45+
project = u"Adafruit l3gd20 Library"
46+
copyright = u"2018 Michael McWethy"
47+
author = u"Michael McWethy"
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 = 'AdafruitL3gd20Librarydoc'
121+
htmlhelp_basename = "AdafruitL3gd20Librarydoc"
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, 'Adafruitl3gd20Library.tex', u'Adafruitl3gd20 Library Documentation',
139-
author, 'manual'),
144+
(
145+
master_doc,
146+
"Adafruitl3gd20Library.tex",
147+
u"Adafruitl3gd20 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, 'Adafruitl3gd20library', u'Adafruit l3gd20 Library Documentation',
148-
[author], 1)
158+
(
159+
master_doc,
160+
"Adafruitl3gd20library",
161+
u"Adafruit l3gd20 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, 'Adafruitl3gd20Library', u'Adafruit l3gd20 Library Documentation',
158-
author, 'Adafruitl3gd20Library', 'One line description of project.',
159-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"Adafruitl3gd20Library",
176+
u"Adafruit l3gd20 Library Documentation",
177+
author,
178+
"Adafruitl3gd20Library",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
160182
]

examples/l3gd20_simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
# SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)
1515

1616
while True:
17-
print('Angular Momentum (rad/s): {}'.format(SENSOR.gyro))
17+
print("Angular Momentum (rad/s): {}".format(SENSOR.gyro))
1818
print()
1919
time.sleep(1)

0 commit comments

Comments
 (0)