Skip to content

Rework with pydantic + svg images in documentation#380

Merged
lord-haffi merged 47 commits intomainfrom
mwe-with-pydantic
Jul 13, 2022
Merged

Rework with pydantic + svg images in documentation#380
lord-haffi merged 47 commits intomainfrom
mwe-with-pydantic

Conversation

@hf-krechan
Copy link
Copy Markdown
Collaborator

@hf-krechan hf-krechan commented Jun 7, 2022

This draft PR should just show an example, how the pydantic approach could look like.

To avoid breaking unit tests I just copied the BO (Business Object) Geschaeftsobjekt and the COM (component) Externe Referenz as well as their unit tests and added the prefix pydantic_ to the file/module names.

Fixes #374

hf-krechan and others added 9 commits June 8, 2022 00:25
- ♻refactor Models and data validation
- 🚧refactor tests
- important note: Now e.g. "2.4" would be accepted as Decimal if the string is parsable (and it will be parsed!) -> a field with e.g. Decimal type hint will always be Decimal. But it can be set/initialized through e.g. a string if the string is parsable into a Decimal.
-> change of some test logic is needed
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Jun 17, 2022

This pull request introduces 111 alerts when merging 384358a into 8afe110 - view on LGTM.com

new alerts:

  • 111 for Unused import

- python 3.10 ist needed (because of NoneType in test-files)
- switch from marschmallow + attr to pydantic
@lord-haffi
Copy link
Copy Markdown
Collaborator

lord-haffi commented Jun 28, 2022

Some notes to the PR:

  • switched from marshmallow + attr / attrs to pydantic
    • data validation and de/serialization will be processed by pydantic
      • serialization with <instance>.json(by_alias=True, ensure_ascii=False)
      • deserialization with <class>.parse_raw(<json_string>)
      • note: pydantic comes with some useful types
    • now schema-classes aren't neccessary anymore -> removed
    • json-schemas for readthedocs are created via .schema_json()
      • note: json-schema files got renamed from <classname>Schema.json to <classname>.json
    • important note: Now e.g. "2.4" would be accepted as Decimal if the string is parsable (and it will be parsed!) -> a field with e.g. Decimal type hint will always be Decimal. But it can be set/initialized through e.g. a string if the string is parsable into a Decimal.
  • auto creation of uml-diagrams and integration with sphinx via graphviz
    • note: If you build the docs local via tox -e docs or tox, Graphviz tools (non-python software) need to be installed on your machine and its bin added to PATH (the install software should do this for you). Otherwise it will crash by unknown command dot.
    • uml-diagrams are generated for all classes in bo and com via docs/conf.py in sphinx on runtime by calling docs/uml.py -> creates *.dot files in docs/api/dots
    • *.dot files can be referenced in docstrings via graphviz directive

Copy link
Copy Markdown
Contributor

@hf-kklein hf-kklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das sieht ja schonmal ganz nice aus 👍

Ich hätte gerne bei den Grafiken noch zwei,drei Improvements (wenn mit vertretbarem Aufwand machbar):

  1. Können wir das Businessobject/die Komponente, die im Zentrum steht nach ganz oben statt nach ganz unten ziehen oder irgendwie hervorheben?
  2. Können wir (wie in der bisherigen Doku) Business Objects und COMponenten verschieden einfärben?
  3. Können wir die Kardinalitäten an die Pfeil dranschreiben?
    grafik


All COMponents inherit from `bo4e.com.COM`.
All Business Objects inherit from `bo4e.bo.Geschaeftsobjekt`.
All COMponents inherit from `bo4e.com.com.COM`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
All COMponents inherit from `bo4e.com.com.COM`.
All COMponents inherit from `bo4e.com.COM`.

Copy link
Copy Markdown
Collaborator

@lord-haffi lord-haffi Jun 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Der Namenspace der Klasse COM ist aber
bo4e.<package>.<module>.<class>
D.h.
bo4e.com.com.COM

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vll wäre sowas wie base_com sinnvoll

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meinste? Ich find com com COM ja großartig 😁

Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
@lord-haffi
Copy link
Copy Markdown
Collaborator

  1. Können wir das Businessobject/die Komponente, die im Zentrum steht nach ganz oben statt nach ganz unten ziehen oder irgendwie hervorheben?

Das wird schwierig. Ich kann mal versuchen, ob die verschiedenen Layout-Algorithmen irgendwas besser machen, aber manuell etwas zu setzen würde nur gehen, wenn man sich einen eigenen Layout-Algorithmus definiert. Wobei ich auch nichtmal sicher bin, ob man den dann so einfach integrieren kann.

  1. Können wir (wie in der bisherigen Doku) Business Objects und COMponenten verschieden einfärben?

Kann gut sein, dass das geht, ich schau mal.

  1. Können wir die Kardinalitäten an die Pfeil dranschreiben?

Das geht auf jeden Fall - sogar mit verhältnismäßig wenig Aufwand.

lord-haffi and others added 8 commits June 29, 2022 12:43
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Added back python versions 3.8 and 3.9 to github CI workflow because `typingx.NoneType` is unnecessary.
@lord-haffi
Copy link
Copy Markdown
Collaborator

lord-haffi commented Jul 8, 2022

Since some things changed, an updated list of important things:

  • switched from marshmallow + attr / attrs to pydantic
    • data validation and de/serialization will be processed by pydantic
      • serialization with <instance>.json(by_alias=True, ensure_ascii=False)
      • deserialization with <class>.parse_raw(<json_string>)
      • note: pydantic comes with some useful types
    • now schema-classes aren't neccessary anymore -> removed
    • json-schemas for readthedocs are created via .schema_json()
      • important note: json-schema files got renamed from <classname>Schema.json to <classname>.json
    • important note: Now e.g. "2.4" would be accepted as Decimal if the string is parsable (and it will be parsed!) -> a field with e.g. Decimal type hint will always be Decimal. But it can be set/initialized through e.g. a string if the string is parsable into a Decimal.
  • auto creation of uml-diagrams and integration with sphinx via plantuml
    • note: If you build the docs local via tox -e docs or tox, Plantuml (Java software) will be downloaded automatically via curl into your docs folder. For instance, this means you must have a Java Runtime Environment installed and Java on path in order to build the docs.
    • uml-diagrams are generated for all classes in bo and com via docs/conf.py in sphinx on runtime by calling docs/uml.py -> creates *.puml files in docs/api/uml
    • these *.puml files are compiled by docs/plantuml.jar into docs/_static/images.
    • *.svg files can be included in docstrings via an object tag, e.g. <object data="../_static/images/bo4e/bo/Marktlokation.svg" type="image/svg+xml"></object>

@lord-haffi lord-haffi marked this pull request as ready for review July 8, 2022 15:32
Copy link
Copy Markdown
Contributor

@hf-kklein hf-kklein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nur noch ein paar kleinigkeiten :) Sonst siehts gut aus. Bitte vor dem squashen dem PR/bzw. dem entstehenden Commit auf main noch einen aussagekräftigen Namen geben (also sinngemäß nicht mehr mwe sondern eher: gesamt-umbau+doku)

@hf-krechan hf-krechan changed the title MWE with pydantic Rework with pydantic + svg images in documentation Jul 11, 2022
lord-haffi and others added 9 commits July 11, 2022 12:05
The cache functionality of the network is now clearer and better. Also some minor enhancements, see PR.
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
@lord-haffi lord-haffi merged commit 63a5ec0 into main Jul 13, 2022
@lord-haffi lord-haffi deleted the mwe-with-pydantic branch July 13, 2022 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Visualiserung / UML-Diagramme

3 participants