Skip to content

Commit

Permalink
Merge pull request #58 from HEPData/replace_find_module
Browse files Browse the repository at this point in the history
Replace `find_module` and `load_module` for Python 3.12 compatibilty
  • Loading branch information
GraemeWatt committed Mar 11, 2024
2 parents 26658e4 + 033f05a commit 1e5b10f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion hepdata_converter/parsers/__init__.py
Expand Up @@ -7,6 +7,7 @@

import pkgutil
import inspect
from importlib.util import module_from_spec


class BadFormat(Exception):
Expand Down Expand Up @@ -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('__'):
Expand Down
5 changes: 4 additions & 1 deletion hepdata_converter/writers/__init__.py
Expand Up @@ -6,6 +6,7 @@
__all__ = []

import abc
from importlib.util import module_from_spec


class Writer(GetConcreteSubclassMixin, OptionInitMixin, metaclass=abc.ABCMeta):
Expand Down Expand Up @@ -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('__'):
Expand Down

0 comments on commit 1e5b10f

Please sign in to comment.