<commit_before>#!/usr/bin/env python2.7

from pydep import *
import argparse

def debug():
    import pdb, traceback, code, sys
    def handle_exception(tp, val, tb):  # open up debugger on exception
        traceback.print_tb(tb)
        print 'ERROR:', val
        pdb.post_mortem(tb)
    sys.excepthook = handle_exception

def get_args():
    parser = argparse.ArgumentParser(description='Grab dependencies from a setup.py file')
    parser.add_argument('rootdir', help='path to root project directory')
    parser.add_argument('--debug', action='store_true', help='enable if you want to enable debugging stacktrace')
    parser.add_argument('--toplevel', action='store_true', help='enable if you want to print just top-level modules')
    return parser.parse_args()

if __name__ == '__main__':
    args = get_args()
    if args.debug:
        print '##### DEBUG ENABLED #####'
        debug()

    deps = import_tree_for_project(args.rootdir, ignore_stdlib=True, ignore_internal=True)

    if args.toplevel:
        for k in sorted(deps.children.keys()):
            print k
    else:
        deps.print_tree()<commit_msg>print error/debug to stderr<commit_after>#!/usr/bin/env python2.7

from pydep import *
import argparse
import sys

def debug():
    import pdb, traceback, code, sys
    def handle_exception(tp, val, tb):  # open up debugger on exception
        traceback.print_tb(tb)
        sys.stderr.write('ERROR: %s' % str(val))
        pdb.post_mortem(tb)
    sys.excepthook = handle_exception

def get_args():
    parser = argparse.ArgumentParser(description='Grab dependencies from a setup.py file')
    parser.add_argument('rootdir', help='path to root project directory')
    parser.add_argument('--debug', action='store_true', help='enable if you want to enable debugging stacktrace')
    parser.add_argument('--toplevel', action='store_true', help='enable if you want to print just top-level modules')
    return parser.parse_args()

if __name__ == '__main__':
    args = get_args()
    if args.debug:
        sys.stderr.write('##### DEBUG ENABLED #####\n')
        debug()

    deps = import_tree_for_project(args.rootdir, ignore_stdlib=True, ignore_internal=True)

    if args.toplevel:
        for k in sorted(deps.children.keys()):
            print k
    else:
        deps.print_tree()
{'fraction_non_alphanumeric': 0.12067474048442907, 'fraction_numerical': 0.0017301038062283738, 'mean_word_length': 3.4825581395348837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5342914', 'n_tokens_mistral': 726, 'n_tokens_neox': 713, 'n_words': 191}