Skip to content
Open
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
8 changes: 5 additions & 3 deletions pygal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -80,22 +82,22 @@
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.*``
module.
"""
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):
Expand Down