From 033f05a6539f94398ba198c5cce73e726db69ba9 Mon Sep 17 00:00:00 2001 From: Graeme Watt Date: Sun, 10 Mar 2024 19:40:46 +0000 Subject: [PATCH] global: replace find_module and load_module * find_module deprecated since Python 3.10 and removed in Python 3.12. * load_module deprecated since Python 3.4. --- hepdata_converter/parsers/__init__.py | 5 ++++- hepdata_converter/writers/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hepdata_converter/parsers/__init__.py b/hepdata_converter/parsers/__init__.py index 75836f9..74e07e6 100644 --- a/hepdata_converter/parsers/__init__.py +++ b/hepdata_converter/parsers/__init__.py @@ -7,6 +7,7 @@ import pkgutil import inspect +from importlib.util import module_from_spec class BadFormat(Exception): @@ -175,7 +176,9 @@ def parse(self, data_in, *args, **kwargs): # import all packages in the parsers package, so that Parser.get_specific_parser will recognise them for loader, name, is_pkg in pkgutil.walk_packages(__path__): - module = loader.find_module(name).load_module(name) + spec = loader.find_spec(name) + module = module_from_spec(spec) + spec.loader.exec_module(module) for name, value in inspect.getmembers(module): if name.startswith('__'): diff --git a/hepdata_converter/writers/__init__.py b/hepdata_converter/writers/__init__.py index 96624d0..d10fc86 100644 --- a/hepdata_converter/writers/__init__.py +++ b/hepdata_converter/writers/__init__.py @@ -6,6 +6,7 @@ __all__ = [] import abc +from importlib.util import module_from_spec class Writer(GetConcreteSubclassMixin, OptionInitMixin, metaclass=abc.ABCMeta): @@ -36,7 +37,9 @@ def write(self, data_in, data_out, *args, **kwargs): # import all packages in the parsers package, so that Writer.get_specific_writer will recognise them for loader, name, is_pkg in pkgutil.walk_packages(__path__): - module = loader.find_module(name).load_module(name) + spec = loader.find_spec(name) + module = module_from_spec(spec) + spec.loader.exec_module(module) for name, value in inspect.getmembers(module): if name.startswith('__'):