Create initial profile data model code generator

Signed-off-by: Dan Yeaw <dan@yeaw.me>
This commit is contained in:
Dan Yeaw 2020-04-18 19:06:33 -04:00
parent 03838afe42
commit 3c9d3adbc3
No known key found for this signature in database
GPG Key ID: 77A923EF537B61A4
8 changed files with 75 additions and 13 deletions

View File

@ -20,16 +20,16 @@ translate: ## Translate and update .po and .mo files (requires PyBabel)
model: gaphor/core/modeling/coremodel.py gaphor/UML/uml.py ## Generate Python model files from Gaphor models (requires Black, MyPy)
gaphor/core/modeling/coremodel.py: models/Core.gaphor models/Core.override gaphor/codegen/autocoder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/core/modeling/coremodel.py: models/Core.gaphor models/Core.override gaphor/codegen/uml_coder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py models/Core.gaphor gaphor/core/modeling/coremodel.py models/Core.override && black $@ && mypy gaphor/core/modeling && isort gaphor/core/modeling/coremodel.py
gaphor/UML/uml.py: models/UML.gaphor models/UML.override gaphor/codegen/autocoder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/UML/uml.py: models/UML.gaphor models/UML.override gaphor/codegen/uml_coder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py models/UML.gaphor gaphor/UML/uml.py models/UML.override && black $@ && mypy gaphor/UML && isort gaphor/UML/UML.py
gaphor/SysML/sysml.py: models/SysML.gaphor models/SysML.override gaphor/codegen/autocoder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py models/SysML.gaphor gaphor/SysML/sysml.py models/SysML.override && black $@ && mypy gaphor/SysML && isort gaphor/SysML/SysML.py
gaphor/SysML/sysml.py: models/SysML.gaphor models/SysML.override gaphor/codegen/profile_coder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py --profile models/SysML.gaphor gaphor/SysML/sysml.py models/SysML.override && black $@ && mypy gaphor/SysML && isort gaphor/SysML/SysML.py
gaphor/Safety/safety.py: models/Safety.gaphor models/Safety.override gaphor/codegen/autocoder.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py models/Safety.gaphor gaphor/Safety/safety.py models/Safety.override && black $@ && mypy gaphor/Safety && isort gaphor/Safety/Safety.py
gaphor/Safety/safety.py: models/Safety.gaphor models/Safety.override gaphor/codegen/profile_coder.py.py gaphor/codegen/override.py gaphor/codegen/writer.py
gaphor/codegen/codegen.py --profile models/Safety.gaphor gaphor/Safety/safety.py models/Safety.override && black $@ && mypy gaphor/Safety && isort gaphor/Safety/Safety.py
.PHONY: help dist test docs icons translate model

View File

@ -0,0 +1,23 @@
# <gaphor.core.modeling.coremodel.Comment element 60cc4486-2105-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 7195b5a4-2105-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 7e1a1dce-2105-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 5c21e374-2109-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 8ea92a5e-210a-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element d477a84e-210a-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 69ebc4e6-210b-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 860de8fc-210b-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element ebe90b96-2112-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 456a4ce0-2116-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 8e1e8d42-2117-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 0a76b0ae-2118-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 175fa730-2118-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element ee0b49c0-213f-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 0ca35346-2140-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 49a557ee-2140-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 403aea0a-2142-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element e9bdbddc-2142-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 23c489a2-2143-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element dc231126-2143-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element f0c9899c-2144-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element c4f2e786-2145-11ea-ab0b-c72c0738acd2>
# <gaphor.core.modeling.coremodel.Comment element 7da2ad34-2146-11ea-ab0b-c72c0738acd2>

View File

@ -9,7 +9,7 @@ import argparse
from distutils.util import byte_compile
from pathlib import Path
from gaphor.codegen import autocoder
from gaphor.codegen import profile_coder, uml_coder
def main() -> None:
@ -17,11 +17,14 @@ def main() -> None:
parser.add_argument("modelfile", type=Path, help="gaphor model filename")
parser.add_argument("outfile", type=Path, help="python data model filename")
parser.add_argument("overrides", type=Path, help="override filename")
parser.add_argument("--profile", help="generate a profile", action="store_true")
args = parser.parse_args()
print(f"Generating {args.outfile} from {args.modelfile}...")
print(" (warnings can be ignored)")
autocoder.generate(args.modelfile, args.outfile, args.overrides)
if args.profile:
profile_coder.generate(args.modelfile, args.outfile, args.overrides)
else:
uml_coder.generate(args.modelfile, args.outfile, args.overrides)
byte_compile([str(args.outfile)])

View File

@ -0,0 +1,35 @@
"""Parse a SysML Gaphor Model and generate a SysML data model."""
from typing import List
from gaphor import UML
from gaphor.application import Session
from gaphor.codegen import override
from gaphor.codegen.writer import Writer
from gaphor.storage import storage
def generate(filename, outfile=None, overridesfile=None):
services = [
"element_dispatcher",
"event_manager",
"component_registry",
"element_factory",
"modeling_language",
]
session = Session(services=services)
element_factory = session.get_service("element_factory")
modeling_language = session.get_service("modeling_language")
with open(filename):
storage.load(
filename, factory=element_factory, modeling_language=modeling_language,
)
comments: List = element_factory.lselect(lambda e: e.isKindOf(UML.Comment))
overrides = override.Overrides(overridesfile)
writer = Writer(overrides)
for comment in comments:
writer.add_comment(comment)
writer.write(outfile, "")
element_factory.shutdown()
session.shutdown()

View File

@ -1,8 +1,8 @@
"""Test case that checks the working of the autocoder.py module."""
"""Test case that checks the working of the uml_coder.py module."""
from gaphor.application import distribution
from gaphor.codegen.autocoder import generate
from gaphor.codegen.override import Overrides
from gaphor.codegen.uml_coder import generate
class PseudoFile:

View File

@ -21,7 +21,8 @@ class Writer:
try:
out.write(header)
out.write(self.overrides.header)
if self.overrides:
out.write(self.overrides.header)
for cls in self.classdefs.values():
if cls[0].endswith(":"):
for d in cls:

View File

@ -44,7 +44,7 @@ class ElementFactory(Service):
create - a new model element is created (element is newly created element)
remove - a model element is removed (element is to be removed element)
model - a new model has been loaded (element is None) flush - model is
flushed: all element are removed from the factory (element is None)
flushed: all element are removed from the factory (element is None)
"""
def __init__(