Handle cubes as packages in cwconfig
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 07 Jun 2016 18:21:13 +0200
changeset 11459 8987a05950dc
parent 11458 db2d627e379e
child 11460 5be729810695
Handle cubes as packages in cwconfig Rely on importlib.import_module in several places in cwconfig.py, so this would not work with python 2.6. Method available_cubes will not list cubes installed as package for now. I'm not sure it's worth implementing this method (used in `cubicweb-ctl list cubes` command) for new cubes layout as the same result can basically be obtained with `pip freeze | grep cubicweb_`. In unittest_cwconfig.py, duplicate CubicWebConfigurationTC test case to test both the "cubes as packages" layout and the "legacy cubes" layout. The former having a custom sys.path set (pointing to datapath('libpython') where all cubes' packages live) and the latter having the previous config attribute setup. All test data cubes are moved to packages in libpython directory and symlinks are introduced in the cubes directory. Related to #13001466.
cubicweb/cwconfig.py
cubicweb/test/data/cubes/comment/__init__.py
cubicweb/test/data/cubes/comment/__pkginfo__.py
cubicweb/test/data/cubes/email/__init__.py
cubicweb/test/data/cubes/email/__pkginfo__.py
cubicweb/test/data/cubes/email/entities.py
cubicweb/test/data/cubes/email/hooks.py
cubicweb/test/data/cubes/email/views/__init__.py
cubicweb/test/data/cubes/file/__init__.py
cubicweb/test/data/cubes/file/__pkginfo__.py
cubicweb/test/data/cubes/file/entities/__init__.py
cubicweb/test/data/cubes/file/hooks/__init__.py
cubicweb/test/data/cubes/file/views.py
cubicweb/test/data/cubes/forge/__init__.py
cubicweb/test/data/cubes/forge/__pkginfo__.py
cubicweb/test/data/cubes/mycube/__init__.py
cubicweb/test/data/cubes/mycube/__pkginfo__.py
cubicweb/test/data/legacy_cubes/comment
cubicweb/test/data/legacy_cubes/email
cubicweb/test/data/legacy_cubes/file
cubicweb/test/data/legacy_cubes/forge
cubicweb/test/data/legacy_cubes/mycube
cubicweb/test/data/libpython/cubicweb_comment/__init__.py
cubicweb/test/data/libpython/cubicweb_comment/__pkginfo__.py
cubicweb/test/data/libpython/cubicweb_email/__init__.py
cubicweb/test/data/libpython/cubicweb_email/__pkginfo__.py
cubicweb/test/data/libpython/cubicweb_email/entities.py
cubicweb/test/data/libpython/cubicweb_email/hooks.py
cubicweb/test/data/libpython/cubicweb_email/views/__init__.py
cubicweb/test/data/libpython/cubicweb_file/__init__.py
cubicweb/test/data/libpython/cubicweb_file/__pkginfo__.py
cubicweb/test/data/libpython/cubicweb_file/entities/__init__.py
cubicweb/test/data/libpython/cubicweb_file/hooks/__init__.py
cubicweb/test/data/libpython/cubicweb_file/views.py
cubicweb/test/data/libpython/cubicweb_forge/__init__.py
cubicweb/test/data/libpython/cubicweb_forge/__pkginfo__.py
cubicweb/test/data/libpython/cubicweb_mycube/__init__.py
cubicweb/test/data/libpython/cubicweb_mycube/__pkginfo__.py
cubicweb/test/unittest_cwconfig.py
--- a/cubicweb/cwconfig.py	Tue Jul 12 16:17:57 2016 +0200
+++ b/cubicweb/cwconfig.py	Tue Jun 07 18:21:13 2016 +0200
@@ -181,11 +181,13 @@
 
 __docformat__ = "restructuredtext en"
 
+import importlib
 import logging
 import logging.config
 import os
 from os.path import (exists, join, expanduser, abspath, normpath,
                      basename, isdir, dirname, splitext)
+import pkgutil
 from smtplib import SMTP
 import stat
 import sys
@@ -262,6 +264,7 @@
         prefix = dirname(prefix)
     return prefix
 
+
 # persistent options definition
 PERSISTENT_OPTIONS = (
     ('encoding',
@@ -444,6 +447,7 @@
 
     @classmethod
     def available_cubes(cls):
+        cls.warning('only listing "legacy" cubes found in cubes path')
         import re
         cubes = set()
         for directory in cls.cubes_search_path():
@@ -483,12 +487,18 @@
         """return the cube directory for the given cube id, raise
         `ConfigurationError` if it doesn't exist
         """
+        loader = pkgutil.find_loader('cubicweb_%s' % cube)
+        if loader:
+            return dirname(loader.get_filename())
+        # Legacy cubes.
         for directory in cls.cubes_search_path():
             cubedir = join(directory, cube)
             if exists(cubedir):
                 return cubedir
-        raise ConfigurationError('no cube %r in %s' % (
-            cube, cls.cubes_search_path()))
+        msg = ('no module cubicweb_%(cube)s in search path '
+               'nor cube %(cube)r in %(path)s')
+        raise ConfigurationError(msg % {'cube': cube,
+                                        'path': cls.cubes_search_path()})
 
     @classmethod
     def cube_migration_scripts_dir(cls, cube):
@@ -498,14 +508,17 @@
     @classmethod
     def cube_pkginfo(cls, cube):
         """return the information module for the given cube"""
-        cube = CW_MIGRATION_MAP.get(cube, cube)
         try:
-            parent = __import__('cubes.%s.__pkginfo__' % cube)
-            return getattr(parent, cube).__pkginfo__
-        except Exception as ex:
-            raise ConfigurationError(
-                'unable to find packaging information for cube %s (%s: %s)'
-                % (cube, ex.__class__.__name__, ex))
+            return importlib.import_module('cubicweb_%s.__pkginfo__' % cube)
+        except ImportError:
+            cube = CW_MIGRATION_MAP.get(cube, cube)
+            try:
+                parent = __import__('cubes.%s.__pkginfo__' % cube)
+                return getattr(parent, cube).__pkginfo__
+            except Exception as ex:
+                raise ConfigurationError(
+                    'unable to find packaging information for cube %s (%s: %s)'
+                    % (cube, ex.__class__.__name__, ex))
 
     @classmethod
     def cube_version(cls, cube):
@@ -827,7 +840,11 @@
         self._cubes = self.reorder_cubes(cubes)
         # load cubes'__init__.py file first
         for cube in cubes:
-            __import__('cubes.%s' % cube)
+            try:
+                importlib.import_module('cubicweb_%s' % cube)
+            except ImportError:
+                # Legacy cube.
+                __import__('cubes.%s' % cube)
         self.load_site_cubicweb()
 
     def cubes(self):
--- a/cubicweb/test/data/cubes/comment/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- a/cubicweb/test/data/cubes/comment/__pkginfo__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-# pylint: disable=W0622
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-comment packaging information"""
-
-distname = "cubicweb-comment"
-modname = distname.split('-', 1)[1]
-
-numversion = (1, 4, 3)
-version = '.'.join(str(num) for num in numversion)
--- a/cubicweb/test/data/cubes/email/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- a/cubicweb/test/data/cubes/email/__pkginfo__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-# pylint: disable=W0622
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-email packaging information"""
-
-distname = "cubicweb-email"
-modname = distname.split('-', 1)[1]
-
-numversion = (1, 4, 3)
-version = '.'.join(str(num) for num in numversion)
-
-
-__depends__ = {'cubicweb': None,
-               'cubicweb-file': None}
-__recommends__ = {'cubicweb-comment': None}
--- a/cubicweb/test/data/cubes/email/entities.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/email/hooks.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/email/views/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/file/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- a/cubicweb/test/data/cubes/file/__pkginfo__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-# pylint: disable=W0622
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-file packaging information"""
-
-distname = "cubicweb-file"
-modname = distname.split('-', 1)[1]
-
-numversion = (1, 4, 3)
-version = '.'.join(str(num) for num in numversion)
--- a/cubicweb/test/data/cubes/file/entities/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/file/hooks/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/file/views.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-"test"
--- a/cubicweb/test/data/cubes/forge/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- a/cubicweb/test/data/cubes/forge/__pkginfo__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-# pylint: disable=W0622
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-forge packaging information"""
-
-distname = "cubicweb-forge"
-modname = distname.split('-', 1)[1]
-
-numversion = (1, 4, 3)
-version = '.'.join(str(num) for num in numversion)
-
-
-__depends__ = {'cubicweb': None,
-               'cubicweb-file': None,
-               'cubicweb-email': None,
-               'cubicweb-comment': None,
-               }
--- a/cubicweb/test/data/cubes/mycube/__init__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""mycube's __init__
-
-"""
--- a/cubicweb/test/data/cubes/mycube/__pkginfo__.py	Tue Jul 12 16:17:57 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
-# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
-#
-# This file is part of CubicWeb.
-#
-# CubicWeb is free software: you can redistribute it and/or modify it under the
-# terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation, either version 2.1 of the License, or (at your option)
-# any later version.
-#
-# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License along
-# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-"""
-distname = 'cubicweb-mycube'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/legacy_cubes/comment	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+../libpython/cubicweb_comment
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/legacy_cubes/email	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+../libpython/cubicweb_email/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/legacy_cubes/file	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+../libpython/cubicweb_file
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/legacy_cubes/forge	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+../libpython/cubicweb_forge
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/legacy_cubes/mycube	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+../libpython/cubicweb_mycube
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_comment/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,17 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_comment/__pkginfo__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,25 @@
+# pylint: disable=W0622
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb-comment packaging information"""
+
+distname = "cubicweb-comment"
+modname = distname.split('-', 1)[1]
+
+numversion = (1, 4, 3)
+version = '.'.join(str(num) for num in numversion)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_email/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,17 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_email/__pkginfo__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,30 @@
+# pylint: disable=W0622
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb-email packaging information"""
+
+distname = "cubicweb-email"
+modname = distname.split('-', 1)[1]
+
+numversion = (1, 4, 3)
+version = '.'.join(str(num) for num in numversion)
+
+
+__depends__ = {'cubicweb': None,
+               'cubicweb-file': None}
+__recommends__ = {'cubicweb-comment': None}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_email/entities.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_email/hooks.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_email/views/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_file/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,17 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_file/__pkginfo__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,25 @@
+# pylint: disable=W0622
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb-file packaging information"""
+
+distname = "cubicweb-file"
+modname = distname.split('-', 1)[1]
+
+numversion = (1, 4, 3)
+version = '.'.join(str(num) for num in numversion)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_file/entities/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_file/hooks/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_file/views.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,1 @@
+"test"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_forge/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,17 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_forge/__pkginfo__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,32 @@
+# pylint: disable=W0622
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""cubicweb-forge packaging information"""
+
+distname = "cubicweb-forge"
+modname = distname.split('-', 1)[1]
+
+numversion = (1, 4, 3)
+version = '.'.join(str(num) for num in numversion)
+
+
+__depends__ = {'cubicweb': None,
+               'cubicweb-file': None,
+               'cubicweb-email': None,
+               'cubicweb-comment': None,
+               }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_mycube/__init__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,20 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""mycube's __init__
+
+"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cubicweb/test/data/libpython/cubicweb_mycube/__pkginfo__.py	Tue Jun 07 18:21:13 2016 +0200
@@ -0,0 +1,21 @@
+# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
+#
+# This file is part of CubicWeb.
+#
+# CubicWeb is free software: you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
+"""
+
+"""
+distname = 'cubicweb-mycube'
--- a/cubicweb/test/unittest_cwconfig.py	Tue Jul 12 16:17:57 2016 +0200
+++ b/cubicweb/test/unittest_cwconfig.py	Tue Jun 07 18:21:13 2016 +0200
@@ -23,6 +23,8 @@
 from os.path import dirname, join, abspath
 import unittest
 
+from six import PY3
+
 from logilab.common.modutils import cleanup_sys_modules
 from logilab.common.testlib import with_tempdir
 from logilab.common.changelog import Version
@@ -30,20 +32,28 @@
 from cubicweb.devtools import ApptestConfiguration, testlib
 from cubicweb.cwconfig import _find_prefix
 
+
 def unabsolutize(path):
     parts = path.split(os.sep)
     for i, part in reversed(tuple(enumerate(parts))):
-        if part.startswith('cubicweb') or part == 'cubes':
-            return '/'.join(parts[i+1:])
+        if part.startswith('cubicweb_'):
+            return os.sep.join([part[len('cubicweb_'):]] + parts[i+1:])
+        if part.startswith('cubicweb') or part == 'legacy_cubes':
+            return os.sep.join(parts[i+1:])
     raise Exception('duh? %s' % path)
 
-CUSTOM_CUBES_DIR = abspath(join(dirname(__file__), 'data', 'cubes'))
-
 
 class CubicWebConfigurationTC(testlib.BaseTestCase):
 
+    @classmethod
+    def setUpClass(cls):
+        sys.path.append(cls.datapath('libpython'))
+
+    @classmethod
+    def tearDownClass(cls):
+        sys.path.remove(cls.datapath('libpython'))
+
     def setUp(self):
-        cleanup_sys_modules([CUSTOM_CUBES_DIR, ApptestConfiguration.CUBES_DIR])
         self.config = ApptestConfiguration('data', __file__)
         self.config._cubes = ('email', 'file')
 
@@ -51,8 +61,6 @@
         ApptestConfiguration.CUBES_PATH = []
 
     def test_reorder_cubes(self):
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
-        self.config.adjust_sys_path()
         # forge depends on email and file and comment
         # email depends on file
         self.assertEqual(self.config.reorder_cubes(['file', 'email', 'forge']),
@@ -69,9 +77,10 @@
                           ('forge', 'email', 'file'))
 
     def test_reorder_cubes_recommends(self):
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
-        self.config.adjust_sys_path()
-        from cubes.comment import __pkginfo__ as comment_pkginfo
+        from cubicweb_comment import __pkginfo__ as comment_pkginfo
+        self._test_reorder_cubes_recommends(comment_pkginfo)
+
+    def _test_reorder_cubes_recommends(self, comment_pkginfo):
         comment_pkginfo.__recommends_cubes__ = {'file': None}
         try:
             # email recommends comment
@@ -88,35 +97,58 @@
             comment_pkginfo.__recommends_cubes__ = {}
 
     def test_expand_cubes(self):
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
-        self.config.adjust_sys_path()
         self.assertEqual(self.config.expand_cubes(('email', 'comment')),
                           ['email', 'comment', 'file'])
 
     def test_appobjects_path(self):
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
-        self.config.adjust_sys_path()
         path = [unabsolutize(p) for p in self.config.appobjects_path()]
         self.assertEqual(path[0], 'entities')
         self.assertCountEqual(path[1:4], ['web/views', 'sobjects', 'hooks'])
         self.assertEqual(path[4], 'file/entities')
-        self.assertCountEqual(path[5:7], ['file/views.py', 'file/hooks'])
+        self.assertCountEqual(path[5:7],
+                              ['file/views.py', 'file/hooks'])
         self.assertEqual(path[7], 'email/entities.py')
-        self.assertCountEqual(path[8:10], ['email/views', 'email/hooks.py'])
+        self.assertCountEqual(path[8:10],
+                              ['email/views', 'email/hooks.py'])
         self.assertEqual(path[10:], ['test/data/entities.py', 'test/data/views.py'])
 
+
+class CubicWebConfigurationWithLegacyCubesTC(CubicWebConfigurationTC):
+
+    @classmethod
+    def setUpClass(cls):
+        pass
+
+    @classmethod
+    def tearDownClass(cls):
+        pass
+
+    def setUp(self):
+        self.custom_cubes_dir = self.datapath('legacy_cubes')
+        cleanup_sys_modules([self.custom_cubes_dir, ApptestConfiguration.CUBES_DIR])
+        super(CubicWebConfigurationWithLegacyCubesTC, self).setUp()
+        self.config.__class__.CUBES_PATH = [self.custom_cubes_dir]
+        self.config.adjust_sys_path()
+
+    def tearDown(self):
+        ApptestConfiguration.CUBES_PATH = []
+
+    def test_reorder_cubes_recommends(self):
+        from cubes.comment import __pkginfo__ as comment_pkginfo
+        self._test_reorder_cubes_recommends(comment_pkginfo)
+
     def test_cubes_path(self):
         # make sure we don't import the email cube, but the stdlib email package
         import email
         self.assertNotEqual(dirname(email.__file__), self.config.CUBES_DIR)
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
+        self.config.__class__.CUBES_PATH = [self.custom_cubes_dir]
         self.assertEqual(self.config.cubes_search_path(),
-                          [CUSTOM_CUBES_DIR, self.config.CUBES_DIR])
-        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR,
+                          [self.custom_cubes_dir, self.config.CUBES_DIR])
+        self.config.__class__.CUBES_PATH = [self.custom_cubes_dir,
                                             self.config.CUBES_DIR, 'unexistant']
         # filter out unexistant and duplicates
         self.assertEqual(self.config.cubes_search_path(),
-                          [CUSTOM_CUBES_DIR,
+                          [self.custom_cubes_dir,
                            self.config.CUBES_DIR])
         self.assertIn('mycube', self.config.available_cubes())
         # test cubes python path
@@ -125,12 +157,13 @@
         self.assertEqual(cubes.__path__, self.config.cubes_search_path())
         # this import should succeed once path is adjusted
         from cubes import mycube
-        self.assertEqual(mycube.__path__, [join(CUSTOM_CUBES_DIR, 'mycube')])
+        self.assertEqual(mycube.__path__, [join(self.custom_cubes_dir, 'mycube')])
         # file cube should be overriden by the one found in data/cubes
         sys.modules.pop('cubes.file', None)
-        del cubes.file
+        if PY3:
+            del cubes.file
         from cubes import file
-        self.assertEqual(file.__path__, [join(CUSTOM_CUBES_DIR, 'file')])
+        self.assertEqual(file.__path__, [join(self.custom_cubes_dir, 'file')])
 
 
 class FindPrefixTC(unittest.TestCase):