From e4acf8c6864807b8112b987a9f733ac456f7e5a9 Mon Sep 17 00:00:00 2001 From: dherrada Date: Sun, 15 Mar 2020 17:13:04 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_irremote.py | 61 ++++++++++++------ docs/conf.py | 110 +++++++++++++++++++------------- examples/irremote_simpletest.py | 2 +- examples/irremote_transmit.py | 7 +- setup.py | 48 ++++++-------- 6 files changed, 131 insertions(+), 99 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_irremote.py b/adafruit_irremote.py index df4f00b..8f3efd4 100644 --- a/adafruit_irremote.py +++ b/adafruit_irremote.py @@ -77,17 +77,18 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_IRRemote.git" + class IRDecodeException(Exception): """Generic decode exception""" - pass + class IRNECRepeatException(Exception): """Exception when a NEC repeat is decoded""" - pass class GenericDecode: """Generic decoding of infrared signals""" + def bin_data(self, pulses): """Compute bins of pulse lengths where pulses are +-25% of the average. @@ -97,17 +98,17 @@ def bin_data(self, pulses): for _, pulse in enumerate(pulses): matchedbin = False - #print(pulse, end=": ") + # print(pulse, end=": ") for b, pulse_bin in enumerate(bins): - if pulse_bin[0]*0.75 <= pulse <= pulse_bin[0]*1.25: - #print("matches bin") + if pulse_bin[0] * 0.75 <= pulse <= pulse_bin[0] * 1.25: + # print("matches bin") bins[b][0] = (pulse_bin[0] + pulse) // 2 # avg em - bins[b][1] += 1 # track it + bins[b][1] += 1 # track it matchedbin = True break if not matchedbin: bins.append([pulse, 1]) - #print(bins) + # print(bins) return bins def decode_bits(self, pulses): @@ -115,8 +116,12 @@ def decode_bits(self, pulses): # pylint: disable=too-many-branches,too-many-statements # special exception for NEC repeat code! - if ((len(pulses) == 3) and (8000 <= pulses[0] <= 10000) and - (2000 <= pulses[1] <= 3000) and (450 <= pulses[2] <= 700)): + if ( + (len(pulses) == 3) + and (8000 <= pulses[0] <= 10000) + and (2000 <= pulses[1] <= 3000) + and (450 <= pulses[2] <= 700) + ): raise IRNECRepeatException() if len(pulses) < 10: @@ -151,7 +156,7 @@ def decode_bits(self, pulses): if len(pulse_bins) == 1: raise IRDecodeException("Pulses do not differ") - elif len(pulse_bins) > 2: + if len(pulse_bins) > 2: raise IRDecodeException("Only mark & space handled") mark = min(pulse_bins[0][0], pulse_bins[1][0]) @@ -159,26 +164,31 @@ def decode_bits(self, pulses): if outliers: # skip outliers - pulses = [p for p in pulses if not - (outliers[0]*0.75) <= p <= (outliers[0]*1.25)] + pulses = [ + p + for p in pulses + if not (outliers[0] * 0.75) <= p <= (outliers[0] * 1.25) + ] # convert marks/spaces to 0 and 1 for i, pulse_length in enumerate(pulses): - if (space*0.75) <= pulse_length <= (space*1.25): + if (space * 0.75) <= pulse_length <= (space * 1.25): pulses[i] = False - elif (mark*0.75) <= pulse_length <= (mark*1.25): + elif (mark * 0.75) <= pulse_length <= (mark * 1.25): pulses[i] = True else: raise IRDecodeException("Pulses outside mark/space") # convert bits to bytes! - output = [0] * ((len(pulses)+7)//8) + output = [0] * ((len(pulses) + 7) // 8) for i, pulse_length in enumerate(pulses): output[i // 8] = output[i // 8] << 1 if pulse_length: output[i // 8] |= 1 return output - def _read_pulses_non_blocking(self, input_pulses, max_pulse=10000, pulse_window=0.10): + def _read_pulses_non_blocking( + self, input_pulses, max_pulse=10000, pulse_window=0.10 + ): """Read out a burst of pulses without blocking until pulses stop for a specified period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``. @@ -207,8 +217,15 @@ def _read_pulses_non_blocking(self, input_pulses, max_pulse=10000, pulse_window= recent_count = 0 time.sleep(pulse_window) - def read_pulses(self, input_pulses, *, max_pulse=10000, blocking=True, - pulse_window=0.10, blocking_delay=0.10): + def read_pulses( + self, + input_pulses, + *, + max_pulse=10000, + blocking=True, + pulse_window=0.10, + blocking_delay=0.10 + ): """Read out a burst of pulses until pulses stop for a specified period (pulse_window), pruning pulses after a pulse longer than ``max_pulse``. @@ -221,14 +238,18 @@ def read_pulses(self, input_pulses, *, max_pulse=10000, blocking=True, :param float blocking_delay: delay between pulse checks when blocking """ while True: - pulses = self._read_pulses_non_blocking(input_pulses, max_pulse, pulse_window) + pulses = self._read_pulses_non_blocking( + input_pulses, max_pulse, pulse_window + ) if blocking and pulses is None: time.sleep(blocking_delay) continue return pulses + class GenericTransmit: """Generic infrared transmit class that handles encoding.""" + def __init__(self, header, one, zero, trail): self.header = header self.one = one @@ -241,7 +262,7 @@ def transmit(self, pulseout, data): :param pulseio.PulseOut pulseout: PulseOut to transmit on :param bytearray data: Data to transmit """ - durations = array.array('H', [0] * (2 + len(data) * 8 * 2 + 1)) + durations = array.array("H", [0] * (2 + len(data) * 8 * 2 + 1)) durations[0] = self.header[0] durations[1] = self.header[1] durations[-1] = self.trail diff --git a/docs/conf.py b/docs/conf.py index 0774943..64c8c60 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,34 +11,37 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit IRREMOTE Library' -copyright = u'2017 Scott Shawcroft' -author = u'Scott Shawcroft' +project = u"Adafruit IRREMOTE Library" +copyright = u"2017 Scott Shawcroft" +author = u"Scott Shawcroft" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -49,7 +53,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -61,7 +65,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -75,59 +79,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitIRREMOTELibrarydoc' +htmlhelp_basename = "AdafruitIRREMOTELibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitIRREMOTELibrary.tex', u'Adafruit IRREMOTE Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitIRREMOTELibrary.tex", + u"Adafruit IRREMOTE Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -135,8 +142,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitIRREMOTElibrary', u'Adafruit IRREMOTE Library Documentation', - [author], 1) + ( + master_doc, + "adafruitIRREMOTElibrary", + u"Adafruit IRREMOTE Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -145,7 +157,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitIRREMOTELibrary', u'Adafruit IRREMOTE Library Documentation', - author, 'AdafruitIRREMOTELibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitIRREMOTELibrary", + u"Adafruit IRREMOTE Library Documentation", + author, + "AdafruitIRREMOTELibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/irremote_simpletest.py b/examples/irremote_simpletest.py index d72171f..a9bb7d3 100644 --- a/examples/irremote_simpletest.py +++ b/examples/irremote_simpletest.py @@ -16,7 +16,7 @@ print("Decoded:", code) except adafruit_irremote.IRNECRepeatException: # unusual short code! print("NEC repeat!") - except adafruit_irremote.IRDecodeException as e: # failed to decode + except adafruit_irremote.IRDecodeException as e: # failed to decode print("Failed to decode: ", e.args) print("----------------------------") diff --git a/examples/irremote_transmit.py b/examples/irremote_transmit.py index d219435..ae68eba 100644 --- a/examples/irremote_transmit.py +++ b/examples/irremote_transmit.py @@ -1,5 +1,5 @@ """IR transmit example using Circuit Playground Express""" -#pylint: disable-msg=no-member +# pylint: disable-msg=no-member import time import pulseio import board @@ -15,8 +15,9 @@ pwm = pulseio.PWMOut(board.IR_TX, frequency=38000, duty_cycle=2 ** 15) pulseout = pulseio.PulseOut(pwm) # Create an encoder that will take numbers and turn them into NEC IR pulses -encoder = adafruit_irremote.GenericTransmit(header=[9500, 4500], one=[550, 550], - zero=[550, 1700], trail=0) +encoder = adafruit_irremote.GenericTransmit( + header=[9500, 4500], one=[550, 550], zero=[550, 1700], trail=0 +) while True: if button.value: diff --git a/setup.py b/setup.py index 3f600e7..25680e1 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-irremote', - + name="adafruit-circuitpython-irremote", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for infrared transmit and receive.', + setup_requires=["setuptools_scm"], + description="CircuitPython library for infrared transmit and receive.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_IRRemote', - + url="https://github.com/adafruit/Adafruit_CircuitPython_IRRemote", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[], - # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit infrared transmit receive tx rx ir hardware micropython circuitpython', - + keywords="adafruit infrared transmit receive tx rx ir hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_irremote'], + py_modules=["adafruit_irremote"], )