Skip to content
Draft
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
3 changes: 3 additions & 0 deletions src/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=140
ignore=E501
6 changes: 6 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.env
.mypy_cache/
.pytest_cache/
.venv/
__pycache__/
venv/
2 changes: 2 additions & 0 deletions src/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=line-too-long
29 changes: 29 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
SHELL := /bin/bash
.DEFAULT_GOAL := help

.PHONY: help
## help| Makefile| Prints this help message
help:
@echo "Usage:"
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s '|' | sed -e 's/^/ /'

.PHONY: init
## init| Python| Create virtual environment
init:
python3 -m venv .venv

.PHONY: lint
## lint| Python| Run linters
lint:
flake8
find -name '*.py' | xargs pylint

.PHONY: format
## format| Python| Run formatter
format:
find -name '*.py' | xargs black --line-length=140

.PHONY: types
## types| Python| Run types linter
types:
find -name '*.py' | xargs mypy --ignore-missing-imports
4 changes: 1 addition & 3 deletions src/adafruit_bitmap_font/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def _verify_bounding_box(self) -> None:
try:
self._boundingbox
except AttributeError as error:
raise RuntimeError(
"Source file does not have the FOUNTBOUNDINGBOX parameter"
) from error
raise RuntimeError("Source file does not have the FOUNTBOUNDINGBOX parameter") from error

def _readline_file(self) -> str:
line = self.file.readline()
Expand Down
4 changes: 1 addition & 3 deletions src/adafruit_bitmap_font/bitmap_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Bitmap_Font.git"


def load_font(
filename: str, bitmap: Optional[Bitmap] = None
) -> Union[bdf.BDF, pcf.PCF, ttf.TTF]:
def load_font(filename: str, bitmap: Optional[Bitmap] = None) -> Union[bdf.BDF, pcf.PCF, ttf.TTF]:
"""Loads a font file. Returns None if unsupported."""
# pylint: disable=import-outside-toplevel, redefined-outer-name, consider-using-with
if not bitmap:
Expand Down
19 changes: 5 additions & 14 deletions src/adafruit_bitmap_font/pcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,7 @@
"ink_maxbounds",
),
)
Encoding = namedtuple(
"Encoding", ("min_byte2", "max_byte2", "min_byte1", "max_byte1", "default_char")
)
Encoding = namedtuple("Encoding", ("min_byte2", "max_byte2", "min_byte1", "max_byte1", "default_char"))
Bitmap = namedtuple("Bitmap", ("glyph_count", "bitmap_sizes"))


Expand Down Expand Up @@ -304,21 +302,15 @@ def load_glyphs(self, code_points: Union[int, str, Iterable[int]]) -> None:
elif isinstance(code_points, str):
code_points = [ord(c) for c in code_points]

code_points = sorted(
c for c in code_points if self._glyphs.get(c, None) is None
)
code_points = sorted(c for c in code_points if self._glyphs.get(c, None) is None)
if not code_points:
return

indices_offset = self.tables[_PCF_BDF_ENCODINGS].offset + 14
bitmap_offset_offsets = self.tables[_PCF_BITMAPS].offset + 8
first_bitmap_offset = self.tables[_PCF_BITMAPS].offset + 4 * (
6 + self._bitmaps.glyph_count
)
first_bitmap_offset = self.tables[_PCF_BITMAPS].offset + 4 * (6 + self._bitmaps.glyph_count)
metrics_compressed = self.tables[_PCF_METRICS].format & _PCF_COMPRESSED_METRICS
first_metric_offset = self.tables[_PCF_METRICS].offset + (
6 if metrics_compressed else 8
)
first_metric_offset = self.tables[_PCF_METRICS].offset + (6 if metrics_compressed else 8)
metrics_size = 5 if metrics_compressed else 12

# These will each _tend to be_ forward reads in the file, at least
Expand All @@ -335,8 +327,7 @@ def load_glyphs(self, code_points: Union[int, str, Iterable[int]]) -> None:
continue

encoding_idx = (
(enc1 - self._encoding.min_byte1)
* (self._encoding.max_byte2 - self._encoding.min_byte2 + 1)
(enc1 - self._encoding.min_byte1) * (self._encoding.max_byte2 - self._encoding.min_byte2 + 1)
+ enc2
- self._encoding.min_byte2
)
Expand Down
20 changes: 5 additions & 15 deletions src/adafruit_display_shapes/multisparkline.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,13 @@ def __init__(
# define class instance variables
self._max_items = max_items # maximum number of items in the list
self._lines = len(colors)
self._buffers = [
_CyclicBuffer(self._max_items, 0.0) for i in range(self._lines)
] # values per sparkline
self._points = [
_CyclicBuffer(self._max_items, (0, 0)) for i in range(self._lines)
] # _points: all points of sparkline
self._buffers = [_CyclicBuffer(self._max_items, 0.0) for i in range(self._lines)] # values per sparkline
self._points = [_CyclicBuffer(self._max_items, (0, 0)) for i in range(self._lines)] # _points: all points of sparkline
self.dyn_xpitch = dyn_xpitch
if not dyn_xpitch:
self._xpitch = (width - 1) / (self._max_items - 1)
self.y_mins = (
[None] * self._lines if y_mins is None else y_mins
) # minimum of each y-axis (None: autoscale)
self.y_maxs = (
[None] * self._lines if y_maxs is None else y_maxs
) # maximum of each y-axis (None: autoscale)
self.y_mins = [None] * self._lines if y_mins is None else y_mins # minimum of each y-axis (None: autoscale)
self.y_maxs = [None] * self._lines if y_maxs is None else y_maxs # maximum of each y-axis (None: autoscale)
self.y_bottoms = self.y_mins.copy()
# y_bottom: The actual minimum value of the vertical scale, will be
# updated if autorange
Expand Down Expand Up @@ -176,9 +168,7 @@ def add_values(self, values: List[float], update: bool = True) -> None:
if value is not None:
top = self.y_tops[i]
bottom = self.y_bottoms[i]
if (
self._buffers[i].len() >= self._max_items
): # if list is full, remove the first item
if self._buffers[i].len() >= self._max_items: # if list is full, remove the first item
first = self._buffers[i].pop()
# check if boundaries have to be updated
if self.y_mins[i] is None and first == bottom:
Expand Down
4 changes: 1 addition & 3 deletions src/adafruit_display_shapes/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def __init__(
self.outline = outline
self.draw(self._bitmap, shifted, self._OUTLINE, close)

super().__init__(
self._bitmap, pixel_shader=self._palette, x=x_offset, y=y_offset
)
super().__init__(self._bitmap, pixel_shader=self._palette, x=x_offset, y=y_offset)

@staticmethod
def draw(
Expand Down
4 changes: 1 addition & 3 deletions src/adafruit_display_shapes/sparkline.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def __init__(
y: int = 0,
color: int = 0xFFFFFF, # line color, default is WHITE
) -> None:
super().__init__(
width, height, max_items, [color], dyn_xpitch, [y_min], [y_max], x, y
)
super().__init__(width, height, max_items, [color], dyn_xpitch, [y_min], [y_max], x, y)

# pylint: enable=too-many-arguments

Expand Down
4 changes: 1 addition & 3 deletions src/adafruit_display_shapes/triangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def __init__(
super().__init__(points)

if fill is not None:
self._draw_filled(
x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0
)
self._draw_filled(x0 - min(xs), 0, x1 - min(xs), y1 - y0, x2 - min(xs), y2 - y0)
self.fill = fill
else:
self.fill = None
Expand Down
33 changes: 7 additions & 26 deletions src/adafruit_display_text/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,9 @@ def measure(text):
else:
extraspace = swidth
leadchar = " "
if (
measure("".join(partial))
+ measure(cur_part)
+ measure(char)
+ measure("-")
+ extraspace
> max_width
):
if measure("".join(partial)) + measure(cur_part) + measure(char) + measure("-") + extraspace > max_width:
if cur_part:
word_parts.append(
"".join(partial) + leadchar + cur_part + "-"
)
word_parts.append("".join(partial) + leadchar + cur_part + "-")

else:
word_parts.append("".join(partial))
Expand Down Expand Up @@ -347,9 +338,7 @@ def background_color(self) -> int:
return self._background_color

def _set_background_color(self, new_color):
raise NotImplementedError(
"{} MUST override '_set_background_color'".format(type(self))
)
raise NotImplementedError("{} MUST override '_set_background_color'".format(type(self)))

@background_color.setter
def background_color(self, new_color: int) -> None:
Expand Down Expand Up @@ -384,9 +373,7 @@ def anchored_position(self, new_position: Tuple[int, int]) -> None:
# Calculate (x,y) position
if (self._anchor_point is not None) and (self._anchored_position is not None):
self.x = int(
new_position[0]
- (self._bounding_box[0] * self.scale)
- round(self._anchor_point[0] * (self._bounding_box[2] * self.scale))
new_position[0] - (self._bounding_box[0] * self.scale) - round(self._anchor_point[0] * (self._bounding_box[2] * self.scale))
)
if self._anchor_point[1] == self._baseline:
self.y = int(new_position[1] - (self._y_offset * self.scale))
Expand Down Expand Up @@ -442,9 +429,7 @@ def line_spacing(self) -> float:
return self._line_spacing

def _set_line_spacing(self, new_line_spacing: float) -> None:
raise NotImplementedError(
"{} MUST override '_set_line_spacing'".format(type(self))
)
raise NotImplementedError("{} MUST override '_set_line_spacing'".format(type(self)))

@line_spacing.setter
def line_spacing(self, new_line_spacing: float) -> None:
Expand All @@ -456,14 +441,10 @@ def label_direction(self) -> str:
return self._label_direction

def _set_label_direction(self, new_label_direction: str) -> None:
raise NotImplementedError(
"{} MUST override '_set_label_direction'".format(type(self))
)
raise NotImplementedError("{} MUST override '_set_label_direction'".format(type(self)))

def _get_valid_label_directions(self) -> Tuple[str, ...]:
raise NotImplementedError(
"{} MUST override '_get_valid_label_direction'".format(type(self))
)
raise NotImplementedError("{} MUST override '_get_valid_label_direction'".format(type(self)))

@label_direction.setter
def label_direction(self, new_label_direction: str) -> None:
Expand Down
Loading