[narval] ensure narval plugins can be imported (closes #3804730)
authorDavid Douard <david.douard@logilab.fr>
Wed, 14 May 2014 11:34:12 +0200
changeset 1515 2a12802efe66
parent 1514 9dd6abde81e7
child 1516 cb61ef3751db
[narval] ensure narval plugins can be imported (closes #3804730) both in tests, when run from sources and from installed packages
__init__.py
_narval/checkers/__init__.py
_narval/checkers/apycot/__init__.py
_narval/preprocessors/__init__.py
_narval/preprocessors/apycot/__init__.py
test/unittest_parser.py
testutils.py
--- a/__init__.py	Wed May 14 11:38:26 2014 +0200
+++ b/__init__.py	Wed May 14 11:34:12 2014 +0200
@@ -3,14 +3,3 @@
 ETYPE_NAME_MAP['TestConfigGroup'] = 'TestConfig'
 
 
-try:
-    # development version
-    import _apycotlib
-except ImportError:
-    pass
-else:
-    import sys
-    sys.modules['apycotlib'] = _apycotlib
-    from os.path import dirname, join
-    sys.path.append(join(dirname(__file__),'_apycotlib'))
-
--- a/_narval/checkers/__init__.py	Wed May 14 11:38:26 2014 +0200
+++ b/_narval/checkers/__init__.py	Wed May 14 11:34:12 2014 +0200
@@ -0,0 +1,20 @@
+# make it work in 'dev' mode: look for checkers in known cubes
+
+try:
+    import narvalbot
+except:
+    from cubes.narval import narvalbot
+    import sys
+    sys.modules['narvalbot'] = narvalbot
+
+if narvalbot.MODE == 'dev':
+    # we are running from sources, cubicweb *should* be available,
+    # let's use it as starting point to look for cubes in which there
+    # is a _narval directory
+    import os, os.path as osp
+    from cubicweb import CW_SOFTWARE_ROOT
+    cubesdir = osp.join(CW_SOFTWARE_ROOT, '..', 'cubes')
+    for cube in os.listdir(cubesdir):
+        pluginsdir = osp.abspath(osp.join(cubesdir, cube, '_narval', 'checkers'))
+        if osp.isdir(pluginsdir):
+            __path__.append(pluginsdir)
--- a/_narval/checkers/apycot/__init__.py	Wed May 14 11:38:26 2014 +0200
+++ b/_narval/checkers/apycot/__init__.py	Wed May 14 11:34:12 2014 +0200
@@ -10,6 +10,13 @@
 from logilab.common.textutils import splitstrip
 from logilab.common.proc import RESOURCE_LIMIT_EXCEPTION
 
+try:
+    import apycotlib
+except ImportError: # allow to run from sources
+    from cubes.apycot import _apycotlib as apycotlib
+    import sys
+    sys.modules['apycotlib'] = apycotlib
+
 from apycotlib import SUCCESS, NODATA, ERROR, TestStatus, ApycotObject
 
 class BaseChecker(ApycotObject):
--- a/_narval/preprocessors/__init__.py	Wed May 14 11:38:26 2014 +0200
+++ b/_narval/preprocessors/__init__.py	Wed May 14 11:34:12 2014 +0200
@@ -0,0 +1,20 @@
+# make it work in 'dev' mode: look for preprocessors in known cubes
+
+try:
+    import narvalbot
+except:
+    from cubes.narval import narvalbot
+    import sys
+    sys.modules['narvalbot'] = narvalbot
+
+if narvalbot.MODE == 'dev':
+    # we are running from sources, cubicweb *should* be available,
+    # let's use it as starting point to look for cubes in which there
+    # is a _narval directory
+    import os, os.path as osp
+    from cubicweb import CW_SOFTWARE_ROOT
+    cubesdir = osp.join(CW_SOFTWARE_ROOT, '..', 'cubes')
+    for cube in os.listdir(cubesdir):
+        pluginsdir = osp.abspath(osp.join(cubesdir, cube, '_narval', 'preprocessors'))
+        if osp.isdir(pluginsdir):
+            __path__.append(pluginsdir)
--- a/_narval/preprocessors/apycot/__init__.py	Wed May 14 11:38:26 2014 +0200
+++ b/_narval/preprocessors/apycot/__init__.py	Wed May 14 11:34:12 2014 +0200
@@ -2,6 +2,13 @@
 
 __docformat__ = "restructuredtext en"
 
+try:
+    import apycotlib
+except ImportError: # allow to run from sources
+    from cubes.apycot import _apycotlib as apycotlib
+    import sys
+    sys.modules['apycotlib'] = apycotlib
+
 from apycotlib import ApycotObject
 
 class BasePreProcessor(ApycotObject):
--- a/test/unittest_parser.py	Wed May 14 11:38:26 2014 +0200
+++ b/test/unittest_parser.py	Wed May 14 11:34:12 2014 +0200
@@ -4,7 +4,7 @@
 from logilab.common.testlib import TestCase, unittest_main
 
 import cubicweb.devtools
-import cubes.apycot # import this first
+import cubes.apycot.testutils # import this first
 
 from apycotlib import SimpleOutputParser
 from apycotlib.writer import AbstractLogWriter
--- a/testutils.py	Wed May 14 11:38:26 2014 +0200
+++ b/testutils.py	Wed May 14 11:34:12 2014 +0200
@@ -1,3 +1,4 @@
+import sys
 import shutil
 import os
 from datetime import datetime
@@ -23,10 +24,12 @@
     from cubes.apycot import _apycotlib as apycotlib
 sys.modules['apycotlib'] = apycotlib
 
+sys.path.append(join(dirname(__file__), '_narval'))
+
+
 from apycotlib.writer import CheckDataWriter, BaseDataWriter
 
 
-
 class DummyStack(object):
 
     def __init__(self):