33from py2puml .domain .package import Package
44from py2puml .domain .umlitem import UmlItem
55
6-
76# templating constants
87INDENT = ' '
98PUML_NAMESPACE_START_TPL = '{indentation}namespace {namespace_name} {{'
109PUML_NAMESPACE_END_TPL = '{indentation}}}\n '
1110
1211
1312def get_or_create_module_package (root_package : Package , domain_parts : List [str ]) -> Package :
14- ''' Returns or create the package containing the tail domain part'''
13+ """ Returns or create the package containing the tail domain part"""
1514 package = root_package
1615 for domain_part in domain_parts :
17- domain_package = next ((
18- sub_package for sub_package in package .children
19- if sub_package . name == domain_part
20- ), None )
16+ domain_package = next (
17+ ( sub_package for sub_package in package .children if sub_package . name == domain_part ),
18+ None ,
19+ )
2120 if domain_package is None :
2221 domain_package = Package (domain_part )
2322 package .children .append (domain_package )
2423 package = domain_package
2524 return package
2625
26+
2727def visit_package (package : Package , parent_namespace_names : Tuple [str ], indentation_level : int ) -> Iterable [str ]:
28- '''
28+ """
2929 Recursively visits the package and its subpackages to produce the PlantUML documentation about the namespace
30- '''
30+ """
3131 package_with_items = package .items_number > 0
3232 # prints the namespace if:
3333 # - it has inner uml_items
@@ -49,7 +49,7 @@ def visit_package(package: Package, parent_namespace_names: Tuple[str], indentat
4949 # initializes the namespace decalaration but not yield yet: we don't know if it should be closed now or if there is inner content
5050 start_of_namespace_line = PUML_NAMESPACE_START_TPL .format (
5151 indentation = INDENT * indentation_level ,
52- namespace_name = '.' .join (namespace_names )
52+ namespace_name = '.' .join (namespace_names ),
5353 )
5454
5555 parent_names = () if print_namespace else namespace_names
@@ -72,21 +72,23 @@ def visit_package(package: Package, parent_namespace_names: Tuple[str], indentat
7272 else :
7373 yield PUML_NAMESPACE_END_TPL .format (indentation = start_of_namespace_line )
7474
75+
7576def build_packages_structure (uml_items : List [UmlItem ]) -> Package :
76- '''
77+ """
7778 Creates the Package arborescent structure with the given UML items with their fully-qualified module names
78- '''
79+ """
7980 root_package = Package (None )
8081 for uml_item in uml_items :
8182 module_package = get_or_create_module_package (root_package , uml_item .fqn .split ('.' )[:- 1 ])
8283 module_package .items_number += 1
8384
8485 return root_package
8586
87+
8688def puml_namespace_content (uml_items : List [UmlItem ]) -> Iterable [str ]:
87- '''
89+ """
8890 Yields the documentation about the packages structure in the PlantUML syntax
89- '''
91+ """
9092 root_package = Package (None )
9193 # creates the Package arborescent structure with the given UML items with their fully-qualified module names
9294 for uml_item in uml_items :
@@ -95,4 +97,4 @@ def puml_namespace_content(uml_items: List[UmlItem]) -> Iterable[str]:
9597
9698 # yields the documentation using a visitor pattern approach
9799 for namespace_line in visit_package (root_package , (), 0 ):
98- yield f" { namespace_line } "
100+ yield f' { namespace_line } '
0 commit comments