diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 22.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 624eaa9..bc66e1d 100644 --- a/README.rst +++ b/README.rst @@ -14,9 +14,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing/actions/ :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff This library provides FeatherWing specific classes for those that require a significant amount of initialization. diff --git a/adafruit_featherwing/alphanum_featherwing.py b/adafruit_featherwing/alphanum_featherwing.py index e3427b0..0f0610f 100755 --- a/adafruit_featherwing/alphanum_featherwing.py +++ b/adafruit_featherwing/alphanum_featherwing.py @@ -16,10 +16,12 @@ import board from adafruit_ht16k33 import segments + from adafruit_featherwing.led_segments import Segments try: from typing import Optional + from busio import I2C except ImportError: pass diff --git a/adafruit_featherwing/dotstar_featherwing.py b/adafruit_featherwing/dotstar_featherwing.py index 1cf78d4..df53a86 100755 --- a/adafruit_featherwing/dotstar_featherwing.py +++ b/adafruit_featherwing/dotstar_featherwing.py @@ -14,12 +14,14 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import board import adafruit_dotstar as dotstar +import board + from adafruit_featherwing.pixelmatrix import PixelMatrix try: - import typing # pylint: disable=unused-import + import typing + from microcontroller import Pin except ImportError: pass @@ -31,9 +33,7 @@ class DotStarFeatherWing(PixelMatrix): The feather uses pins D13 and D11""" - def __init__( - self, clock: Pin = board.D13, data: Pin = board.D11, brightness: float = 0.2 - ): + def __init__(self, clock: Pin = board.D13, data: Pin = board.D11, brightness: float = 0.2): """ :param pin clock: The clock pin for the featherwing :param pin data: The data pin for the featherwing diff --git a/adafruit_featherwing/gps_featherwing.py b/adafruit_featherwing/gps_featherwing.py index 377d2ee..077ce00 100644 --- a/adafruit_featherwing/gps_featherwing.py +++ b/adafruit_featherwing/gps_featherwing.py @@ -14,9 +14,9 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" +import adafruit_gps import board import busio -import adafruit_gps try: from typing import Optional @@ -46,10 +46,8 @@ def __init__(self, update_period: int = 1000, baudrate: int = 9600): self._uart = busio.UART(board.TX, board.RX, baudrate=baudrate, timeout=timeout) self._gps = adafruit_gps.GPS(self._uart, debug=False) # Turn on the basic GGA and RMC info - self._gps.send_command( - bytes("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "utf-8") - ) - self._gps.send_command(bytes("PMTK220,{}".format(update_period), "utf-8")) + self._gps.send_command(bytes("PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", "utf-8")) + self._gps.send_command(bytes(f"PMTK220,{update_period}", "utf-8")) def update(self) -> bool: """ diff --git a/adafruit_featherwing/ina219_featherwing.py b/adafruit_featherwing/ina219_featherwing.py index 3aaae93..dfcc610 100644 --- a/adafruit_featherwing/ina219_featherwing.py +++ b/adafruit_featherwing/ina219_featherwing.py @@ -17,11 +17,12 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import board import adafruit_ina219 +import board try: from typing import Optional + from busio import I2C except ImportError: pass diff --git a/adafruit_featherwing/joy_featherwing.py b/adafruit_featherwing/joy_featherwing.py index c93a4d4..2a7079f 100644 --- a/adafruit_featherwing/joy_featherwing.py +++ b/adafruit_featherwing/joy_featherwing.py @@ -14,12 +14,13 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" +import adafruit_seesaw.seesaw import board from micropython import const -import adafruit_seesaw.seesaw try: from typing import Optional, Tuple + from busio import I2C except ImportError: pass diff --git a/adafruit_featherwing/keyboard_featherwing.py b/adafruit_featherwing/keyboard_featherwing.py index f441ab0..ba184c5 100644 --- a/adafruit_featherwing/keyboard_featherwing.py +++ b/adafruit_featherwing/keyboard_featherwing.py @@ -19,19 +19,17 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import board import adafruit_ili9341 -from bbq10keyboard import BBQ10Keyboard +import board import neopixel +from bbq10keyboard import BBQ10Keyboard - -# pylint: disable-msg=too-few-public-methods -# pylint: disable-msg=too-many-arguments from adafruit_featherwing.tft_featherwing import TFTFeatherWing try: from typing import Optional - from busio import SPI, I2C + + from busio import I2C, SPI from microcontroller import Pin except ImportError: pass @@ -59,9 +57,7 @@ def __init__( if neopixel_pin is None: neopixel_pin = board.D11 - self.display = adafruit_ili9341.ILI9341( - self._display_bus, width=320, height=240 - ) + self.display = adafruit_ili9341.ILI9341(self._display_bus, width=320, height=240) self.neopixel = neopixel.NeoPixel(neopixel_pin, 1) """Status NeoPixel.""" self.keyboard = BBQ10Keyboard(i2c) diff --git a/adafruit_featherwing/led_segments.py b/adafruit_featherwing/led_segments.py index f5cae99..2da48e5 100755 --- a/adafruit_featherwing/led_segments.py +++ b/adafruit_featherwing/led_segments.py @@ -14,8 +14,6 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -# pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation - try: from typing import Union except ImportError: diff --git a/adafruit_featherwing/matrix_featherwing.py b/adafruit_featherwing/matrix_featherwing.py index c6a7bee..40d6b09 100755 --- a/adafruit_featherwing/matrix_featherwing.py +++ b/adafruit_featherwing/matrix_featherwing.py @@ -22,6 +22,7 @@ try: from typing import Optional, Tuple, Union + from busio import I2C except ImportError: pass @@ -34,7 +35,6 @@ class MatrixFeatherWing(AutoWriteable): Automatically uses the feather's I2C bus.""" def __init__(self, address: int = 0x70, i2c: Optional[I2C] = None): - if i2c is None: i2c = board.I2C() self._matrix = matrix.Matrix16x8(i2c, address) diff --git a/adafruit_featherwing/minitft_featherwing.py b/adafruit_featherwing/minitft_featherwing.py index 91afeda..0165a8d 100755 --- a/adafruit_featherwing/minitft_featherwing.py +++ b/adafruit_featherwing/minitft_featherwing.py @@ -16,15 +16,17 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" from collections import namedtuple + import board -from micropython import const -from adafruit_seesaw.seesaw import Seesaw -from adafruit_seesaw.pwmout import PWMOut import displayio +from adafruit_seesaw.pwmout import PWMOut +from adafruit_seesaw.seesaw import Seesaw from adafruit_st7735r import ST7735R +from micropython import const try: from typing import Optional + from busio import I2C, SPI from microcontroller import Pin except ImportError: @@ -57,7 +59,7 @@ class MiniTFTFeatherWing: | (1 << BUTTON_A) | (1 << BUTTON_B) ) - # pylint: disable-msg=too-many-arguments + def __init__( self, address: int = 0x5E, @@ -86,8 +88,6 @@ def __init__( display_bus, width=160, height=80, colstart=24, rotation=270, bgr=True ) - # pylint: enable-msg=too-many-arguments - @property def backlight(self): """ diff --git a/adafruit_featherwing/neopixel_featherwing.py b/adafruit_featherwing/neopixel_featherwing.py index 0fd992c..7987622 100755 --- a/adafruit_featherwing/neopixel_featherwing.py +++ b/adafruit_featherwing/neopixel_featherwing.py @@ -16,10 +16,12 @@ import board import neopixel + from adafruit_featherwing.pixelmatrix import PixelMatrix try: - import typing # pylint: disable=unused-import + import typing + from microcontroller import Pin except ImportError: pass diff --git a/adafruit_featherwing/pixelmatrix.py b/adafruit_featherwing/pixelmatrix.py index 550bc67..5e43db3 100755 --- a/adafruit_featherwing/pixelmatrix.py +++ b/adafruit_featherwing/pixelmatrix.py @@ -15,12 +15,10 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -# pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation - from adafruit_featherwing.auto_writeable import AutoWriteable try: - from typing import Union, Tuple, List, Sequence + from typing import List, Sequence, Tuple, Union IndexUnion = Union[Tuple[int, int], slice, int] RGBSequence = Union[List[int], Tuple[int, int, int]] @@ -71,16 +69,16 @@ def _get_index(self, indices: IndexUnion) -> Union[int, slice]: """ if isinstance(indices, int): if not 0 <= indices < self.rows * self.columns: - raise ValueError("The index of {} is out of range".format(indices)) + raise ValueError(f"The index of {indices} is out of range") return indices if isinstance(indices, slice): return indices if len(indices) == 2: x, y = indices if not 0 <= x < self.columns: - raise ValueError("The X value of {} is out of range".format(x)) + raise ValueError(f"The X value of {x} is out of range") if not 0 <= y < self.rows: - raise ValueError("The Y value of {} is out of range".format(y)) + raise ValueError(f"The Y value of {y} is out of range") return y * self.columns + x raise ValueError("Index must be 1 or 2 number") @@ -117,9 +115,7 @@ def shift_right(self, rotate: bool = False): for y in range(0, self.rows): last_pixel = self._matrix[(y + 1) * self.columns - 1] if rotate else 0 for x in range(self.columns - 1, 0, -1): - self._matrix[y * self.columns + x] = self._matrix[ - y * self.columns + x - 1 - ] + self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x - 1] self._matrix[y * self.columns] = last_pixel self._update() @@ -132,9 +128,7 @@ def shift_left(self, rotate: bool = False): for y in range(0, self.rows): last_pixel = self._matrix[y * self.columns] if rotate else 0 for x in range(0, self.columns - 1): - self._matrix[y * self.columns + x] = self._matrix[ - y * self.columns + x + 1 - ] + self._matrix[y * self.columns + x] = self._matrix[y * self.columns + x + 1] self._matrix[(y + 1) * self.columns - 1] = last_pixel self._update() @@ -145,13 +139,9 @@ def shift_up(self, rotate: bool = False): :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False) """ for x in range(0, self.columns): - last_pixel = ( - self._matrix[(self.rows - 1) * self.columns + x] if rotate else 0 - ) + last_pixel = self._matrix[(self.rows - 1) * self.columns + x] if rotate else 0 for y in range(self.rows - 1, 0, -1): - self._matrix[y * self.columns + x] = self._matrix[ - (y - 1) * self.columns + x - ] + self._matrix[y * self.columns + x] = self._matrix[(y - 1) * self.columns + x] self._matrix[x] = last_pixel self._update() @@ -164,9 +154,7 @@ def shift_down(self, rotate: bool = False): for x in range(0, self.columns): last_pixel = self._matrix[x] if rotate else 0 for y in range(0, self.rows - 1): - self._matrix[y * self.columns + x] = self._matrix[ - (y + 1) * self.columns + x - ] + self._matrix[y * self.columns + x] = self._matrix[(y + 1) * self.columns + x] self._matrix[(self.rows - 1) * self.columns + x] = last_pixel self._update() diff --git a/adafruit_featherwing/rtc_featherwing.py b/adafruit_featherwing/rtc_featherwing.py index 0268ba1..05bae50 100755 --- a/adafruit_featherwing/rtc_featherwing.py +++ b/adafruit_featherwing/rtc_featherwing.py @@ -17,11 +17,13 @@ import time from collections import namedtuple -import board + import adafruit_ds3231 +import board try: - from typing import Optional, Dict + from typing import Dict, Optional + from busio import I2C except ImportError: pass @@ -115,9 +117,7 @@ def is_leap_year(self, year: Optional[int] = None) -> bool: year = self._get_time_value("year") return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) - def get_month_days( - self, month: Optional[int] = None, year: Optional[int] = None - ) -> int: + def get_month_days(self, month: Optional[int] = None, year: Optional[int] = None) -> int: """ Return the number of days for the month of the given year @@ -169,9 +169,7 @@ def set_date(self, day: int, month: int, year: int): month_days = self.get_month_days(month, year) if not isinstance(day, int) or not 1 <= day <= month_days: - raise ValueError( - "The day must be an integer in the range of 1-{}".format(month_days) - ) + raise ValueError(f"The day must be an integer in the range of 1-{month_days}") now = self._get_now() now["day"] = day @@ -231,9 +229,7 @@ def day(self, day: int): if isinstance(day, int) and 1 <= day <= month_days: self._set_time_value("day", day) else: - raise ValueError( - "The day must be an integer in the range of 1-{}".format(month_days) - ) + raise ValueError(f"The day must be an integer in the range of 1-{month_days}") @property def hour(self): diff --git a/adafruit_featherwing/sevensegment_featherwing.py b/adafruit_featherwing/sevensegment_featherwing.py index fe473b1..1fc0cac 100755 --- a/adafruit_featherwing/sevensegment_featherwing.py +++ b/adafruit_featherwing/sevensegment_featherwing.py @@ -16,10 +16,12 @@ import board from adafruit_ht16k33 import segments + from adafruit_featherwing.led_segments import Segments try: from typing import Optional + from busio import I2C except ImportError: pass diff --git a/adafruit_featherwing/tempmotion_featherwing.py b/adafruit_featherwing/tempmotion_featherwing.py index c90d6f0..055d388 100755 --- a/adafruit_featherwing/tempmotion_featherwing.py +++ b/adafruit_featherwing/tempmotion_featherwing.py @@ -15,9 +15,9 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import board -import adafruit_adxl34x import adafruit_adt7410 +import adafruit_adxl34x +import board try: from typing import Optional diff --git a/adafruit_featherwing/tft_featherwing.py b/adafruit_featherwing/tft_featherwing.py index c64d995..9d66f01 100644 --- a/adafruit_featherwing/tft_featherwing.py +++ b/adafruit_featherwing/tft_featherwing.py @@ -15,7 +15,9 @@ Requires: * adafruit_stmpe610 """ + import time + import board import digitalio import displayio @@ -38,13 +40,13 @@ try: from typing import Optional - from busio import SPI, I2C + + from busio import I2C, SPI from microcontroller import Pin except ImportError: pass -# pylint: disable-msg=too-few-public-methods, too-many-arguments, too-many-branches class TFTFeatherWing: """Base class for TFT FeatherWings.""" diff --git a/adafruit_featherwing/tft_featherwing_24.py b/adafruit_featherwing/tft_featherwing_24.py index 81e9631..54c81f8 100644 --- a/adafruit_featherwing/tft_featherwing_24.py +++ b/adafruit_featherwing/tft_featherwing_24.py @@ -20,19 +20,20 @@ __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git" -import board import adafruit_ili9341 +import board + from adafruit_featherwing.tft_featherwing import TFTFeatherWing try: from typing import Optional - from busio import SPI, I2C + + from busio import I2C, SPI from microcontroller import Pin except ImportError: pass -# pylint: disable-msg=too-few-public-methods, too-many-arguments class TFTFeatherWing24(TFTFeatherWing): """Class representing a TFT FeatherWing 2.4 V1 Attempts to mount the SD card to /sd. @@ -49,13 +50,10 @@ def __init__( super().__init__( spi, cs_pin=cs, dc_pin=dc, ts_cs_pin=ts_cs, sd_cs_pin=sd_cs, resistive=True ) - self.display = adafruit_ili9341.ILI9341( - self._display_bus, width=320, height=240 - ) + self.display = adafruit_ili9341.ILI9341(self._display_bus, width=320, height=240) """Display object for the FeatherWing's screen.""" -# pylint: disable-msg=too-few-public-methods, too-many-arguments class TFTFeatherWing24V2(TFTFeatherWing): """Class representing a `TFT FeatherWing 2.4 V2 `_. @@ -80,7 +78,5 @@ def __init__( i2c=i2c, resistive=True, ) - self.display = adafruit_ili9341.ILI9341( - self._display_bus, width=320, height=240 - ) + self.display = adafruit_ili9341.ILI9341(self._display_bus, width=320, height=240) """Display object for the FeatherWing's screen.""" diff --git a/adafruit_featherwing/tft_featherwing_35.py b/adafruit_featherwing/tft_featherwing_35.py index b5d56d6..181b76d 100644 --- a/adafruit_featherwing/tft_featherwing_35.py +++ b/adafruit_featherwing/tft_featherwing_35.py @@ -22,17 +22,18 @@ import board from adafruit_hx8357 import HX8357 + from adafruit_featherwing.tft_featherwing import TFTFeatherWing try: from typing import Optional - from busio import SPI, I2C + + from busio import I2C, SPI from microcontroller import Pin except ImportError: pass -# pylint: disable-msg=too-few-public-methods, too-many-arguments class TFTFeatherWing35(TFTFeatherWing): """Class representing a TFT FeatherWing 3.5 V1 Attempts to mount the SD card to /sd. @@ -53,7 +54,6 @@ def __init__( """Display object for the FeatherWing's screen.""" -# pylint: disable-msg=too-few-public-methods, too-many-arguments class TFTFeatherWing35V2(TFTFeatherWing): """Class representing a `TFT FeatherWing 3.5 V2 `_. diff --git a/docs/api.rst b/docs/api.rst index 3d3ed9b..fe19c8d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,6 +1,9 @@ .. If you created a package, create one automodule per module in the package. +API Reference +############# + .. automodule:: adafruit_featherwing.alphanum_featherwing :inherited-members: :members: diff --git a/docs/conf.py b/docs/conf.py index ea17bcc..ba1f353 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -62,9 +60,7 @@ creation_year = "2017" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Scott Shawcroft" author = "Scott Shawcroft" diff --git a/examples/featherwing_alphanum_simpletest.py b/examples/featherwing_alphanum_simpletest.py index 4f8268e..e1627cc 100755 --- a/examples/featherwing_alphanum_simpletest.py +++ b/examples/featherwing_alphanum_simpletest.py @@ -6,6 +6,7 @@ and then shows off the new marquee features.""" from time import sleep + from adafruit_featherwing import alphanum_featherwing display = alphanum_featherwing.AlphaNumFeatherWing() diff --git a/examples/featherwing_dotstar_palette_example.py b/examples/featherwing_dotstar_palette_example.py index eba2bf8..496edea 100644 --- a/examples/featherwing_dotstar_palette_example.py +++ b/examples/featherwing_dotstar_palette_example.py @@ -6,11 +6,13 @@ rotates through the palette creating a moving rainbow. """ -from math import sqrt, cos, sin, radians +from math import cos, radians, sin, sqrt + from adafruit_featherwing import dotstar_featherwing dotstar = dotstar_featherwing.DotStarFeatherWing() + # Remap the calculated rotation to 0 - 255 def remap(vector): return int(((255 * vector + 85) * 0.75) + 0.5) diff --git a/examples/featherwing_dotstar_simpletest.py b/examples/featherwing_dotstar_simpletest.py index 597cb95..3f3ebbd 100755 --- a/examples/featherwing_dotstar_simpletest.py +++ b/examples/featherwing_dotstar_simpletest.py @@ -6,12 +6,14 @@ and then draws random pixels at random locations """ -from time import sleep import random +from time import sleep + from adafruit_featherwing import dotstar_featherwing dotstar = dotstar_featherwing.DotStarFeatherWing() + # HELPERS # a random color 0 -> 224 def random_color(): diff --git a/examples/featherwing_gps_simpletest.py b/examples/featherwing_gps_simpletest.py index 5ac9c22..74c3908 100644 --- a/examples/featherwing_gps_simpletest.py +++ b/examples/featherwing_gps_simpletest.py @@ -6,7 +6,9 @@ update once per second. Initialization is automatically handled and there are some additional features such as MPH and KPH calculations. """ + import time + from adafruit_featherwing import gps_featherwing # Create a GPS featherwing instance. @@ -31,7 +33,7 @@ # Print out details about the fix like location, date, etc. print("=" * 40) # Print a separator line. print( - "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format( + "Fix timestamp: {}/{}/{} {:02}:{:02}:{:02}".format( # noqa: UP032 gps.timestamp.tm_mon, # Grab parts of the time from the gps.timestamp.tm_mday, # struct_time object that holds gps.timestamp.tm_year, # the fix time. Note you might @@ -40,24 +42,24 @@ gps.timestamp.tm_sec, ) ) - print("Latitude: {0:.6f} degrees".format(gps.latitude)) - print("Longitude: {0:.6f} degrees".format(gps.longitude)) - print("Fix quality: {}".format(gps.fix_quality)) + print(f"Latitude: {gps.latitude:.6f} degrees") + print(f"Longitude: {gps.longitude:.6f} degrees") + print(f"Fix quality: {gps.fix_quality}") # Some attributes beyond latitude, longitude and timestamp are optional # and might not be present. Check if they're None before trying to use! if gps.satellites is not None: - print("# satellites: {}".format(gps.satellites)) + print(f"# satellites: {gps.satellites}") if gps.altitude is not None: - print("Altitude: {} meters".format(gps.altitude)) + print(f"Altitude: {gps.altitude} meters") if gps.speed_knots is not None: - print("Speed (Knots): {} knots".format(gps.speed_knots)) + print(f"Speed (Knots): {gps.speed_knots} knots") if gps.speed_mph is not None: - print("Speed (Miles Per Hour): {} MPH".format(gps.speed_mph)) + print(f"Speed (Miles Per Hour): {gps.speed_mph} MPH") if gps.speed_kph is not None: - print("Speed (KM Per Hour): {} KPH".format(gps.speed_kph)) + print(f"Speed (KM Per Hour): {gps.speed_kph} KPH") if gps.track_angle is not None: - print("Track angle: {} degrees".format(gps.track_angle)) + print(f"Track angle: {gps.track_angle} degrees") if gps.horizontal_dilution is not None: - print("Horizontal dilution: {}".format(gps.horizontal_dilution)) + print(f"Horizontal dilution: {gps.horizontal_dilution}") if gps.height_geoid is not None: - print("Height geo ID: {} meters".format(gps.height_geoid)) + print(f"Height geo ID: {gps.height_geoid} meters") diff --git a/examples/featherwing_ina219_simpletest.py b/examples/featherwing_ina219_simpletest.py index f427b66..0f8f8ae 100755 --- a/examples/featherwing_ina219_simpletest.py +++ b/examples/featherwing_ina219_simpletest.py @@ -1,16 +1,18 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -""" Example to print out the voltage and current using the INA219 """ +"""Example to print out the voltage and current using the INA219""" + import time + from adafruit_featherwing import ina219_featherwing INA219 = ina219_featherwing.INA219FeatherWing() while True: - print("Bus Voltage: {} V".format(INA219.bus_voltage)) - print("Shunt Voltage: {} V".format(INA219.shunt_voltage)) - print("Voltage: {} V".format(INA219.voltage)) - print("Current: {} mA".format(INA219.current)) + print(f"Bus Voltage: {INA219.bus_voltage} V") + print(f"Shunt Voltage: {INA219.shunt_voltage} V") + print(f"Voltage: {INA219.voltage} V") + print(f"Current: {INA219.current} mA") print("") time.sleep(0.5) diff --git a/examples/featherwing_joy_simpletest.py b/examples/featherwing_joy_simpletest.py index c6b9940..35f37fe 100644 --- a/examples/featherwing_joy_simpletest.py +++ b/examples/featherwing_joy_simpletest.py @@ -2,8 +2,10 @@ # SPDX-License-Identifier: MIT """This example zeros the joystick, and prints when the joystick moves - or the buttons are pressed.""" +or the buttons are pressed.""" + import time + from adafruit_featherwing import joy_featherwing wing = joy_featherwing.JoyFeatherWing() diff --git a/examples/featherwing_keyboard_featherwing.py b/examples/featherwing_keyboard_featherwing.py index 5e0b217..e709bb9 100644 --- a/examples/featherwing_keyboard_featherwing.py +++ b/examples/featherwing_keyboard_featherwing.py @@ -10,7 +10,9 @@ It will also set the color of the neopixel on the featherwing. """ -from bbq10keyboard import STATE_RELEASE, STATE_LONG_PRESS + +from bbq10keyboard import STATE_LONG_PRESS, STATE_RELEASE + from adafruit_featherwing import keyboard_featherwing kbd_featherwing = keyboard_featherwing.KeyboardFeatherwing() @@ -23,10 +25,10 @@ with open("/sd/tft_featherwing.txt", "w") as f: f.write("Blinka\nBlackberry Q10 Keyboard") - with open("/sd/tft_featherwing.txt", "r") as f: + with open("/sd/tft_featherwing.txt") as f: print(f.read()) -except OSError as error: +except OSError: print("Unable to write to SD Card.") while True: @@ -43,7 +45,4 @@ STATE = "held down" elif key[0] == STATE_RELEASE: STATE = "released" - print( - "key: '%s' (dec %d, hex %02x) %s" - % (key[1], ord(key[1]), ord(key[1]), STATE) - ) + print("key: '%s' (dec %d, hex %02x) %s" % (key[1], ord(key[1]), ord(key[1]), STATE)) diff --git a/examples/featherwing_matrix_simpletest.py b/examples/featherwing_matrix_simpletest.py index 0d6dd26..0be1c32 100644 --- a/examples/featherwing_matrix_simpletest.py +++ b/examples/featherwing_matrix_simpletest.py @@ -5,7 +5,9 @@ This example will demonstrate some graphic effects and then draw a smiley face and shift it around the display """ + import time + from adafruit_featherwing import matrix_featherwing matrix = matrix_featherwing.MatrixFeatherWing() diff --git a/examples/featherwing_minitft_simpletest.py b/examples/featherwing_minitft_simpletest.py index 359792c..559bc8d 100755 --- a/examples/featherwing_minitft_simpletest.py +++ b/examples/featherwing_minitft_simpletest.py @@ -5,7 +5,9 @@ This example display a CircuitPython console and print which button that is being pressed if any """ + import time + from adafruit_featherwing import minitft_featherwing minitft = minitft_featherwing.MiniTFTFeatherWing() diff --git a/examples/featherwing_neopixel_palette_example.py b/examples/featherwing_neopixel_palette_example.py index 1b87475..fad8998 100644 --- a/examples/featherwing_neopixel_palette_example.py +++ b/examples/featherwing_neopixel_palette_example.py @@ -6,11 +6,13 @@ rotates through the palette creating a moving rainbow. """ -from math import sqrt, cos, sin, radians +from math import cos, radians, sin, sqrt + from adafruit_featherwing import neopixel_featherwing neopixel = neopixel_featherwing.NeoPixelFeatherWing() + # Remap the calculated rotation to 0 - 255 def remap(vector): return int(((255 * vector + 85) * 0.75) + 0.5) diff --git a/examples/featherwing_neopixel_simpletest.py b/examples/featherwing_neopixel_simpletest.py index 3be0935..8a90989 100644 --- a/examples/featherwing_neopixel_simpletest.py +++ b/examples/featherwing_neopixel_simpletest.py @@ -6,12 +6,14 @@ and then draws random pixels at random locations """ -from time import sleep import random +from time import sleep + from adafruit_featherwing import neopixel_featherwing neopixel = neopixel_featherwing.NeoPixelFeatherWing() + # HELPERS # a random color 0 -> 224 def random_color(): diff --git a/examples/featherwing_rtc_simpletest.py b/examples/featherwing_rtc_simpletest.py index bf1b3c0..99b87a8 100755 --- a/examples/featherwing_rtc_simpletest.py +++ b/examples/featherwing_rtc_simpletest.py @@ -5,7 +5,9 @@ This example will allow you to set the date and time and then loop through and display the current time """ + import time + from adafruit_featherwing import rtc_featherwing days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") @@ -13,7 +15,6 @@ # Create the RTC instance: rtc = rtc_featherwing.RTCFeatherWing() -# pylint: disable-msg=using-constant-test if True: # Change this to True to set the date and time rtc.set_time(13, 34) # Set the time (seconds are optional) print(rtc.now) @@ -32,14 +33,10 @@ # Main loop: while True: now = rtc.now - print( - "The date is {} {}/{}/{}".format( - days[now.weekday], now.day, now.month, now.year - ) - ) - print("The time is {}:{:02}:{:02}".format(now.hour, now.minute, now.second)) - print("The UNIX timestamp is {}".format(rtc.unixtime)) - print("The number of days in the current month is {}".format(rtc.get_month_days())) + print(f"The date is {days[now.weekday]} {now.day}/{now.month}/{now.year}") + print(f"The time is {now.hour}:{now.minute:02}:{now.second:02}") + print(f"The UNIX timestamp is {rtc.unixtime}") + print(f"The number of days in the current month is {rtc.get_month_days()}") if rtc.is_leap_year(): print("This year is a leap year") else: diff --git a/examples/featherwing_sevensegment_simpletest.py b/examples/featherwing_sevensegment_simpletest.py index 924b817..6a98ca9 100644 --- a/examples/featherwing_sevensegment_simpletest.py +++ b/examples/featherwing_sevensegment_simpletest.py @@ -6,6 +6,7 @@ and then shows off the new marquee features.""" from time import sleep + from adafruit_featherwing import sevensegment_featherwing display = sevensegment_featherwing.SevenSegmentFeatherWing() @@ -43,7 +44,7 @@ # Display a Time hour = 12 for minute in range(15, 26): - display.print("{}:{}".format(hour, minute)) + display.print(f"{hour}:{minute}") sleep(1) # Show the Marquee diff --git a/examples/featherwing_tempmotion_simpletest.py b/examples/featherwing_tempmotion_simpletest.py index 622ea01..bed8fdc 100644 --- a/examples/featherwing_tempmotion_simpletest.py +++ b/examples/featherwing_tempmotion_simpletest.py @@ -7,6 +7,7 @@ """ import time + from adafruit_featherwing import tempmotion_featherwing temp_motion = tempmotion_featherwing.TempMotionFeatherWing() diff --git a/examples/featherwing_tft24_simpletest.py b/examples/featherwing_tft24_simpletest.py index 2aee653..efc2d40 100644 --- a/examples/featherwing_tft24_simpletest.py +++ b/examples/featherwing_tft24_simpletest.py @@ -8,6 +8,7 @@ It will also try to write and then read a file on the SD Card. """ + from adafruit_featherwing import tft_featherwing_24 tft_featherwing = tft_featherwing_24.TFTFeatherWing24() @@ -16,10 +17,10 @@ with open("/sd/tft_featherwing.txt", "w") as f: f.write("Blinka\nBlackberry Q10 Keyboard") - with open("/sd/tft_featherwing.txt", "r") as f: + with open("/sd/tft_featherwing.txt") as f: print(f.read()) -except OSError as error: +except OSError: print("Unable to write to SD Card.") diff --git a/examples/featherwing_tft24v2_simpletest.py b/examples/featherwing_tft24v2_simpletest.py index 69b6cf5..8cc17e9 100644 --- a/examples/featherwing_tft24v2_simpletest.py +++ b/examples/featherwing_tft24v2_simpletest.py @@ -8,6 +8,7 @@ It will also try to write and then read a file on the SD Card. """ + from adafruit_featherwing import tft_featherwing_24 tft_featherwing = tft_featherwing_24.TFTFeatherWing24V2() @@ -16,10 +17,10 @@ with open("/sd/tft_featherwing.txt", "w") as f: f.write("Blinka\nBlackberry Q10 Keyboard") - with open("/sd/tft_featherwing.txt", "r") as f: + with open("/sd/tft_featherwing.txt") as f: print(f.read()) -except OSError as error: +except OSError: print("Unable to write to SD Card.") diff --git a/examples/featherwing_tft35_simpletest.py b/examples/featherwing_tft35_simpletest.py index 26a6720..127d9de 100644 --- a/examples/featherwing_tft35_simpletest.py +++ b/examples/featherwing_tft35_simpletest.py @@ -8,6 +8,7 @@ It will also try to write and then read a file on the SD Card. """ + from adafruit_featherwing import tft_featherwing_35 tft_featherwing = tft_featherwing_35.TFTFeatherWing35() @@ -16,9 +17,9 @@ with open("/sd/tft_featherwing.txt", "w") as f: f.write("Blinka\nBlackberry Q10 Keyboard") - with open("/sd/tft_featherwing.txt", "r") as f: + with open("/sd/tft_featherwing.txt") as f: print(f.read()) -except OSError as error: +except OSError: print("Unable to write to SD Card.") diff --git a/examples/featherwing_tft35v2_simpletest.py b/examples/featherwing_tft35v2_simpletest.py index e02a270..a0ba891 100644 --- a/examples/featherwing_tft35v2_simpletest.py +++ b/examples/featherwing_tft35v2_simpletest.py @@ -8,6 +8,7 @@ It will also try to write and then read a file on the SD Card. """ + from adafruit_featherwing import tft_featherwing_35 tft_featherwing = tft_featherwing_35.TFTFeatherWing35V2() @@ -16,9 +17,9 @@ with open("/sd/tft_featherwing.txt", "w") as f: f.write("Blinka\nBlackberry Q10 Keyboard") - with open("/sd/tft_featherwing.txt", "r") as f: + with open("/sd/tft_featherwing.txt") as f: print(f.read()) -except OSError as error: +except OSError: print("Unable to write to SD Card.") diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..73e9efc --- /dev/null +++ b/ruff.toml @@ -0,0 +1,108 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions + "PLR6301", # could-be-static no-self-use + "PLC0415", # import outside toplevel + "PLC2701", # private import +] + +[format] +line-ending = "lf"