# Path: starterpyth/log.py
# def display(text, color=None, bold=False, newline=True):
#     if not isinstance(text, text_type):
#         text = text.decode('utf-8')
#     if bold and color:
#         text = u("\033[1;{0}m{1}\033[0m").format(color, text)
#     text = u("\033[{0}m{1}\033[0m").format(color, text)
#     if newline:
#         text += u('\n')
#     end = u('')
#     if __encode_stdout:
#         text = text.encode('utf-8')
#         end = b('')
#     print_(text, end=end)
# 
# GREEN = '32'
# 
# YELLOW = '33'
# 
# Path: starterpyth/core.py
# def load_module(modulename):
#     parents = modulename.split('.')
#     path = sys.path
#     module = None
#     abs_module_name = ''
#     cwd = os.getcwd()
#     for module_name in parents:
#         (file_, pathname, description) = imp.find_module(module_name, path)
#         name_to_import = abs_module_name + module_name
#         if name_to_import in sys.modules:
#             module = sys.modules[name_to_import]
#         else:
#             module = imp.load_module(name_to_import, file_, pathname, description)
#         path = [os.path.dirname(module.__file__)]
#         abs_module_name += module_name + '.'
#     os.chdir(cwd)
#     return module


import os
import doctest
from setuptools import find_packages
from starterpyth.log import display, GREEN, YELLOW
from starterpyth.core import load_module
from distutils.core import Command
  python setup.py doc_test

"""

__author__ = 'Matthieu Gallet'


class DocTest(Command):
    description = 'Run examples provided in docstrings'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        module_names = find_packages()
        for module_name in module_names:
            module = load_module(module_name)
            display('Processing %s.' % module_name, color=YELLOW)
            doctest.testmod(module)
            module_root = os.path.dirname(module.__file__)
            for filename in os.listdir(module_root):
                basename, sep, ext = filename.rpartition('.')
                if ext != 'py' or filename == '__init__.py':
                    continue
                submodule_name = '%s.%s' % (module_name, basename)
                try:

# Path: starterpyth/log.py
# def display(text, color=None, bold=False, newline=True):
#     if not isinstance(text, text_type):
#         text = text.decode('utf-8')
#     if bold and color:
#         text = u("\033[1;{0}m{1}\033[0m").format(color, text)
#     text = u("\033[{0}m{1}\033[0m").format(color, text)
#     if newline:
#         text += u('\n')
#     end = u('')
#     if __encode_stdout:
#         text = text.encode('utf-8')
#         end = b('')
#     print_(text, end=end)
# 
# GREEN = '32'
# 
# YELLOW = '33'
# 
# Path: starterpyth/core.py
# def load_module(modulename):
#     parents = modulename.split('.')
#     path = sys.path
#     module = None
#     abs_module_name = ''
#     cwd = os.getcwd()
#     for module_name in parents:
#         (file_, pathname, description) = imp.find_module(module_name, path)
#         name_to_import = abs_module_name + module_name
#         if name_to_import in sys.modules:
#             module = sys.modules[name_to_import]
#         else:
#             module = imp.load_module(name_to_import, file_, pathname, description)
#         path = [os.path.dirname(module.__file__)]
#         abs_module_name += module_name + '.'
#     os.chdir(cwd)
#     return module


# Path: starterpyth/commands/doc_test.py
import os
import doctest
from setuptools import find_packages
from starterpyth.log import display, GREEN, YELLOW
from starterpyth.core import load_module
from distutils.core import Command

  python setup.py doc_test

"""

__author__ = 'Matthieu Gallet'


class DocTest(Command):
    description = 'Run examples provided in docstrings'
    user_options = []

    def initialize_options(self):
        pass

    def finalize_options(self):
        pass

    def run(self):
        module_names = find_packages()
        for module_name in module_names:
            module = load_module(module_name)
            display('Processing %s.' % module_name, color=YELLOW)
            doctest.testmod(module)
            module_root = os.path.dirname(module.__file__)
            for filename in os.listdir(module_root):
                basename, sep, ext = filename.rpartition('.')
                if ext != 'py' or filename == '__init__.py':
                    continue
                submodule_name = '%s.%s' % (module_name, basename)
                try:

                    module = load_module(submodule_name)