From d2857c18ced8d2c384b0a38fedc30878d8ff1dc8 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 2 Mar 2020 18:31:41 -0500 Subject: [PATCH] Ran black, resolved conflicts with pylint, prepared for update to pylint 2.x --- adafruit_msa301.py | 102 +++++++++++++++++------------ docs/conf.py | 120 +++++++++++++++++++++------------- examples/msa301_simpletest.py | 2 +- setup.py | 55 +++++++--------- 4 files changed, 156 insertions(+), 123 deletions(-) diff --git a/adafruit_msa301.py b/adafruit_msa301.py index 1719dcc..df912b8 100644 --- a/adafruit_msa301.py +++ b/adafruit_msa301.py @@ -78,7 +78,9 @@ _STANDARD_GRAVITY = 9.806 -class Mode: # pylint: disable=too-few-public-methods + + +class Mode: # pylint: disable=too-few-public-methods """An enum-like class representing the different modes that the MSA301 can use. The values can be referenced like ``Mode.NORMAL`` or ``Mode.SUSPEND`` Possible values are @@ -87,12 +89,14 @@ class Mode: # pylint: disable=too-few-public-methods - ``Mode.LOW_POWER`` - ``Mode.SUSPEND`` """ + # pylint: disable=invalid-name NORMAL = 0b00 LOWPOWER = 0b01 SUSPEND = 0b010 -class DataRate: # pylint: disable=too-few-public-methods + +class DataRate: # pylint: disable=too-few-public-methods """An enum-like class representing the different data rates that the MSA301 can use. The values can be referenced like ``DataRate.RATE_1_HZ`` or ``DataRate.RATE_1000_HZ`` Possible values are @@ -109,19 +113,21 @@ class DataRate: # pylint: disable=too-few-public-methods - ``DataRate.RATE_500_HZ`` - ``DataRate.RATE_1000_HZ`` """ - RATE_1_HZ = 0b0000 # 1 Hz + + RATE_1_HZ = 0b0000 # 1 Hz RATE_1_95_HZ = 0b0001 # 1.95 Hz - RATE_3_9_HZ = 0b0010 # 3.9 Hz + RATE_3_9_HZ = 0b0010 # 3.9 Hz RATE_7_81_HZ = 0b0011 # 7.81 Hz - RATE_15_63_HZ = 0b0100 # 15.63 Hz - RATE_31_25_HZ = 0b0101 # 31.25 Hz + RATE_15_63_HZ = 0b0100 # 15.63 Hz + RATE_31_25_HZ = 0b0101 # 31.25 Hz RATE_62_5_HZ = 0b0110 # 62.5 Hz - RATE_125_HZ = 0b0111 # 125 Hz - RATE_250_HZ = 0b1000 # 250 Hz - RATE_500_HZ = 0b1001 # 500 Hz + RATE_125_HZ = 0b0111 # 125 Hz + RATE_250_HZ = 0b1000 # 250 Hz + RATE_500_HZ = 0b1001 # 500 Hz RATE_1000_HZ = 0b1010 # 1000 Hz -class BandWidth: # pylint: disable=too-few-public-methods + +class BandWidth: # pylint: disable=too-few-public-methods """An enum-like class representing the different bandwidths that the MSA301 can use. The values can be referenced like ``BandWidth.WIDTH_1_HZ`` or ``BandWidth.RATE_500_HZ`` Possible values are @@ -138,17 +144,19 @@ class BandWidth: # pylint: disable=too-few-public-methods - ``BandWidth.RATE_500_HZ`` - ``BandWidth.RATE_1000_HZ`` """ + WIDTH_1_95_HZ = 0b0000 # 1.95 Hz - WIDTH_3_9_HZ = 0b0011 # 3.9 Hz + WIDTH_3_9_HZ = 0b0011 # 3.9 Hz WIDTH_7_81_HZ = 0b0100 # 7.81 Hz - WIDTH_15_63_HZ = 0b0101 # 15.63 Hz - WIDTH_31_25_HZ = 0b0110 # 31.25 Hz + WIDTH_15_63_HZ = 0b0101 # 15.63 Hz + WIDTH_31_25_HZ = 0b0110 # 31.25 Hz WIDTH_62_5_HZ = 0b0111 # 62.5 Hz - WIDTH_125_HZ = 0b1000 # 125 Hz - WIDTH_250_HZ = 0b1001 # 250 Hz - WIDTH_500_HZ = 0b1010 # 500 Hz + WIDTH_125_HZ = 0b1000 # 125 Hz + WIDTH_250_HZ = 0b1001 # 250 Hz + WIDTH_500_HZ = 0b1010 # 500 Hz + -class Range: # pylint: disable=too-few-public-methods +class Range: # pylint: disable=too-few-public-methods """An enum-like class representing the different acceleration measurement ranges that the MSA301 can use. The values can be referenced like ``Range.RANGE_2_G`` or ``Range.RANGE_16_G`` Possible values are @@ -158,12 +166,14 @@ class Range: # pylint: disable=too-few-public-methods - ``Range.RANGE_8_G`` - ``Range.RANGE_16_G`` """ + RANGE_2_G = 0b00 # +/- 2g (default value) RANGE_4_G = 0b01 # +/- 4g RANGE_8_G = 0b10 # +/- 8g - RANGE_16_G = 0b11 # +/- 16g + RANGE_16_G = 0b11 # +/- 16g + -class Resolution: # pylint: disable=too-few-public-methods +class Resolution: # pylint: disable=too-few-public-methods """An enum-like class representing the different measurement ranges that the MSA301 can use. The values can be referenced like ``Range.RANGE_2_G`` or ``Range.RANGE_16_G`` Possible values are @@ -173,29 +183,33 @@ class Resolution: # pylint: disable=too-few-public-methods - ``Resolution.RESOLUTION_10_BIT`` - ``Resolution.RESOLUTION_8_BIT`` """ + RESOLUTION_14_BIT = 0b00 RESOLUTION_12_BIT = 0b01 RESOLUTION_10_BIT = 0b10 RESOLUTION_8_BIT = 0b11 -class TapDuration: #pylint: disable=too-few-public-methods,too-many-instance-attributes + +class TapDuration: # pylint: disable=too-few-public-methods,too-many-instance-attributes """An enum-like class representing the options for the "double_tap_window" parameter of `enable_tap_detection`""" - DURATION_50_MS = 0b000 #< 50 millis - DURATION_100_MS = 0b001 #< 100 millis - DURATION_150_MS = 0b010 #< 150 millis - DURATION_200_MS = 0b011 #< 200 millis - DURATION_250_MS = 0b100 #< 250 millis - DURATION_375_MS = 0b101 #< 375 millis - DURATION_500_MS = 0b110 #< 500 millis - DURATION_700_MS = 0b111 #< 50 millis700 millis + DURATION_50_MS = 0b000 # < 50 millis + DURATION_100_MS = 0b001 # < 100 millis + DURATION_150_MS = 0b010 # < 150 millis + DURATION_200_MS = 0b011 # < 200 millis + DURATION_250_MS = 0b100 # < 250 millis + DURATION_375_MS = 0b101 # < 375 millis + DURATION_500_MS = 0b110 # < 500 millis + DURATION_700_MS = 0b111 # < 50 millis700 millis -class MSA301:#pylint: disable=too-many-instance-attributes + +class MSA301: # pylint: disable=too-many-instance-attributes """Driver for the MSA301 Accelerometer. :param ~busio.I2C i2c_bus: The I2C bus the MSA is connected to. """ + _part_id = ROUnaryStruct(_MSA301_REG_PARTID, ">(8*shift) & 0xFF) + bottom_byte = raw_data >> (8 * shift) & 0xFF acc_bytes.append(bottom_byte) # unpack three LE, signed shorts @@ -265,18 +278,21 @@ def acceleration(self): scale = 4096.0 # shift down to the actual 14 bits and scale based on the range - x_acc = ((x>>2) / scale) * _STANDARD_GRAVITY - y_acc = ((y>>2) / scale) * _STANDARD_GRAVITY - z_acc = ((z>>2) / scale) * _STANDARD_GRAVITY + x_acc = ((x >> 2) / scale) * _STANDARD_GRAVITY + y_acc = ((y >> 2) / scale) * _STANDARD_GRAVITY + z_acc = ((z >> 2) / scale) * _STANDARD_GRAVITY return (x_acc, y_acc, z_acc) - def enable_tap_detection(self, *, - tap_count=1, - threshold=25, - long_initial_window=True, - long_quiet_window=True, - double_tap_window=TapDuration.DURATION_250_MS): + def enable_tap_detection( # pylint: disable=bad-continuation + self, + *, + tap_count=1, + threshold=25, + long_initial_window=True, + long_quiet_window=True, + double_tap_window=TapDuration.DURATION_250_MS + ): """ Enables tap detection with configurable parameters. @@ -332,12 +348,12 @@ def tapped(self): motion_int_status = self._motion_int_status - if motion_int_status == 0: # no interrupts triggered + if motion_int_status == 0: # no interrupts triggered return False - if self._tap_count == 1 and motion_int_status & 1<<5: + if self._tap_count == 1 and motion_int_status & 1 << 5: return True - if self._tap_count == 2 and motion_int_status & 1<<4: + if self._tap_count == 2 and motion_int_status & 1 << 4: return True return False diff --git a/docs/conf.py b/docs/conf.py index 6b6c4a3..547092d 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,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # Uncomment the below if you use native CircuitPython modules such as @@ -22,29 +23,40 @@ autodoc_mock_imports = ["micropython", "adafruit_register", "adafruit_bus_device"] -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)} +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), +} # 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 MSA301 Library' -copyright = u'2019 Bryan Siepert' -author = u'Bryan Siepert' +project = "Adafruit MSA301 Library" +copyright = "2019 Bryan Siepert" +author = "Bryan Siepert" # 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 = "1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -56,7 +68,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. @@ -68,7 +80,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 @@ -83,59 +95,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 = 'AdafruitMsa301Librarydoc' +htmlhelp_basename = "AdafruitMsa301Librarydoc" # -- 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, 'AdafruitMSA301Library.tex', u'AdafruitMSA301 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitMSA301Library.tex", + "AdafruitMSA301 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -143,8 +158,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitMSA301library', u'Adafruit MSA301 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitMSA301library", + "Adafruit MSA301 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -153,7 +173,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitMSA301Library', u'Adafruit MSA301 Library Documentation', - author, 'AdafruitMSA301Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitMSA301Library", + "Adafruit MSA301 Library Documentation", + author, + "AdafruitMSA301Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/msa301_simpletest.py b/examples/msa301_simpletest.py index 8d78739..20723b7 100755 --- a/examples/msa301_simpletest.py +++ b/examples/msa301_simpletest.py @@ -7,5 +7,5 @@ msa = adafruit_msa301.MSA301(i2c) while True: - print("%f %f %f"%msa.acceleration) + print("%f %f %f" % msa.acceleration) time.sleep(0.5) diff --git a/setup.py b/setup.py index 7d288d9..7a9b550 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,52 +14,42 @@ 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-msa301', - + name="adafruit-circuitpython-msa301", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for the MSA301 Accelerometer', + setup_requires=["setuptools_scm"], + description="CircuitPython library for the MSA301 Accelerometer", 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_MSA301', - + url="https://github.com/adafruit/Adafruit_CircuitPython_MSA301", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[ - 'Adafruit-Blinka', - 'adafruit-circuitpython-busdevice', - 'adafruit-circuitpython-register' + "Adafruit-Blinka", + "adafruit-circuitpython-busdevice", + "adafruit-circuitpython-register", ], - # 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 blinka circuitpython micropython msa301 accelerometer msa', - + keywords="adafruit blinka circuitpython micropython msa301 accelerometer msa", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - - py_modules=['adafruit_msa301'], + py_modules=["adafruit_msa301"], )