add a quick recipe that uses virtualenv draft
authorDavid Douard <david.douard@logilab.fr>
Fri, 14 Nov 2014 12:55:15 +0100
changeset 1760 db82548222eb
parent 1759 b9915807bddb
child 1761 0c0c9c026299
add a quick recipe that uses virtualenv also rename ATest.dependencie in src_configuration
_apycotlib/atest.py
recipes/apycot.quick.py
recipes/apycot.setup.distutils.py
recipes/apycot.venv.quick.py
--- a/_apycotlib/atest.py	Sun Oct 26 00:26:31 2014 +0200
+++ b/_apycotlib/atest.py	Fri Nov 14 12:55:15 2014 +0100
@@ -88,6 +88,33 @@
 
     # resource accessors #######################################################
 
+    def src_configuration(self):
+        '''Return the sources configuration needed for setting the
+        project environment in place for testing.
+
+        Return a list of (cset, url, repo eid, checkout recipe, setup recipe)
+
+        cset: the changeset to consider
+        url: the URL of the repository to clone
+        repoeid: the EID of the Repository entity
+        checkout recpe: the name of the Recipe to be used to perform the checkout
+                        (clone and update to given cset)
+        setup recipe: the name of the recipe to be used to make the installation
+        '''
+        for pe in self.writer.cnxh.rql('Any E WHERE E eid %s' % self.texec['eid'],
+                                       vid='apycot.get_dependencies').json()[0]:
+            repoeid = pe['repository']['eid']
+            repourl = pe['repository']['source_url']
+            co_rcp = self.writer.cnxh.rql('Any RN WHERE REPO eid %(eid)s, '
+                                          'REPO checkout_recipe R, R name RN' %
+                                          {'eid': repoeid}).json()[0][0]
+            setup_rcp = self.writer.cnxh.rql('Any RN WHERE PE eid %(eid)s, '
+                                             'PE setup_recipe R, R name RN' %
+                                             {'eid': pe['eid']}).json()[0][0]
+            cset = self.texec['branch']
+            yield cset, repourl, repoeid, co_rcp, setup_rcp
+
+
     def get_entity(self, eid):
         """Retrieve the entity from cw"""
         return self.writer.cnxh.rql('Any E WHERE E eid %s' % eid,
--- a/recipes/apycot.quick.py	Sun Oct 26 00:26:31 2014 +0200
+++ b/recipes/apycot.quick.py	Fri Nov 14 12:55:15 2014 +0100
@@ -8,11 +8,15 @@
 # `plan` (narvalbot.engine.Plan) exists in the globals
 
 with na.apycot_environment(plan) as test:
-    for cset, url, repoeid, checkout, setup in test.dependencies():
-        # first need to retrieve the sources of the dependency
-        # use the correct recipe to make the checkout and ensure the working
-        # directory is at the selected revision
+    # 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)
@@ -21,7 +25,7 @@
                          test=test,
                          prefix=test.tmpdir,
                          wdir=src)
-
+    # we can now run the checkers
     repoeid = test.penvironment['repository']['eid']
     checker, status = test.run_checker('pyunit',
                                    path=join(test.tmpdir, 'src', str(repoeid)))
--- a/recipes/apycot.setup.distutils.py	Sun Oct 26 00:26:31 2014 +0200
+++ b/recipes/apycot.setup.distutils.py	Fri Nov 14 12:55:15 2014 +0100
@@ -7,19 +7,24 @@
 from os.path import join
 from apycotlib import Command, SUCCESS
 
-# ensure environment variables are OK
-test.update_env(wdir, 'PATH',
-                os.pathsep.join((join(prefix, 'sbin'), join(wdir, 'sbin'),)),
-                os.pathsep)
-test.update_env(wdir, 'PYTHONPATH',
-                join(prefix, 'lib', 'python'),
-                os.pathsep)
-test.update_env(wdir, 'LD_LIBRARY_PATH',
-                join(prefix, 'lib'),
-                os.pathsep)
+cmdargs = ['python', 'setup.py', 'install']
+try:
+    assert prefix is not None
+    test.writer.info('Installing with prefix=%s' % prefix)
+    # ensure environment variables are OK
+    test.update_env(wdir, 'PATH',
+                    os.pathsep.join((join(prefix, 'sbin'), join(wdir, 'sbin'),)),
+                    os.pathsep)
+    test.update_env(wdir, 'PYTHONPATH',
+                    join(prefix, 'lib', 'python'),
+                    os.pathsep)
+    test.update_env(wdir, 'LD_LIBRARY_PATH',
+                    join(prefix, 'lib'),
+                    os.pathsep)
+    cmdargs.extend(['--home', prefix])
+except:
+    test.writer.warning('No prefix given, hope you have set up a virtualenv...')
 
-test.writer.warning('Installing with prefix=%s' % prefix)
-cmdargs = ['python', 'setup.py', 'install', '--home', prefix]
 st = Command(test.writer, cmdargs, raises=True, cwd=wdir).run()
 if st == SUCCESS:
     test.writer.info('Installation successfull')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/recipes/apycot.venv.quick.py	Fri Nov 14 12:55:15 2014 +0100
@@ -0,0 +1,34 @@
+# 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']
+    checker, status = test.run_checker('pyunit',
+                                   path=join(test.tmpdir, 'src', str(repoeid)))