Skip to content

Commit

Permalink
Drop support for Python 3.7 (#65)
Browse files Browse the repository at this point in the history
* ci: update dependencies

* drop support for python 3.7

* tests: use test font

* lint fix
  • Loading branch information
thijstriemstra authored Oct 26, 2024
1 parent 4f82166 commit adc26e3
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-minor-version: [7, 8, 9, 10, 11]
python-minor-version: [8, 9, 10, 11, 12, 13]
name: Python 3.${{ matrix.python-minor-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup pip cache
uses: actions/cache@v3
uses: actions/cache@v4
id: pipcache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.${{ matrix.python-minor-version }}
check-latest: true
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish Package

permissions:
id-token: write

on:
push:
tags:
Expand All @@ -13,11 +13,11 @@ jobs:
name: Build and publish Python package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.9
python-version: 3.10
- name: Install pypa/build
run: |
python -m pip install --upgrade setuptools pip wheel twine
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ChangeLog
+------------+---------------------------------------------------------------------+------------+
| Version | Description | Date |
+============+=====================================================================+============+
| **1.6.0** | * Drop support for Python 3.7 | TBD |
+------------+---------------------------------------------------------------------+------------+
| **1.5.0** | * Drop support for Python 3.6 | 2023/08/31 |
| | * Switch to implicit namespace package configuration | |
+------------+---------------------------------------------------------------------+------------+
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ classifiers =
Topic :: System :: Hardware :: Hardware Drivers
Topic :: Software Development :: Libraries :: pygame
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13

[options]
zip_safe = False
packages = find_namespace:
python_requires = >=3.7, <4
python_requires = >=3.8, <4
include_package_data = True
install_requires =
luma.core>=2.4.0
Expand Down
8 changes: 5 additions & 3 deletions tests/baseline_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

from .helpers import test_font


def primitives(device, draw):
padding = 2
Expand All @@ -20,5 +22,5 @@ def primitives(device, draw):
draw.line((x, bottom, x + shape_width, top), fill="yellow")
draw.line((x, top, x + shape_width, bottom), fill="yellow")
x += shape_width + padding
draw.text((x, top), 'Hello', fill="cyan")
draw.text((x, top + 20), 'World!', fill="purple")
draw.text((x, top), 'Hello', font=test_font, fill="cyan")
draw.text((x, top + 20), 'World!', font=test_font, fill="purple")
23 changes: 20 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2023 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

import sys
import hashlib
from pathlib import Path
from io import StringIO
from contextlib import contextmanager
from PIL import ImageFont


def md5(fname):
with open(fname, 'rb') as fp:
return hashlib.md5(fp.read()).hexdigest()


def get_reference_image(fname):
def get_reference_file(fname):
"""
Get absolute path for ``fname``.
Expand All @@ -25,6 +26,22 @@ def get_reference_image(fname):
return str(Path(__file__).resolve().parent.joinpath('reference', fname))


def get_reference_pillow_font(fname):
"""
Load :py:class:`PIL.ImageFont` type font from provided fname
:param fname: The name of the file that contains the PIL.ImageFont
:type fname: str
:rtype: :py:class:`PIL.ImageFont`
"""
path = get_reference_file(Path('font').joinpath(fname))
return ImageFont.load(path)


# font used in (most) tests
test_font = get_reference_pillow_font('courB08.pil')


def assert_identical(rname, fname):
"""
Files that are compared have the same MD5 hash.
Expand All @@ -34,7 +51,7 @@ def assert_identical(rname, fname):
:param fname: Target file location.
:type fname: str
"""
reference = get_reference_image(rname)
reference = get_reference_file(rname)
md5_ref = md5(reference)
md5_target = md5(fname)
assert md5_ref == md5_target, \
Expand Down
Binary file modified tests/reference/anim.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/reference/font/courB08.pbm
Binary file not shown.
Binary file added tests/reference/font/courB08.pil
Binary file not shown.
7 changes: 3 additions & 4 deletions tests/test_asciiblock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2022 Richard Hull and contributors
# Copyright (c) 2018-2024 Richard Hull and contributors
# See LICENSE.rst for details.

"""
Expand All @@ -10,13 +10,12 @@
import sys
import struct
import hashlib
from pathlib import Path
from unittest.mock import patch

from luma.core.render import canvas

from .baseline_data import primitives
from .helpers import md5, redirect_stdout
from .helpers import md5, redirect_stdout, get_reference_file


def noop():
Expand Down Expand Up @@ -48,7 +47,7 @@ def test_display():
out = f.getvalue().encode('utf-8')

digest = hashlib.md5(out).hexdigest()
fname = Path(__file__).resolve().parent.joinpath('reference', 'asciiblock.txt')
fname = get_reference_file('asciiblock.txt')
assert md5(str(fname)) == digest


Expand Down
8 changes: 4 additions & 4 deletions tests/test_gifanim.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2022 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

"""
Expand All @@ -18,7 +18,7 @@
import pytest

from .baseline_data import primitives
from .helpers import get_reference_image, assert_identical
from .helpers import get_reference_file, test_font, assert_identical


def test_gifanim_write():
Expand All @@ -30,7 +30,7 @@ def test_gifanim_write():
primitives(device, draw)

with canvas(device) as draw:
draw.text((30, 10), text="Blipvert", fill="white")
draw.text((30, 10), text="Blipvert", font=test_font, fill="white")

with canvas(device) as draw:
primitives(device, draw)
Expand All @@ -48,7 +48,7 @@ def test_gifanim_noimages():


def test_gifanim_max_frames():
reference = get_reference_image('anim.gif')
reference = get_reference_file('anim.gif')
img = Image.open(reference)
with NamedTemporaryFile(suffix='.gif') as temp:
fname = temp.name
Expand Down
22 changes: 11 additions & 11 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2022 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

"""
Expand All @@ -14,11 +14,11 @@
from luma.core.render import canvas
from luma.emulator.render import transformer

from .helpers import get_reference_image
from .helpers import get_reference_file, test_font


def baseline_im():
return pygame.image.load(get_reference_image("capture.png"))
return pygame.image.load(get_reference_file("capture.png"))


def to_pillow_img(surface):
Expand All @@ -31,7 +31,7 @@ def to_pygame_surface(im):


def test_none():
with open(get_reference_image("capture.png"), "rb") as fp:
with open(get_reference_file("capture.png"), "rb") as fp:
ref = Image.open(fp)
surface = baseline_im()
tf = transformer(pygame, 128, 64, 1)
Expand All @@ -41,7 +41,7 @@ def test_none():


def test_scale2x():
with open(get_reference_image("scale2x.png"), "rb") as fp:
with open(get_reference_file("scale2x.png"), "rb") as fp:
ref = Image.open(fp)
surface = baseline_im()
tf = transformer(pygame, 128, 64, 2)
Expand All @@ -51,7 +51,7 @@ def test_scale2x():


def test_smoothscale():
with open(get_reference_image("smoothscale.png"), "rb") as fp:
with open(get_reference_file("smoothscale.png"), "rb") as fp:
ref = Image.open(fp)
surface = baseline_im()
tf = transformer(pygame, 128, 64, 2)
Expand All @@ -61,7 +61,7 @@ def test_smoothscale():


def test_identity():
with open(get_reference_image("identity.png"), "rb") as fp:
with open(get_reference_file("identity.png"), "rb") as fp:
ref = Image.open(fp)
surface = baseline_im()
tf = transformer(pygame, 128, 64, 2)
Expand All @@ -71,13 +71,13 @@ def test_identity():


def test_led_matrix():
with open(get_reference_image("led_matrix.png"), "rb") as fp:
with open(get_reference_file("led_matrix.png"), "rb") as fp:
ref = Image.open(fp)
device = dummy(width=40, height=24)
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white")
draw.text((5, 2), "Hello", fill="white")
draw.text((5, 10), "World", fill="white")
draw.text((5, 2), "Hello", font=test_font, fill="white")
draw.text((5, 10), "World", font=test_font, fill="white")
surface = to_pygame_surface(device.image)
tf = transformer(pygame, device.width, device.height, 16)
im = to_pillow_img(tf.led_matrix(surface))
Expand All @@ -86,7 +86,7 @@ def test_led_matrix():


def test_seven_segment():
with open(get_reference_image("seven_segment.png"), "rb") as fp:
with open(get_reference_file("seven_segment.png"), "rb") as fp:
ref = Image.open(fp)
chars = [
# Alphabet with omissions
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2017-2023 Richard Hull and contributors
# Copyright (c) 2017-2024 Richard Hull and contributors
# See LICENSE.rst for details.

[tox]
envlist = py{37,38,39,310,311,312},qa,doc
envlist = py{38,39,310,311,312,313,314},qa,doc
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit adc26e3

Please sign in to comment.