optionsinstall=python_setup
apycot statussuccess
branchdefault
keep_archiveno
for environmentcommon env

recipe information

# an apycot recipe that run tox for a python project
import os
from os.path import join
import sys
import hglib
import json

from checkers.apycot import python # trigger registration
from apycotlib import Command, narvalactions as na, SUCCESS, ERROR


with na.apycot_environment(plan) as test:
    os.environ.pop('NO_SETUPTOOLS', None) # ensure we do not have this env var for venv setup

    os.environ['HGRCPATH'] = os.devnull
    configs = [('ui.username', 'narval'),
               ('phases.publish', 'False'),
              ]
    repo = test.environment['repository']
    dst_dir = join(test.tmpdir, 'src', str(repo['eid']))
    source_url = repo['source_url']
    rev = test.texec['branch']
    if not os.path.exists(dst_dir):
        os.makedirs(dst_dir)
    hglib.clone(source_url, dst_dir, updaterev=rev)

    # link the current test execution with the revision 
    cset = hglib.open(dst_dir).parents()[0].node[:12]
    test.writer.raw(source_url, cset, 'revision')

    # write a default tox fine if not provided by the project
    os.chdir(dst_dir)
    if not os.path.exists('tox.ini'):
        open('tox.ini', 'wb').write('''[tox]
envlist=py27,py34
[testenv]
commands=pytest
''')
    
    toxcmd = ['python2', '-m', 'tox', '--result-json=tox-results.json']
    if test.options.get('system-site-packages', '').lower() in ('yes', 'y', 'ok', '1', 'true'):
        toxcmd.append('--sitepackages')
    if test.options.get('recreate', '').lower() in ('yes', 'y', 'ok', '1', 'true'):
        toxcmd.append('--recreate')
    if test.options.get('envlist', ''):
        toxcmd.extend(['--envlist', test.options['envlist']]) # XXX should sanitize this

    toxw = test.writer.make_check_writer()
    try:
        toxw.start(None, 'tox')
        Command(toxw, toxcmd, raises=True, cwd=dst_dir).run()
        status = SUCCESS
    except Exception as exc:
        msg = 'Error while running checker tox: %s'
        toxw.fatal(msg, exc, tb=True)
        status = ERROR
    finally:
        try:
            with open('tox-results.json') as fresult:
                results = json.load(fresult)
        except:
            results = None
        if results:
            for k in ('platform', 'host', 'toxversion', 'reportversion'):
                toxw.raw(k, results[k], 'infos')
        toxw.end(status)

    if results:
        for k, tenv in results['testenvs'].items():
            toxw = test.writer.make_check_writer()
            toxw.start(None, k)
            try:
                for tst in tenv['test']:
                    lvl = 'INFO' if tst['retcode'] == 0 else 'ERROR'
                    toxw.log(lvl, tst['output'], path=' '.join(tst['command']))
            finally:
                toxw.end(status)

version configuration

execution information

typelabelvalue
versionapycot3.4.2
log
severitypath or commandlinemessage
 DEBUG  
Set NO_SETUPTOOLS=u'1'
 DEBUG  
Set DISPLAY=u':1.0'
 DEBUG  
Set LC_ALL=u'fr_FR.UTF-8'
execution log
severitypath or commandlinemessage
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOengine.py133
fire transition start of https://www.logilab.org/6681351
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org
 INFOengine.py133
fire transition end of https://www.logilab.org/6681351
 INFOconnectionpool.py697
Starting new HTTPS connection (1): www.logilab.org