Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace find_module and load_module for Python 3.12 compatibility #58

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hepdata_converter/parsers/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading