Exemplo n.º 1
0
def create_test_ve(args):
    """create a virtual env to run tests in"""
    ve_path = tempfile.mkdtemp()
    proc.exe(['virtual'])
    proc.exe(['pip', 'install'] + glob.glob('dist/*.tar.gz'))

    def rm_test_ve():
        shutil.rmtree(ve_path)

    atexit.register(rm_test_ve)
    return ve_path
Exemplo n.º 2
0
def sdist(args):
    """create source distribution

    returns path
    :rtype: str
    """
    if os.path.exists('dist'):
        shutil.rmtree('dist')
    python = get_python_interpreter(args)
    proc.exe([python, 'setup.py', 'sdist', '--dev'])
    dist = os.listdir('dist')
    assert len(dist) == 1
    return os.path.abspath('dist/' + dist[0])
Exemplo n.º 3
0
def test(args):
    # save state of virtualenv on testing start
    freeze = subprocess.check_output(['pip', 'freeze', '--local'])
    open('.rve-pip-freeze.txt', 'w').write(freeze)

    setup_data = fpt.get_setup_data('setup.py')
    pkgs = setup_data['packages']
    pkgs = set(pkg.split('.')[0] for pkg in pkgs)
    pkgs = list(pkgs)

    if args.cfg['test.pytest']:
        LOG.info('running py.test')

        py_test = ['py.test']
        for pkg in pkgs:
            py_test.extend(('--cov', pkg))

        if args.ci:
            py_test += ['--cov-report', 'xml', '--junitxml=junit.xml']

        py_test.extend(pkgs)

        LOG.info('starting' + repr(py_test))
        proc.exe(py_test)

        if args.ci:
            proc.exe(['coverage', 'html'])

    if args.cfg['test.pylint']:
        LOG.info('running pylint')
        pylint = ['pylint', '-f', 'parseable'] + pkgs
        # maybe check pylint return code
        # http://lists.logilab.org/pipermail/python-projects/2009-November/002068.html
        pylint_out = proc.read(pylint, check_exit_code=False)
        open('pylint.out', 'w').write(pylint_out)

    if args.cfg['test.behave']:
        LOG.info('running behave')
        for path in args.cfg['test.behave.features']:
            proc.exe(['behave', path])
Exemplo n.º 4
0
def ci(args):
    args.ci = True

    # get info about package
    name = subprocess.check_output(['python', 'setup.py', '--name'])
    name = name.strip()
    if not PACKAGE_NAME.match(name):
        print 'invalid package name', name
        sys.exit(1)

    if args.branch:
        branch = args.branch
    else:
        branch = guess_current_branch()

    # read config
    LOG.info('Working path %s', os.path.abspath('.'))
    config_arg = ''
    cfg = get_config_path(args)
    if cfg:
        config_arg = '--config ' + shellquote(cfg)

    # setup(args)
    dist = sdist(args)

    if os.path.exists('tox.ini'):
        print("package tox.ini cannot be handled at this time")

    deps = ''
    if name != 'rsetup':
        # if we are not testing ourselves right now install rsetup into test environment
        deps = 'deps: rsetup>0.0.0.git0'

    tox = open('tox.ini', 'w')
    tox.write("""[tox]
envlist = {envist}

[testenv]
{deps}
sitepackages = {sitepackages}
commands =
  rve setup --ci {config_arg}
  pip install 'file://{path}#egg={name}[test]'
  rve test --ci {config_arg}
""".format(sitepackages=args.cfg['tox.sitepackages'],
           deps=deps,
           envist=args.cfg['envlist'],
           config_arg=config_arg,
           path=dist,
           name=name))
    tox.close()
    # delete tox dir if existent
    if os.path.exists('.tox'):
        shutil.rmtree('.tox')
    tox = ['tox']

    # if we are going to upload the result make sure we build with the same index
    # we are going to upload to
    if 'DEVPI_SERVER' in os.environ:
        devpi_branch = branch
        if devpi_branch not in ('master', 'staging', 'production'):
            # if we are not inside a "upload-branch" we default to "master" since
            # we probably are inside a dev-branch
            devpi_branch = 'master'
        tox.extend([
            '--set-home', '-i',
            '{}/{}/+simple'.format(os.environ['DEVPI_SERVER'].rstrip('/ '),
                                   'ci/' + devpi_branch)
        ])
    proc.exe(tox)

    ## alternative to tox:
    # initve(args)
    # setup(args)
    # test(args)

    # TODO
    # there will be more than one .rve-pip-freeze.txt be created if we run tox on multiple python versions

    ## upload result to devpi
    if branch in ('master', 'staging',
                  'production') and 'DEVPI_SERVER' in os.environ:
        LOG.info('uploading to devpi server')
        # on the ci the virtualenv containing rve might be read-only
        # the default build path (<venvpath>/build) is read-only
        # in this case as well so we specify an alternative build path
        build_dir = tempfile.mkdtemp('pip_build_')
        # proc.exe(['pip', 'install', '-U', 'devpi-client==1.2.1'])
        proc.exe(['devpi', 'use', os.environ['DEVPI_SERVER']])
        proc.exe([
            'devpi', 'login', os.environ['DEVPI_USER'], '--password',
            os.environ['DEVPI_PASSWORD']
        ])
        proc.exe(['devpi', 'use', os.environ['DEVPI_USER'] + '/' + branch])
        proc.exe(['devpi', 'upload', '--from-dir', 'dist'])
        # proc.exe(['pip', 'wheel', '-r', '.rve-pip-freeze.txt',
        #                           '-b', build_dir])
        # proc.exe(['devpi', 'upload', '--from-dir', 'wheelhouse'])
    else:
        LOG.info('DEVPI_SERVER environment variable not set. not uploading')

    if os.path.exists('/srv/pypi-requirements/'):
        fname = '{}.{}.txt'.format(name, branch)
        LOG.info('updating requirements-txt.r0k.de/' + fname)
        shutil.copy('.rve-pip-freeze.txt', '/srv/pypi-requirements/' + fname)
Exemplo n.º 5
0
def setup(args):
    # ensure we have tox installed
    pkgs = TEST_PKGS[:]
    # if args.cfg['test.behave']:
    #     pkgs.append('rbehave>=0.0.0.git0')
    proc.exe(['pip', 'install', '-I'] + pkgs)