Skip to content

Commit f2fa749

Browse files
committed
Ran black, updated to pylint 2.x
1 parent b9116a4 commit f2fa749

File tree

5 files changed

+117
-99
lines changed

5 files changed

+117
-99
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_tmp007.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ class TMP007:
8282
# thread safe!
8383
_BUFFER = bytearray(4)
8484

85-
86-
8785
def __init__(self, i2c, address=_TMP007_I2CADDR, samplerate=CFG_16SAMPLE):
8886
"""Initialize TMP007 device on the specified I2C address and bus number.
8987
Address defaults to 0x40 and bus number defaults to the appropriate bus
@@ -96,19 +94,26 @@ def __init__(self, i2c, address=_TMP007_I2CADDR, samplerate=CFG_16SAMPLE):
9694
"""
9795
self._device = I2CDevice(i2c, address)
9896
self._write_u16(_TMP007_CONFIG, _TMP007_CFG_RESET)
99-
time.sleep(.5)
100-
if samplerate not in (CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE,
101-
CFG_16SAMPLE):
102-
raise ValueError('Unexpected samplerate value! Must be one of: ' \
103-
'CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE, or CFG_16SAMPLE')
97+
time.sleep(0.5)
98+
if samplerate not in (
99+
CFG_1SAMPLE,
100+
CFG_2SAMPLE,
101+
CFG_4SAMPLE,
102+
CFG_8SAMPLE,
103+
CFG_16SAMPLE,
104+
):
105+
raise ValueError(
106+
"Unexpected samplerate value! Must be one of: "
107+
"CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE, or CFG_16SAMPLE"
108+
)
104109
# Set configuration register to turn on chip, enable data ready output,
105110
# and start sampling at the specified rate.
106111
config = _TMP007_CFG_MODEON | _TMP007_CFG_DRDYEN | samplerate
107112
self._write_u16(_TMP007_CONFIG, config)
108113
# Check device ID match expected value.
109114
dev_id = self.read_register(_TMP007_DEVID)
110115
if dev_id != 0x78:
111-
raise RuntimeError('Init failed - Did not find TMP007')
116+
raise RuntimeError("Init failed - Did not find TMP007")
112117

113118
def sleep(self):
114119
"""Put TMP007 into low power sleep mode. No measurement data will be
@@ -131,7 +136,7 @@ def raw_voltage(self):
131136
"""
132137
raw = self._read_u16(_TMP007_VOBJ)
133138
if raw > 32767:
134-
raw = (raw & 0x7fff) - 32768
139+
raw = (raw & 0x7FFF) - 32768
135140
return raw
136141

137142
@property
@@ -154,28 +159,25 @@ def temperature(self):
154159
"""
155160
raw = self._read_u16(_TMP007_TOBJ)
156161
if raw & 1:
157-
return -9999.
162+
return -9999.0
158163
raw = raw >> 2
159164
return raw * 0.03125
160165

161166
def read_register(self, register):
162167
"""Read sensor Register."""
163-
return self._read_u16(register)
164-
168+
return self._read_u16(register)
165169

166170
def _read_u8(self, address):
167171
with self._device as i2c:
168172
self._BUFFER[0] = address & 0xFF
169-
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
170-
out_end=1, in_end=1)
173+
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=1)
171174
return self._BUFFER[0]
172175

173176
def _read_u16(self, address):
174177
with self._device as i2c:
175178
self._BUFFER[0] = address & 0xFF
176-
i2c.write_then_readinto(self._BUFFER, self._BUFFER,
177-
out_end=1, in_end=2)
178-
return self._BUFFER[0]<<8 | self._BUFFER[1]
179+
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=2)
180+
return self._BUFFER[0] << 8 | self._BUFFER[1]
179181

180182
def _write_u8(self, address, val):
181183
with self._device as i2c:

docs/conf.py

Lines changed: 69 additions & 47 deletions
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_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),'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+
"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 TMP007 Library'
38-
copyright = u'2018 Jerry Needell'
39-
author = u'Jerry Needell'
45+
project = u"Adafruit TMP007 Library"
46+
copyright = u"2018 Jerry Needell"
47+
author = u"Jerry Needell"
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 = 'AdafruitTmp007Librarydoc'
121+
htmlhelp_basename = "AdafruitTmp007Librarydoc"
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, 'AdafruitTMP007Library.tex', u'AdafruitTMP007 Library Documentation',
139-
author, 'manual'),
144+
(
145+
master_doc,
146+
"AdafruitTMP007Library.tex",
147+
u"AdafruitTMP007 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, 'AdafruitTMP007library', u'Adafruit TMP007 Library Documentation',
148-
[author], 1)
158+
(
159+
master_doc,
160+
"AdafruitTMP007library",
161+
u"Adafruit TMP007 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, 'AdafruitTMP007Library', u'Adafruit TMP007 Library Documentation',
158-
author, 'AdafruitTMP007Library', 'One line description of project.',
159-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"AdafruitTMP007Library",
176+
u"Adafruit TMP007 Library Documentation",
177+
author,
178+
"AdafruitTMP007Library",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
160182
]

examples/tmp007_simpletest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ def c_to_f(c):
1414
return c * 9.0 / 5.0 + 32.0
1515

1616

17-
1817
# Create library object using our Bus I2C port
1918
i2c = busio.I2C(board.SCL, board.SDA)
2019
sensor = adafruit_tmp007.TMP007(i2c)
2120

2221

23-
2422
# Initialize communication with the sensor, using the default 16 samples per conversion.
2523
# This is the best accuracy but a little slower at reacting to changes.
2624
# The first sample will be meaningless
2725
while True:
2826
die_temp = sensor.die_temperature
29-
print(' Die temperature: {0:0.3F}*C / {1:0.3F}*F'.format(die_temp, c_to_f(die_temp)))
27+
print(
28+
" Die temperature: {0:0.3F}*C / {1:0.3F}*F".format(die_temp, c_to_f(die_temp))
29+
)
3030
obj_temp = sensor.temperature
31-
print('Object temperature: {0:0.3F}*C / {1:0.3F}*F'.format(obj_temp, c_to_f(obj_temp)))
31+
print(
32+
"Object temperature: {0:0.3F}*C / {1:0.3F}*F".format(obj_temp, c_to_f(obj_temp))
33+
)
3234
time.sleep(5.0)

0 commit comments

Comments
 (0)