Skip to content

Commit 7ac2b29

Browse files
committed
Ran black, updated to pylint 2.x
1 parent 6919489 commit 7ac2b29

File tree

5 files changed

+129
-107
lines changed

5 files changed

+129
-107
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_as726x.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
_AS726X_DEVICE_TEMP = const(0x06)
5050
_AS726X_LED_CONTROL = const(0x07)
5151

52-
#for reading sensor data
52+
# for reading sensor data
5353
_AS7262_V_HIGH = const(0x08)
5454
_AS7262_V_LOW = const(0x09)
5555
_AS7262_B_HIGH = const(0x0A)
@@ -70,7 +70,7 @@
7070
_AS7262_O_CAL = const(0x24)
7171
_AS7262_R_CAL = const(0x28)
7272

73-
#hardware registers
73+
# hardware registers
7474
_AS726X_SLAVE_STATUS_REG = const(0x00)
7575
_AS726X_SLAVE_WRITE_REG = const(0x01)
7676
_AS726X_SLAVE_READ_REG = const(0x02)
@@ -92,9 +92,9 @@
9292

9393
_AS726X_NUM_CHANNELS = const(6)
9494

95-
#pylint: disable=too-many-instance-attributes
96-
#pylint: disable=too-many-public-methods
97-
class Adafruit_AS726x(object):
95+
# pylint: disable=too-many-instance-attributes
96+
# pylint: disable=too-many-public-methods
97+
class Adafruit_AS726x():
9898
"""AS726x spectral sensor.
9999
100100
:param ~busio.I2C i2c_bus: The I2C bus connected to the sensor
@@ -108,7 +108,7 @@ class Adafruit_AS726x(object):
108108
"""Continuously gather samples of green, yellow, orange and red. Violet and blue are skipped
109109
and read zero."""
110110

111-
MODE_2 = 0b10 #default
111+
MODE_2 = 0b10 # default
112112
"""Continuously gather samples of all colors"""
113113

114114
ONE_SHOT = 0b11
@@ -132,18 +132,20 @@ def __init__(self, i2c_bus):
132132

133133
self.i2c_device = I2CDevice(i2c_bus, _AS726X_ADDRESS)
134134

135-
#reset device
135+
# reset device
136136
self._virtual_write(_AS726X_CONTROL_SETUP, 0x80)
137137

138-
#wait for it to boot up
138+
# wait for it to boot up
139139
time.sleep(1)
140140

141-
#try to read the version reg to make sure we can connect
141+
# try to read the version reg to make sure we can connect
142142
version = self._virtual_read(_AS726X_HW_VERSION)
143143

144-
#TODO: add support for other devices
144+
# TODO: add support for other devices
145145
if version != 0x40:
146-
raise ValueError("device could not be reached or this device is not supported!")
146+
raise ValueError(
147+
"device could not be reached or this device is not supported!"
148+
)
147149

148150
self.integration_time = 140
149151
self.conversion_mode = Adafruit_AS726x.MODE_2
@@ -258,7 +260,7 @@ def gain(self, val):
258260
self._gain = val
259261
state = self._virtual_read(_AS726X_CONTROL_SETUP)
260262
state &= ~(0x3 << 4)
261-
state |= (Adafruit_AS726x.GAIN.index(val) << 4)
263+
state |= Adafruit_AS726x.GAIN.index(val) << 4
262264
self._virtual_write(_AS726X_CONTROL_SETUP, state)
263265

264266
@property
@@ -274,7 +276,7 @@ def integration_time(self, val):
274276
if self._integration_time == val:
275277
return
276278
self._integration_time = val
277-
self._virtual_write(_AS726X_INT_T, int(val/2.8))
279+
self._virtual_write(_AS726X_INT_T, int(val / 2.8))
278280

279281
def start_measurement(self):
280282
"""Begin a measurement.
@@ -298,7 +300,7 @@ def read_calibrated_value(self, channel):
298300
val[1] = self._virtual_read(channel + 1)
299301
val[2] = self._virtual_read(channel + 2)
300302
val[3] = self._virtual_read(channel + 3)
301-
return struct.unpack('!f', val)[0]
303+
return struct.unpack("!f", val)[0]
302304

303305
@property
304306
def data_ready(self):
@@ -413,18 +415,18 @@ def _virtual_write(self, addr, value):
413415
# Read slave I2C status to see if the write buffer is ready.
414416
status = self._read_u8(_AS726X_SLAVE_STATUS_REG)
415417
if (status & _AS726X_SLAVE_TX_VALID) == 0:
416-
break # No inbound TX pending at slave. Okay to write now.
418+
break # No inbound TX pending at slave. Okay to write now.
417419
# Send the virtual register address (setting bit 7 to indicate a pending write).
418420
self.__write_u8(_AS726X_SLAVE_WRITE_REG, (addr | 0x80))
419421
while True:
420422
# Read the slave I2C status to see if the write buffer is ready.
421423
status = self._read_u8(_AS726X_SLAVE_STATUS_REG)
422424
if (status & _AS726X_SLAVE_TX_VALID) == 0:
423-
break # No inbound TX pending at slave. Okay to write data now.
425+
break # No inbound TX pending at slave. Okay to write data now.
424426

425427
# Send the data to complete the operation.
426428
self.__write_u8(_AS726X_SLAVE_WRITE_REG, value)
427429

428430

429-
#pylint: enable=too-many-instance-attributes
430-
#pylint: enable=too-many-public-methods
431+
# pylint: enable=too-many-instance-attributes
432+
# pylint: enable=too-many-public-methods

docs/conf.py

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,56 @@
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.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.todo",
1617
]
1718

18-
autodoc_member_order = 'bysource'
19-
20-
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)}
19+
autodoc_member_order = "bysource"
20+
21+
intersphinx_mapping = {
22+
"python": ("https://docs.python.org/3.4", None),
23+
"BusDevice": (
24+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
25+
None,
26+
),
27+
"Register": (
28+
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
29+
None,
30+
),
31+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
32+
}
2133

2234
# Add any paths that contain templates here, relative to this directory.
23-
templates_path = ['_templates']
35+
templates_path = ["_templates"]
2436

25-
source_suffix = '.rst'
37+
source_suffix = ".rst"
2638

2739
# The master toctree document.
28-
master_doc = 'index'
40+
master_doc = "index"
2941

3042
# General information about the project.
31-
project = u'Adafruit AS726x Library'
32-
copyright = u'2017 Dean Miller'
33-
author = u'Dean Miller'
43+
project = u"Adafruit AS726x Library"
44+
copyright = u"2017 Dean Miller"
45+
author = u"Dean Miller"
3446

3547
# The version info for the project you're documenting, acts as replacement for
3648
# |version| and |release|, also used in various other places throughout the
3749
# built documents.
3850
#
3951
# The short X.Y version.
40-
version = u'1.0'
52+
version = u"1.0"
4153
# The full version, including alpha/beta/rc tags.
42-
release = u'1.0'
54+
release = u"1.0"
4355

4456
# The language for content autogenerated by Sphinx. Refer to documentation
4557
# for a list of supported languages.
@@ -51,7 +63,7 @@
5163
# List of patterns, relative to source directory, that match files and
5264
# directories to ignore when looking for source files.
5365
# This patterns also effect to html_static_path and html_extra_path
54-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
66+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5567

5668
# The reST default role (used for this markup: `text`) to use for all
5769
# documents.
@@ -63,7 +75,7 @@
6375
add_function_parentheses = True
6476

6577
# The name of the Pygments (syntax highlighting) style to use.
66-
pygments_style = 'sphinx'
78+
pygments_style = "sphinx"
6779

6880
# If true, `todo` and `todoList` produce output, else they produce nothing.
6981
todo_include_todos = False
@@ -77,62 +89,70 @@
7789
# The theme to use for HTML and HTML Help pages. See the documentation for
7890
# a list of builtin themes.
7991
#
80-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
92+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8193

8294
if not on_rtd: # only import and set the theme if we're building docs locally
8395
try:
8496
import sphinx_rtd_theme
85-
html_theme = 'sphinx_rtd_theme'
86-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
97+
98+
html_theme = "sphinx_rtd_theme"
99+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
87100
except:
88-
html_theme = 'default'
89-
html_theme_path = ['.']
101+
html_theme = "default"
102+
html_theme_path = ["."]
90103
else:
91-
html_theme_path = ['.']
104+
html_theme_path = ["."]
92105

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

98111
# Output file base name for HTML help builder.
99-
htmlhelp_basename = 'AdafruitAs726xLibrarydoc'
112+
htmlhelp_basename = "AdafruitAs726xLibrarydoc"
100113

101114
# -- Options for LaTeX output ---------------------------------------------
102115

103116
latex_elements = {
104-
# The paper size ('letterpaper' or 'a4paper').
105-
#
106-
# 'papersize': 'letterpaper',
107-
108-
# The font size ('10pt', '11pt' or '12pt').
109-
#
110-
# 'pointsize': '10pt',
111-
112-
# Additional stuff for the LaTeX preamble.
113-
#
114-
# 'preamble': '',
115-
116-
# Latex figure (float) alignment
117-
#
118-
# 'figure_align': 'htbp',
117+
# The paper size ('letterpaper' or 'a4paper').
118+
#
119+
# 'papersize': 'letterpaper',
120+
# The font size ('10pt', '11pt' or '12pt').
121+
#
122+
# 'pointsize': '10pt',
123+
# Additional stuff for the LaTeX preamble.
124+
#
125+
# 'preamble': '',
126+
# Latex figure (float) alignment
127+
#
128+
# 'figure_align': 'htbp',
119129
}
120130

121131
# Grouping the document tree into LaTeX files. List of tuples
122132
# (source start file, target name, title,
123133
# author, documentclass [howto, manual, or own class]).
124134
latex_documents = [
125-
(master_doc, 'AdafruitAS726xLibrary.tex', u'AdafruitAS726x Library Documentation',
126-
author, 'manual'),
135+
(
136+
master_doc,
137+
"AdafruitAS726xLibrary.tex",
138+
u"AdafruitAS726x Library Documentation",
139+
author,
140+
"manual",
141+
),
127142
]
128143

129144
# -- Options for manual page output ---------------------------------------
130145

131146
# One entry per manual page. List of tuples
132147
# (source start file, name, description, authors, manual section).
133148
man_pages = [
134-
(master_doc, 'AdafruitAS726xlibrary', u'Adafruit AS726x Library Documentation',
135-
[author], 1)
149+
(
150+
master_doc,
151+
"AdafruitAS726xlibrary",
152+
u"Adafruit AS726x Library Documentation",
153+
[author],
154+
1,
155+
)
136156
]
137157

138158
# -- Options for Texinfo output -------------------------------------------
@@ -141,7 +161,13 @@
141161
# (source start file, target name, title, author,
142162
# dir menu entry, description, category)
143163
texinfo_documents = [
144-
(master_doc, 'AdafruitAS726xLibrary', u'Adafruit AS726x Library Documentation',
145-
author, 'AdafruitAS726xLibrary', 'One line description of project.',
146-
'Miscellaneous'),
164+
(
165+
master_doc,
166+
"AdafruitAS726xLibrary",
167+
u"Adafruit AS726x Library Documentation",
168+
author,
169+
"AdafruitAS726xLibrary",
170+
"One line description of project.",
171+
"Miscellaneous",
172+
),
147173
]

examples/as726x_simpletest.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55

66
from adafruit_as726x import Adafruit_AS726x
77

8-
#maximum value for sensor reading
8+
# maximum value for sensor reading
99
max_val = 16000
1010

11-
#max number of characters in each graph
11+
# max number of characters in each graph
1212
max_graph = 80
1313

14+
1415
def graph_map(x):
1516
return min(int(x * max_graph / max_val), max_graph)
1617

18+
1719
# Initialize I2C bus and sensor.
1820
i2c = busio.I2C(board.SCL, board.SDA)
1921
sensor = Adafruit_AS726x(i2c)
@@ -23,15 +25,15 @@ def graph_map(x):
2325
while True:
2426
# Wait for data to be ready
2527
while not sensor.data_ready:
26-
time.sleep(.1)
28+
time.sleep(0.1)
2729

28-
#plot plot the data
30+
# plot plot the data
2931
print("\n")
30-
print("V: " + graph_map(sensor.violet)*'=')
31-
print("B: " + graph_map(sensor.blue)*'=')
32-
print("G: " + graph_map(sensor.green)*'=')
33-
print("Y: " + graph_map(sensor.yellow)*'=')
34-
print("O: " + graph_map(sensor.orange)*'=')
35-
print("R: " + graph_map(sensor.red)*'=')
32+
print("V: " + graph_map(sensor.violet) * "=")
33+
print("B: " + graph_map(sensor.blue) * "=")
34+
print("G: " + graph_map(sensor.green) * "=")
35+
print("Y: " + graph_map(sensor.yellow) * "=")
36+
print("O: " + graph_map(sensor.orange) * "=")
37+
print("R: " + graph_map(sensor.red) * "=")
3638

3739
time.sleep(1)

0 commit comments

Comments
 (0)