import os

import pydevd_pycharm


def import_pydevd(loader_path, port, suspend=False):
    # type: (str, int, bool) -> None
    if "DEBUG" in os.environ:
        dir_path = os.path.dirname(os.path.realpath(loader_path))
        filename = os.path.join(dir_path, "debug.txt")
        if os.path.isfile(filename):
            pydevd_pycharm.settrace('localhost',
                                    port=port,
                                    suspend=suspend,
                                    stdoutToServer=True,
                                    stderrToServer=True)
