Skip to content

Commit 4787c5d

Browse files
Add minimal support fot abstract classes (#27)
* add support for abstract classes * update pytest version * undo changes * requested changes * implement pr changes * remove extra line break * tests(py2puml) fixed encodings * doc(CONTRIBUTING) contributors list and version number upgrade Co-authored-by: Luc Sorel-Giffo <[email protected]>
1 parent 9f25ca7 commit 4787c5d

File tree

14 files changed

+88
-14
lines changed

14 files changed

+88
-14
lines changed

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@ Corresponding unit tests must be added or adapted according to what was discusse
2323

2424
All text files are expected to be encoded in UTF-8.
2525

26+
## Contributions and version update
27+
28+
Add yourself at the bottom of the [contributions section of the README.md](README.md#contributions) file:
29+
30+
```text
31+
# Contributions
32+
33+
* [Luc Sorel-Giffo](https://github.com/lucsorel)
34+
* ...
35+
* [Your Full Name](https://github.com/yourgithubname)
36+
```
37+
38+
Discuss the new version number in the pull request and add a changelog line at the top of the [Changelog section of the README.md](README.md#changelog) file:
39+
40+
```text
41+
# Changelog
42+
43+
* `major.minor.patch`: the feature you added
44+
* ...
45+
```
46+
47+
The version number is carried by the [pyproject.toml](pyproject.toml) file, which is not installed along the production code.
48+
Some manual changes thus need to be made to update it in the CLI; please, update the version number:
49+
50+
- in the [version attribute of the pyproject.toml](pyproject.toml#L3) file
51+
52+
```toml
53+
[tool.poetry]
54+
name = "py2puml"
55+
version = "major.minor.patch"
56+
```
57+
58+
- in the [cli.py module](py2puml/cli.py#L12) (the string value associated to the `version` parameter)
59+
- in the [test__init__.py](tests/py2puml/test__init__.py#L5) file
60+
61+
2662
# Code practices
2763

2864
It takes time to write comprehensive guidelines.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Pipe the result of the CLI with a PlantUML server for instantaneous documentatio
134134

135135
```sh
136136
# runs a local PlantUML server from a docker container:
137-
docker run -d --rm -p 1234:8080 --name plantumlserver plantuml/plantuml-server:jetty
137+
docker run -d --rm -p 1234:8080 --name plantumlserver plantuml/plantuml-server:jetty
138138

139139
py2puml py2puml/domain py2puml.domain | curl -X POST --data-binary @- http://localhost:1234/svg/ --output - | display
140140

@@ -181,6 +181,7 @@ poetry run python -m pytest -v --cov=py2puml --cov-branch --cov-report term-miss
181181

182182
# Changelog
183183

184+
* `0.6.0`: handle abstract classes
184185
* `0.5.4`: fixed the packaging so that the contribution guide is included in the published package
185186
* `0.5.3`: handle constructors decorated by wrapping decorators (decorators making uses of `functools.wrap`)
186187
* `0.5.2`: specify in pyproject.toml that py2puml requires python 3.8+ (`ast.get_source_segment` was introduced in 3.8)
@@ -201,6 +202,7 @@ Unless stated otherwise all works are licensed under the [MIT license](http://sp
201202
* [Luc Sorel-Giffo](https://github.com/lucsorel)
202203
* [Doyou Jung](https://github.com/doyou89)
203204
* [Julien Jerphanion](https://github.com/jjerphan)
205+
* [Luis Fernando Villanueva Pérez](https://github.com/jonykalavera)
204206

205207
Pull-requests are welcome and will be processed on a best-effort basis.
206208
Follow the [contributing guide](CONTRIBUTING.md).

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py2puml/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def run():
1010
argparser = ArgumentParser(description='Generate PlantUML class diagrams to document your Python application.')
1111

12-
argparser.add_argument('-v', '--version', action='version', version='py2puml 0.5.4')
12+
argparser.add_argument('-v', '--version', action='version', version='py2puml 0.6.0')
1313
argparser.add_argument('path', metavar='path', type=str, help='the path of the domain')
1414
argparser.add_argument('module', metavar='module', type=str, help='the module of the domain', default=None)
1515

py2puml/domain/umlclass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ class UmlAttribute(object):
1212
@dataclass
1313
class UmlClass(UmlItem):
1414
attributes: List[UmlAttribute]
15+
is_abstract: bool = False

py2puml/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
))
77

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

py2puml/exportpuml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def to_puml_content(uml_items: List[UmlItem], uml_relations: List[UmlRelation])
2828
yield PUML_ITEM_END
2929
elif isinstance(uml_item, UmlClass):
3030
uml_class: UmlClass = uml_item
31-
yield PUML_ITEM_START_TPL.format(item_type='class', item_fqn=uml_class.fqn)
31+
yield PUML_ITEM_START_TPL.format(item_type='abstract class' if uml_item.is_abstract else 'class', item_fqn=uml_class.fqn)
3232
for uml_attr in uml_class.attributes:
3333
yield PUML_ATTR_TPL.format(attr_name=uml_attr.name, attr_type=uml_attr.type, staticity=FEATURE_STATIC if uml_attr.static else FEATURE_INSTANCE)
3434
yield PUML_ITEM_END

py2puml/inspection/inspectclass.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
from inspect import isabstract
23
from typing import Type, List, Dict
34

45
from re import compile
@@ -42,7 +43,8 @@ def inspect_static_attributes(
4243
uml_class = UmlClass(
4344
name=class_type.__name__,
4445
fqn=class_type_fqn,
45-
attributes=definition_attrs
46+
attributes=definition_attrs,
47+
is_abstract=isabstract(class_type)
4648
)
4749
domain_items_by_fqn[class_type_fqn] = uml_class
4850
# inspect_domain_definition(class_type)

py2puml/py2puml.domain.puml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class py2puml.domain.umlclass.UmlAttribute {
66
}
77
class py2puml.domain.umlclass.UmlClass {
88
attributes: List[UmlAttribute]
9+
is_abstract: bool
910
}
1011
class py2puml.domain.umlitem.UmlItem {
1112
name: str

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "py2puml"
3-
version = "0.5.4"
3+
version = "0.6.0"
44
description = "Generate PlantUML class diagrams to document your Python application."
55
keywords = ["class diagram", "PlantUML", "documentation", "inspection", "AST"]
66
readme = "README.md"
@@ -20,7 +20,7 @@ python = "^3.8"
2020

2121
[tool.poetry.dev-dependencies]
2222
pylint = "2.12.2"
23-
pytest = "6.2.2"
23+
pytest = "6.2.5"
2424
pytest-cov = "2.12.1"
2525

2626
[tool.pytest.ini_options]

0 commit comments

Comments
 (0)