# Path: libraries/stack_meter.py
# class StackMeter:
#     """Reentrant context manager counting the reentrancy depth."""
# 
#     def __init__(self, depth=0):
#         super().__init__()
#         self.depth = depth
# 
#     def __enter__(self):
#         depth = self.depth
#         self.depth += 1
#         return depth
# 
#     def __exit__(self, *exc_info):
#         self.depth -= 1


import sublime
import sublime_plugin
import os
import threading
import builtins
import functools
import importlib
import sys
import types
from contextlib import contextmanager
from .stack_meter import StackMeter
@contextmanager
def importing_fromlist_aggresively(modules):
    orig___import__ = builtins.__import__

    @functools.wraps(orig___import__)
    def __import__(name, globals=None, locals=None, fromlist=(), level=0):
        module = orig___import__(name, globals, locals, fromlist, level)
        if fromlist and module.__name__ in modules:
            if '*' in fromlist:
                fromlist = list(fromlist)
                fromlist.remove('*')
                fromlist.extend(getattr(module, '__all__', []))
            for x in fromlist:
                if isinstance(getattr(module, x, None), types.ModuleType):
                    from_name = '{}.{}'.format(module.__name__, x)
                    if from_name in modules:
                        importlib.import_module(from_name)
        return module

    builtins.__import__ = __import__
    try:
        yield
    finally:
        builtins.__import__ = orig___import__


class FilterFinder:

    def __init__(self, modules):
        self._modules = modules

# Path: libraries/stack_meter.py
# class StackMeter:
#     """Reentrant context manager counting the reentrancy depth."""
# 
#     def __init__(self, depth=0):
#         super().__init__()
#         self.depth = depth
# 
#     def __enter__(self):
#         depth = self.depth
#         self.depth += 1
#         return depth
# 
#     def __exit__(self, *exc_info):
#         self.depth -= 1


# Path: libraries/reloader.py
import sublime
import sublime_plugin
import os
import threading
import builtins
import functools
import importlib
import sys
import types
from contextlib import contextmanager
from .stack_meter import StackMeter

@contextmanager
def importing_fromlist_aggresively(modules):
    orig___import__ = builtins.__import__

    @functools.wraps(orig___import__)
    def __import__(name, globals=None, locals=None, fromlist=(), level=0):
        module = orig___import__(name, globals, locals, fromlist, level)
        if fromlist and module.__name__ in modules:
            if '*' in fromlist:
                fromlist = list(fromlist)
                fromlist.remove('*')
                fromlist.extend(getattr(module, '__all__', []))
            for x in fromlist:
                if isinstance(getattr(module, x, None), types.ModuleType):
                    from_name = '{}.{}'.format(module.__name__, x)
                    if from_name in modules:
                        importlib.import_module(from_name)
        return module

    builtins.__import__ = __import__
    try:
        yield
    finally:
        builtins.__import__ = orig___import__


class FilterFinder:

    def __init__(self, modules):
        self._modules = modules

        self._stack_meter = StackMeter()