From 684174bd7566e145504d95c9e604797acf0881ff Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 5 Dec 2023 15:12:55 +0100 Subject: [PATCH] Replace imp module usage `imp` was removed in Python 3.12. --- DDCore/python/dd4hep_base.py | 6 +++--- DDDigi/python/dddigi.py | 4 ++-- DDG4/python/DDG4.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index b3f843380..e42723c2b 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -10,7 +10,7 @@ # ========================================================================== from __future__ import absolute_import, unicode_literals import cppyy -import imp +import importlib import logging @@ -35,8 +35,8 @@ def compileAClick(dictionary, g4=True): gSystem.AddIncludePath(inc) gSystem.AddLinkedLibs(lib) logger.info('Loading AClick %s', dictionary) - package = imp.find_module('DDG4') - dic = os.path.dirname(package[1]) + os.sep + dictionary + package_spec = importlib.util.find_spec('DDG4') + dic = os.path.dirname(package_spec.origin) + os.sep + dictionary gInterpreter.ProcessLine('.L ' + dic + '+') from ROOT import dd4hep as module return module diff --git a/DDDigi/python/dddigi.py b/DDDigi/python/dddigi.py index 4e68c842c..4b3ba73cb 100644 --- a/DDDigi/python/dddigi.py +++ b/DDDigi/python/dddigi.py @@ -94,8 +94,8 @@ def importConstants(description, namespace=None, debug=False): """ ns = current if namespace is not None and not hasattr(current, namespace): - import imp - m = imp.new_module('dddigi.' + namespace) + import types + m = types.ModuleType('dddigi.' + namespace) setattr(current, namespace, m) ns = m evaluator = dd4hep.g4Evaluator() diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index afccaa280..10584b35f 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -82,8 +82,8 @@ def importConstants(description, namespace=None, debug=False): """ ns = current if namespace is not None and not hasattr(current, namespace): - import imp - m = imp.new_module('DDG4.' + namespace) + import types + m = types.ModuleType('DDG4.' + namespace) setattr(current, namespace, m) ns = m evaluator = dd4hep.g4Evaluator()