Skip to content

Commit b1c6c8b

Browse files
JustKiddingCodeKonstantin Zangerle
andauthored
feat: parse __init__.py files in packages. Closes: #52 (#76)
Co-authored-by: Konstantin Zangerle <[email protected]>
1 parent 702fd71 commit b1c6c8b

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ poetry run pytest -v --cov=py2puml --cov-branch --cov-report term-missing --cov-
203203
# Changelog
204204

205205
* `upcoming`: replaced yapf by the ruff formatter
206+
* `0.8.2`: add classes defined in `__init__.py` files to plantuml output
206207
* `0.8.1`: delegated the grouping of nested namespaces (see `0.7.0`) to the PlantUML binary, which handles it natively
207208
* `0.8.0`: added support for union types, and github actions (pre-commit hooks + automated tests)
208209
* `0.7.2`: added the current working directory to the import path to make py2puml work in any directory or in native virtual environment (not handled by poetry)
@@ -231,6 +232,7 @@ Unless stated otherwise all works are licensed under the [MIT license](http://sp
231232
* [Doyou Jung](https://github.com/doyou89)
232233
* [Julien Jerphanion](https://github.com/jjerphan)
233234
* [Luis Fernando Villanueva Pérez](https://github.com/jonykalavera)
235+
* [Konstantin Zangerle](https://github.com/justkiddingcode)
234236

235237
## Pull requests
236238

py2puml/inspection/inspectpackage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ def inspect_package(
1515
if not is_pkg:
1616
domain_item_module: ModuleType = import_module(name)
1717
inspect_module(domain_item_module, domain_module, domain_items_by_fqn, domain_relations)
18+
item_module = import_module(f'{domain_module}', f'{domain_module}.')
19+
inspect_module(item_module, domain_module, domain_items_by_fqn, domain_relations)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "py2puml"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
description = "Generate PlantUML class diagrams to document your Python application."
55
keywords = ["class diagram", "PlantUML", "documentation", "inspection", "AST"]
66
readme = "README.md"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
""" This is a package with a __init__.py file only """
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class InInitTest:
7+
test_member: str
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
""" This is a package with a __init__.py file only """
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class InTestModule:
7+
test_member: str
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@startuml tests.modules.withpkginitandmodule
2+
!pragma useIntermediatePackages false
3+
4+
class tests.modules.withpkginitandmodule.test.InTestModule {
5+
test_member: str
6+
}
7+
class tests.modules.withpkginitandmodule.InInitTest {
8+
test_member: str
9+
}
10+
footer Generated by //py2puml//
11+
@enduml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
""" This is a package with a __init__.py file only """
2+
from dataclasses import dataclass
3+
4+
5+
@dataclass
6+
class InitOnlyTest:
7+
test_member: str
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@startuml tests.modules.withpkginitonly
2+
!pragma useIntermediatePackages false
3+
4+
class tests.modules.withpkginitonly.InitOnlyTest {
5+
test_member: str
6+
}
7+
footer Generated by //py2puml//
8+
@enduml

tests/py2puml/test_py2puml.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,30 @@ def test_py2puml_model_on_py2uml_domain():
1515
assert_py2puml_is_file_content('py2puml/domain', 'py2puml.domain', domain_diagram_file_path)
1616

1717

18+
def test_py2puml_with_pkg_init_only():
19+
"""
20+
Ensure that __init__.py files are also parsed
21+
"""
22+
domain_diagram_file_path = CURRENT_DIR.parent / 'modules/withpkginitonly' / 'tests.modules.withpkginitonly.puml'
23+
24+
assert_py2puml_is_file_content(
25+
'tests/modules/withpkginitonly', 'tests.modules.withpkginitonly', domain_diagram_file_path
26+
)
27+
28+
29+
def test_py2puml_with_pkg_init_and_module():
30+
"""
31+
Ensure that __init__.py files are also parsed, in combination with other module
32+
"""
33+
domain_diagram_file_path = (
34+
CURRENT_DIR.parent / 'modules/withpkginitandmodule' / 'tests.modules.withpkginitandmodule.puml'
35+
)
36+
37+
assert_py2puml_is_file_content(
38+
'tests/modules/withpkginitandmodule', 'tests.modules.withpkginitandmodule', domain_diagram_file_path
39+
)
40+
41+
1842
def test_py2puml_with_heavily_nested_model():
1943
domain_diagram_file_path = (
2044
CURRENT_DIR.parent / 'modules' / 'withnestednamespace' / 'tests.modules.withnestednamespace.puml'

0 commit comments

Comments
 (0)