Skip to content

Commit

Permalink
Set 3.9 as base version, fix 3.12 compatibility
Browse files Browse the repository at this point in the history
3.7 shouldn't be tested (in tox), fix the spelling on python_requires in
setup.cfg, pull in importlib_metadata for Python 3.9, and fix the
entry_points deprecation in Python 3.12.
  • Loading branch information
waveform80 committed Feb 14, 2024
1 parent 981e3f7 commit fa11431
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- os: ubuntu-22.04
python: "3.11"
experimental: false
- os: ubuntu-22.04
python: "3.12"
experimental: false

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
Expand Down
10 changes: 7 additions & 3 deletions gpiozero/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from collections import namedtuple
from itertools import chain
from types import FunctionType
from importlib.metadata import entry_points

# NOTE: Remove try when compatibility moves beyond Python 3.10
try:
from importlib_metadata import entry_points
except ImportError:
from importlib.metadata import entry_points

from .threads import _threads_shutdown
from .mixins import (
Expand Down Expand Up @@ -303,8 +308,7 @@ def _default_pin_factory():
with warnings.catch_warnings():
# The dict interface of entry_points is deprecated ... already
# and this deprecation is for us to worry about, not our users
warnings.simplefilter('ignore', category=DeprecationWarning)
group = entry_points()['gpiozero_pin_factories']
group = entry_points(group='gpiozero_pin_factories')
for ep in group:
if ep.name == name:
return ep.load()()
Expand Down
9 changes: 7 additions & 2 deletions gpiozero/pins/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
from time import time, sleep, monotonic
from threading import Thread, Event
from math import isclose
from importlib.metadata import entry_points

# NOTE: Remove try when compatibility moves beyond Python 3.10
try:
from importlib_metadata import entry_points
except ImportError:
from importlib.metadata import entry_points

from ..exc import (
PinPWMUnsupported,
Expand Down Expand Up @@ -463,7 +468,7 @@ def __init__(self, revision=None, pin_class=None):
if isinstance(pin_class, bytes):
pin_class = pin_class.decode('ascii')
if isinstance(pin_class, str):
group = entry_points()['gpiozero_mock_pin_classes']
group = entry_points(group='gpiozero_mock_pin_classes')
pin_class = group[pin_class.lower()].load()
if not issubclass(pin_class, MockPin):
raise ValueError(f'invalid mock pin_class: {pin_class!r}')
Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ classifiers =
Topic :: Education
Topic :: System :: Hardware
License :: OSI Approved :: BSD License
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 :: Implementation :: PyPy

[options]
packages = find:
python_requres = >=3.9
python_requires = >=3.9
install_requires =
colorzero
importlib_metadata~=4.6;python_version<'3.10'

[options.package_data]
gpiozero =
Expand Down
17 changes: 9 additions & 8 deletions tests/test_real_pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from time import time, sleep
from math import isclose
from unittest import mock
from importlib.metadata import entry_points

# NOTE: Remove try when compatibility moves beyond Python 3.10
try:
from importlib_metadata import entry_points
except ImportError:
from importlib.metadata import entry_points

import pytest

Expand Down Expand Up @@ -52,11 +57,9 @@ def local_hardware_spi_only(intf):


with warnings.catch_warnings():
# The dict interface of entry_points is deprecated ... already
warnings.simplefilter('ignore', category=DeprecationWarning)
@pytest.fixture(
scope='module',
params=[ep.name for ep in entry_points()['gpiozero_pin_factories']])
params=[ep.name for ep in entry_points(group='gpiozero_pin_factories')])
def pin_factory_name(request):
return request.param

Expand All @@ -65,9 +68,7 @@ def pin_factory_name(request):
def pin_factory(request, pin_factory_name):
try:
with warnings.catch_warnings():
# The dict interface of entry_points is deprecated ... already
warnings.simplefilter('ignore', category=DeprecationWarning)
eps = entry_points()['gpiozero_pin_factories']
eps = entry_points(group='gpiozero_pin_factories')
for ep in eps:
if ep.name == pin_factory_name:
factory = ep.load()()
Expand Down Expand Up @@ -280,7 +281,7 @@ def test_envvar_factory(no_default_factory, pin_factory_name):
pin_factory_name=pin_factory_name, e=e))
else:
try:
group = entry_points()['gpiozero_pin_factories']
group = entry_points(group='gpiozero_pin_factories')
for ep in group:
if ep.name == pin_factory_name:
factory_class = ep.load()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = {py35,py36,py37,py38,py39}
envlist = {py39,py310,py311,py312}

[testenv]
deps = .[test]
Expand Down

0 comments on commit fa11431

Please sign in to comment.