Skip to content

Commit

Permalink
Drop support for Python 3.6 (#58)
Browse files Browse the repository at this point in the history
* ci: test against python 3.11

* add python 3.10

* update year

* update year

* update year

* ci: test against python 3.11

* don't use parentheses for assert statements

* fix typo

* update changelog

* switch to implicit namespace package configuration

* drop support for python 3.6

* drop support for python 3.6

* only include src dir in wheel

* use f-string

* fix Pillow DeprecationWarning and use Resampling.LANCZOS instead (fixes #59)

* tests: improve error message format

* ci: update actions

* ci: add pypi publish workflow

* ci: check for latest python

* tests: use relative imports

* use python 3.9 on readthedocs

* ci: use pytyon 3.11 release

* 3.8 is latest supported version on rtd

* add python 3.11

* luma.core 2.4 or newer is required now

* fix deprecationwarning for pillow

* remove maintenance badge

* remove maintenance badge

* happy new year

* ci:update pygame deps

* ci: publish when semantic versioned tag is pushed

* add py3.12

* fix tests

* fix lint error

* bump version

* restore constant reference

* doc update
  • Loading branch information
thijstriemstra authored Aug 3, 2023
1 parent dae670a commit 23a74c0
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 78 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,35 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-minor-version: [6, 7, 8, 9]
python-minor-version: [7, 8, 9, 10, 11]
name: Python 3.${{ matrix.python-minor-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup pip cache
uses: actions/cache@v2
uses: actions/cache@v3
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@v2
uses: actions/setup-python@v4
with:
python-version: 3.${{ matrix.python-minor-version }}
check-latest: true
- name: Install system dependencies
run: sudo apt-get install graphviz libsdl-dev python3-dev python3-numpy libsdl-image1.2-dev
run: sudo apt-get install graphviz libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev libfreetype6-dev libjpeg-dev python3-setuptools python3-dev python3-numpy
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Install Python packages
run: pip install --upgrade setuptools pip wheel tox coveralls
- name: Run tests
env:
TOX_ENV: py3${{ matrix.python-minor-version }}
run: python -m tox -e $TOX_ENV
run: |
python_env=$(echo $TOX_ENV | sed -e s/-dev$//)
python -m tox -e ${python_env}
- name: QA
env:
TOX_ENV: qa,doc
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish Package

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
build-and-publish:
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
with:
python-version: 3.9
- name: Install pypa/build
run: |
python -m pip install --upgrade setuptools pip wheel twine
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
twine check --strict dist/*
- name: Publish package to test PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish package to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
python:
version: 3.6
version: 3.8
pip_install: true
extra_requirements:
- docs
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ChangeLog
+------------+---------------------------------------------------------------------+------------+
| Version | Description | Date |
+============+=====================================================================+============+
| **1.5.0** | * Drop support for Python 3.6 | 2023/08/03 |
| | * Switch to implicit namespace package configuration | |
+------------+---------------------------------------------------------------------+------------+
| **1.4.0** | * Remove Python 3.5 support. Only Python 3.6 or newer is supported. | 2020/12/29 |
+------------+---------------------------------------------------------------------+------------+
| **1.3.0** | * Remove Python 2.7 support. Only Python 3.5 or newer is supported. | 2020/07/04 |
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)
---------------------

Copyright (c) 2017-2021 Richard Hull and contributors
Copyright (c) 2017-2023 Richard Hull and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Luma.Emulator
.. image:: https://img.shields.io/pypi/dm/luma.emulator
:target: https://pypi.python.org/project/luma.emulator

.. image:: https://img.shields.io/maintenance/yes/2021.svg?maxAge=2592000

**luma.emulator** provides a series of pseudo-display devices which allow
the `luma.core <https://github.com/rm-hull/luma.core>`_ components to be used
without running a physical device. These include:
Expand Down Expand Up @@ -59,7 +57,7 @@ License
-------
The MIT License (MIT)

Copyright (c) 2017-2020 Richard Hull and contributors
Copyright (c) 2017-2023 Richard Hull and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.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-2020 Richard Hull and contributors
# Copyright (c) 2017-2022 Richard Hull and contributors
# See LICENSE.rst for details.

# luma.emulator documentation build configuration file, created by
Expand Down Expand Up @@ -82,7 +82,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
Expand Down
2 changes: 0 additions & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Luma.Emulator
.. image:: https://coveralls.io/repos/github/rm-hull/luma.emulator/badge.svg?branch=master
:target: https://coveralls.io/github/rm-hull/luma.emulator?branch=master

.. image:: https://img.shields.io/maintenance/yes/2021.svg?maxAge=2592000

.. image:: https://img.shields.io/pypi/pyversions/luma.emulator.svg
:target: https://pypi.python.org/pypi/luma.emulator

Expand Down
6 changes: 3 additions & 3 deletions doc/install.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Installation
------------
.. note:: The library has been tested against Python 3.6 and newer.
.. note:: The library is supported for Python 3.7 and newer.

System packages
^^^^^^^^^^^^^^^

Install dependencies for pygame first::

$ sudo apt install python3-dev python3-pip build-essential
$ sudo apt install libsdl-dev libportmidi-dev libsdl-ttf2.0-dev libsdl-mixer1.2-dev libsdl-image1.2-dev
$ sudo apt install python3-dev python3-pip python3-numpy libfreetype6-dev libjpeg-dev build-essential
$ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev

And upgrade ``pip`` and ``setuptools``::

Expand Down
8 changes: 0 additions & 8 deletions luma/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions luma/emulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Richard Hull and contributors
# Copyright (c) 2017-2023 Richard Hull and contributors
# See LICENSE.rst for details.

__version__ = '1.4.0'
__version__ = '1.5.0'
23 changes: 11 additions & 12 deletions luma/emulator/device.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Richard Hull and contributors
# Copyright (c) 2017-2023 Richard Hull and contributors
# See LICENSE.rst for details.

import os
Expand Down Expand Up @@ -59,7 +59,7 @@ def hide(self):
self.contrast(0x00)

def contrast(self, value):
assert(0 <= value <= 255)
assert 0 <= value <= 255
self._contrast = value / 255.0
if self._last_image is not None:
self.display(self._last_image)
Expand All @@ -73,7 +73,7 @@ def to_surface(self, image, alpha=1.0):
transforming it according to the ``transform`` and ``scale``
constructor arguments.
"""
assert(0.0 <= alpha <= 1.0)
assert 0.0 <= alpha <= 1.0
if alpha < 1.0:
im = image.convert("RGBA")
black = Image.new(im.mode, im.size, "black")
Expand Down Expand Up @@ -107,7 +107,7 @@ def display(self, image):
"""
Takes a :py:mod:`PIL.Image` and dumps it to a numbered PNG file.
"""
assert(image.size == self.size)
assert image.size == self.size
self._last_image = image

self._count += 1
Expand Down Expand Up @@ -142,7 +142,7 @@ def display(self, image):
Takes an image, scales it according to the nominated transform, and
stores it for later building into an animated GIF.
"""
assert(image.size == self.size)
assert image.size == self.size
self._last_image = image

image = self.preprocess(image)
Expand All @@ -152,7 +152,7 @@ def display(self, image):
self._images.append(im)

self._count += 1
logger.debug("Recording frame: {0}".format(self._count))
logger.debug(f"Recording frame: {self._count}")

if self._max_frames and self._count >= self._max_frames:
sys.exit(0)
Expand All @@ -167,8 +167,7 @@ def write_animation(self):
optimize=True, format="GIF")

file_size = os.stat(self._filename).st_size
logger.debug("Wrote {0} frames to file: {1} ({2} bytes)".format(
self._count, self._filename, file_size))
logger.debug(f"Wrote {self._count} frames to file: {self._filename} ({file_size} bytes)")


class pygame(emulator):
Expand Down Expand Up @@ -200,7 +199,7 @@ def display(self, image):
"""
Takes a :py:mod:`PIL.Image` and renders it to a pygame display surface.
"""
assert(image.size == self.size)
assert image.size == self.size
self._last_image = image

image = self.preprocess(image)
Expand Down Expand Up @@ -286,7 +285,7 @@ def display(self, image):
Takes a :py:mod:`PIL.Image` and renders it to the current terminal as
ASCII-art.
"""
assert(image.size == self.size)
assert image.size == self.size
self._last_image = image

surface = self.to_surface(self.preprocess(image), alpha=self._contrast)
Expand Down Expand Up @@ -372,7 +371,7 @@ def display(self, image):
Takes a :py:mod:`PIL.Image` and renders it to the current terminal as
ASCII-blocks.
"""
assert(image.size == self.size)
assert image.size == self.size
self._last_image = image

surface = self.to_surface(self.preprocess(image), alpha=self._contrast)
Expand All @@ -385,7 +384,7 @@ def display(self, image):
self._CSI('1;1H') # Move to top/left

for (fg, bg) in self._generate_art(image, int(image.width * scale), int(image.height * scale)):
self._CSI('38;5;{0};48;5;{1}m'.format(fg, bg))
self._CSI(f'38;5;{fg};48;5;{bg}m')
sys.stdout.write('▄')

self._CSI('0m')
Expand Down
4 changes: 2 additions & 2 deletions luma/emulator/render.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Richard Hull and contributors
# Copyright (c) 2017-2022 Richard Hull and contributors
# See LICENSE.rst for details.

from pathlib import Path
Expand Down Expand Up @@ -33,7 +33,7 @@ def scale2x(self, surface):
Scales using the AdvanceMAME Scale2X algorithm which does a
'jaggie-less' scale of bitmap graphics.
"""
assert(self._scale == 2)
assert self._scale == 2
return self._pygame.transform.scale2x(surface)

def smoothscale(self, surface):
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pytest]
addopts = --timeout=10 -v -r wsx -s
addopts = --import-mode=importlib --timeout=10 -v -r wsx -s
26 changes: 16 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,41 @@ classifiers =
Topic :: System :: Hardware :: Hardware Drivers
Topic :: Software Development :: Libraries :: pygame
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
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

[options]
zip_safe = False
packages = find:
python_requires = >=3.6, <4
namespace_packages = luma
packages = find_namespace:
python_requires = >=3.7, <4
include_package_data = True
install_requires =
luma.core>=2.2.0
luma.core>=2.4.0
pygame
tests_require =
pytest
pytest-cov
pytest-timeout

[options.packages.find]
include = luma*

[options.extras_require]
docs = sphinx>=1.5.1
qa = flake8; rstcheck
test = pytest; pytest-cov; pytest-timeout
qa =
flake8
rstcheck
test =
pytest
pytest-cov
pytest-timeout

[options.package_data]
luma.emulator.images =
luma/emulator/images/led_on.png
luma/emulator/images/led_off.png
luma/emulator/images/7-segment.png
*.png

[bdist_wheel]
universal = 1
Expand Down
9 changes: 6 additions & 3 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017-2020 Richard Hull and contributors
# Copyright (c) 2017-2023 Richard Hull and contributors
# See LICENSE.rst for details.

import sys
Expand Down Expand Up @@ -37,8 +37,11 @@ def assert_identical(rname, fname):
reference = get_reference_image(rname)
md5_ref = md5(reference)
md5_target = md5(fname)
assert md5_ref == md5_target,\
f"Files are not identical.\nReference: {reference} ({md5_ref})\nTarget: {fname} ({md5_target})"
assert md5_ref == md5_target, \
f"""Generated file is not identical to {rname}
- generated: {fname} (MD5: {md5_target})
- reference: {reference} (MD5: {md5_ref})
"""


@contextmanager
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.
Loading

0 comments on commit 23a74c0

Please sign in to comment.