Skip to content

Commit 4b9778b

Browse files
authored
Merge pull request #31 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents 1c19545 + 7d5d177 commit 4b9778b

File tree

6 files changed

+132
-110
lines changed

6 files changed

+132
-110
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

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ spelling-store-unknown-words=no
119119
[MISCELLANEOUS]
120120

121121
# List of note tags to take in consideration, separated by a comma.
122-
notes=FIXME,XXX,TODO
122+
# notes=FIXME,XXX,TODO
123+
notes=FIXME,XXX
123124

124125

125126
[TYPECHECK]

adafruit_tsl2561.py

+35-32
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,29 @@
5454
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_TSL2561.git"
5555

5656
# pylint: disable=bad-whitespace
57-
_DEFAULT_ADDRESS = const(0x39)
58-
_COMMAND_BIT = const(0x80)
59-
_WORD_BIT = const(0x20)
60-
61-
_CONTROL_POWERON = const(0x03)
62-
_CONTROL_POWEROFF = const(0x00)
63-
64-
_REGISTER_CONTROL = const(0x00)
65-
_REGISTER_TIMING = const(0x01)
66-
_REGISTER_TH_LOW = const(0x02)
67-
_REGISTER_TH_HIGH = const(0x04)
68-
_REGISTER_INT_CTRL = const(0x06)
69-
_REGISTER_CHAN0_LOW = const(0x0C)
70-
_REGISTER_CHAN1_LOW = const(0x0E)
71-
_REGISTER_ID = const(0x0A)
57+
_DEFAULT_ADDRESS = const(0x39)
58+
_COMMAND_BIT = const(0x80)
59+
_WORD_BIT = const(0x20)
60+
61+
_CONTROL_POWERON = const(0x03)
62+
_CONTROL_POWEROFF = const(0x00)
63+
64+
_REGISTER_CONTROL = const(0x00)
65+
_REGISTER_TIMING = const(0x01)
66+
_REGISTER_TH_LOW = const(0x02)
67+
_REGISTER_TH_HIGH = const(0x04)
68+
_REGISTER_INT_CTRL = const(0x06)
69+
_REGISTER_CHAN0_LOW = const(0x0C)
70+
_REGISTER_CHAN1_LOW = const(0x0E)
71+
_REGISTER_ID = const(0x0A)
7272

7373
_GAIN_SCALE = (16, 1)
7474
_TIME_SCALE = (1 / 0.034, 1 / 0.252, 1)
7575
_CLIP_THRESHOLD = (4900, 37000, 65000)
7676
# pylint: enable=bad-whitespace
7777

78-
class TSL2561():
78+
79+
class TSL2561:
7980
"""Class which provides interface to TSL2561 light sensor."""
8081

8182
def __init__(self, i2c, address=_DEFAULT_ADDRESS):
@@ -84,15 +85,17 @@ def __init__(self, i2c, address=_DEFAULT_ADDRESS):
8485
partno, revno = self.chip_id
8586
# data sheet says TSL2561 = 0001, reality says 0101
8687
if not partno == 5:
87-
raise RuntimeError('Failed to find TSL2561! Part 0x%x Rev 0x%x' % (partno, revno))
88+
raise RuntimeError(
89+
"Failed to find TSL2561! Part 0x%x Rev 0x%x" % (partno, revno)
90+
)
8891
self.enabled = True
8992

9093
@property
9194
def chip_id(self):
9295
"""A tuple containing the part number and the revision number."""
9396
chip_id = self._read_register(_REGISTER_ID)
94-
partno = (chip_id >> 4) & 0x0f
95-
revno = chip_id & 0x0f
97+
partno = (chip_id >> 4) & 0x0F
98+
revno = chip_id & 0x0F
9699
return (partno, revno)
97100

98101
@property
@@ -141,7 +144,7 @@ def gain(self, value):
141144
value <<= 4
142145
current = self._read_register(_REGISTER_TIMING)
143146
self.buf[0] = _COMMAND_BIT | _REGISTER_TIMING
144-
self.buf[1] = (current & 0xef) | value
147+
self.buf[1] = (current & 0xEF) | value
145148
with self.i2c_device as i2c:
146149
i2c.write(self.buf, end=2)
147150

@@ -157,7 +160,7 @@ def integration_time(self, value):
157160
value &= 0x03
158161
current = self._read_register(_REGISTER_TIMING)
159162
self.buf[0] = _COMMAND_BIT | _REGISTER_TIMING
160-
self.buf[1] = (current & 0xfc) | value
163+
self.buf[1] = (current & 0xFC) | value
161164
with self.i2c_device as i2c:
162165
i2c.write(self.buf, end=2)
163166

@@ -170,8 +173,8 @@ def threshold_low(self):
170173
@threshold_low.setter
171174
def threshold_low(self, value):
172175
self.buf[0] = _COMMAND_BIT | _WORD_BIT | _REGISTER_TH_LOW
173-
self.buf[1] = value & 0xff
174-
self.buf[2] = (value >> 8) & 0xff
176+
self.buf[1] = value & 0xFF
177+
self.buf[2] = (value >> 8) & 0xFF
175178
with self.i2c_device as i2c:
176179
i2c.write(self.buf)
177180

@@ -184,8 +187,8 @@ def threshold_high(self):
184187
@threshold_high.setter
185188
def threshold_high(self, value):
186189
self.buf[0] = _COMMAND_BIT | _WORD_BIT | _REGISTER_TH_HIGH
187-
self.buf[1] = value & 0xff
188-
self.buf[2] = (value >> 8) & 0xff
190+
self.buf[1] = value & 0xFF
191+
self.buf[2] = (value >> 8) & 0xFF
189192
with self.i2c_device as i2c:
190193
i2c.write(self.buf)
191194

@@ -194,13 +197,13 @@ def cycles(self):
194197
"""The number of integration cycles for which an out of bounds
195198
value must persist to cause an interrupt."""
196199
value = self._read_register(_REGISTER_INT_CTRL)
197-
return value & 0x0f
200+
return value & 0x0F
198201

199202
@cycles.setter
200203
def cycles(self, value):
201204
current = self._read_register(_REGISTER_INT_CTRL)
202205
self.buf[0] = _COMMAND_BIT | _REGISTER_INT_CTRL
203-
self.buf[1] = current | (value & 0x0f)
206+
self.buf[1] = current | (value & 0x0F)
204207
with self.i2c_device as i2c:
205208
i2c.write(self.buf, end=2)
206209

@@ -224,13 +227,13 @@ def interrupt_mode(self):
224227
def interrupt_mode(self, value):
225228
current = self._read_register(_REGISTER_INT_CTRL)
226229
self.buf[0] = _COMMAND_BIT | _REGISTER_INT_CTRL
227-
self.buf[1] = (current & 0x0f) | ((value & 0x03) << 4)
230+
self.buf[1] = (current & 0x0F) | ((value & 0x03) << 4)
228231
with self.i2c_device as i2c:
229232
i2c.write(self.buf, end=2)
230233

231234
def clear_interrupt(self):
232235
"""Clears any pending interrupt."""
233-
self.buf[0] = 0xc0
236+
self.buf[0] = 0xC0
234237
with self.i2c_device as i2c:
235238
i2c.write(self.buf, end=1)
236239

@@ -244,16 +247,16 @@ def _compute_lux(self):
244247
if ch1 > _CLIP_THRESHOLD[self.integration_time]:
245248
return None
246249
ratio = ch1 / ch0
247-
if ratio >= 0 and ratio <= 0.50:
248-
lux = 0.0304 * ch0 - 0.062 * ch0 * ratio**1.4
250+
if 0 <= ratio <= 0.50:
251+
lux = 0.0304 * ch0 - 0.062 * ch0 * ratio ** 1.4
249252
elif ratio <= 0.61:
250253
lux = 0.0224 * ch0 - 0.031 * ch1
251254
elif ratio <= 0.80:
252255
lux = 0.0128 * ch0 - 0.0153 * ch1
253256
elif ratio <= 1.30:
254257
lux = 0.00146 * ch0 - 0.00112 * ch1
255258
else:
256-
lux = 0.
259+
lux = 0.0
257260
# Pretty sure the floating point math formula on pg. 23 of datasheet
258261
# is based on 16x gain and 402ms integration time. Need to scale
259262
# result for other settings.

docs/conf.py

+72-46
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,59 @@
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),'Register': ('https://circuitpython.readthedocs.io/projects/register/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+
"Register": (
31+
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
32+
None,
33+
),
34+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
35+
}
2436

2537
# Add any paths that contain templates here, relative to this directory.
26-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
2739

28-
source_suffix = '.rst'
40+
source_suffix = ".rst"
2941

3042
# The master toctree document.
31-
master_doc = 'index'
43+
master_doc = "index"
3244

3345
# General information about the project.
34-
project = u'Adafruit CIRCUITPYTHON_TSL2561 Library'
35-
copyright = u'2017 Carter Nelson'
36-
author = u'Carter Nelson'
46+
project = u"Adafruit CIRCUITPYTHON_TSL2561 Library"
47+
copyright = u"2017 Carter Nelson"
48+
author = u"Carter Nelson"
3749

3850
# The version info for the project you're documenting, acts as replacement for
3951
# |version| and |release|, also used in various other places throughout the
4052
# built documents.
4153
#
4254
# The short X.Y version.
43-
version = u'1.0'
55+
version = u"1.0"
4456
# The full version, including alpha/beta/rc tags.
45-
release = u'1.0'
57+
release = u"1.0"
4658

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

5971
# The reST default role (used for this markup: `text`) to use for all
6072
# documents.
@@ -66,7 +78,7 @@
6678
add_function_parentheses = True
6779

6880
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = 'sphinx'
81+
pygments_style = "sphinx"
7082

7183
# If true, `todo` and `todoList` produce output, else they produce nothing.
7284
todo_include_todos = False
@@ -80,68 +92,76 @@
8092
# The theme to use for HTML and HTML Help pages. See the documentation for
8193
# a list of builtin themes.
8294
#
83-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
95+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8496

8597
if not on_rtd: # only import and set the theme if we're building docs locally
8698
try:
8799
import sphinx_rtd_theme
88-
html_theme = 'sphinx_rtd_theme'
89-
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(), "."]
90103
except:
91-
html_theme = 'default'
92-
html_theme_path = ['.']
104+
html_theme = "default"
105+
html_theme_path = ["."]
93106
else:
94-
html_theme_path = ['.']
107+
html_theme_path = ["."]
95108

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

101114
# The name of an image file (relative to this directory) to use as a favicon of
102115
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103116
# pixels large.
104117
#
105-
html_favicon = '_static/favicon.ico'
118+
html_favicon = "_static/favicon.ico"
106119

107120
# Output file base name for HTML help builder.
108-
htmlhelp_basename = 'AdafruitCIRCUITPYTHON_TSL2561Librarydoc'
121+
htmlhelp_basename = "AdafruitCIRCUITPYTHON_TSL2561Librarydoc"
109122

110123
# -- Options for LaTeX output ---------------------------------------------
111124

112125
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',
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',
128138
}
129139

130140
# Grouping the document tree into LaTeX files. List of tuples
131141
# (source start file, target name, title,
132142
# author, documentclass [howto, manual, or own class]).
133143
latex_documents = [
134-
(master_doc, 'AdafruitCIRCUITPYTHON_TSL2561Library.tex', u'Adafruit CIRCUITPYTHON_TSL2561 Library Documentation',
135-
author, 'manual'),
144+
(
145+
master_doc,
146+
"AdafruitCIRCUITPYTHON_TSL2561Library.tex",
147+
u"Adafruit CIRCUITPYTHON_TSL2561 Library Documentation",
148+
author,
149+
"manual",
150+
),
136151
]
137152

138153
# -- Options for manual page output ---------------------------------------
139154

140155
# One entry per manual page. List of tuples
141156
# (source start file, name, description, authors, manual section).
142157
man_pages = [
143-
(master_doc, 'AdafruitCIRCUITPYTHON_TSL2561library', u'Adafruit CIRCUITPYTHON_TSL2561 Library Documentation',
144-
[author], 1)
158+
(
159+
master_doc,
160+
"AdafruitCIRCUITPYTHON_TSL2561library",
161+
u"Adafruit CIRCUITPYTHON_TSL2561 Library Documentation",
162+
[author],
163+
1,
164+
)
145165
]
146166

147167
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +170,13 @@
150170
# (source start file, target name, title, author,
151171
# dir menu entry, description, category)
152172
texinfo_documents = [
153-
(master_doc, 'AdafruitCIRCUITPYTHON_TSL2561Library', u'Adafruit CIRCUITPYTHON_TSL2561 Library Documentation',
154-
author, 'AdafruitCIRCUITPYTHON_TSL2561Library', 'One line description of project.',
155-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"AdafruitCIRCUITPYTHON_TSL2561Library",
176+
u"Adafruit CIRCUITPYTHON_TSL2561 Library Documentation",
177+
author,
178+
"AdafruitCIRCUITPYTHON_TSL2561Library",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
156182
]

examples/tsl2561_simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
infrared = tsl.infrared
3535

3636
# Get raw (luminosity) readings using tuple unpacking
37-
#broadband, infrared = tsl.luminosity
37+
# broadband, infrared = tsl.luminosity
3838

3939
# Get computed lux value (tsl.lux can return None or a float)
4040
lux = tsl.lux

0 commit comments

Comments
 (0)