Skip to content

Commit 1ef8b9a

Browse files
authored
docs: bugfix arch modeling (eclipse-score#875)
* docs: bugfix arch modeling * docs: additional bugfixes - follow up PR 807 - include additional error handling
1 parent f037323 commit 1ef8b9a

File tree

2 files changed

+198
-125
lines changed

2 files changed

+198
-125
lines changed

docs/_tooling/extensions/score_draw_uml_funcs/__init__.py

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@
3636
from sphinx_needs.logging import get_logger
3737

3838
from score_draw_uml_funcs.helpers import (
39-
gen_alias,
4039
gen_header,
4140
gen_interface_element,
4241
gen_link_text,
4342
gen_struct_element,
43+
get_alias,
44+
get_hierarchy_text,
4445
get_impl_comp_from_real_iface,
4546
get_interface_from_component,
4647
get_interface_from_int,
4748
get_logical_interface_real,
48-
get_module,
4949
get_real_interface_logical,
5050
)
5151

@@ -87,10 +87,20 @@ def scripts_directory_hash():
8787

8888
def draw_comp_incl_impl_int(
8989
need: dict[str, str],
90-
all_needs: dict[str, dict[str, Any]],
90+
all_needs: dict[str, dict[str, str]],
9191
proc_impl_interfaces: dict[str, str],
9292
proc_used_interfaces: dict[str, list[str]],
9393
) -> tuple[str, str, dict[str, str], dict[str, list[str]]]:
94+
"""This function draws a component including any interfaces which are implemented
95+
by the component
96+
97+
:param dict[str,str] need: Component which should be drawn
98+
:param dict all_needs: Dictionary containing all needs
99+
:param dict[str,dict] proc_impl_interfaces: Dictionary containing all implemented interfaces
100+
which were already processed during this cycle
101+
:param dict[str,dict] proc_used_interfaces: Dictionary containing all used interfaces
102+
which were already processed during this cycle
103+
"""
94104
# Draw outer component
95105
structure_text = f"{gen_struct_element('component', need)} {{\n"
96106
linkage_text = ""
@@ -160,7 +170,7 @@ def draw_comp_incl_impl_int(
160170

161171
def draw_module(
162172
need: dict[str, str],
163-
all_needs: dict[str, dict[str, Any]],
173+
all_needs: dict[str, dict[str, str]],
164174
) -> tuple[str, str]:
165175
"""
166176
Drawing and parsing function of a component.
@@ -215,9 +225,9 @@ def draw_module(
215225
Processed Logical Interfaces)
216226
"""
217227
# Store all Elements which have already been processed
218-
proc_impl_interfaces = dict()
219-
proc_used_interfaces = dict()
220-
proc_logical_interfaces = dict()
228+
proc_impl_interfaces: dict[str, str] = dict()
229+
proc_used_interfaces: dict[str, list[str]] = dict()
230+
proc_logical_interfaces: dict[str, str] = dict()
221231

222232
linkage_text = ""
223233

@@ -230,7 +240,7 @@ def draw_module(
230240

231241
# check for misspelled include
232242
if not curr_need:
233-
logger.info(f"{need}: include {need_inc} could not be found")
243+
logger.info(f"{need}: include with id {need_inc} could not be found")
234244
continue
235245

236246
if curr_need["type"] not in ["comp_arc_sta", "mod_view_sta"]:
@@ -253,9 +263,10 @@ def draw_module(
253263
if not (proc_logical_interfaces.get(iface, [])):
254264
# Currently only one Logical Interface per Real Interface supported
255265
logical_iface_tmp = get_logical_interface_real(iface, all_needs)
256-
assert (
257-
len(logical_iface_tmp) == 1
258-
), "only one logical interface per real interface supported"
266+
if len(logical_iface_tmp) > 1:
267+
logger.warning(
268+
f"{logical_iface_tmp}: only one logical interface per real interface supported"
269+
)
259270
if logical_iface_tmp:
260271
logical_iface = logical_iface_tmp[0]
261272
proc_logical_interfaces[logical_iface] = iface
@@ -279,16 +290,16 @@ def draw_module(
279290
# Add implementing components and modules
280291
impl_comp_str = get_impl_comp_from_real_iface(iface, all_needs)
281292

282-
impl_comp = all_needs.get(impl_comp_str, {}) if impl_comp_str else ""
293+
impl_comp = all_needs.get(impl_comp_str[0], {}) if impl_comp_str else ""
283294

284295
if impl_comp:
285-
retval = get_module(impl_comp_str, all_needs)
296+
retval = get_hierarchy_text(impl_comp_str[0], all_needs)
286297
structure_text += retval[2] # module open
287298
structure_text += retval[0] # rest open
288299

289300
structure_text += retval[1] # rest close
290-
structure_text += gen_interface_element(iface, all_needs, True)
291301
structure_text += retval[3] # module close
302+
structure_text += gen_interface_element(iface, all_needs, True)
292303

293304
# Draw connection between implementing components and interface
294305
linkage_text += f"{gen_link_text(impl_comp, '-u->', all_needs[iface], 'implements')} \n"
@@ -319,13 +330,13 @@ def __repr__(self):
319330
return "draw_full_feature" + " in " + scripts_directory_hash()
320331

321332
def __call__(
322-
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
333+
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
323334
) -> str:
324-
interfacelist = []
325-
impl_comp = dict()
335+
interfacelist: list[str] = []
336+
impl_comp: dict[str, str] = dict()
326337

327338
structure_text = (
328-
f'actor "Feature User" as {gen_alias({"id": "Feature_User"})} \n'
339+
f'actor "Feature User" as {get_alias({"id": "Feature_User"})} \n'
329340
)
330341

331342
# Define Feature as a package
@@ -340,44 +351,56 @@ def __call__(
340351
interfacelist.append(iface)
341352

342353
for iface in interfacelist:
343-
structure_text += gen_interface_element(iface, all_needs, True)
354+
if imcomp := all_needs.get(iface):
355+
structure_text += gen_interface_element(iface, all_needs, True)
344356

345-
# Determine Components which implement the interfaces
346-
real_iface = get_real_interface_logical(iface, all_needs)
347-
if real_iface:
348-
comps = get_impl_comp_from_real_iface(real_iface[0], all_needs)
357+
# Determine Components which implement the interfaces
358+
real_iface = get_real_interface_logical(iface, all_needs)
359+
if real_iface:
360+
comps = get_impl_comp_from_real_iface(real_iface[0], all_needs)
349361

350-
if comps:
351-
impl_comp[iface] = comps
362+
if comps:
363+
impl_comp[iface] = comps[0]
352364

353-
if imcomp := impl_comp.get(iface):
354-
structure_text += (
355-
f"{gen_struct_element('component', all_needs[imcomp])}\n"
356-
)
365+
if imcomp := impl_comp.get(iface, {}):
366+
structure_text += (
367+
f"{gen_struct_element('component', all_needs[imcomp])}\n"
368+
)
369+
else:
370+
logger.info(f"{need}: Interface {iface} could not be found")
371+
continue
357372

358373
# Close Package
359374
# structure_text += f"}} /' {need['title']} '/ \n\n"
360375

361376
link_text = ""
362377

363378
for iface in interfacelist:
364-
# Add relation between Actor and Interfaces
365-
link_text += f"{
366-
gen_link_text({'id': 'Feature_User'}, '-d->', all_needs[iface], 'use')
367-
} \n"
368-
369-
# Add relation between interface and component
370379
if imcomp := impl_comp.get(iface):
380+
# Add relation between Actor and Interfaces
371381
link_text += f"{
372382
gen_link_text(
373-
all_needs[imcomp],
374-
'-u->',
375-
all_needs[iface],
376-
'implements',
383+
{'id': 'Feature_User'}, '-d->', all_needs[iface], 'use'
377384
)
378385
} \n"
386+
387+
# Add relation between interface and component
388+
if imcomp := impl_comp.get(iface):
389+
link_text += f"{
390+
gen_link_text(
391+
all_needs[imcomp],
392+
'-u->',
393+
all_needs[iface],
394+
'implements',
395+
)
396+
} \n"
397+
else:
398+
logger.info(
399+
f"Interface {iface} is not implemented by any component"
400+
)
379401
else:
380-
print(f"Interface {iface} is not implemented by any component")
402+
logger.info(f"{need}: Interface {iface} could not be found")
403+
continue
381404

382405
return gen_header() + structure_text + link_text
383406

@@ -387,7 +410,7 @@ def __repr__(self):
387410
return "draw_full_module" + " in " + scripts_directory_hash()
388411

389412
def __call__(
390-
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
413+
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
391414
) -> str:
392415
structure_text, linkage_text = draw_module(need, all_needs)
393416

@@ -399,7 +422,7 @@ def __repr__(self):
399422
return "draw_full_component" + " in " + scripts_directory_hash()
400423

401424
def __call__(
402-
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
425+
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
403426
) -> str:
404427
structure_text, linkage_text, _, _ = draw_comp_incl_impl_int(
405428
need, all_needs, dict(), dict()
@@ -413,7 +436,7 @@ def __repr__(self):
413436
return "draw_full_interface" + " in " + scripts_directory_hash()
414437

415438
def __call__(
416-
self, need: dict[str, Any], all_needs: dict[str, dict[str, Any]]
439+
self, need: dict[str, str], all_needs: dict[str, dict[str, str]]
417440
) -> str:
418441
structure_text = gen_interface_element(need["id"], all_needs, True)
419442

0 commit comments

Comments
 (0)