# logger print("%s: %s" % (fn.name, doc))
            if doc is None:
                continue
            ndocs += 0.75
            if "args:" in doc:
                ndocs += 0.125
            else:
                comment("%s has no 'args:'" % fn.name)
            if "returns:" in doc:
                ndocs += 0.125
            else:
                comment("%s has no 'returns:'" % fn.name)
    if ndocs/nfns >= 0.8:
        comment("Good docstring coverage")
    return ndocs/nfns


def comment_density(code, comment):
    lines, nlines = code.split("\n"), len(code.split("\n"))
    inline_comments = sum([1 if "#" in line else 0 for line in lines])
    return 1.0 if inline_comments > 3 else 0.8 if inline_comments > 0 else 0.5


def examine_descriptiveness(code, comment):
    return {
        "inline comments": comment_density(code, comment),
        "docstring comments": docstring_check(code, comment)
    }
# create the metric
Descriptiveness = create_metric("descriptiveness", examine_descriptiveness)
from subprocess import PIPE
from subprocess import STDOUT
from subprocess import Popen as process
from metric import create_metric

temp_dir = os.getenv('temp', "./")
temp_file = "{tmp}/lintable.py"


def lint(code, comment):
    # write input code to tmp file
    fp = temp_file.format(tmp=temp_dir)
    with open(fp, "w") as fh:
        fh.write(code)
        fh.close()

    # lint it
    out, err = process(["pep8", "--count", abspath(fp)],
                       stdout=PIPE,
                       stderr=STDOUT).communicate()

    if out == b'':
        comment("Good adherence to PEP8")
        return 1
    else:
        comment(out)
        return 1 - len(str(out).split("\n")) / len(code.split("\n"))

# create the metric
Formatting = create_metric("formatting", lint)