From d2be53ea7c18d08525f4a467bd694907307eedef Mon Sep 17 00:00:00 2001 From: dherrada Date: Sun, 15 Mar 2020 17:14:57 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_lis3mdl.py | 121 +++++++++++++++++------------ docs/conf.py | 120 +++++++++++++++++----------- examples/lis3mdl_data_rate_test.py | 8 +- examples/lis3mdl_range_test.py | 16 ++-- examples/lis3mdl_simpletest.py | 4 +- setup.py | 54 ++++++------- 7 files changed, 185 insertions(+), 140 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_lis3mdl.py b/adafruit_lis3mdl.py index fa065b3..0c1775f 100644 --- a/adafruit_lis3mdl.py +++ b/adafruit_lis3mdl.py @@ -49,6 +49,7 @@ from adafruit_register.i2c_struct import ROUnaryStruct, Struct from adafruit_register.i2c_bits import RWBits from adafruit_register.i2c_bit import RWBit + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git" @@ -64,16 +65,17 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS3MDL.git" _LIS3MDL_WHO_AM_I = const(0x0F) # Register that contains the part ID -_LIS3MDL_CTRL_REG1 = const(0x20) # Register address for control 1 -_LIS3MDL_CTRL_REG2 = const(0x21) # Register address for control 2 -_LIS3MDL_CTRL_REG3 = const(0x22) # Register address for control 3 -_LIS3MDL_CTRL_REG4 = const(0x23) # Register address for control 3 -_LIS3MDL_OUT_X_L = const(0x28) # Register address for X axis lower byte -_LIS3MDL_INT_CFG = const(0x30) # Interrupt configuration register -_LIS3MDL_INT_THS_L = const(0x32) # Low byte of the irq threshold +_LIS3MDL_CTRL_REG1 = const(0x20) # Register address for control 1 +_LIS3MDL_CTRL_REG2 = const(0x21) # Register address for control 2 +_LIS3MDL_CTRL_REG3 = const(0x22) # Register address for control 3 +_LIS3MDL_CTRL_REG4 = const(0x23) # Register address for control 3 +_LIS3MDL_OUT_X_L = const(0x28) # Register address for X axis lower byte +_LIS3MDL_INT_CFG = const(0x30) # Interrupt configuration register +_LIS3MDL_INT_THS_L = const(0x32) # Low byte of the irq threshold _GAUSS_TO_UT = 100 + class CV: """struct helper""" @@ -94,27 +96,39 @@ def is_valid(cls, value): "Returns true if the given value is a member of the CV" return value in cls.string + class Range(CV): """Options for ``accelerometer_range``""" - pass #pylint: disable=unnecessary-pass -Range.add_values(( - ('RANGE_4_GAUSS', 0, 4, 6842), - ('RANGE_8_GAUSS', 1, 8, 3421), - ('RANGE_12_GAUSS', 2, 12, 2281), - ('RANGE_16_GAUSS', 3, 16, 1711) -)) + pass # pylint: disable=unnecessary-pass + + +Range.add_values( + ( + ("RANGE_4_GAUSS", 0, 4, 6842), + ("RANGE_8_GAUSS", 1, 8, 3421), + ("RANGE_12_GAUSS", 2, 12, 2281), + ("RANGE_16_GAUSS", 3, 16, 1711), + ) +) + class PerformanceMode(CV): """Options for `performance_mode` """ - pass #pylint: disable=unnecessary-pass - -PerformanceMode.add_values(( - ('MODE_LOW_POWER', 0, 'Low Power', None), - ('MODE_MEDIUM', 1, 'Medium Performance', None), - ('MODE_HIGH', 2, 'High Performance', None), - ('MODE_ULTRA', 3, 'Ultra-high Performance', None) -)) + + pass # pylint: disable=unnecessary-pass + + +PerformanceMode.add_values( + ( + ("MODE_LOW_POWER", 0, "Low Power", None), + ("MODE_MEDIUM", 1, "Medium Performance", None), + ("MODE_HIGH", 2, "High Performance", None), + ("MODE_ULTRA", 3, "Ultra-high Performance", None), + ) +) + + class Rate(CV): """Options for `data_rate` @@ -136,23 +150,28 @@ class Rate(CV): ============================= ============================================ """ - pass #pylint: disable=unnecessary-pass + + pass # pylint: disable=unnecessary-pass + # The magnetometer data rate, includes FAST_ODR bit -Rate.add_values(( - ('RATE_0_625_HZ', 0b0000, 0.625, None), - ('RATE_1_25_HZ', 0b0010, 1.25, None), - ('RATE_2_5_HZ', 0b0100, 2.5, None), - ('RATE_5_HZ', 0b0110, 5.0, None), - ('RATE_10_HZ', 0b1000, 10.0, None), - ('RATE_20_HZ', 0b1010, 20.0, None), - ('RATE_40_HZ', 0b1100, 40.0, None), - ('RATE_80_HZ', 0b1110, 80.0, None), - ('RATE_155_HZ', 0b0001, 155.0, None), - ('RATE_300_HZ', 0b0011, 300.0, None), - ('RATE_560_HZ', 0b0101, 560.0, None), - ('RATE_1000_HZ', 0b0111, 1000.0, None), -)) +Rate.add_values( + ( + ("RATE_0_625_HZ", 0b0000, 0.625, None), + ("RATE_1_25_HZ", 0b0010, 1.25, None), + ("RATE_2_5_HZ", 0b0100, 2.5, None), + ("RATE_5_HZ", 0b0110, 5.0, None), + ("RATE_10_HZ", 0b1000, 10.0, None), + ("RATE_20_HZ", 0b1010, 20.0, None), + ("RATE_40_HZ", 0b1100, 40.0, None), + ("RATE_80_HZ", 0b1110, 80.0, None), + ("RATE_155_HZ", 0b0001, 155.0, None), + ("RATE_300_HZ", 0b0011, 300.0, None), + ("RATE_560_HZ", 0b0101, 560.0, None), + ("RATE_1000_HZ", 0b0111, 1000.0, None), + ) +) + class OperationMode(CV): """Options for `operation_mode` @@ -166,13 +185,17 @@ class OperationMode(CV): ============================= ============================================ """ - pass #pylint: disable=unnecessary-pass -OperationMode.add_values(( - ('CONTINUOUS', 0b00, 'Continuous', None), - ('SINGLE', 0b01, 'Single', None), - ('POWER_DOWN', 0b11, 'Power Down', None) -)) + pass # pylint: disable=unnecessary-pass + + +OperationMode.add_values( + ( + ("CONTINUOUS", 0b00, "Continuous", None), + ("SINGLE", 0b01, "Single", None), + ("POWER_DOWN", 0b11, "Power Down", None), + ) +) # /** The magnetometer operation mode */ # typedef enum { # LIS3MDL_CONTINUOUSMODE = , ///< Continuous conversion @@ -180,11 +203,13 @@ class OperationMode(CV): # LIS3MDL_POWERDOWNMODE = , ///< Powered-down mode # } lis3mdl_operationmode_t; + class LIS3MDL: """Driver for the LIS3MDL 3-axis magnetometer. :param ~busio.I2C i2c_bus: The I2C bus the LIS3MDL is connected to. :param address: The I2C slave address of the sensor """ + _chip_id = ROUnaryStruct(_LIS3MDL_WHOAMI, "1: + if (time.monotonic() - start_time) > 1: break diff --git a/examples/lis3mdl_range_test.py b/examples/lis3mdl_range_test.py index c19e933..a550b87 100644 --- a/examples/lis3mdl_range_test.py +++ b/examples/lis3mdl_range_test.py @@ -1,5 +1,5 @@ """ Test Each range """ -#pylint: disable=no-member +# pylint: disable=no-member import time import board import busio @@ -10,14 +10,16 @@ while True: - for mag_range in [Range.RANGE_4_GAUSS, - Range.RANGE_8_GAUSS, - Range.RANGE_12_GAUSS, - Range.RANGE_16_GAUSS]: + for mag_range in [ + Range.RANGE_4_GAUSS, + Range.RANGE_8_GAUSS, + Range.RANGE_12_GAUSS, + Range.RANGE_16_GAUSS, + ]: sensor.range = mag_range print("Range: %d Gauss" % Range.string[sensor.range]) mag_x, mag_y, mag_z = sensor.magnetic - print('X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT'.format(mag_x, mag_y, mag_z)) - print('') + print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z)) + print("") time.sleep(0.3) diff --git a/examples/lis3mdl_simpletest.py b/examples/lis3mdl_simpletest.py index 9be8eff..ef91880 100644 --- a/examples/lis3mdl_simpletest.py +++ b/examples/lis3mdl_simpletest.py @@ -11,6 +11,6 @@ while True: mag_x, mag_y, mag_z = sensor.magnetic - print('X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT'.format(mag_x, mag_y, mag_z)) - print('') + print("X:{0:10.2f}, Y:{1:10.2f}, Z:{2:10.2f} uT".format(mag_x, mag_y, mag_z)) + print("") time.sleep(1.0) diff --git a/setup.py b/setup.py index d7fd53a..a5f110d 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,53 +14,44 @@ 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-lis3mdl', - + name="adafruit-circuitpython-lis3mdl", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython helper library for the LIS3MDL 3-axis magnetometer', + setup_requires=["setuptools_scm"], + description="CircuitPython helper library for the LIS3MDL 3-axis magnetometer", 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_LIS3MDL', - + url="https://github.com/adafruit/Adafruit_CircuitPython_LIS3MDL", # 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 lis3mdl magnetometer LSM6DS33 IMU', - + keywords="adafruit blinka circuitpython micropython lis3mdl magnetometer LSM6DS33 IMU", # 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_lis3mdl'], + py_modules=["adafruit_lis3mdl"], )