Skip to content

Commit

Permalink
feat: Support Python 3.12
Browse files Browse the repository at this point in the history
* Replace the use of pkg_resources (from setuptools, which is
  no longer included in virtual environments as of 3.12) with
  importlib.metadata and importlib_resources.

* Add Python 3.12 to the test matrix.
  • Loading branch information
Maari Tamm committed Mar 15, 2024
1 parent aaa99da commit 253af5a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- 3.9
- "3.10"
- 3.11
- 3.12

steps:
- name: Check out code
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

* [Enhancement] Support Python 3.12.

## Version 2.4.0 (2024-03-13)

* [Enhancement] Make the location and revision of the webhook-receiver application repository configurable.
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[tox]
envlist = gitlint,py{38,39,310,311},flake8
envlist = gitlint,py{38,39,310,311,312},flake8

[gh-actions]
python =
3.8: gitlint,py38,flake8
3.9: gitlint,py39,flake8
3.10: gitlint,py310,flake8
3.11: gitlint,py311,flake8
3.12: gitlint,py312,flake8

[flake8]
ignore = E124,W504
Expand Down
5 changes: 2 additions & 3 deletions tutorwebhookreceiver/__about__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pkg_resources
from importlib import metadata
# __version__ attribute as suggested by (deferred) PEP 396:
# https://www.python.org/dev/peps/pep-0396/
#
# Single-source package definition as suggested (among several
# options) by:
# https://packaging.python.org/guides/single-sourcing-package-version/
__version__ = pkg_resources.get_distribution(
'tutor-contrib-webhook-receiver').version
__version__ = metadata.version('tutor-contrib-webhook-receiver')
20 changes: 10 additions & 10 deletions tutorwebhookreceiver/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from .__about__ import __version__
from glob import glob
import os
import pkg_resources
# When Tutor drops support for Python 3.8, we'll need to update this to:
# from importlib import resources as importlib_resources
# See: https://github.com/overhangio/tutor/issues/966#issuecomment-1938681102
import importlib_resources
from tutor import hooks


Expand Down Expand Up @@ -33,8 +36,8 @@
}

for service in ["mysql", "lms", "webhookreceiver"]:
path = pkg_resources.resource_filename(
"tutorwebhookreceiver", os.path.join(
path = str(
importlib_resources.files("tutorwebhookreceiver") / os.path.join(
"templates", "webhookreceiver", "tasks", service, "init")
)
with open(path, encoding="utf-8") as task_file:
Expand All @@ -59,7 +62,7 @@

# Add the "templates" folder as a template root
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutorwebhookreceiver", "templates")
str(importlib_resources.files("tutorwebhookreceiver") / "templates")
)
# Render the "build" and "apps" folders
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
Expand All @@ -69,12 +72,9 @@
],
)
# Load patches from files
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutorwebhookreceiver", "patches"),
"*",
)
):
for path in glob(str(
importlib_resources.files("tutorwebhookreceiver") / "patches" / "*")):

with open(path, encoding="utf-8") as patch_file:
hooks.Filters.ENV_PATCHES.add_item(
(os.path.basename(path), patch_file.read())
Expand Down

0 comments on commit 253af5a

Please sign in to comment.