From 6135dd4d055b7ac1b97543aa9f28e2965a50309d Mon Sep 17 00:00:00 2001 From: Florian Haas Date: Wed, 20 Dec 2023 09:52:55 +0100 Subject: [PATCH] refactor: Use importlib.metadata to define version, support Python 3.12 We previously made use of the pkg_resources module to determine the package version (as defined by setuptools-scm) in __about__.py. This module is included in setuptools, which as of Python 3.12 has been removed from the standard library and is now its own third-party package. There are multiple ways to address this, one being to include setuptools in the install_requires list for Python 3.12 and later. Another, also listed in the Python Packaging User Guide, is to instead use importlib.metadata.version. Since this approach works for all Python versions we intend to support (that is, from 3.8 forward), this is the better solution. Thus, refactor __about__.py to use importlib, and add Python 3.12 to the test matrix. Note that Tutor itself does not support Python 3.12 prior to version 17, so we cannot support the combination of Python 3.12 and Tutor version 16 or earlier. Reference: https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ --- .github/workflows/tox.yml | 1 + CHANGELOG.md | 1 + tox.ini | 3 ++- tutors3/__about__.py | 4 ++-- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index e089c4d..f87e202 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -14,6 +14,7 @@ jobs: - 3.9 - "3.10" - 3.11 + - 3.12 steps: - name: Check out code diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae2a80..6342bab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Unreleased * [Enhancement] Support Tutor 17 and Open edX Quince. +* [Enhancement] Support Python 3.12, add it to the test matrix. ## Version 1.2.0 (2023-07-21) diff --git a/tox.ini b/tox.ini index 927b9be..f6e9e71 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = gitlint,py{38,39,310,311},flake8 +envlist = gitlint,py{38,39,310,311,312},flake8 [gh-actions] python = @@ -7,6 +7,7 @@ python = 3.9: gitlint,py39,flake8 3.10: gitlint,py310,flake8 3.11: gitlint,py311,flake8 + 3.12: gitlint,py312,flake8 [flake8] ignore = E124,W504 diff --git a/tutors3/__about__.py b/tutors3/__about__.py index d894b27..4575fed 100644 --- a/tutors3/__about__.py +++ b/tutors3/__about__.py @@ -1,8 +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-s3').version +__version__ = metadata.version('tutor-contrib-s3')