From 92f911d4a6b78b2dc14594be9478dca29e1aa16b Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 5 Dec 2023 15:12:55 +0100 Subject: [PATCH 1/2] 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() From 530670ecee78269ae3679117d3e49bb5f314e285 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 5 Dec 2023 15:25:03 +0100 Subject: [PATCH 2/2] replace one more use of `imp` --- DDCore/python/dd4hep_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DDCore/python/dd4hep_base.py b/DDCore/python/dd4hep_base.py index e42723c2b..3d5073c8d 100644 --- a/DDCore/python/dd4hep_base.py +++ b/DDCore/python/dd4hep_base.py @@ -11,6 +11,7 @@ from __future__ import absolute_import, unicode_literals import cppyy import importlib +import types import logging @@ -155,7 +156,7 @@ def unicode_2_string(value): tools = dd4hep.tools align = dd4hep.align detail = dd4hep.detail -units = imp.new_module('units') +units = types.ModuleType('units') # --------------------------------------------------------------------------- import_namespace_item('tools', 'Evaluator') # ---------------------------------------------------------------------------