Merge fix for #4126 (branch 'gh-4126--py-3.15')

refactor module loading to use exec_module: deprecated load_module is removed in py-3.15;
closes gh-4126
This commit is contained in:
sebres 2026-01-01 21:53:09 +01:00 committed by sebres
commit 948e923589
3 changed files with 10 additions and 6 deletions

View file

@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13', '3.14.0-rc.2', pypy3.11]
python-version: [3.8, 3.9, '3.10', '3.11', '3.12', '3.13', '3.14', '3.15.0-alpha.3', pypy3.11]
fail-fast: false
# Steps represent a sequence of tasks that will be executed as part of the job
steps:

View file

@ -29,6 +29,7 @@ import subprocess
import sys
from threading import Lock
import time
import types
from ..helpers import getLogger, _merge_dicts, uni_decode
from collections import OrderedDict
@ -352,6 +353,7 @@ class Utils():
def load_python_module(pythonModule):
pythonModuleName = os.path.splitext(
os.path.basename(pythonModule))[0]
mod = importlib.machinery.SourceFileLoader(
pythonModuleName, pythonModule).load_module()
ldr = importlib.machinery.SourceFileLoader(pythonModuleName, pythonModule)
mod = types.ModuleType(ldr.name)
ldr.exec_module(mod)
return mod

View file

@ -22,6 +22,7 @@ import threading
import unittest
import re
import sys
import types
import importlib
from ..dummyjail import DummyJail
@ -296,10 +297,11 @@ try:
self.jail = DummyJail()
pythonModule = os.path.join(CONFIG_DIR, "action.d", "smtp.py")
pythonModuleName = os.path.basename(pythonModule.rstrip(".py"))
customActionModule = importlib.machinery.SourceFileLoader(
pythonModuleName, pythonModule).load_module()
ldr = importlib.machinery.SourceFileLoader(pythonModuleName, pythonModule)
mod = types.ModuleType(ldr.name)
ldr.exec_module(mod)
self.action = customActionModule.Action(
self.action = mod.Action(
self.jail, "test", host="localhost:%i" % self.port)
self.action.ssl = True