recipes/apycot.python.venv.quick.py
author David Douard <david.douard@logilab.fr>
Tue, 13 Jan 2015 14:19:00 +0100
changeset 1783 e3aad84adf03
parent 1769 8e817371cba1
permissions -rw-r--r--
[pkg] prepare 4.0.0

# an apycot recipe that run unit tests for python projects
import os
from os.path import join
import sys

from checkers.apycot import python # trigger registration
from apycotlib import Command, narvalactions as na
# `plan` (narvalbot.engine.Plan) exists in the globals

with na.apycot_environment(plan) as test:
    # setup a virtualenv
    Command(test.writer, ['virtualenv', '--system-site-packages', test.tmpdir], raises=True).run()
    os.environ['PATH'] = ':'.join([join(test.tmpdir, 'bin'), os.environ['PATH']])
    os.environ['VIRTUAL_ENV'] = test.tmpdir
    # for each source of the source configuration, we need the URL of
    # the source repo, the changeset to use, the recipes to use to
    # make the checkout then the install, and the eid of the
    # Repository
    for cset, url, repoeid, checkout, setup in test.src_configuration():
        # we clone each repo in a dedicated directory (ensure there is
        # no collision)
        src = join(test.tmpdir, 'src', str(repoeid))
        # then execute the checkout (clone + up to cset)
        test.exec_recipe(checkout, rev=cset,
                         dst_dir=src,
                         source_url=url)
        # now perform the setup process (build and install)
        test.exec_recipe(setup,
                         test=test,
                         wdir=src)
    # we can now run the checkers
    repoeid = test.penvironment['repository']['eid']
    test.set_project_path(join(test.tmpdir, 'src', str(repoeid)))
    checker, status = test.run_checker('pyunit')