Revision 9209c192cab7766d1b57dcf98b806c888a0492f9 authored by Mikko Korpela on 28 February 2012, 11:42:16 UTC, committed by Mikko Korpela on 28 February 2012, 11:42:16 UTC
1 parent e402cb8
Raw File
pavement.py
import os
from os.path import join, isdir, isfile
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_package_data


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 = bool(re.match('^(\d*\.){1,2}\d*$', VERSION))


def find_packages(where):
    def is_package(path):
        return isdir(path) and isfile(join(path ,'__init__.py'))
    pkgs = []
    for dirpath, dirs, _ in os.walk(where):
        for dirname in dirs:
            pkg_path = join(dirpath, dirname)
            if is_package(pkg_path):
                pkgs.append('.'.join((pkg_path.split(os.sep)[1:])))
    return pkgs


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       = 'Robot Framework Developers',
      author_email = 'robotframework-devel@googlegroups,com',
      url          = 'https://github.com/robotframework/RIDE/',
      package_dir  = {'' : str(SOURCE_DIR)},
      packages     = find_packages(str(SOURCE_DIR)) + \
                        ['robotide.lib.%s' % str(name) for name
                         in find_packages(str(LIB_SOURCE))],
      package_data = find_package_data(str(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"""
    pass

@task
@consume_args
def set_version(args):
    with open('VERSION.txt', 'w') as version_file:
        version_file.write(args[0])

@task
@needs('clean', '_prepare_build', 'generate_setup', 'minilib',
       'setuptools.command.sdist')
def sdist():
    """Creates source distribution with bundled dependencies"""
    _after_distribution()

@task
@needs('_windows', 'clean', '_prepare_build',
       'setuptools.command.bdist_wininst')
def wininst():
    """Creates Windows installer with bundled dependencies"""
    _after_distribution()

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

@task
def _prepare_build():
    _update_version()
    if not LIB_TARGET.exists():
        LIB_SOURCE.copytree(LIB_TARGET)

@task
def clean():
    _clean()

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

def _remove_bytecode_files():
    for d in SOURCE_DIR, TEST_DIR:
        for f in d.walkfiles(pattern='*.pyc'):
            os.remove(f)

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

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 _after_distribution():
    _release_notes()
    _announce()
    _clean(keep_dist=True)

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'
                   '&q=target%3A${version}&can=1')
    reader = csv.reader(urlopen(URL.substitute({'version': VERSION})))
    total_issues = 0
    writer = HtmlWriter(StringIO())
    writer.element('h2', 'Release notes for %s' % VERSION)
    writer.start('table', attrs={'border': '1'})
    for row in reader:
        if not row or row[1] == 'Task':
            continue
        row = row[:4]
        writer.start('tr')
        if reader.line_num == 1:
            row = [ '*%s*' % cell for cell in row ]
        else:
            row[0] = '<a href="http://code.google.com/p/robotframework-ride/'\
                     'issues/detail?id=%s">Issue %s</a>' % (row[0], row[0])
            total_issues += 1
        for cell in row:
            if reader.line_num == 1:
                cell = html_escape(cell, formatting=True)
            writer.element('td', cell, escape=False)
        writer.end('tr')
    writer.end('table')
    writer.element('p', 'Altogether %d issues.' % total_issues)
    return writer.output.getvalue()

def _update_release_notes_plugin(changes):
    plugin_path = os.path.join(ROBOTIDE_PACKAGE, 'application', 'releasenotes.py')
    content = open(plugin_path).read().rsplit('RELEASE_NOTES =', 1)[0]
    content += 'RELEASE_NOTES = """\n%s"""\n' % changes
    open(plugin_path, 'w').write(content)

def _announce():
    _log('Created:')
    for path in os.listdir(DIST_DIR):
        _log(os.path.abspath(os.path.join(DIST_DIR, path)))

def _log(msg):
    print msg
back to top