Skip to content

Commit

Permalink
refactor: Use importlib.metadata to define version, support Python 3.12
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
fghaas committed Dec 20, 2023
1 parent 549db06 commit 6135dd4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

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
4 changes: 2 additions & 2 deletions tutors3/__about__.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 6135dd4

Please sign in to comment.