Ticket #15696: all_categories.py

File all_categories.py, 1.3 KB (added by nthiery, 7 years ago)
Line 
1import inspect
2from sage.misc.lazy_import import LazyImport
3abstract_classes_for_categories = [Category]
4from sage.categories.category_types import Category_over_base_ring
5
6def contained_categories(container):
7    if isinstance(container, Category):
8        container_class = type(container).__base__
9    else:
10        container_class = container
11    result = []
12    for key,cls in container_class.__dict__.items():
13        if isinstance(cls, LazyImport):
14            cls = cls._get_object()
15        if not (inspect.isclass(cls) and issubclass(cls, Category) and cls not in abstract_classes_for_categories):
16            continue
17        if key in ["DualCategory", "Morphism"]:
18            continue
19        if isinstance(container, Category) and key == "Algebras":
20            cat = getattr(container, key)(QQ)
21        elif isinstance(container, Category):
22            cat = getattr(container, key)()
23        else:
24            cat = cls.an_instance()
25        result.append(cat)
26    return result
27
28def category_sample():
29    return tuple(cat
30                 for cat in RecursivelyEnumeratedSet(seeds=[sage.categories.all],
31                                                     successors=contained_categories)
32                 if isinstance(cat, Category))
33
34def category_graph():
35    return sage.categories.category.category_graph(category_sample())