From ad795f6de8dfc669abbc2095d485dfa9b60149a1 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 12 Mar 2020 19:38:31 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_dps310.py | 138 ++++++++++++++++++++-------------- docs/conf.py | 121 +++++++++++++++++------------ examples/dps310_simpletest.py | 4 +- setup.py | 56 ++++++-------- 5 files changed, 182 insertions(+), 139 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_dps310.py b/adafruit_dps310.py index 4e74363..6dd6a19 100644 --- a/adafruit_dps310.py +++ b/adafruit_dps310.py @@ -51,21 +51,22 @@ from adafruit_register.i2c_bit import RWBit, ROBit from adafruit_register.i2c_bits import RWBits, ROBits -_DPS310_DEFAULT_ADDRESS = 0x77 # DPS310 default i2c address -_DPS310_DEVICE_ID = 0x10 # DPS310 device identifier - -_DPS310_PRSB2 = 0x00 # Highest byte of pressure data -_DPS310_TMPB2 = 0x03 # Highest byte of temperature data -_DPS310_PRSCFG = 0x06 # Pressure configuration -_DPS310_TMPCFG = 0x07 # Temperature configuration -_DPS310_MEASCFG = 0x08 # Sensor configuration -_DPS310_CFGREG = 0x09 # Interrupt/FIFO configuration -_DPS310_RESET = 0x0C # Soft reset -_DPS310_PRODREVID = 0x0D # Register that contains the part ID -_DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src - -#pylint: enable=bad-whitespace -#pylint: disable=no-member,unnecessary-pass +_DPS310_DEFAULT_ADDRESS = 0x77 # DPS310 default i2c address +_DPS310_DEVICE_ID = 0x10 # DPS310 device identifier + +_DPS310_PRSB2 = 0x00 # Highest byte of pressure data +_DPS310_TMPB2 = 0x03 # Highest byte of temperature data +_DPS310_PRSCFG = 0x06 # Pressure configuration +_DPS310_TMPCFG = 0x07 # Temperature configuration +_DPS310_MEASCFG = 0x08 # Sensor configuration +_DPS310_CFGREG = 0x09 # Interrupt/FIFO configuration +_DPS310_RESET = 0x0C # Soft reset +_DPS310_PRODREVID = 0x0D # Register that contains the part ID +_DPS310_TMPCOEFSRCE = 0x28 # Temperature calibration src + +# pylint: enable=bad-whitespace +# pylint: disable=no-member,unnecessary-pass + class CV: """struct helper""" @@ -87,6 +88,7 @@ def is_valid(cls, value): """Validate that a given value is a member""" return value in cls.string + class Mode(CV): """Options for ``mode`` @@ -112,49 +114,63 @@ class Mode(CV): +--------------------------+------------------------------------------------------------------+ """ - pass #pylint: disable=unnecessary-pass -Mode.add_values(( - ('IDLE', 0, "Idle", None), - ('ONE_PRESSURE', 1, "One-Shot Pressure", None), - ('ONE_TEMPERATURE', 2, "One-Shot Temperature", None), - ('CONT_PRESSURE', 5, "Continuous Pressure", None), - ('CONT_TEMP', 6, "Continuous Temperature", None), - ('CONT_PRESTEMP', 7, "Continuous Pressure & Temperature", None), -)) + pass # pylint: disable=unnecessary-pass + + +Mode.add_values( + ( + ("IDLE", 0, "Idle", None), + ("ONE_PRESSURE", 1, "One-Shot Pressure", None), + ("ONE_TEMPERATURE", 2, "One-Shot Temperature", None), + ("CONT_PRESSURE", 5, "Continuous Pressure", None), + ("CONT_TEMP", 6, "Continuous Temperature", None), + ("CONT_PRESTEMP", 7, "Continuous Pressure & Temperature", None), + ) +) + class Rate(CV): """Options for `pressure_rate` and `temperature_rate`""" + pass -Rate.add_values(( - ('RATE_1_HZ', 0, 1, None), - ('RATE_2_HZ', 1, 2, None), - ('RATE_4_HZ', 2, 4, None), - ('RATE_8_HZ', 3, 8, None), - ('RATE_16_HZ', 4, 16, None), - ('RATE_32_HZ', 5, 32, None), - ('RATE_64_HZ', 6, 64, None), - ('RATE_128_HZ', 7, 128, None) -)) + +Rate.add_values( + ( + ("RATE_1_HZ", 0, 1, None), + ("RATE_2_HZ", 1, 2, None), + ("RATE_4_HZ", 2, 4, None), + ("RATE_8_HZ", 3, 8, None), + ("RATE_16_HZ", 4, 16, None), + ("RATE_32_HZ", 5, 32, None), + ("RATE_64_HZ", 6, 64, None), + ("RATE_128_HZ", 7, 128, None), + ) +) + class SampleCount(CV): """Options for `temperature_oversample_count` and `pressure_oversample_count`""" + pass -SampleCount.add_values(( - ('COUNT_1', 0, 1, None), - ('COUNT_2', 1, 2, None), - ('COUNT_4', 2, 4, None), - ('COUNT_8', 3, 8, None), - ('COUNT_16', 4, 16, None), - ('COUNT_32', 5, 32, None), - ('COUNT_64', 6, 64, None), - ('COUNT_128', 7, 128, None), -)) -#pylint: enable=unnecessary-pass + +SampleCount.add_values( + ( + ("COUNT_1", 0, 1, None), + ("COUNT_2", 1, 2, None), + ("COUNT_4", 2, 4, None), + ("COUNT_8", 3, 8, None), + ("COUNT_16", 4, 16, None), + ("COUNT_32", 5, 32, None), + ("COUNT_64", 6, 64, None), + ("COUNT_128", 7, 128, None), + ) +) +# pylint: enable=unnecessary-pass class DPS310: - #pylint: disable=too-many-instance-attributes + # pylint: disable=too-many-instance-attributes """Library for the DPS310 Precision Barometric Pressure Sensor. :param ~busio.I2C i2c_bus: The I2C bus the DPS310 is connected to. @@ -205,8 +221,16 @@ def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS): self._c20 = None self._c21 = None self._c30 = None - self._oversample_scalefactor = (524288, 1572864, 3670016, 7864320, 253952, - 516096, 1040384, 2088960) + self._oversample_scalefactor = ( + 524288, + 1572864, + 3670016, + 7864320, + 253952, + 516096, + 1040384, + 2088960, + ) self.initialize() def initialize(self): @@ -251,9 +275,11 @@ def pressure(self): p_red = raw_pressure / self._pressure_scale - - pres_calc = (self._c00 + p_red * (self._c10 + p_red * (self._c20 + p_red * self._c30)) + - _scaled_rawtemp * (self._c01 + p_red * (self._c11 + p_red * self._c21))) + pres_calc = ( + self._c00 + + p_red * (self._c10 + p_red * (self._c20 + p_red * self._c30)) + + _scaled_rawtemp * (self._c01 + p_red * (self._c11 + p_red * self._c21)) + ) final_pressure = pres_calc / 100 return final_pressure @@ -309,7 +335,7 @@ def pressure_oversample_count(self, value): raise AttributeError("pressure_oversample_count must be a SampleCount") self._pressure_osbits = value - self._pressure_shiftbit = (value > SampleCount.COUNT_8) + self._pressure_shiftbit = value > SampleCount.COUNT_8 self._pressure_scale = self._oversample_scalefactor[value] @property @@ -335,12 +361,12 @@ def temperature_oversample_count(self, value): self._temp_osbits = value self._temp_scale = self._oversample_scalefactor[value] - self._temp_shiftbit = (value > SampleCount.COUNT_8) + self._temp_shiftbit = value > SampleCount.COUNT_8 @staticmethod def _twos_complement(val, bits): if val & (1 << (bits - 1)): - val -= (1 << bits) + val -= 1 << bits return val @@ -350,7 +376,7 @@ def _read_calibration(self): sleep(0.001) buffer = bytearray(19) - coeffs = [None]*18 + coeffs = [None] * 18 for offset in range(18): buffer = bytearray(2) buffer[0] = 0x10 + offset @@ -369,7 +395,7 @@ def _read_calibration(self): self._c00 = (coeffs[3] << 12) | (coeffs[4] << 4) | ((coeffs[5] >> 4) & 0x0F) self._c00 = self._twos_complement(self._c00, 20) - self._c10 = ((coeffs[5] & 0x0F) << 16) | (coeffs[6] << 8) |coeffs[7] + self._c10 = ((coeffs[5] & 0x0F) << 16) | (coeffs[6] << 8) | coeffs[7] self._c10 = self._twos_complement(self._c10, 20) self._c01 = self._twos_complement((coeffs[8] << 8) | coeffs[9], 16) diff --git a/docs/conf.py b/docs/conf.py index 14a2a9c..23e06de 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", ] # TODO: Please Read! @@ -23,30 +24,40 @@ autodoc_mock_imports = ["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 DPS310 Library' -copyright = u'2020 Bryan Siepert' -author = u'Bryan Siepert' +project = u"Adafruit DPS310 Library" +copyright = u"2020 Bryan Siepert" +author = u"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 = 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. @@ -58,7 +69,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. @@ -70,7 +81,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 @@ -85,59 +96,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 = 'AdafruitDps310Librarydoc' +htmlhelp_basename = "AdafruitDps310Librarydoc" # -- 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, 'AdafruitDPS310Library.tex', u'AdafruitDPS310 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitDPS310Library.tex", + u"AdafruitDPS310 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -145,8 +159,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitDPS310library', u'Adafruit DPS310 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitDPS310library", + u"Adafruit DPS310 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -155,7 +174,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitDPS310Library', u'Adafruit DPS310 Library Documentation', - author, 'AdafruitDPS310Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitDPS310Library", + u"Adafruit DPS310 Library Documentation", + author, + "AdafruitDPS310Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/dps310_simpletest.py b/examples/dps310_simpletest.py index 1ad6a8a..31e33d9 100644 --- a/examples/dps310_simpletest.py +++ b/examples/dps310_simpletest.py @@ -8,7 +8,7 @@ dps310 = adafruit_dps310.DPS310(i2c) while True: - print("Temperature = %.2f *C"%dps310.temperature) - print("Pressure = %.2f hPa"%dps310.pressure) + print("Temperature = %.2f *C" % dps310.temperature) + print("Pressure = %.2f hPa" % dps310.pressure) print("") time.sleep(1.0) diff --git a/setup.py b/setup.py index f6477de..07aeb5e 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,54 +14,45 @@ 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-dps310', - + name="adafruit-circuitpython-dps310", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Library for the DPS310 Precision Barometric Pressure Sensor', + setup_requires=["setuptools_scm"], + description="Library for the DPS310 Precision Barometric Pressure Sensor", 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_DPS310', - + url="https://github.com/adafruit/Adafruit_CircuitPython_DPS310", # 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 dps310 pressure sensor barometric ' - 'altimeter altitude', - + keywords="adafruit blinka circuitpython micropython dps310 pressure sensor barometric " + "altimeter altitude", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_dps310'], + py_modules=["adafruit_dps310"], )