Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying ruff #204

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# SPDX-License-Identifier: Unlicense

repos:
- repo: https://github.com/python/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/fsfe/reuse-tool
rev: v1.1.2
hooks:
Expand All @@ -17,26 +13,9 @@ repos:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/pylint
rev: v2.17.4
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
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
args: [ "--select", "I", "--fix" ]
- id: ruff-format
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Introduction
:target: https://github.com/adafruit/Adafruit_CircuitPython_Display_Text/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

Displays text using CircuitPython's displayio.

Expand Down
3 changes: 2 additions & 1 deletion adafruit_display_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from displayio import Group, Palette

try:
from typing import Optional, List, Tuple
from typing import List, Optional, Tuple

from fontio import FontProtocol
except ImportError:
pass
Expand Down
8 changes: 5 additions & 3 deletions adafruit_display_text/bitmap_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import displayio

from adafruit_display_text import LabelBase

try:
Expand All @@ -37,6 +38,7 @@

try:
from typing import Optional, Tuple

from fontio import FontProtocol
except ImportError:
pass
Expand Down Expand Up @@ -294,9 +296,9 @@ def _text_bounding_box(

lines = 1

xposition = (
x_start
) = yposition = y_start = 0 # starting x and y position (left margin)
xposition = x_start = yposition = y_start = (
0 # starting x and y position (left margin)
)

left = None
right = x_start
Expand Down
2 changes: 2 additions & 0 deletions adafruit_display_text/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@


from displayio import Bitmap, Palette, TileGrid

from adafruit_display_text import LabelBase

try:
from typing import Optional, Tuple

from fontio import FontProtocol
except ImportError:
pass
Expand Down
9 changes: 6 additions & 3 deletions adafruit_display_text/outlined_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
https://circuitpython.org/downloads

"""

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import bitmaptools
from displayio import Palette, Bitmap
from displayio import Bitmap, Palette

from adafruit_display_text import bitmap_label

try:
from typing import Optional, Tuple, Union

from fontio import FontProtocol
except ImportError:
pass
Expand All @@ -56,7 +59,7 @@ def __init__(
padding_bottom: Optional[int] = None,
padding_left: Optional[int] = None,
padding_right: Optional[int] = None,
**kwargs
**kwargs,
):
if padding_top is None:
padding_top = outline_size + 0
Expand All @@ -73,7 +76,7 @@ def __init__(
padding_bottom=padding_bottom,
padding_left=padding_left,
padding_right=padding_right,
**kwargs
**kwargs,
)

_background_color = self._palette[0]
Expand Down
4 changes: 3 additions & 1 deletion adafruit_display_text/scrolling_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Display_Text.git"

import time

from adafruit_display_text import bitmap_label

try:
from typing import Optional

from fontio import FontProtocol
except ImportError:
pass
Expand Down Expand Up @@ -58,7 +60,7 @@ def __init__(
text: Optional[str] = "",
animate_time: Optional[float] = 0.3,
current_index: Optional[int] = 0,
**kwargs
**kwargs,
) -> None:
super().__init__(font, **kwargs)
self.animate_time = animate_time
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#
# SPDX-License-Identifier: MIT

import datetime
import os
import sys
import datetime

import sphinx_rtd_theme

sys.path.insert(0, os.path.abspath(".."))

Expand Down Expand Up @@ -101,7 +103,6 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
Expand Down
6 changes: 4 additions & 2 deletions examples/display_text_advance_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"""

import time

import board
import displayio
import terminalio
import fontio
import terminalio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label, bitmap_label

from adafruit_display_text import bitmap_label, label

display = board.DISPLAY
main_group = displayio.Group()
Expand Down
4 changes: 3 additions & 1 deletion examples/display_text_anchored_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"""
This examples shows the use of anchor_point and anchored_position.
"""

import board
import terminalio
import displayio
import terminalio

from adafruit_display_text import label

DISPLAY_WIDTH = 320
Expand Down
3 changes: 3 additions & 0 deletions examples/display_text_background_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"""
This example shows the use color and background_color
"""

import time

import board
import terminalio

from adafruit_display_text import label

text = " Color Background Hello world"
Expand Down
5 changes: 3 additions & 2 deletions examples/display_text_background_color_padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"""
This example shows the use color and background_color
"""

import time

import board
import displayio

from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label

from adafruit_display_text import label

# Setup the SPI display
if "DISPLAY" in dir(board):
Expand Down
2 changes: 1 addition & 1 deletion examples/display_text_bitmap_label_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import board
import terminalio
from adafruit_display_text import bitmap_label

from adafruit_display_text import bitmap_label

text = "Hello world"
text_area = bitmap_label.Label(terminalio.FONT, text=text)
Expand Down
2 changes: 1 addition & 1 deletion examples/display_text_label_align_baseline_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text import label

from adafruit_display_text import label

display = board.DISPLAY

Expand Down
4 changes: 2 additions & 2 deletions examples/display_text_label_vs_bitmap_label_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
# pylint: disable=no-member

import gc

import board
import displayio
import terminalio
from adafruit_bitmap_font import bitmap_font

from adafruit_display_text import bitmap_label
from adafruit_display_text import label
from adafruit_display_text import bitmap_label, label

# pylint: disable=no-member

Expand Down
3 changes: 3 additions & 0 deletions examples/display_text_magtag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
Basic display_text.label example script
adapted for use on MagTag.
"""

import time

import board
import displayio
import terminalio

from adafruit_display_text import label

# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
Expand Down
2 changes: 2 additions & 0 deletions examples/display_text_matrixportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@

Copy it from the current libraries bundle into the lib folder on your device.
"""

import terminalio
from adafruit_matrixportal.matrix import Matrix

from adafruit_display_text import label

matrix = Matrix()
Expand Down
1 change: 1 addition & 0 deletions examples/display_text_outlined_label_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import board
import terminalio

from adafruit_display_text import outlined_label

if board.DISPLAY.width <= 150:
Expand Down
3 changes: 2 additions & 1 deletion examples/display_text_pyportal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import os
import time

import board
import displayio

from adafruit_bitmap_font import bitmap_font

from adafruit_display_text.label import Label

FONT_DIR = "/fonts/"
Expand Down
2 changes: 1 addition & 1 deletion examples/display_text_scrolling_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import board
import terminalio
from adafruit_display_text.scrolling_label import ScrollingLabel

from adafruit_display_text.scrolling_label import ScrollingLabel

text = "Hello world CircuitPython scrolling label"
my_scrolling_label = ScrollingLabel(
Expand Down
2 changes: 1 addition & 1 deletion examples/display_text_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import board
import terminalio
from adafruit_display_text import label

from adafruit_display_text import label

text = "Hello world"
text_area = label.Label(terminalio.FONT, text=text)
Expand Down
3 changes: 2 additions & 1 deletion examples/display_text_textarea_boundingbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# SPDX-License-Identifier: MIT

import os

import board
import displayio
from adafruit_bitmap_font import bitmap_font
from adafruit_display_text.label import Label

from adafruit_display_text.label import Label

# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]
Expand Down
1 change: 1 addition & 0 deletions examples/display_text_wrap_pixels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import board
import displayio
import terminalio

from adafruit_display_text import label, wrap_text_to_pixels

WRAP_WIDTH = 140
Expand Down
2 changes: 2 additions & 0 deletions examples/display_text_wraptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
This example illustrates how to use the wrap_text_to_lines
helper function.
"""

import board
import terminalio

from adafruit_display_text import label, wrap_text_to_lines

# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
Expand Down
Loading