From 775fb145233a4dba0735f52c840f23b25a8607e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 14 Jan 2023 16:14:18 +0100 Subject: [PATCH] Replace find_module by find_spec find_module is deprecated since Python 3.4 but MetaPathFinder implements it for backwards compatibility. --- pygal/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pygal/__init__.py b/pygal/__init__.py index 304296c0..866401d8 100644 --- a/pygal/__init__.py +++ b/pygal/__init__.py @@ -28,6 +28,8 @@ import sys import traceback import warnings +from importlib.abc import MetaPathFinder +from importlib.util import spec_from_loader import pkg_resources @@ -80,14 +82,14 @@ CHARTS = list(CHARTS_BY_NAME.values()) -class PluginImportFixer(object): +class PluginImportFixer(MetaPathFinder): """ Allow external map plugins to be imported from pygal.maps package. It is a ``sys.meta_path`` loader. """ - def find_module(self, fullname, path=None): + def find_spec(self, fullname, path, target=None): """ Tell if the module to load can be loaded by the load_module function, ie: if it is a ``pygal.maps.*`` @@ -95,7 +97,7 @@ def find_module(self, fullname, path=None): """ if fullname.startswith('pygal.maps.') and hasattr( maps, fullname.split('.')[2]): - return self + return spec_from_loader(fullname, self) return None def load_module(self, name):