# HG changeset patch # User Philippe Pepiot # Date 1490102246 -3600 # Node ID 82d2c1cdf0c20425a370db27282c072ae061beec # Parent f5fee548588dbe37712460a9e919d68e363c0e3b [cwconfig] don't rely on _CubeImporter while loading cubes _CubeImporter can load cube subpackages twice (there is a test for submodules in cubicweb.test.unittest_cubes.test_no_double_import() but not with a subpackage). Since _CubeImporter is for backward compatibility and is supposed to be deprecated as soon as possible, don't rely on it when loading cube schema or appobjects and always load the real modname (eg. cubicweb_ if exists else cubes.). diff -r f5fee548588d -r 82d2c1cdf0c2 cubicweb/cwconfig.py --- a/cubicweb/cwconfig.py Fri Mar 17 16:29:38 2017 +0100 +++ b/cubicweb/cwconfig.py Tue Mar 21 14:17:26 2017 +0100 @@ -276,6 +276,15 @@ return cube +def _cube_modname(cube): + modname = _cube_pkgname(cube) + loader = pkgutil.find_loader(modname) + if loader: + return modname + else: + return 'cubes.' + cube + + def _expand_modname(modname): """expand modules names `modname` if exists by walking non package submodules and yield (submodname, filepath) including `modname` itself @@ -817,7 +826,8 @@ for name in ('bootstrap', 'base', 'workflow', 'Bookmark'): modnames.append(('cubicweb', 'cubicweb.schemas.' + name)) for cube in reversed(self.cubes()): - for modname, filepath in _expand_modname('cubes.{0}.schema'.format(cube)): + for modname, filepath in _expand_modname( + '{0}.schema'.format(_cube_modname(cube))): modnames.append((cube, modname)) if self.apphome: apphome = realpath(self.apphome) @@ -1335,9 +1345,10 @@ def appobjects_cube_modnames(self, cube): modnames = [] + cube_modname = _cube_modname(cube) cube_submodnames = self._sorted_appobjects(self.cube_appobject_path) for name in cube_submodnames: - for modname, filepath in _expand_modname('.'.join(['cubes', cube, name])): + for modname, filepath in _expand_modname('.'.join([cube_modname, name])): modnames.append(modname) return modnames diff -r f5fee548588d -r 82d2c1cdf0c2 cubicweb/test/unittest_cwconfig.py --- a/cubicweb/test/unittest_cwconfig.py Fri Mar 17 16:29:38 2017 +0100 +++ b/cubicweb/test/unittest_cwconfig.py Tue Mar 21 14:17:26 2017 +0100 @@ -450,9 +450,9 @@ ('cubicweb', 'cubicweb.schemas.workflow'), ('cubicweb', 'cubicweb.schemas.Bookmark'), ('bar', 'cubes.bar.schema'), - ('foo', 'cubes.foo.schema'), - ('foo', 'cubes.foo.schema.a'), - ('foo', 'cubes.foo.schema.b'), + ('foo', 'cubicweb_foo.schema'), + ('foo', 'cubicweb_foo.schema.a'), + ('foo', 'cubicweb_foo.schema.b'), ] # app has schema file instance_dir, cubes_dir = ( @@ -497,9 +497,9 @@ 'cubicweb.entities.sources', 'cubicweb.entities.wfobjs', 'cubes.bar.hooks', - 'cubes.foo.entities', - 'cubes.foo.entities.a', - 'cubes.foo.hooks', + 'cubicweb_foo.entities', + 'cubicweb_foo.entities.a', + 'cubicweb_foo.hooks', ] # data1 has entities with temp_config('data1', instance_dir, cubes_dir,