# Path: sumatra/dependency_finder/core.py
# def find_versions_from_versioncontrol(dependencies):
# def find_versions(dependencies, heuristics):
# def find_file(path, current_directory, search_dirs):
#     def __init__(self, name, path=None, version='unknown', diff='', source=None):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
# class BaseDependency(object):
# 
# Path: sumatra/core.py
# def get_encoding():
#     if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
#         encoding = sys.stdout.encoding
#     else:
#         encoding = locale.getpreferredencoding()
#         if encoding == '':  # getpreferredencoding does not guarantee to return an encoding
#             encoding = sys.getdefaultencoding()
#     return encoding


from builtins import str
from modulefinder import Module
from sumatra.dependency_finder import core
from ..core import get_encoding
    from types import ModuleType
    from sumatra import programs
import os
import sys
import textwrap
import warnings
import inspect
import logging
    import textwrap
    import subprocess
    import sys
        import distutils.sysconfig
        stdlib_path = distutils.sysconfig.get_python_lib(standard_lib=True)
        stdlib_paths = (stdlib_path,
                        os.path.join(stdlib_path, "plat-mac"),
                        os.path.join(stdlib_path, "plat-mac", "lib-scriptpackages"))
        exclude_stdlib = %s
        finder = ModuleFinder(path=sys.path, debug=%d, excludes=['jinja2.asyncsupport'])
        try:
            finder.run_script("%s")
        except Exception as ex:
            sys.stdout.write("Determining dependencies failed for some Python modules.")
        top_level_packages = {}
        for name, module in finder.modules.items():
            if module.__path__ and "." not in name:
                if not(exclude_stdlib and os.path.dirname(module.__path__[0]) in stdlib_paths):
                    top_level_packages[name] = module
        sys.stdout.write("%s" + str(top_level_packages))""" % (exclude_stdlib, int(debug), filename, SENTINEL))
    return run_script(executable_path, script)


def find_dependencies(filename, executable):
    """Return a list of Dependency objects representing all the top-level
       modules or packages imported (directly or indirectly) by a given Python file."""
    heuristics = [core.find_versions_from_versioncontrol,
                  lambda deps: find_versions_by_attribute(deps, executable),
                  find_versions_from_egg]
    logger.debug("Finding imported packages")
    packages = find_imported_packages(filename, executable.path, exclude_stdlib=True)
    dependencies = [Dependency.from_module(module, executable.path) for module in packages.values()]
    logger.debug("Finding versions of dependencies")

# Path: sumatra/dependency_finder/core.py
# def find_versions_from_versioncontrol(dependencies):
# def find_versions(dependencies, heuristics):
# def find_file(path, current_directory, search_dirs):
#     def __init__(self, name, path=None, version='unknown', diff='', source=None):
#     def __repr__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
# class BaseDependency(object):
# 
# Path: sumatra/core.py
# def get_encoding():
#     if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
#         encoding = sys.stdout.encoding
#     else:
#         encoding = locale.getpreferredencoding()
#         if encoding == '':  # getpreferredencoding does not guarantee to return an encoding
#             encoding = sys.getdefaultencoding()
#     return encoding


# Path: sumatra/dependency_finder/python.py
from builtins import str
from modulefinder import Module
from sumatra.dependency_finder import core
from ..core import get_encoding
    from types import ModuleType
    from sumatra import programs
import os
import sys
import textwrap
import warnings
import inspect
import logging
    import textwrap
    import subprocess
    import sys

        import distutils.sysconfig
        stdlib_path = distutils.sysconfig.get_python_lib(standard_lib=True)
        stdlib_paths = (stdlib_path,
                        os.path.join(stdlib_path, "plat-mac"),
                        os.path.join(stdlib_path, "plat-mac", "lib-scriptpackages"))
        exclude_stdlib = %s
        finder = ModuleFinder(path=sys.path, debug=%d, excludes=['jinja2.asyncsupport'])
        try:
            finder.run_script("%s")
        except Exception as ex:
            sys.stdout.write("Determining dependencies failed for some Python modules.")
        top_level_packages = {}
        for name, module in finder.modules.items():
            if module.__path__ and "." not in name:
                if not(exclude_stdlib and os.path.dirname(module.__path__[0]) in stdlib_paths):
                    top_level_packages[name] = module
        sys.stdout.write("%s" + str(top_level_packages))""" % (exclude_stdlib, int(debug), filename, SENTINEL))
    return run_script(executable_path, script)


def find_dependencies(filename, executable):
    """Return a list of Dependency objects representing all the top-level
       modules or packages imported (directly or indirectly) by a given Python file."""
    heuristics = [core.find_versions_from_versioncontrol,
                  lambda deps: find_versions_by_attribute(deps, executable),
                  find_versions_from_egg]
    logger.debug("Finding imported packages")
    packages = find_imported_packages(filename, executable.path, exclude_stdlib=True)
    dependencies = [Dependency.from_module(module, executable.path) for module in packages.values()]
    logger.debug("Finding versions of dependencies")

    return core.find_versions(dependencies, heuristics)