Skip to content

Commit db134ca

Browse files
authored
32 add namespace structure in the PlantUML result (#37)
* mentions the pyreverse alternative, closes #31 * prevents example.py from producing artifacts when being imported * removed object inheritance, added comments and docstring * WIP add namespace * docs(readme): homogenize code formatting * tests(astvisitors): shorten type annotations * added py2puml footer * do not version diagram files generated by the PlantUML vscode extension * docs: comments about module resolver * refactor(py2puml): externalize inspect_package for test reuse * tests(namespace): add integration test with a deeply-nested namespace * docs(readme): update the PlantUML diagram of the py2puml domain model * fix(tests): remove undeclared variable, remove unused import * tests(fixtures): mutualized fixtures for tests that parse modules * refactor: remove merge files * build(dependencies): update dev dependencies
1 parent d708fac commit db134ca

Some content is hidden

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

56 files changed

+1173
-518
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ dist/
66
.vscode/
77
# data generated by pytest-cov
88
.coverage
9+
# directory where the PlantUML extension produced diagram files
10+
out/

README.md

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,30 @@ For example, to create the diagram of the classes used by `py2puml`, run:
7474
py2puml py2puml/domain py2puml.domain
7575
```
7676

77-
This outputs the following PlantUML script:
77+
This outputs the following PlantUML content:
7878

7979
```plantuml
80-
@startuml
80+
@startuml py2puml.domain
81+
namespace py2puml.domain {
82+
namespace package {}
83+
namespace umlclass {}
84+
namespace umlitem {}
85+
namespace umlenum {}
86+
namespace umlrelation {}
87+
}
88+
class py2puml.domain.package.Package {
89+
name: str
90+
children: List[Package]
91+
items_number: int
92+
}
8193
class py2puml.domain.umlclass.UmlAttribute {
8294
name: str
8395
type: str
8496
static: bool
8597
}
8698
class py2puml.domain.umlclass.UmlClass {
8799
attributes: List[UmlAttribute]
100+
is_abstract: bool
88101
}
89102
class py2puml.domain.umlitem.UmlItem {
90103
name: str
@@ -106,17 +119,19 @@ class py2puml.domain.umlrelation.UmlRelation {
106119
target_fqn: str
107120
type: RelType
108121
}
122+
py2puml.domain.package.Package *-- py2puml.domain.package.Package
109123
py2puml.domain.umlclass.UmlClass *-- py2puml.domain.umlclass.UmlAttribute
110124
py2puml.domain.umlitem.UmlItem <|-- py2puml.domain.umlclass.UmlClass
111125
py2puml.domain.umlenum.UmlEnum *-- py2puml.domain.umlenum.Member
112126
py2puml.domain.umlitem.UmlItem <|-- py2puml.domain.umlenum.UmlEnum
113127
py2puml.domain.umlrelation.UmlRelation *-- py2puml.domain.umlrelation.RelType
128+
footer Generated by //py2puml//
114129
@enduml
115130
```
116131

117-
Using PlantUML, this script renders this diagram:
132+
Using PlantUML, this content is rendered as this diagram:
118133

119-
![py2puml UML Diagram](http://www.plantuml.com/plantuml/png/ZPB1Qy8m5CRl-IlUMR277Oi7HOGLfXrTTnfZfFLj59AqIru7elxlUuqQ1ewcftmcvlTzUL-NZgIbNYjHA-aST8U7Zdyb-rRBnYGi_NxogjMAo3PLJmX70M2anXGSMTPqw89c7ZLr2bNRAd6EKzU3y4HvuxiKdXf7RtyztqTO3Q4UK1clTza-lusN8_VHz3hPegxGtbt_aQh7IG0EiE7L4xI7tTvnGGyl6FxuptsBYeVMcgH0LV8iFMETRv_pbwpCybqACpXU1dlcasptk2coShLRRr9OdC9HI3ZYm2cBg_OkhkrjZHzXIW0axHTIs0drNhEnIRJDsNm-wKCIaIuN9mR5t4Ia3muptlca5ECcOjh4VPPu_MA9Pi_xlm00)
134+
![py2puml domain UML Diagram](https://www.plantuml.com/plantuml/png/ZPD1Yzim48Nl-XLpNbWRUZHxs2M4rj1DbZGzbIN8zcmgAikkD2wO9F-zigqWEw1L3i6HPgJlFUdfsH3NrDKIslvBQxz9rTHSAAPuZQRb9TuKuCG0PaLU_k5776S1IicDkLcGk9RaRT4wRPA18Ut6vMyXAuqgW-_2q2_N_kwgWh0s1zNL1UeCXA9n_iAcdnTamQEApnHTUvAVjNmXqgBeAAoB-dOnDiH9b1aKJIETYBj8gvai07xb6kTtfiMRDWTUM38loV62feVpYNWUMWOXkVq6tNxyLMuO8g7g8gIn9Nd5uQw2e7zSTZX7HJUqqjUU3L2FWElvJRZti6wDafDeb5i_shWb-QvaXtBVjpuMg-ths_P7li-tcmmUu3J5uEAg-URRUfVlNpQhTGPFPr-EUlD4ws-tr0XWcawNU5ZS2W1nVKJoi_EWEjspSxYmo8jyU7oCF5eMoxNV8_BCM2INJsUxKOp68WdnOWAfl5j56CBkl4cd9H8pzj4qX1g-eaBD2IieUaXJjp1DsJEgolvZ_m40)
120135

121136
For a full overview of the CLI, run:
122137

@@ -147,40 +162,42 @@ docker start plantumlserver
147162

148163
For example, to create the diagram of the classes used by `py2puml`:
149164

150-
* import the py2puml function in your script (see [py2puml/example.py](py2puml/example.py)):
165+
* import the `py2puml` function in your script (see [py2puml/example.py](py2puml/example.py)):
151166

152167
```python
153168
from py2puml.py2puml import py2puml
154169

155-
# outputs the PlantUML content in the terminal
156-
print(''.join(py2puml('py2puml/domain', 'py2puml.domain')))
170+
if __name__ == '__main__':
171+
# outputs the PlantUML content in the terminal
172+
print(''.join(py2puml('py2puml/domain', 'py2puml.domain')))
157173

158-
# writes the PlantUML content in a file
159-
with open('py2puml/domain.puml', 'w') as puml_file:
160-
puml_file.writelines(py2puml('py2puml/domain', 'py2puml.domain'))
174+
# writes the PlantUML content in a file
175+
with open('py2puml/domain.puml', 'w') as puml_file:
176+
puml_file.writelines(py2puml('py2puml/domain', 'py2puml.domain'))
161177
```
162178

163-
* running it (`python3 -m py2puml.example`) will output the previous PlantUML diagram in the terminal and write it in a file.
179+
* running it (`python3 -m py2puml.example`) outputs the previous PlantUML diagram in the terminal and writes it in a file.
164180

165181

166182
# Tests
167183

168184
```sh
169185
# directly with poetry
170-
poetry run python -m pytest -v
186+
poetry run pytest -v
171187

172188
# in a virtual environment
173189
python3 -m pytest -v
174190
```
175191

176-
Code coverage (with missed [branch statements](https://pytest-cov.readthedocs.io/en/latest/config.html?highlight=--cov-branch)):
192+
Code coverage (with [missed branch statements](https://pytest-cov.readthedocs.io/en/latest/config.html?highlight=--cov-branch)):
177193

178194
```sh
179-
poetry run python -m pytest -v --cov=py2puml --cov-branch --cov-report term-missing --cov-fail-under 90
195+
poetry run pytest -v --cov=py2puml --cov-branch --cov-report term-missing --cov-fail-under 90
180196
```
181197

182198
# Changelog
183199

200+
* `0.7.0`: improved the generated PlantUML documentation (added the namespace structure of the code base, homogenized type between inspection and parsing), improved relationships management (handle forward references, deduplicate relationships)
184201
* `0.6.1`: handle class names with digits
185202
* `0.6.0`: handle abstract classes
186203
* `0.5.4`: fixed the packaging so that the contribution guide is included in the published package
@@ -231,6 +248,7 @@ Follow the [contributing guide](CONTRIBUTING.md).
231248

232249
If `py2puml` does not meet your needs (suggestions and pull-requests are **welcome**), you can have a look at these projects which follow other approaches (AST, linting, modeling):
233250

251+
* [pyreverse](https://pylint.pycqa.org/en/latest/additional_commands/index.html#pyreverse), which includes a PlantUML printer [since version 2.10.0](https://pylint.pycqa.org/en/latest/whatsnew/changelog.html?highlight=plantuml#what-s-new-in-pylint-2-10-0)
234252
* [cb109/pyplantuml](https://github.com/cb109/pyplantuml)
235253
* [deadbok/py-puml-tools](https://github.com/deadbok/py-puml-tools)
236254
* [caballero/genUML](https://github.com/jose-caballero/genUML)

0 commit comments

Comments
 (0)