# Path: sibilant/module.py
# def init_module(module, source_stream,
#                 builtins=None, filename=None, defaults=None,
#                 reader=None, compiler=None, compiler_factory=None,
#                 compiler_factory_params=None,
#                 evaluator=None):
# 
#     """
#     Initializes a module object for use with sibilant.
# 
#     The module can either be an object, or a MutableMapping instance
#     such as a dict. If it is a mapping, then a new FakeModule will be
#     creating to act as an object wrapper for the mapping.
# 
#     Returns the module object or the FakeModule that was created.
#     """
# 
#     # while FakeModule can wrap another object as needed, we want to
#     # preserve the object we're passed in this case, and so only wrap
#     # MutableMappings.
#     if isinstance(module, MutableMapping):
#         module = fake_module_from_env(module)
# 
#     if defaults:
#         module.__dict__.update(defaults)
# 
#     if source_stream and not filename:
#         filename = source_stream.filename
# 
#     if filename:
#         module.__file__ = filename
# 
#         modpath = split(filename)
#         if modpath[1].startswith("__init__."):
#             module.__path__ = modpath[:1]
# 
#     module.__stream__ = source_stream
# 
#     if builtins is None:
#         import sibilant.builtins as builtins
#     module.__builtins__ = builtins
# 
#     if reader:
#         module.__reader__ = reader
# 
#     if compiler:
#         module.__compiler__ = compiler
# 
#     if compiler_factory:
#         module.__compiler_factory__ = compiler_factory
# 
#     if compiler_factory_params:
#         module.__compiler_factory_params__ = compiler_factory_params
# 
#     if evaluator:
#         module.__evaluator__ = evaluator
# 
#     return module
# 
# def load_module(module, parse_time=parse_time,
#                 compile_time=compile_time, run_time=run_time):
# 
#     """
#     Parse, compile, and evaluate all of the expressions in a module.
#     """
# 
#     while True:
#         source_expr = parse_time(module)
#         if source_expr is None:
#             break
# 
#         code_obj = compile_time(module, source_expr)
#         run_time(module, code_obj)
# 
# Path: sibilant/parse.py
# def source_str(source_str, filename, auto_skip_exec=True,
#                line_no=1, col_no=0):
#     return SourceStream(StringIO(source_str), filename,
#                         auto_skip_exec=auto_skip_exec)


import sys
from importlib.abc import FileLoader
from importlib.machinery import FileFinder, PathFinder
from os import getcwd
from .module import init_module, load_module
from .parse import source_str
                # a valid directory later on.
                return None
        try:
            finder = path_importer_cache[path]
        except KeyError:
            finder = cls._path_hooks(path)
            path_importer_cache[path] = finder
        return finder


class SibilantSourceFileLoader(FileLoader):


    def create_module(self, spec):
        # return None to let the Python system allocate its own
        # preferred module type
        return None


    def get_source(self, fullname):
        # with open(self.get_filename(fullname), "rt") as sf:
        #    data = sf.read()
        # return data

        return self.get_data(self.get_filename(fullname)).decode("utf8")


    def exec_module(self, module):
        name = module.__name__
        filename = self.get_filename(name)

# Path: sibilant/module.py
# def init_module(module, source_stream,
#                 builtins=None, filename=None, defaults=None,
#                 reader=None, compiler=None, compiler_factory=None,
#                 compiler_factory_params=None,
#                 evaluator=None):
# 
#     """
#     Initializes a module object for use with sibilant.
# 
#     The module can either be an object, or a MutableMapping instance
#     such as a dict. If it is a mapping, then a new FakeModule will be
#     creating to act as an object wrapper for the mapping.
# 
#     Returns the module object or the FakeModule that was created.
#     """
# 
#     # while FakeModule can wrap another object as needed, we want to
#     # preserve the object we're passed in this case, and so only wrap
#     # MutableMappings.
#     if isinstance(module, MutableMapping):
#         module = fake_module_from_env(module)
# 
#     if defaults:
#         module.__dict__.update(defaults)
# 
#     if source_stream and not filename:
#         filename = source_stream.filename
# 
#     if filename:
#         module.__file__ = filename
# 
#         modpath = split(filename)
#         if modpath[1].startswith("__init__."):
#             module.__path__ = modpath[:1]
# 
#     module.__stream__ = source_stream
# 
#     if builtins is None:
#         import sibilant.builtins as builtins
#     module.__builtins__ = builtins
# 
#     if reader:
#         module.__reader__ = reader
# 
#     if compiler:
#         module.__compiler__ = compiler
# 
#     if compiler_factory:
#         module.__compiler_factory__ = compiler_factory
# 
#     if compiler_factory_params:
#         module.__compiler_factory_params__ = compiler_factory_params
# 
#     if evaluator:
#         module.__evaluator__ = evaluator
# 
#     return module
# 
# def load_module(module, parse_time=parse_time,
#                 compile_time=compile_time, run_time=run_time):
# 
#     """
#     Parse, compile, and evaluate all of the expressions in a module.
#     """
# 
#     while True:
#         source_expr = parse_time(module)
#         if source_expr is None:
#             break
# 
#         code_obj = compile_time(module, source_expr)
#         run_time(module, code_obj)
# 
# Path: sibilant/parse.py
# def source_str(source_str, filename, auto_skip_exec=True,
#                line_no=1, col_no=0):
#     return SourceStream(StringIO(source_str), filename,
#                         auto_skip_exec=auto_skip_exec)


# Path: sibilant/importlib.py
import sys
from importlib.abc import FileLoader
from importlib.machinery import FileFinder, PathFinder
from os import getcwd
from .module import init_module, load_module
from .parse import source_str

                # a valid directory later on.
                return None
        try:
            finder = path_importer_cache[path]
        except KeyError:
            finder = cls._path_hooks(path)
            path_importer_cache[path] = finder
        return finder


class SibilantSourceFileLoader(FileLoader):


    def create_module(self, spec):
        # return None to let the Python system allocate its own
        # preferred module type
        return None


    def get_source(self, fullname):
        # with open(self.get_filename(fullname), "rt") as sf:
        #    data = sf.read()
        # return data

        return self.get_data(self.get_filename(fullname)).decode("utf8")


    def exec_module(self, module):
        name = module.__name__
        filename = self.get_filename(name)

        source_stream = source_str(self.get_source(name), filename=filename)