<commit_before>import os
import csv
import re
from urllib2 import urlopen
from string import Template
from StringIO import StringIO
from paver.easy import *
from paver.setuputils import setup, find_packages, find_package_data


SOURCE_DIR = 'src'
ROOT_DIR = path(__file__).dirname()
DIST_DIR = ROOT_DIR/'dist'
BUILD_DIR = ROOT_DIR/'build'
ROBOTIDE_PACKAGE = ROOT_DIR/'src'/'robotide'
LIB_TARGET = ROBOTIDE_PACKAGE/'lib'
LIB_SOURCE = ROOT_DIR/'lib'
MANIFEST = ROOT_DIR/'MANIFEST.in'

VERSION = open(ROOT_DIR/'VERSION.txt').read().strip()
FINAL_RELEASE = re.match('^\d.\d*$', VERSION)

setup(name         = 'robotframework-ride',
      version      = VERSION,
      description  = 'RIDE :: Robot Framework Test Data Editor',
      long_description ="""
Robot Framework is a generic test automation framework for acceptance
level testing. RIDE is a lightweight and intuitive editor for Robot
Framework test data.
          """.strip(),
      license      = 'Apache License 2.0',
      keywords     = 'robotframework testing testautomation',
      platforms    = 'any',
      classifiers  = """
Development Status :: 4 - Beta
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python
Topic :: Software Development :: Testing
          """.strip().splitlines(),
      author       = '<NAME>',
      author_email = '<EMAIL>',
      url          = 'http://code.google.com/p/robotframework-ride',
      package_dir  = {'' : SOURCE_DIR},
      packages     = find_packages(SOURCE_DIR) + \
                        ['robotide.lib.%s' % str(name) for name
                         in find_packages(LIB_SOURCE)],
      package_data = find_package_data(SOURCE_DIR),
      # Robot Framework package data is not included, but RIDE does not need it.
      scripts      = ['src/bin/ride.py']
      )

@task
@consume_args
def run(args):
    """Start development version of RIDE"""
    _set_development_path()
    from robotide import main
    main(args)

@task
@consume_args
def test(args):
    """Run unit tests (requires nose and mock)"""
    assert _run_nose(args) is True

@task
def test_parallel():
    """Run tests with --processes 4"""
    excluded_packages = ['^ui', '^settings', '^editor']
    excluded_files = [os.path.join('utest', 'controller', 'test_resource_import'),
                      os.path.join('utest', 'controller', 'test_filecontrollers'),
                      os.path.join('utest', 'plugin', 'test_plugin_settings')]
    args = ['--processes', '4']
    for name in excluded_packages + excluded_files:
        args.extend(['--exclude', os.path.basename(name)])
    success = _run_nose(args)
    args = ['--tests']
    for pkg in excluded_packages:
        args.append(os.path.join('utest', pkg[1:]))
    args.extend(['%s.py' % name for name in excluded_files])
    assert _run_nose(args) and success is True

@task
@needs('_prepare_build', 'setuptools.command.install')
def install():
    """Installs development version and dependencies"""
    _clean()
    pass

@task
@needs('_prepare_build', 'generate_setup', 'minilib', 'setuptools.command.sdist')
def sdist():
    """Creates source distribution with bundled dependencies"""
    _announce()
    _clean(keep_dist=True)

@task
@needs('_windows', '_prepare_build', 'setuptools.command.bdist_wininst')
def wininst():
    """Creates Windows installer with bundled dependencies"""
    _announce()
    _clean(keep_dist=True)

@task
def _windows():
    if os.sep != '\\':
        sys.exit('Windows installers may only be created in Windows')

@task
def _prepare_build():
    _clean()
    _create_manifest()
    _update_version()
    _release_notes()
    LIB_SOURCE.copytree(LIB_TARGET)

def _clean(keep_dist=False):
    if not keep_dist:
        DIST_DIR.rmtree()
    BUILD_DIR.rmtree()
    LIB_TARGET.rmtree()
    for name in 'setup.py', 'paver-minilib.zip', 'MANIFEST.in':
        path(name).remove()

def _run_nose(args):
    from nose import run as noserun
    _set_development_path()
    return noserun(defaultTest=os.path.join(ROOT_DIR, 'utest'),
                   argv=['', '--m=^test_'] + args)

def _create_manifest():
    with open(MANIFEST, 'w') as output:
        output.write('recursive-include lib *.*')

def _update_version():
    _log('Using version %s from VERSION.txt' % VERSION)
    with (path(ROBOTIDE_PACKAGE)/'version.py').open('w') as version_file:
        version_file.write("""# Automatically generated by `pavement.py`.
VERSION = '%s'
""" % VERSION)

def _set_development_path():
    sys.path.insert(0, LIB_SOURCE)
    sys.path.insert(0, SOURCE_DIR)

def _release_notes():
    if FINAL_RELEASE:
        changes = _download_and_format_issues()
        _update_release_notes_plugin(changes)

def _download_and_format_issues():
    try:
        from robot.utils import HtmlWriter, html_escape
    except ImportError:
        sys.exit('creating release requires Robot Framework to be installed.')
    URL = Template('http://code.google.com/p/robotframework-ride/issues/csv?'
                   'sort=priority+type&colspec=ID%20Type%20Priority%20Summary'<commit_msg>pavement: remove bytecode files before running the tests<commit_after>import os
import csv
import re
from urllib2 import urlopen
from string import Template
from StringIO import StringIO
from paver.easy import *
from paver.setuputils import setup, find_packages, find_package_data
from paver import tasks


ROOT_DIR = path(__file__).dirname()
SOURCE_DIR = ROOT_DIR/'src'
TEST_DIR = ROOT_DIR/'utest'
DIST_DIR = ROOT_DIR/'dist'
BUILD_DIR = ROOT_DIR/'build'
ROBOTIDE_PACKAGE = ROOT_DIR/'src'/'robotide'
LIB_TARGET = ROBOTIDE_PACKAGE/'lib'
LIB_SOURCE = ROOT_DIR/'lib'
MANIFEST = ROOT_DIR/'MANIFEST.in'

VERSION = open(ROOT_DIR/'VERSION.txt').read().strip()
FINAL_RELEASE = re.match('^\d.\d*$', VERSION)

setup(name         = 'robotframework-ride',
      version      = VERSION,
      description  = 'RIDE :: Robot Framework Test Data Editor',
      long_description ="""
Robot Framework is a generic test automation framework for acceptance
level testing. RIDE is a lightweight and intuitive editor for Robot
Framework test data.
          """.strip(),
      license      = 'Apache License 2.0',
      keywords     = 'robotframework testing testautomation',
      platforms    = 'any',
      classifiers  = """
Development Status :: 4 - Beta
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python
Topic :: Software Development :: Testing
          """.strip().splitlines(),
      author       = '<NAME>',
      author_email = '<EMAIL>',
      url          = 'http://code.google.com/p/robotframework-ride',
      package_dir  = {'' : SOURCE_DIR},
      packages     = find_packages(SOURCE_DIR) + \
                        ['robotide.lib.%s' % str(name) for name
                         in find_packages(LIB_SOURCE)],
      package_data = find_package_data(SOURCE_DIR),
      # Robot Framework package data is not included, but RIDE does not need it.
      scripts      = ['src/bin/ride.py']
      )

@task
@consume_args
def run(args):
    """Start development version of RIDE"""
    _set_development_path()
    from robotide import main
    main(args)

@task
@consume_args
def test(args):
    """Run unit tests (requires nose and mock)"""
    _remove_bytecode_files()
    assert _run_nose(args) is True

@task
def test_parallel():
    """Run tests with --processes 4"""
    _remove_bytecode_files()
    excluded_packages = ['^ui', '^settings', '^editor']
    excluded_files = [os.path.join('utest', 'controller', 'test_resource_import'),
                      os.path.join('utest', 'controller', 'test_filecontrollers'),
                      os.path.join('utest', 'plugin', 'test_plugin_settings')]
    args = ['--processes', '4']
    for name in excluded_packages + excluded_files:
        args.extend(['--exclude', os.path.basename(name)])
    success = _run_nose(args)
    args = ['--tests']
    for pkg in excluded_packages:
        args.append(os.path.join('utest', pkg[1:]))
    args.extend(['%s.py' % name for name in excluded_files])
    assert _run_nose(args) and success is True

@task
@needs('_prepare_build', 'setuptools.command.install')
def install():
    """Installs development version and dependencies"""
    _clean()
    pass

@task
@needs('_prepare_build', 'generate_setup', 'minilib', 'setuptools.command.sdist')
def sdist():
    """Creates source distribution with bundled dependencies"""
    _announce()
    _clean(keep_dist=True)

@task
@needs('_windows', '_prepare_build', 'setuptools.command.bdist_wininst')
def wininst():
    """Creates Windows installer with bundled dependencies"""
    _announce()
    _clean(keep_dist=True)

@task
def _windows():
    if os.sep != '\\':
        sys.exit('Windows installers may only be created in Windows')

@task
def _prepare_build():
    _clean()
    _create_manifest()
    _update_version()
    _release_notes()
    LIB_SOURCE.copytree(LIB_TARGET)

def _clean(keep_dist=False):
    if not keep_dist:
        DIST_DIR.rmtree()
    BUILD_DIR.rmtree()
    LIB_TARGET.rmtree()
    for name in 'setup.py', 'paver-minilib.zip', 'MANIFEST.in':
        path(name).remove()

def _remove_bytecode_files():
    tasks.environment.quiet = True
    for d in SOURCE_DIR, TEST_DIR:
        for f in d.walkfiles(pattern='*.pyc'):
            f.remove()
    tasks.environment.quiet = False

def _run_nose(args):
    from nose import run as noserun
    _set_development_path()
    return noserun(defaultTest=TEST_DIR,
                   argv=['', '--m=^test_'] + args)

def _create_manifest():
    with open(MANIFEST, 'w') as output:
        output.write('recursive-include lib *.*')

def _update_version():
    _log('Using version %s from VERSION.txt' % VERSION)
    with (path(ROBOTIDE_PACKAGE)/'version.py').open('w') as version_file:
        version_file.write("""# Automatically generated by `pavement.py`.
VERSION = '%s'
""" % VERSION)

def _set_development_path():
    sys.path.insert(0, LIB_SOURCE)
    sys.path.insert(0, SOURCE_DIR)

def _release_notes():
    if FINAL_RELEASE:
        changes = _download_and_format_issues()
        _update_release_notes_plugin(changes)

def _download_and_format_issues():
    try:
        from robot.utils import HtmlWriter, html_escape
    except ImportError:
        sys.exit('creating release requires Robot Framework to be installed.')
    URL = Template('http://code.google.com/p/robotframework-ride/issues/csv?'
                   'sort=priority+type&colspec=ID%20Type%20Priority%20Summary'
{'fraction_non_alphanumeric': 0.12725203868765408, 'fraction_numerical': 0.002844680447563057, 'mean_word_length': 3.4092809364548495, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '285688', 'n_tokens_mistral': 3376, 'n_tokens_neox': 3277, 'n_words': 809}