Pyolian: improve a bit the namespace generation

I still think that namespaces should be directly exposed by eolian.
Currently pyolian provide a namespace implementation but it's
hard to get it right, and it should be really shared between
all eolian users.
This commit is contained in:
Davide Andreoli 2018-02-18 09:33:22 +01:00
parent bfbe038921
commit 0af53f4bc6
4 changed files with 153 additions and 48 deletions

View File

@ -10,12 +10,6 @@ Pratically there is nothing python related currently in this documentation,
so it can be considered valid for all languages.
^** Some numbers just for information **^^
<!--(for label, val in totals)-->
| ${label}$ | **${val}$** |
<!--(end)-->
<!--(for ns in nspaces)-->
===== ${ns.name}$ (namespace) =====

View File

@ -76,6 +76,47 @@ def page_path_for_object(obj):
return os.path.join(args.root_path, *path, output_file)
# render a (temporary) page for analizying the namespaces hierarchy
t = Template('namespaces.template')
nspaces = [ ns for ns in eolian_db.all_namespaces
if ns.name.startswith(args.namespace) ]
tot_classes = tot_regulars = tot_abstracts = tot_mixins = tot_ifaces = 0
tot_enums = tot_structs = tot_aliases = 0
for ns in nspaces:
for cls in ns.classes:
tot_classes += 1
if cls.type == eolian.Eolian_Class_Type.REGULAR:
tot_regulars += 1
elif cls.type == eolian.Eolian_Class_Type.ABSTRACT:
tot_abstracts += 1
elif cls.type == eolian.Eolian_Class_Type.MIXIN:
tot_mixins += 1
elif cls.type == eolian.Eolian_Class_Type.INTERFACE:
tot_ifaces += 1
tot_enums += len(ns.enums)
tot_structs += len(ns.structs)
tot_aliases += len(ns.aliases)
totals = [
('Namespaces', len(nspaces)),
('ALL Classes', tot_classes),
('Regular classes', tot_regulars),
('Abstract classes', tot_abstracts),
('Mixins', tot_mixins),
('Interfaces', tot_ifaces),
('Enums', tot_enums),
('Structs', tot_structs),
('Aliases', tot_aliases),
]
root_ns = eolian_db.namespace_get_by_name(args.namespace)
output_file = os.path.join(args.root_path,'data','pages','develop','api','namespaces.txt')
t.render(output_file, args.verbose, root_ns=root_ns, totals=totals)
# render the main start.txt page
if args.step in ('start', None):
t = Template('doc_start.template')
@ -83,29 +124,8 @@ if args.step in ('start', None):
nspaces = [ ns for ns in eolian_db.all_namespaces
if ns.name.startswith(args.namespace) ]
tot_classes = tot_regulars = tot_abstracts = tot_mixins = tot_ifaces = 0
for ns in nspaces:
for cls in ns.classes:
tot_classes += 1
if cls.type == eolian.Eolian_Class_Type.REGULAR:
tot_regulars += 1
elif cls.type == eolian.Eolian_Class_Type.ABSTRACT:
tot_abstracts += 1
elif cls.type == eolian.Eolian_Class_Type.MIXIN:
tot_mixins += 1
elif cls.type == eolian.Eolian_Class_Type.INTERFACE:
tot_ifaces += 1
totals = [
('Namespaces', len(nspaces)),
('ALL Classes', tot_classes),
('Regular classes', tot_regulars),
('Abstract classes', tot_abstracts),
('Mixins', tot_mixins),
('Interfaces', tot_ifaces),
]
output_file = os.path.join(args.root_path,'data','pages','develop','api','start.txt')
t.render(output_file, args.verbose, nspaces=nspaces, totals=totals)
t.render(output_file, args.verbose, nspaces=nspaces)
# render a page for each Class

View File

@ -0,0 +1,83 @@
~~Title: EFL Namespaces~~
#!##############################################################################
#!#### CLS_LINK(cls) #########################################################
#!##############################################################################
<!--(macro CLS_LINK)-->
[[:develop:api#!
<!--(for n in cls.namespaces)-->
:${n.lower()}$#!
<!--(end)-->
:${cls.name.lower()}$|${cls.name}$]]
<!--(end)-->
#!##############################################################################
#!#### TYPEDECL_LINK(typedecl) ###############################################
#!##############################################################################
<!--(macro TYPEDECL_LINK)-->
[[:develop:api#!
<!--(for n in typedecl.namespaces)-->
:${n.lower()}$#!
<!--(end)-->
:${typedecl.name.lower()}$|${typedecl.name}$]]
<!--(end)-->
#!##############################################################################
#!#### NAMESPACE_ITEM(ns) ####################################################
#!##############################################################################
<!--(macro NAMESPACE_ITEM)-->
**${ns.name}$** #!
<!--(if len(ns.regulars))-->
\\ Classes: <!--(for cls in ns.regulars)--> ${CLS_LINK(cls=cls)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.abstracts))-->
\\ Abstracts: <!--(for cls in ns.abstracts)--> ${CLS_LINK(cls=cls)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.mixins))-->
\\ Mixins: <!--(for cls in ns.mixins)--> ${CLS_LINK(cls=cls)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.interfaces))-->
\\ Interfaces: <!--(for cls in ns.interfaces)--> ${CLS_LINK(cls=cls)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.structs))-->
\\ Structs: <!--(for struct in ns.structs)--> ${TYPEDECL_LINK(typedecl=struct)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.enums))-->
\\ Enums: <!--(for enum in ns.enums)--> ${TYPEDECL_LINK(typedecl=enum)}$, <!--(end)--> #!
<!--(end)-->
<!--(if len(ns.aliases))-->
\\ Aliases: <!--(for alias in ns.aliases)--> ${TYPEDECL_LINK(typedecl=alias)}$, <!--(end)--> #!
<!--(end)-->
<!--(end)-->
====== Unified-API namespaces hierarchy ======
This page is just a temporary work to analyze the namespaces in the new API
^** Some numbers just for information **^^
<!--(for label, val in totals)-->
| ${label}$ | **${val}$** |
<!--(end)-->
===== Namespaces hierarchy =====
* ${NAMESPACE_ITEM(ns=root_ns)}$
<!--(for sub in root_ns.sub_namespaces)-->
* ${NAMESPACE_ITEM(ns=sub)}$
<!--(for sub in sub.sub_namespaces)-->
* ${NAMESPACE_ITEM(ns=sub)}$
<!--(for sub in sub.sub_namespaces)-->
* ${NAMESPACE_ITEM(ns=sub)}$
<!--(for sub in sub.sub_namespaces)-->
* ${NAMESPACE_ITEM(ns=sub)}$
<!--(end)-->
<!--(end)-->
<!--(end)-->
<!--(end)-->

View File

@ -509,49 +509,57 @@ class Namespace(object):
def namespaces(self):
return self._name.split('.')
@property
def sub_namespaces(self):
base = self._name + '.'
deep = self._name.count('.') + 1
return [ ns for ns in self._unit.all_namespaces
if ns.name.startswith(base) and ns.name.count('.') == deep ]
@property
def classes(self):
return [ c for c in self._unit.all_classes
if c.namespace == self._name ]
return sorted([ c for c in self._unit.all_classes
if c.namespace == self._name ])
@property
def regulars(self):
return [ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.REGULAR and
c.namespace == self._name]
return sorted([ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.REGULAR and
c.namespace == self._name])
@property
def abstracts(self):
return [ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.ABSTRACT and
c.namespace == self._name]
return sorted([ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.ABSTRACT and
c.namespace == self._name])
@property
def mixins(self):
return [ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.MIXIN and
c.namespace == self._name]
return sorted([ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.MIXIN and
c.namespace == self._name])
@property
def interfaces(self):
return [ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.INTERFACE and
c.namespace == self._name]
return sorted([ c for c in self._unit.all_classes
if c.type == Eolian_Class_Type.INTERFACE and
c.namespace == self._name])
@property
def aliases(self):
return [ td for td in self._unit.typedecl_all_aliases
if td.namespace == self._name]
return sorted([ td for td in self._unit.typedecl_all_aliases
if td.namespace == self._name])
@property
def structs(self):
return [ td for td in self._unit.typedecl_all_structs
if td.namespace == self._name]
return sorted([ td for td in self._unit.typedecl_all_structs
if td.namespace == self._name])
@property
def enums(self):
return [ td for td in self._unit.typedecl_all_enums
if td.namespace == self._name]
return sorted([ td for td in self._unit.typedecl_all_enums
if td.namespace == self._name])
### Eolian Classes ##########################################################