Skip to content

Commit e4acf8c

Browse files
committed
Ran black, updated to pylint 2.x
1 parent c5d0a68 commit e4acf8c

File tree

6 files changed

+131
-99
lines changed

6 files changed

+131
-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_irremote.py

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@
7777
__version__ = "0.0.0-auto.0"
7878
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git"
7979

80+
8081
class IRDecodeException(Exception):
8182
"""Generic decode exception"""
82-
pass
83+
8384

8485
class IRNECRepeatException(Exception):
8586
"""Exception when a NEC repeat is decoded"""
86-
pass
8787

8888

8989
class GenericDecode:
9090
"""Generic decoding of infrared signals"""
91+
9192
def bin_data(self, pulses):
9293
"""Compute bins of pulse lengths where pulses are +-25% of the average.
9394
@@ -97,26 +98,30 @@ def bin_data(self, pulses):
9798

9899
for _, pulse in enumerate(pulses):
99100
matchedbin = False
100-
#print(pulse, end=": ")
101+
# print(pulse, end=": ")
101102
for b, pulse_bin in enumerate(bins):
102-
if pulse_bin[0]*0.75 <= pulse <= pulse_bin[0]*1.25:
103-
#print("matches bin")
103+
if pulse_bin[0] * 0.75 <= pulse <= pulse_bin[0] * 1.25:
104+
# print("matches bin")
104105
bins[b][0] = (pulse_bin[0] + pulse) // 2 # avg em
105-
bins[b][1] += 1 # track it
106+
bins[b][1] += 1 # track it
106107
matchedbin = True
107108
break
108109
if not matchedbin:
109110
bins.append([pulse, 1])
110-
#print(bins)
111+
# print(bins)
111112
return bins
112113

113114
def decode_bits(self, pulses):
114115
"""Decode the pulses into bits."""
115116
# pylint: disable=too-many-branches,too-many-statements
116117

117118
# special exception for NEC repeat code!
118-
if ((len(pulses) == 3) and (8000 <= pulses[0] <= 10000) and
119-
(2000 <= pulses[1] <= 3000) and (450 <= pulses[2] <= 700)):
119+
if (
120+
(len(pulses) == 3)
121+
and (8000 <= pulses[0] <= 10000)
122+
and (2000 <= pulses[1] <= 3000)
123+
and (450 <= pulses[2] <= 700)
124+
):
120125
raise IRNECRepeatException()
121126

122127
if len(pulses) < 10:
@@ -151,34 +156,39 @@ def decode_bits(self, pulses):
151156

152157
if len(pulse_bins) == 1:
153158
raise IRDecodeException("Pulses do not differ")
154-
elif len(pulse_bins) > 2:
159+
if len(pulse_bins) > 2:
155160
raise IRDecodeException("Only mark & space handled")
156161

157162
mark = min(pulse_bins[0][0], pulse_bins[1][0])
158163
space = max(pulse_bins[0][0], pulse_bins[1][0])
159164

160165
if outliers:
161166
# skip outliers
162-
pulses = [p for p in pulses if not
163-
(outliers[0]*0.75) <= p <= (outliers[0]*1.25)]
167+
pulses = [
168+
p
169+
for p in pulses
170+
if not (outliers[0] * 0.75) <= p <= (outliers[0] * 1.25)
171+
]
164172
# convert marks/spaces to 0 and 1
165173
for i, pulse_length in enumerate(pulses):
166-
if (space*0.75) <= pulse_length <= (space*1.25):
174+
if (space * 0.75) <= pulse_length <= (space * 1.25):
167175
pulses[i] = False
168-
elif (mark*0.75) <= pulse_length <= (mark*1.25):
176+
elif (mark * 0.75) <= pulse_length <= (mark * 1.25):
169177
pulses[i] = True
170178
else:
171179
raise IRDecodeException("Pulses outside mark/space")
172180

173181
# convert bits to bytes!
174-
output = [0] * ((len(pulses)+7)//8)
182+
output = [0] * ((len(pulses) + 7) // 8)
175183
for i, pulse_length in enumerate(pulses):
176184
output[i // 8] = output[i // 8] << 1
177185
if pulse_length:
178186
output[i // 8] |= 1
179187
return output
180188

181-
def _read_pulses_non_blocking(self, input_pulses, max_pulse=10000, pulse_window=0.10):
189+
def _read_pulses_non_blocking(
190+
self, input_pulses, max_pulse=10000, pulse_window=0.10
191+
):
182192
"""Read out a burst of pulses without blocking until pulses stop for a specified
183193
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
184194
@@ -207,8 +217,15 @@ def _read_pulses_non_blocking(self, input_pulses, max_pulse=10000, pulse_window=
207217
recent_count = 0
208218
time.sleep(pulse_window)
209219

210-
def read_pulses(self, input_pulses, *, max_pulse=10000, blocking=True,
211-
pulse_window=0.10, blocking_delay=0.10):
220+
def read_pulses(
221+
self,
222+
input_pulses,
223+
*,
224+
max_pulse=10000,
225+
blocking=True,
226+
pulse_window=0.10,
227+
blocking_delay=0.10
228+
):
212229
"""Read out a burst of pulses until pulses stop for a specified
213230
period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``.
214231
@@ -221,14 +238,18 @@ def read_pulses(self, input_pulses, *, max_pulse=10000, blocking=True,
221238
:param float blocking_delay: delay between pulse checks when blocking
222239
"""
223240
while True:
224-
pulses = self._read_pulses_non_blocking(input_pulses, max_pulse, pulse_window)
241+
pulses = self._read_pulses_non_blocking(
242+
input_pulses, max_pulse, pulse_window
243+
)
225244
if blocking and pulses is None:
226245
time.sleep(blocking_delay)
227246
continue
228247
return pulses
229248

249+
230250
class GenericTransmit:
231251
"""Generic infrared transmit class that handles encoding."""
252+
232253
def __init__(self, header, one, zero, trail):
233254
self.header = header
234255
self.one = one
@@ -241,7 +262,7 @@ def transmit(self, pulseout, data):
241262
:param pulseio.PulseOut pulseout: PulseOut to transmit on
242263
:param bytearray data: Data to transmit
243264
"""
244-
durations = array.array('H', [0] * (2 + len(data) * 8 * 2 + 1))
265+
durations = array.array("H", [0] * (2 + len(data) * 8 * 2 + 1))
245266
durations[0] = self.header[0]
246267
durations[1] = self.header[1]
247268
durations[-1] = self.trail

docs/conf.py

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,46 @@
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

18-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
19+
intersphinx_mapping = {
20+
"python": ("https://docs.python.org/3.4", None),
21+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
22+
}
1923

2024
# Add any paths that contain templates here, relative to this directory.
21-
templates_path = ['_templates']
25+
templates_path = ["_templates"]
2226

23-
source_suffix = '.rst'
27+
source_suffix = ".rst"
2428

2529
# The master toctree document.
26-
master_doc = 'index'
30+
master_doc = "index"
2731

2832
# General information about the project.
29-
project = u'Adafruit IRREMOTE Library'
30-
copyright = u'2017 Scott Shawcroft'
31-
author = u'Scott Shawcroft'
33+
project = u"Adafruit IRREMOTE Library"
34+
copyright = u"2017 Scott Shawcroft"
35+
author = u"Scott Shawcroft"
3236

3337
# The version info for the project you're documenting, acts as replacement for
3438
# |version| and |release|, also used in various other places throughout the
3539
# built documents.
3640
#
3741
# The short X.Y version.
38-
version = u'1.0'
42+
version = u"1.0"
3943
# The full version, including alpha/beta/rc tags.
40-
release = u'1.0'
44+
release = u"1.0"
4145

4246
# The language for content autogenerated by Sphinx. Refer to documentation
4347
# for a list of supported languages.
@@ -49,7 +53,7 @@
4953
# List of patterns, relative to source directory, that match files and
5054
# directories to ignore when looking for source files.
5155
# This patterns also effect to html_static_path and html_extra_path
52-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
56+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5357

5458
# The reST default role (used for this markup: `text`) to use for all
5559
# documents.
@@ -61,7 +65,7 @@
6165
add_function_parentheses = True
6266

6367
# The name of the Pygments (syntax highlighting) style to use.
64-
pygments_style = 'sphinx'
68+
pygments_style = "sphinx"
6569

6670
# If true, `todo` and `todoList` produce output, else they produce nothing.
6771
todo_include_todos = False
@@ -75,68 +79,76 @@
7579
# The theme to use for HTML and HTML Help pages. See the documentation for
7680
# a list of builtin themes.
7781
#
78-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
82+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
7983

8084
if not on_rtd: # only import and set the theme if we're building docs locally
8185
try:
8286
import sphinx_rtd_theme
83-
html_theme = 'sphinx_rtd_theme'
84-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
87+
88+
html_theme = "sphinx_rtd_theme"
89+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
8590
except:
86-
html_theme = 'default'
87-
html_theme_path = ['.']
91+
html_theme = "default"
92+
html_theme_path = ["."]
8893
else:
89-
html_theme_path = ['.']
94+
html_theme_path = ["."]
9095

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

96101
# The name of an image file (relative to this directory) to use as a favicon of
97102
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
98103
# pixels large.
99104
#
100-
html_favicon = '_static/favicon.ico'
105+
html_favicon = "_static/favicon.ico"
101106

102107
# Output file base name for HTML help builder.
103-
htmlhelp_basename = 'AdafruitIRREMOTELibrarydoc'
108+
htmlhelp_basename = "AdafruitIRREMOTELibrarydoc"
104109

105110
# -- Options for LaTeX output ---------------------------------------------
106111

107112
latex_elements = {
108-
# The paper size ('letterpaper' or 'a4paper').
109-
#
110-
# 'papersize': 'letterpaper',
111-
112-
# The font size ('10pt', '11pt' or '12pt').
113-
#
114-
# 'pointsize': '10pt',
115-
116-
# Additional stuff for the LaTeX preamble.
117-
#
118-
# 'preamble': '',
119-
120-
# Latex figure (float) alignment
121-
#
122-
# 'figure_align': 'htbp',
113+
# The paper size ('letterpaper' or 'a4paper').
114+
#
115+
# 'papersize': 'letterpaper',
116+
# The font size ('10pt', '11pt' or '12pt').
117+
#
118+
# 'pointsize': '10pt',
119+
# Additional stuff for the LaTeX preamble.
120+
#
121+
# 'preamble': '',
122+
# Latex figure (float) alignment
123+
#
124+
# 'figure_align': 'htbp',
123125
}
124126

125127
# Grouping the document tree into LaTeX files. List of tuples
126128
# (source start file, target name, title,
127129
# author, documentclass [howto, manual, or own class]).
128130
latex_documents = [
129-
(master_doc, 'AdafruitIRREMOTELibrary.tex', u'Adafruit IRREMOTE Library Documentation',
130-
author, 'manual'),
131+
(
132+
master_doc,
133+
"AdafruitIRREMOTELibrary.tex",
134+
u"Adafruit IRREMOTE Library Documentation",
135+
author,
136+
"manual",
137+
),
131138
]
132139

133140
# -- Options for manual page output ---------------------------------------
134141

135142
# One entry per manual page. List of tuples
136143
# (source start file, name, description, authors, manual section).
137144
man_pages = [
138-
(master_doc, 'adafruitIRREMOTElibrary', u'Adafruit IRREMOTE Library Documentation',
139-
[author], 1)
145+
(
146+
master_doc,
147+
"adafruitIRREMOTElibrary",
148+
u"Adafruit IRREMOTE Library Documentation",
149+
[author],
150+
1,
151+
)
140152
]
141153

142154
# -- Options for Texinfo output -------------------------------------------
@@ -145,7 +157,13 @@
145157
# (source start file, target name, title, author,
146158
# dir menu entry, description, category)
147159
texinfo_documents = [
148-
(master_doc, 'AdafruitIRREMOTELibrary', u'Adafruit IRREMOTE Library Documentation',
149-
author, 'AdafruitIRREMOTELibrary', 'One line description of project.',
150-
'Miscellaneous'),
160+
(
161+
master_doc,
162+
"AdafruitIRREMOTELibrary",
163+
u"Adafruit IRREMOTE Library Documentation",
164+
author,
165+
"AdafruitIRREMOTELibrary",
166+
"One line description of project.",
167+
"Miscellaneous",
168+
),
151169
]

examples/irremote_simpletest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
print("Decoded:", code)
1717
except adafruit_irremote.IRNECRepeatException: # unusual short code!
1818
print("NEC repeat!")
19-
except adafruit_irremote.IRDecodeException as e: # failed to decode
19+
except adafruit_irremote.IRDecodeException as e: # failed to decode
2020
print("Failed to decode: ", e.args)
2121

2222
print("----------------------------")

examples/irremote_transmit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""IR transmit example using Circuit Playground Express"""
2-
#pylint: disable-msg=no-member
2+
# pylint: disable-msg=no-member
33
import time
44
import pulseio
55
import board
@@ -15,8 +15,9 @@
1515
pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15)
1616
pulseout = pulseio.PulseOut(pwm)
1717
# Create an encoder that will take numbers and turn them into NEC IR pulses
18-
encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550],
19-
zero=[550, 1700], trail=0)
18+
encoder = adafruit_irremote.GenericTransmit(
19+
header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0
20+
)
2021

2122
while True:
2223
if button.value:

0 commit comments

Comments
 (0)