Coverage for gws-app/gws/spec/generator/extractor.py: 95%
76 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
1from . import base
2from .base import Type
5def extract(gen: base.Generator):
6 """Extracts server specs from the types library.
8 For the server, we need
9 - all gws.ext.object.xxx, but not their properties (too many)
10 - all gws.ext.config.xxx and gws.ext.properties.xxx
11 - their properties, recursively
12 - command methods (gws.ext.command.xxx)
13 - their args and rets, recursively
14 """
16 out: dict[str, Type] = {}
17 _extract(gen, out)
18 gen.serverTypes = [out[uid] for uid in sorted(out)]
21def _extract(gen: base.Generator, out: dict[str, Type]):
22 queue = []
24 def _add(typ: Type, **kwargs):
25 mod = gen.get_type(typ.tModule)
26 if mod:
27 kwargs['modName'] = mod.name
28 kwargs['modPath'] = mod.modPath
29 vars(typ).update(kwargs)
30 out[typ.uid] = typ
32 typ = gen.require_type('gws.base.application.core.Config')
33 _add(typ)
34 queue.extend(typ.tProperties.values())
36 typ = gen.require_type('gws.base.application.core.Object')
37 _add(typ)
39 queue.extend(set(typ.uid for typ in gen.typeDict.values() if typ.extName))
41 while queue:
42 typ = gen.require_type(queue.pop(0))
43 if typ.uid in out or typ.c == base.c.ATOM:
44 continue
46 if typ.c == base.c.METHOD and typ.extName.startswith(base.v.EXT_COMMAND_PREFIX):
47 _add(typ)
48 queue.append(typ.tOwner)
49 queue.append(typ.tArg)
50 continue
52 if typ.c == base.c.CLASS and typ.extName.startswith(base.v.EXT_OBJECT_PREFIX):
53 _add(typ)
54 continue
56 if typ.c == base.c.CLASS:
57 _add(typ)
58 queue.extend(typ.tProperties.values())
59 continue
61 if typ.c == base.c.DICT:
62 _add(typ)
63 queue.append(typ.tKey)
64 queue.append(typ.tValue)
65 continue
67 if typ.c in {base.c.LIST, base.c.SET}:
68 _add(typ)
69 queue.append(typ.tItem)
70 continue
72 if typ.c in {base.c.OPTIONAL, base.c.TYPE}:
73 _add(typ)
74 queue.append(typ.tTarget)
75 continue
77 if typ.c in {base.c.TUPLE, base.c.UNION}:
78 _add(typ)
79 queue.extend(typ.tItems)
80 continue
82 if typ.c == base.c.VARIANT:
83 _add(typ)
84 queue.extend(typ.tMembers.values())
85 continue
87 if typ.c == base.c.PROPERTY:
88 _add(typ)
89 queue.append(typ.tValue)
90 queue.append(typ.tOwner)
91 continue
93 if typ.c == base.c.CLASS:
94 _add(typ)
95 queue.extend(typ.tProperties.values())
96 continue
98 if typ.c == base.c.ENUM:
99 _add(typ)
100 continue
102 if typ.c == base.c.LITERAL:
103 _add(typ)
104 continue
106 if typ.c == base.c.EXT:
107 continue
109 raise base.GeneratorError(f'unbound object {typ.c}: {typ.uid!r} in {typ.pos}')