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 a dependency on the importlib-resources library for Python<3.9
  (importlib.resources became part of the standard library in 3.9;
  importlib-resources is a backport for older versions).
* Add Python 3.12 to the test matrix.
* Update the Trove classifiers in setup.py: drop support for Python
  3.6 and 3.7, add support for Python 3.12.

References:
https://importlib-resources.readthedocs.io/en/latest/migration.html
  • Loading branch information
fghaas committed Feb 20, 2024
1 parent 6878708 commit 0a5a7b7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 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

* feat: Support Python 3.12.

## Version 1.3.2 (2024-01-22)

* fix: Un-break cluster template creation with `openstacksdk>=1.0.0`.
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ def load_readme():
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python",
"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",
"Programming Language :: Python :: 3.12",
],
)
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 tutoropenstack/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
https://packaging.python.org/guides/single-sourcing-package-version/
"""

import pkg_resources
__version__ = pkg_resources.get_distribution(
'tutor-contrib-openstack').version
from importlib import metadata
__version__ = metadata.version('tutor-contrib-openstack')
34 changes: 23 additions & 11 deletions tutoropenstack/plugin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
"""Plugin definition for the Tutor openstack plugin."""

from glob import glob
from .command import openstack as openstack_command

import os
import pkg_resources

# importlib.resources is the standard library module, available since
# Python 3.7. importlib_resources is the backport for older Python
# versions. Normally, we would attempt to import importlib.resources,
# and fall back to importlib_resources on ImportError.
#
# However, in this case we need the files attribute, which was only
# added in 3.9. Thus, we install importlib_resources as a library on
# 3.8 and try to import it here. If importlib_resources is *not*
# installed as a library, we assume we're on 3.9 or later, where we
# can use importlib.resources.files rather than
# importlib_resources.files.
#
# Confused yet?
try:
import importlib_resources as resources
except ImportError:
from importlib import resources

from tutor import hooks

Expand All @@ -31,9 +47,10 @@
hooks.Filters.CLI_COMMANDS.add_item(openstack_command)

# Add the "templates" folder as a template root
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
pkg_resources.resource_filename("tutoropenstack", "templates")
)
templates = resources.files('tutoropenstack') / 'templates'
with resources.as_file(templates) as path:
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(path)

# Render the "build" and "apps" folders
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
[
Expand All @@ -42,12 +59,7 @@
],
)
# Load patches from files
for path in glob(
os.path.join(
pkg_resources.resource_filename("tutoropenstack", "patches"),
"*",
)
):
for path in resources.files('tutoropenstack.patches').iterdir():
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 0a5a7b7

Please sign in to comment.