Skip to content

Commit 951c6fb

Browse files
authored
Merge pull request #27 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 44e82c0 + ba71ef3 commit 951c6fb

File tree

5 files changed

+114
-103
lines changed

5 files changed

+114
-103
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_sgp30.py

+19-24
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@
5050

5151

5252
# pylint: disable=bad-whitespace
53-
_SGP30_DEFAULT_I2C_ADDR = const(0x58)
54-
_SGP30_FEATURESETS = (0x0020, 0x0022)
53+
_SGP30_DEFAULT_I2C_ADDR = const(0x58)
54+
_SGP30_FEATURESETS = (0x0020, 0x0022)
5555

56-
_SGP30_CRC8_POLYNOMIAL = const(0x31)
57-
_SGP30_CRC8_INIT = const(0xFF)
58-
_SGP30_WORD_LEN = const(2)
56+
_SGP30_CRC8_POLYNOMIAL = const(0x31)
57+
_SGP30_CRC8_INIT = const(0xFF)
58+
_SGP30_WORD_LEN = const(2)
5959
# pylint: enable=bad-whitespace
6060

61+
6162
class Adafruit_SGP30:
6263
"""
6364
A driver for the SGP30 gas sensor.
@@ -70,40 +71,35 @@ def __init__(self, i2c, address=_SGP30_DEFAULT_I2C_ADDR):
7071
# get unique serial, its 48 bits so we store in an array
7172
self.serial = self._i2c_read_words_from_cmd([0x36, 0x82], 0.01, 3)
7273
# get featureset
73-
featureset = self._i2c_read_words_from_cmd([0x20, 0x2f], 0.01, 1)
74+
featureset = self._i2c_read_words_from_cmd([0x20, 0x2F], 0.01, 1)
7475
if featureset[0] not in _SGP30_FEATURESETS:
75-
raise RuntimeError('SGP30 Not detected')
76+
raise RuntimeError("SGP30 Not detected")
7677
self.iaq_init()
7778

78-
7979
@property
8080
# pylint: disable=invalid-name
8181
def TVOC(self):
8282
"""Total Volatile Organic Compound in parts per billion."""
8383
return self.iaq_measure()[1]
8484

85-
8685
@property
8786
# pylint: disable=invalid-name
8887
def baseline_TVOC(self):
8988
"""Total Volatile Organic Compound baseline value"""
9089
return self.get_iaq_baseline()[1]
9190

92-
9391
@property
9492
# pylint: disable=invalid-name
9593
def eCO2(self):
9694
"""Carbon Dioxide Equivalent in parts per million"""
9795
return self.iaq_measure()[0]
9896

99-
10097
@property
10198
# pylint: disable=invalid-name
10299
def baseline_eCO2(self):
103100
"""Carbon Dioxide Equivalent baseline value"""
104101
return self.get_iaq_baseline()[0]
105102

106-
107103
def iaq_init(self):
108104
"""Initialize the IAQ algorithm"""
109105
# name, command, signals, delay
@@ -119,18 +115,18 @@ def get_iaq_baseline(self):
119115
# name, command, signals, delay
120116
return self._run_profile(["iaq_get_baseline", [0x20, 0x15], 2, 0.01])
121117

122-
def set_iaq_baseline(self, eCO2, TVOC): # pylint: disable=invalid-name
118+
def set_iaq_baseline(self, eCO2, TVOC): # pylint: disable=invalid-name
123119
"""Set the previously recorded IAQ algorithm baseline for eCO2 and TVOC"""
124120
if eCO2 == 0 and TVOC == 0:
125-
raise RuntimeError('Invalid baseline')
121+
raise RuntimeError("Invalid baseline")
126122
buffer = []
127123
for value in [TVOC, eCO2]:
128124
arr = [value >> 8, value & 0xFF]
129125
arr.append(self._generate_crc(arr))
130126
buffer += arr
131-
self._run_profile(["iaq_set_baseline", [0x20, 0x1e] + buffer, 0, 0.01])
127+
self._run_profile(["iaq_set_baseline", [0x20, 0x1E] + buffer, 0, 0.01])
132128

133-
def set_iaq_humidity(self, gramsPM3): # pylint: disable=invalid-name
129+
def set_iaq_humidity(self, gramsPM3): # pylint: disable=invalid-name
134130
"""Set the humidity in g/m3 for eCO2 and TVOC compensation algorithm"""
135131
tmp = int(gramsPM3 * 256)
136132
buffer = []
@@ -148,29 +144,28 @@ def _run_profile(self, profile):
148144
name, command, signals, delay = profile
149145
# pylint: enable=unused-variable
150146

151-
#print("\trunning profile: %s, command %s, %d, delay %0.02f" %
147+
# print("\trunning profile: %s, command %s, %d, delay %0.02f" %
152148
# (name, ["0x%02x" % i for i in command], signals, delay))
153149
return self._i2c_read_words_from_cmd(command, delay, signals)
154150

155-
156151
def _i2c_read_words_from_cmd(self, command, delay, reply_size):
157152
"""Run an SGP command query, get a reply and CRC results if necessary"""
158153
with self._device:
159154
self._device.write(bytes(command))
160155
time.sleep(delay)
161156
if not reply_size:
162157
return None
163-
crc_result = bytearray(reply_size * (_SGP30_WORD_LEN +1))
158+
crc_result = bytearray(reply_size * (_SGP30_WORD_LEN + 1))
164159
self._device.readinto(crc_result)
165-
#print("\tRaw Read: ", crc_result)
160+
# print("\tRaw Read: ", crc_result)
166161
result = []
167162
for i in range(reply_size):
168-
word = [crc_result[3*i], crc_result[3*i+1]]
169-
crc = crc_result[3*i+2]
163+
word = [crc_result[3 * i], crc_result[3 * i + 1]]
164+
crc = crc_result[3 * i + 2]
170165
if self._generate_crc(word) != crc:
171-
raise RuntimeError('CRC Error')
166+
raise RuntimeError("CRC Error")
172167
result.append(word[0] << 8 | word[1])
173-
#print("\tOK Data: ", [hex(i) for i in result])
168+
# print("\tOK Data: ", [hex(i) for i in result])
174169
return result
175170

176171
# pylint: disable=no-self-use

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 = ["adafruit_bus_device", "micropython"]
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 sgp30 Library'
35-
copyright = u'2017 Ladyada'
36-
author = u'Ladyada'
42+
project = u"Adafruit sgp30 Library"
43+
copyright = u"2017 Ladyada"
44+
author = u"Ladyada"
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 = 'AdafruitSgp30Librarydoc'
117+
htmlhelp_basename = "AdafruitSgp30Librarydoc"
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, 'Adafruitsgp30Library.tex', u'Adafruitsgp30 Library Documentation',
135-
author, 'manual'),
140+
(
141+
master_doc,
142+
"Adafruitsgp30Library.tex",
143+
u"Adafruitsgp30 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, 'Adafruitsgp30library', u'Adafruit sgp30 Library Documentation',
144-
[author], 1)
154+
(
155+
master_doc,
156+
"Adafruitsgp30library",
157+
u"Adafruit sgp30 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, 'Adafruitsgp30Library', u'Adafruit sgp30 Library Documentation',
154-
author, 'Adafruitsgp30Library', 'One line description of project.',
155-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"Adafruitsgp30Library",
172+
u"Adafruit sgp30 Library Documentation",
173+
author,
174+
"Adafruitsgp30Library",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
156178
]

examples/sgp30_simpletest.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
print("SGP30 serial #", [hex(i) for i in sgp30.serial])
1414

1515
sgp30.iaq_init()
16-
sgp30.set_iaq_baseline(0x8973, 0x8aae)
16+
sgp30.set_iaq_baseline(0x8973, 0x8AAE)
1717

1818
elapsed_sec = 0
1919

@@ -23,5 +23,7 @@
2323
elapsed_sec += 1
2424
if elapsed_sec > 10:
2525
elapsed_sec = 0
26-
print("**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
27-
% (sgp30.baseline_eCO2, sgp30.baseline_TVOC))
26+
print(
27+
"**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x"
28+
% (sgp30.baseline_eCO2, sgp30.baseline_TVOC)
29+
)

0 commit comments

Comments
 (0)