sogno-platform / cimgen

Code generation from CIM data model for several programming languages
Apache License 2.0
13 stars 6 forks source link

Modernpython #18

Closed guillaume-alliander closed 9 months ago

guillaume-alliander commented 11 months ago

Adding Python 3.9+ langpack, with pydantic dataclasses.

Those classes cannot be used directly with cimpy, but they do simplify quite a lot of coding. The class tree crawling is built into Base, profiles to which an attribute belongs are added to the attribute definition itself, json dump/parsing is built in.

Sonarcloud complains about code smells - those are logical, but fixing those would cause discrepancy with the style of the rest of the code, so I leave them as is for now. If that's not the best option, let me know.

sonarcloud[bot] commented 11 months ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

chicco785 commented 11 months ago

@guillaume-alliander interesting work!

I am working on something similar (albeit I am not using dataclass but BaseModel), and found out a few issues with recursive models across multiple files, which lead me to generate a single file:

https://github.com/zaphiro-technologies/cimgen/pull/5

did you test the generated code?

happy to help :)

guillaume-alliander commented 11 months ago

@chicco785

I based this a lot on the current python serialization. As the recursion aspect was not there, it's not present in my classes :)

You are correct that I do not use other dataclasses as attributes. It would be nice indeed. I am currently heavily using the generated classes, and adding dataclasses as possible attributes could have very interesting aspects. My final goal would be to load the graph in rdflib (to export to xml, json-ld, ttl... for free), and that could help.

chicco785 commented 11 months ago

@chicco785

I based this a lot on the current python serialization. As the recursion aspect was not there, it's not present in my classes :)

to keep simple and the parse easy, it may make completely sense! it is just more complex to navigate a linked object (you will have to search it by id through the full list of objects)

You are correct that I do not use other dataclasses as attributes. It would be nice indeed. I am currently heavily using the generated classes, and adding dataclasses as possible attributes could have very interesting aspects. My final goal would be to load the graph in rdflib (to export to xml, json-ld, ttl... for free), and that could help.

of course we want also to be able to import and export to different format, plus ideally make easy to manipulate / filter the objects via APIs (that's why we have been looking into pydantic and we tested the recursion support), beyond that, for us, also storage in a database (so adding also SQL Alchemy support) is an interesting feature.

Maybe we can have a short call, exchange ideas, and see if there is a chance for a collaboration?

guillaume-alliander commented 11 months ago

Maybe we can have a short call, exchange ideas, and see if there is a chance for a collaboration?

Sure, that sounds great! To avoid sharing publicly email addresses, I found you on LinkedIn and will send a message here.

guillaume-alliander commented 9 months ago

@iripiri Would it be possible to get a review for this PR?

More updates here will come, but this PR is a nicely self-contained.

iripiri commented 9 months ago

Sorry for the delay, the changes look good to me. Thanks for your efforts!