<commit_before>"""
Checking and reinstalling the external packages
"""
import os
import sys

if sys.platform =='win32':
    IS_WIN = True
else:
    IS_WIN = False
try:
    import setuptools
    print "==> setuptools-%s installed."% setuptools.__version__
    if setuptools.__version__ != '0.6c11':
        print "!!! Recommend to install 0.6c11." 
except:
    print "!!! setuptools-0.6c11 not installed."
try:
    import pyparsing
    print "==> pyparsing-%s installed."% pyparsing.__version__
    if pyparsing.__version__ != '1.5.5':
        print "!!! 1.5.5 recommended."
except:
    print "==> pyparsing-1.5.5 not installed."
try:
    import html5lib
    print "==> html5lib-%s installed."% html5lib.__version__
    if html5lib.__version__.count('0.95') > 0:
        print "!!! 0.95 recommended."
except:
    print "!!! html5lib-0.95 not installed."
try:
    import pyPdf
    print "==> pyPdf-%s installed."% pyPdf.__version__
    if pyPdf.__version__ != '1.13':
	print "!!! 1.13 recommended."
except:
    print "!!! pyPdf-1.13 not installed (optional)."
try:
    import reportlab
    print "==> reportlab-%s installed."% reportlab.__version__
    if reportlab.__version__ != '2.5':
        print "!!! 2.5 recommended"
except:
    print "!!! reportlab-2.5 not installed."
try:
    import lxml
    print "==> lxml-%s installed."% lxml.__version__
    if lxml.__version__ != '2.3':
        print "!!! 2.3 recommended"
except:
    print "!!! lxml-2.3 not installed."
try:
    import Image
    print "==> PIL-%s installed."% Image.VERSION
    if Image.VERSION != '1.1.7':
        print "!!! 1.1.7 recommended."
except:
    print "!!! PIL-1.1.7 not installed."
try:
    import pylint
    print "==> pylint installed."
except:
    print "!!! pylint not installed (optional)."
    #os.system("START /B C:\python26\Scripts\easy_install pylint==0.25.0")
try:
    import periodictable
    print "==> periodictable-%s installed."% periodictable.__version__
    if periodictable.__version__ != '1.3.0':
        print "!!! Recommend to install 1.3.0." 
except:
    print "!!! periodictable-1.3.0 is not installed."
try:
    import numpy
    print "==> numpy-%s installed."% numpy.__version__
    if numpy.__version__ != '1.6.1':
        print "==> Recommend to install 1.6.1 (1.5.1 for MAC)." 
except:
    print "!!! numpy-1.6.1 not installed (1.5.1 for MAC)."
try:
    import scipy
    print "==> scipy-%s installed."% scipy.__version__
    if scipy.__version__ != '0.10.1':
        print "!!! Recommend to install 0.10.1 (1.10.0 for MAC)." 
except:
    print "!!! scipy-0.10.1 not installed (1.10.0 for MAC)."
try:
    import wx
    print "==> wxpython-%s installed."% wx.__version__
    if wx.__version__ != '2.8.12.1':
        print "!!! Recommend to install unicode-2.8.12.1." 
except:
    print "!!! wxpython-unicode-2.8.12.1 not installed."
try:
    import matplotlib
    print "==> matplotlib-%s installed."% matplotlib.__version__
    if matplotlib.__version__ != '1.1.0':
        print "!!! Recommend to install 1.1.0 (1.0.1 for MAC) or higher." 
except:
    print "!!! matplotlib-1.1.0 not installed (1.0.1 for MAC)."
try:
    from ho import pisa
    if pisa.__version__ == '3.0.27':
        print "==> pisa-%s installed."% pisa.__version__
    else:
        print "!!! Incorrect version of pisa installed."
        print "!!! 3.0.27 required."
except:
    print "!!! pisa-3.0.27 not installed."
if IS_WIN:
    try:
        import pywin
        print "==> pywin32 installed."
    except:
        print "!!! pywin32 not installed. Please install pywin32-217."
    try:
        import py2exe
        print "==> py2exe-%s installed."% py2exe.__version__
        if py2exe.__version__ != '0.6.9':
            print "!!! Recommend to install 0.6.9." 
    except:
        print "!!! py2exe-0.6.9 not installed. Installing..."
    try:
        import comtypes
        print "==> comtypes-%s installed."% comtypes.__version__
        if comtypes.__version__ != '0.6.2':
            print "!!! Recommend to install 0.6.2." 
    except:
        print "!!! comtypes-0.6.2 not installed. Installing..."
    print "==> Require subversion = 1.6.0 or lower version."
    print "Installed:"
    os.system("CALL svn --version --quiet")
    print "==> Checking gcc compiler ( >= 4.2 required):"
    os.system("CALL gcc -v")
else:
    try:
        import py2app
        print "==> py2app-%s installed."% py2app.__version__
    except:
        print "!!! py2app not installed (optional for MAC bundling."
<commit_msg>Updated check_packages.py to determine packages in use.<commit_after>"""
Checking and reinstalling the external packages
"""
import os
import sys

common_required_package_list = {'setuptools':{'version':'0.6c11','import_name':'setuptools','test':'__version__'},
                'pyparsing':{'version':'1.5.5','import_name':'pyparsing','test':'__version__'},
                'html5lib':{'version':'0.95','import_name':'html5lib','test':'__version__'},
                'reportlab':{'version':'2.5','import_name':'reportlab','test':'Version'},
                'lxml':{'version':'2.3','import_name':'lxml.etree','test':'LXML_VERSION'},
                'PIL':{'version':'1.1.7','import_name':'Image','test':'VERSION'},
                'pylint':{'version':None,'import_name':'pylint','test':None},
                'periodictable':{'version':'1.3.0','import_name':'periodictable','test':'__version__'},
                'numpy':{'version':'1.6.1','import_name':'numpy','test':'__version__'},
                'scipy':{'version':'0.10.1','import_name':'scipy','test':'__version__'},
                'wx':{'version':'2.8.12.1','import_name':'wx','test':'__version__'},
                'matplotlib':{'version':'1.1.0','import_name':'matplotlib','test':'__version__'},
                'pisa':{'version':'3.0.28','import_name':'ho.pisa','test':'__version__'}

}
win_required_package_list = {'comtypes':{'version':'0.6.2','import_name':'comtypes','test':'__version__'},
                             'pywin':{'version':'217','import_name':'pywin','test':'__version__'},
                             'py2exe':{'version':'0.6.9','import_name':'py2exe','test':'__version__'}
}
mac_required_package_list = {'py2app':{'version':None,'import_name':'py2app','test':'__version__'}}

deprecated_package_list = {'pyPdf':{'version':'1.13','import_name':'pyPdf','test':'__version__'}}

print "Checking Required Package Versions...."
print
print "Common Packages"
for package_name,test_vals in common_required_package_list.iteritems():
    try:
        i = __import__(test_vals['import_name'],fromlist=[''])
        if test_vals['test'] == None:
            print "%s Installed (Unknown version)" % package_name
        elif package_name == 'lxml':
            verstring = str(getattr(i,'LXML_VERSION'))
            print "%s Version Installed: %s"% (package_name,verstring.replace(', ','.').lstrip('(').rstrip(')'))
        else:
            print "%s Version Installed: %s"% (package_name,getattr(i,test_vals['test']))
    except:
        print '%s NOT INSTALLED'% package_name

if sys.platform == 'win32':
    print
    print "Windows Specific Packages:"
    for package_name,test_vals in win_required_package_list.iteritems():
        try:
            i = __import__(test_vals['import_name'],fromlist=[''])
            print "%s Version Installed: %s"% (package_name,getattr(i,test_vals['test']))
        except:
            print '%s NOT INSTALLED'% package_name

if sys.platform == 'darwin':
    print
    print "MacOS Specific Packages:"
    for package_name,test_vals in mac_required_package_list.iteritems():
        try:
            i = __import__(test_vals['import_name'],fromlist=[''])
            print "%s Version Installed: %s"% (package_name,getattr(i,test_vals['test']))
        except:
            print '%s NOT INSTALLED'% package_name


print
print "Deprecated Packages"
print "You can remove these unless you need them for other reasons!"
for package_name,test_vals in deprecated_package_list.iteritems():
    try:
        i = __import__(test_vals['import_name'],fromlist=[''])
        if package_name == 'pyPdf':
            #pyPdf doesn't have the version number internally
            print 'pyPDF Installed (Version unknown)'
        else:
            print "%s Version Installed: %s"% (package_name,getattr(i,test_vals['test']))
    except:
        print '%s NOT INSTALLED'% package_name
{'fraction_non_alphanumeric': 0.169887854927225, 'fraction_numerical': 0.031018849916487713, 'mean_word_length': 3.0458494208494207, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 4, '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': '5677024', 'n_tokens_mistral': 2855, 'n_tokens_neox': 2694, 'n_words': 603}