402 version = cls.cube_pkginfo(cube).numversion |
402 version = cls.cube_pkginfo(cube).numversion |
403 assert len(version) == 3, version |
403 assert len(version) == 3, version |
404 return Version(version) |
404 return Version(version) |
405 |
405 |
406 @classmethod |
406 @classmethod |
|
407 def _cube_deps(cls, cube, key, oldkey): |
|
408 """return cubicweb cubes used by the given cube""" |
|
409 pkginfo = cls.cube_pkginfo(cube) |
|
410 try: |
|
411 deps = getattr(pkginfo, key) |
|
412 except AttributeError: |
|
413 if hasattr(pkginfo, oldkey): |
|
414 warn('[3.6] %s is deprecated, use %s dict' % (oldkey, key), |
|
415 DeprecationWarning) |
|
416 deps = getattr(pkginfo, oldkey) |
|
417 else: |
|
418 deps = {} |
|
419 if not isinstance(deps, dict): |
|
420 deps = dict((key, None) for key in deps) |
|
421 warn('[3.6] cube %s should define %s as a dict' % (cube, key), |
|
422 DeprecationWarning) |
|
423 return deps |
|
424 |
|
425 @classmethod |
407 def cube_dependencies(cls, cube): |
426 def cube_dependencies(cls, cube): |
408 """return cubicweb cubes used by the given cube""" |
427 """return cubicweb cubes used by the given cube""" |
409 return getattr(cls.cube_pkginfo(cube), '__use__', ()) |
428 return cls._cube_deps(cube, '__depends_cubes__', '__use__') |
410 |
429 |
411 @classmethod |
430 @classmethod |
412 def cube_recommends(cls, cube): |
431 def cube_recommends(cls, cube): |
413 """return cubicweb cubes recommended by the given cube""" |
432 """return cubicweb cubes recommended by the given cube""" |
414 return getattr(cls.cube_pkginfo(cube), '__recommend__', ()) |
433 return cls._cube_deps(cube, '__recommends_cubes__', '__recommend__') |
415 |
434 |
416 @classmethod |
435 @classmethod |
417 def expand_cubes(cls, cubes, with_recommends=False): |
436 def expand_cubes(cls, cubes, with_recommends=False): |
418 """expand the given list of top level cubes used by adding recursivly |
437 """expand the given list of top level cubes used by adding recursivly |
419 each cube dependencies |
438 each cube dependencies |
442 """ |
461 """ |
443 from logilab.common.graph import get_cycles |
462 from logilab.common.graph import get_cycles |
444 graph = {} |
463 graph = {} |
445 for cube in cubes: |
464 for cube in cubes: |
446 cube = CW_MIGRATION_MAP.get(cube, cube) |
465 cube = CW_MIGRATION_MAP.get(cube, cube) |
447 deps = cls.cube_dependencies(cube) + \ |
466 graph[cube] = set(dep for dep in cls.cube_dependencies(cube) |
448 cls.cube_recommends(cube) |
467 if dep in cubes) |
449 graph[cube] = set(dep for dep in deps if dep in cubes) |
468 graph[cube] |= set(dep for dep in cls.cube_recommends(cube) |
|
469 if dep in cubes) |
450 cycles = get_cycles(graph) |
470 cycles = get_cycles(graph) |
451 if cycles: |
471 if cycles: |
452 cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
472 cycles = '\n'.join(' -> '.join(cycle) for cycle in cycles) |
453 raise ConfigurationError('cycles in cubes dependencies: %s' |
473 raise ConfigurationError('cycles in cubes dependencies: %s' |
454 % cycles) |
474 % cycles) |