Skip to content

Commit a2750b2

Browse files
jonykalaveralucsorel
authored andcommitted
feat: add support to detect and document methods
1 parent 175997a commit a2750b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1762
-829
lines changed

init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ echo "$(date '+%Y-%m-%d_%H:%M:%S') $(poetry --version) will be used to install d
2121

2222
# installs the project dependencies
2323
echo "$(date '+%Y-%m-%d_%H:%M:%S') poetry ${depsinstall}"
24-
poetry ${depsinstall}
24+
poetry ${depsinstall}

py2puml/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from py2puml.cli import run
22

3-
if __name__ == '__main__':
3+
if __name__ == "__main__":
44
run()

py2puml/asserts.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
from py2puml.py2puml import py2puml
66

77

8-
def assert_py2puml_is_file_content(domain_path: str, domain_module: str, diagram_filepath: Union[str, Path]):
8+
def assert_py2puml_is_file_content(
9+
domain_path: str, domain_module: str, diagram_filepath: Union[str, Path]
10+
):
911
# reads the existing class diagram
10-
with open(diagram_filepath, 'r', encoding='utf8') as expected_puml_file:
12+
with open(diagram_filepath, "r", encoding="utf8") as expected_puml_file:
1113
assert_py2puml_is_stringio(domain_path, domain_module, expected_puml_file)
1214

13-
def assert_py2puml_is_stringio(domain_path: str, domain_module: str, expected_content_stream: StringIO):
15+
16+
def assert_py2puml_is_stringio(
17+
domain_path: str, domain_module: str, expected_content_stream: StringIO
18+
):
1419
# generates the PlantUML documentation
1520
puml_content = list(py2puml(domain_path, domain_module))
1621

@@ -19,7 +24,14 @@ def assert_py2puml_is_stringio(domain_path: str, domain_module: str, expected_co
1924

2025
def assert_multilines(actual_multilines: List[str], expected_multilines: Iterable[str]):
2126
line_index = 0
22-
for line_index, (actual_line, expected_line) in enumerate(zip(actual_multilines, expected_multilines)):
23-
assert actual_line == expected_line, f'actual and expected contents have changed at line {line_index + 1}: {actual_line=}, {expected_line=}'
24-
25-
assert line_index + 1 == len(actual_multilines), f'actual and expected diagrams have {line_index + 1} lines'
27+
for line_index, (actual_line, expected_line) in enumerate(
28+
zip(actual_multilines, expected_multilines)
29+
):
30+
# print(actual_line[:-1])
31+
assert (
32+
actual_line == expected_line
33+
), f"actual and expected contents have changed at line {line_index + 1}: {actual_line=}, {expected_line=}"
34+
35+
assert line_index + 1 == len(
36+
actual_multilines
37+
), f"actual and expected diagrams have {line_index + 1} lines"

py2puml/cli.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,21 @@ def run():
1414
if current_working_directory not in path:
1515
path.append(current_working_directory)
1616

17-
argparser = ArgumentParser(description='Generate PlantUML class diagrams to document your Python application.')
17+
argparser = ArgumentParser(
18+
description="Generate PlantUML class diagrams to document your Python application."
19+
)
1820

19-
argparser.add_argument('-v', '--version', action='version', version='py2puml 0.7.2')
20-
argparser.add_argument('path', metavar='path', type=str, help='the filepath to the domain')
21-
argparser.add_argument('module', metavar='module', type=str, help='the module name of the domain', default=None)
21+
argparser.add_argument("-v", "--version", action="version", version="py2puml 0.7.2")
22+
argparser.add_argument(
23+
"path", metavar="path", type=str, help="the filepath to the domain"
24+
)
25+
argparser.add_argument(
26+
"module",
27+
metavar="module",
28+
type=str,
29+
help="the module name of the domain",
30+
default=None,
31+
)
2232

2333
args = argparser.parse_args()
24-
print(''.join(py2puml(args.path, args.module)))
34+
print("".join(py2puml(args.path, args.module)))

py2puml/domain/package.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from dataclasses import dataclass, field
22
from typing import List
33

4+
45
@dataclass
56
class Package:
6-
'''A folder or a python module'''
7+
"""A folder or a python module"""
8+
79
name: str
8-
children: List['Package'] = field(default_factory=list)
10+
children: List["Package"] = field(default_factory=list)
911
items_number: int = 0

py2puml/domain/umlclass.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
1-
from typing import List
2-
from dataclasses import dataclass
1+
from dataclasses import dataclass, field
2+
from typing import Dict, List
33

44
from py2puml.domain.umlitem import UmlItem
55

6+
67
@dataclass
78
class UmlAttribute:
89
name: str
910
type: str
1011
static: bool
1112

13+
14+
@dataclass
15+
class UmlMethod:
16+
name: str
17+
arguments: Dict = field(default_factory=dict)
18+
is_static: bool = False
19+
is_class: bool = False
20+
return_type: str = None
21+
22+
def represent_as_puml(self):
23+
items = []
24+
if self.is_static:
25+
items.append("{static}")
26+
if self.return_type:
27+
items.append(self.return_type)
28+
items.append(f"{self.name}({self.signature})")
29+
return " ".join(items)
30+
31+
@property
32+
def signature(self):
33+
if self.arguments:
34+
return ", ".join(
35+
[
36+
f"{arg_type} {arg_name}" if arg_type else f"{arg_name}"
37+
for arg_name, arg_type in self.arguments.items()
38+
]
39+
)
40+
return ""
41+
42+
1243
@dataclass
1344
class UmlClass(UmlItem):
1445
attributes: List[UmlAttribute]
46+
methods: List[UmlMethod]
1547
is_abstract: bool = False

py2puml/domain/umlenum.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
from typing import List
21
from dataclasses import dataclass
2+
from typing import List
33

44
from py2puml.domain.umlitem import UmlItem
55

6+
67
@dataclass
78
class Member:
89
name: str
910
value: str
1011

12+
1113
@dataclass
1214
class UmlEnum(UmlItem):
1315
members: List[Member]

py2puml/domain/umlitem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22

3+
34
@dataclass
45
class UmlItem:
56
name: str
6-
fqn: str
7+
fqn: str

py2puml/domain/umlrelation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from dataclasses import dataclass
22
from enum import Enum, unique
33

4+
45
@unique
56
class RelType(Enum):
6-
COMPOSITION = '*'
7-
INHERITANCE = '<|'
7+
COMPOSITION = "*"
8+
INHERITANCE = "<|"
9+
810

911
@dataclass
1012
class UmlRelation:

py2puml/example.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from py2puml.py2puml import py2puml
22

3-
if __name__ == '__main__':
3+
if __name__ == "__main__":
44
# outputs the PlantUML content in the terminal
5-
print(''.join(
6-
py2puml('py2puml/domain', 'py2puml.domain')
7-
))
5+
print("".join(py2puml("py2puml/domain", "py2puml.domain")))
86

97
# writes the PlantUML content in a file
10-
with open('py2puml/py2puml.domain.puml', 'w', encoding='utf8') as puml_file:
11-
puml_file.writelines(py2puml('py2puml/domain', 'py2puml.domain'))
8+
with open("py2puml/py2puml.domain.puml", "w", encoding="utf8") as puml_file:
9+
puml_file.writelines(py2puml("py2puml/domain", "py2puml.domain"))

0 commit comments

Comments
 (0)