Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pydantic code generation #5

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f4029b8
base pydantic code generator
chicco785 Jul 28, 2023
a89ad7a
fix __init__.py import
chicco785 Jul 29, 2023
d92eadc
Automated Black fmt fixes
Jul 29, 2023
b3d7f6c
docs(release_notes): update RELEASE_NOTES.md
chicco785 Jul 29, 2023
2d2faeb
support cyclic reference serialization
chicco785 Jul 31, 2023
b2779cc
add pydantic to tests
chicco785 Jul 31, 2023
03a514d
Automated Black fmt fixes
Jul 31, 2023
267849c
docs(release_notes): update RELEASE_NOTES.md
chicco785 Jul 31, 2023
de05e72
fix import issue
chicco785 Jul 31, 2023
d6ac0fb
improve datatype support
chicco785 Jul 31, 2023
ab3a612
fix multiplicity support in validator generation
chicco785 Jul 31, 2023
bfcef79
add schema and pydantic to docker build
chicco785 Jul 31, 2023
65aa211
Automated Black fmt fixes
Jul 31, 2023
d7021fd
fix Enum for CgmesProfile
chicco785 Jul 31, 2023
169f3bf
generates only EQ profile (tested in CIM-Manager)
chicco785 Aug 2, 2023
860ab89
fix rendering for usage of &quote; in CMGES3.0
chicco785 Aug 2, 2023
91f5338
fix copy file path
chicco785 Aug 2, 2023
d9cdc71
docs(release_notes): update RELEASE_NOTES.md
chicco785 Aug 2, 2023
35d00f0
Automated Black fmt fixes
Aug 2, 2023
87eacd0
add support for GL profile
chicco785 Aug 2, 2023
bf33749
fix model for PositionPoint
chicco785 Aug 2, 2023
02d5e61
fix model for PositionPoint
chicco785 Aug 2, 2023
2ab84c6
Update langPack.py
chicco785 Aug 2, 2023
c733ad6
Automated Black fmt fixes
Aug 2, 2023
d927b76
improve multiplicity handling
chicco785 Aug 2, 2023
8ca17e0
fix representation configuration for point
chicco785 Aug 2, 2023
4e18810
Automated Black fmt fixes
Aug 2, 2023
74e6030
use string as mrid while default value is uuid (serialized as a string)
chicco785 Aug 3, 2023
f19cd4a
revert change
chicco785 Aug 3, 2023
3c00f69
Automated Black fmt fixes
Aug 3, 2023
4916422
docs(release_notes): update RELEASE_NOTES.md
chicco785 Aug 3, 2023
335848a
support defaults
chicco785 Aug 3, 2023
230d157
Automated Black fmt fixes
Aug 3, 2023
e7f77c9
docs(release_notes): update RELEASE_NOTES.md
chicco785 Sep 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- cpp
- java
- javascript
- pydantic

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ cimpy/*
*.py[cod]
__pycache__/
.vscode/launch.json
CGMES_2.4.15_27JAN2020_pydantic/
32 changes: 31 additions & 1 deletion CIMgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,16 @@ def addSubClassesOfSubClasses(class_dict):
)


def addSubClassesOfSubClassesClean(class_dict, source):
temp = {}
for className in class_dict:
for name in class_dict[className].subClasses():
if name not in class_dict:
temp[name] = source[name]
addSubClassesOfSubClassesClean(temp, source)
class_dict.update(temp)


def cim_generate(directory, outputPath, version, langPack):
"""Generates cgmes python classes from cgmes ontology

Expand Down Expand Up @@ -729,6 +739,8 @@ def cim_generate(directory, outputPath, version, langPack):
# merge classes from different profiles into one class and track origin of the classes and their attributes
class_dict_with_origins = _merge_classes(profiles_dict)

clean_class_dict = {}

# work out the subclasses for each class by noting the reverse relationship
for className in class_dict_with_origins:
superClassName = class_dict_with_origins[className].superClass()
Expand All @@ -742,7 +754,25 @@ def cim_generate(directory, outputPath, version, langPack):
# recursively add the subclasses of subclasses
addSubClassesOfSubClasses(class_dict_with_origins)

for className in class_dict_with_origins:
superClassName = class_dict_with_origins[className].superClass()
if (
superClassName == None
and class_dict_with_origins[className].has_instances()
):
clean_class_dict[className] = class_dict_with_origins[className]

for className in class_dict_with_origins:
superClassName = class_dict_with_origins[className].superClass()
if (
superClassName == None
and not class_dict_with_origins[className].has_instances()
):
clean_class_dict[className] = class_dict_with_origins[className]

addSubClassesOfSubClassesClean(clean_class_dict, class_dict_with_origins)

# get information for writing python files and write python files
_write_python_files(class_dict_with_origins, langPack, outputPath, version)
_write_python_files(clean_class_dict, langPack, outputPath, version)

logger.info("Elapsed Time: {}s\n\n".format(time() - t0))
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ COPY cpp/ /CIMgen/cpp/
COPY java/ /CIMgen/java/
COPY javascript/ /CIMgen/javascript/
COPY python/ /CIMgen/python/
COPY pydantic/ /CIMgen/pydantic/
COPY CIMgen.py build.py /CIMgen/
COPY cgmes_schema/ /cgmes_schema
WORKDIR /CIMgen
ENTRYPOINT [ "/usr/bin/python3", "build.py", "--outdir=/cgmes_output", "--schemadir=/cgmes_schema" ]
CMD [ "--langdir=cpp" ]
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# cimgen Release Notes

## 0.0.1-dev - 2023-07-28
## 0.0.1-dev - 2023-09-13

### Features

- Support pydantic code generation (PR #5 by @chicco785)

### Continuous Integration

Expand Down
21 changes: 21 additions & 0 deletions pydantic/Base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pydantic import BaseModel


class Base(BaseModel):
"""
Base Class for CIM
"""

"""
not valid for pydantic 2.0
class Config:
@staticmethod
def schema_extra(schema: dict, _):
props = {}
for k, v in schema.get("properties", {}).items():
if not v.get("hidden", False):
props[k] = v
schema["properties"] = props """

def printxml(self, dict={}):
return dict
1 change: 1 addition & 0 deletions pydantic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import pydantic.langPack
13 changes: 13 additions & 0 deletions pydantic/enum_header.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from enum import Enum, IntEnum


class CgmesProfileEnum(IntEnum):
EQ = 0
SSH = 1
TP = 2
SV = 3
DY = 4
GL = 5
DL = 5
TP_BD = 7
EQ_BD = 8
Loading