Skip to content

Instantly share code, notes, and snippets.

@ResidentMario
Last active February 22, 2019 02:42
Show Gist options
  • Save ResidentMario/de0b533cab52bf5635418a04724b99a4 to your computer and use it in GitHub Desktop.
Save ResidentMario/de0b533cab52bf5635418a04724b99a4 to your computer and use it in GitHub Desktop.
from importlib.machinery import ModuleSpec
class DataPackageFinder:
"""
Data package module loader finder. This class sits on `sys.meta_path` and returns the
loader it knows for a given path, if it knows a compatible loader.
"""
@classmethod
def find_spec(cls, fullname, path=None, target=None):
"""
This functions is what gets executed by the loader.
"""
name_parts = fullname.split('.')
if name_parts[:2] != ['t4', 'data'] or len(name_parts) > 3:
return None
else:
return ModuleSpec(fullname, DataPackageImporter())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment