Skip to content

Commit

Permalink
#376: make avnav run on python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Oct 11, 2024
1 parent 91d77ac commit 065da40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 5 additions & 3 deletions server/handler/pluginhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# parts from this software (AIS decoding) are taken from the gpsd project
# so refer to this BSD licencse also (see ais.py) or omit ais.py
###############################################################################
import imp
import importlib.util
import inspect
import json
from typing import Dict, Any
Expand Down Expand Up @@ -656,9 +656,11 @@ def loadPluginFromDir(self, dir, name):
if not os.path.exists(moduleFile):
return None
try:
rt = imp.load_source(name, moduleFile)
spec = importlib.util.spec_from_file_location(name, moduleFile)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
AVNLog.info("loaded %s as %s", moduleFile, name)
return rt
return module
except:
AVNLog.error("unable to load %s:%s", moduleFile, traceback.format_exc())
return None
Expand Down
9 changes: 7 additions & 2 deletions server/test/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,19 @@ def addData(self,path,value):
return
print("@@DATA@@:%s->%s"%(path,value))

import os, glob, imp
import os, glob, importlib.util

def loadModule(name,path):
spec = importlib.util.spec_from_file_location(name, path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def loadModulesFromDir(dir,logger,prefix=''):
modules = {}
for path in glob.glob(os.path.join(dir, '[!_]*.py')):
name, ext = os.path.splitext(os.path.basename(path))
try:
modules[prefix+name] = imp.load_source(prefix + name, path)
modules[prefix+name] = loadModule(prefix + name, path)
logger.log("loaded %s as %s",path, prefix+name)
except:
logger.error("unable to load %s:%s",path,traceback.format_exc())
Expand Down

0 comments on commit 065da40

Please sign in to comment.