import os

import pydevd_pycharm


def import_pydevd(loader_path, port, suspend=False):
    # type: (str, int, bool) -> None
    if "DEBUG" not in os.environ:
        return

    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(
            host="localhost",
            port=port,
            suspend=suspend,
            stdout_to_server=True,
            stderr_to_server=True,
        )
