Skip to content

Commit 11ad227

Browse files
committed
Revisit codebase and emf packages
1 parent fcefff1 commit 11ad227

9 files changed

+177
-155
lines changed

pylasu/codebase/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from codebase_file import CodebaseFile
2+
from lwlanguage import CODEBASE_LANGUAGE, CODEBASE_FILE
3+
from serialization import register_codebase_deserializers
4+
5+
__all__ = ["CodebaseFile", "CODEBASE_LANGUAGE", "CODEBASE_FILE", "register_codebase_deserializers"]

pylasu/codebase/codebase_file.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from typing import Optional
2+
3+
from lionwebpython.model.classifier_instance_utils import ClassifierInstanceUtils
4+
from lionwebpython.model.impl.dynamic_node import DynamicNode
5+
from lionwebpython.model.node import Node
6+
7+
8+
class CodebaseFile(DynamicNode):
9+
language_name: str
10+
relative_path: str
11+
code: str
12+
ast: Optional[Node]
13+
14+
@property
15+
def language_name(self):
16+
return ClassifierInstanceUtils.get_property_value_by_name(self, 'language_name')
17+
18+
@language_name.setter
19+
def language_name(self, value):
20+
ClassifierInstanceUtils.set_property_value_by_name(self, 'language_name', value)
21+
22+
@property
23+
def relative_path(self):
24+
return ClassifierInstanceUtils.get_property_value_by_name(self, 'relative_path')
25+
26+
@relative_path.setter
27+
def relative_path(self, value):
28+
ClassifierInstanceUtils.set_property_value_by_name(self, 'relative_path', value)
29+
30+
@property
31+
def code(self):
32+
return ClassifierInstanceUtils.get_property_value_by_name(self, 'code')
33+
34+
@code.setter
35+
def code(self, value):
36+
ClassifierInstanceUtils.set_property_value_by_name(self, 'code', value)
37+
38+
@property
39+
def ast(self):
40+
containment = self.get_classifier().get_containment_by_name('ast')
41+
children = self.get_children(containment=containment)
42+
if len(children) == 0:
43+
return None
44+
else:
45+
return children[0]
46+
47+
@ast.setter
48+
def ast(self, value):
49+
containment = self.get_classifier().get_containment_by_name('ast')
50+
children = self.get_children(containment=containment)
51+
if value is None:
52+
if len(children) != 0:
53+
self.remove_child(child=children[0])
54+
else:
55+
if len(children) != 0:
56+
self.remove_child(child=children[0])
57+
self.add_child(containment=containment, child=value)
58+
59+
def __init__(self, language_name: str, relative_path: str, code: str, ast: Optional[Node] = None,
60+
id: Optional[str] = None):
61+
from pylasu.lionweb.utils import to_lionweb_identifier
62+
from pylasu.codebase.lwlanguage import CODEBASE_FILE
63+
super().__init__(id or f"codebase_file_{to_lionweb_identifier(relative_path)}", CODEBASE_FILE)
64+
self.language_name = language_name
65+
self.relative_path = relative_path
66+
self.code = code
67+
self.ast = ast

pylasu/codebase/lionweb.py

-154
This file was deleted.

pylasu/codebase/lwlanguage.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from lionwebpython.language import Language, Concept, Property, Containment
2+
from lionwebpython.language.lioncore_builtins import LionCoreBuiltins
3+
4+
from pylasu.lionweb.utils import LW_REFERENCE_VERSION
5+
6+
CODEBASE_LANGUAGE = Language(
7+
lion_web_version=LW_REFERENCE_VERSION, name="Codebase",
8+
id="strumenta-codebase", version="1", key="strumenta-codebase")
9+
10+
CODEBASE_FILE = Concept(
11+
lion_web_version=LW_REFERENCE_VERSION, name="CodebaseFile",
12+
id="strumenta-codebase-file", key="strumenta-codebase-file")
13+
CODEBASE_LANGUAGE.add_element(CODEBASE_FILE)
14+
15+
CODEBASE_FILE_LANGUAGE_NAME = Property(
16+
lion_web_version=LW_REFERENCE_VERSION, name="language_name",
17+
id="strumenta-codebase-file-language-name")
18+
CODEBASE_FILE.add_feature(CODEBASE_FILE_LANGUAGE_NAME)
19+
CODEBASE_FILE_LANGUAGE_NAME.set_key("strumenta-codebase-file-language-name")
20+
CODEBASE_FILE_LANGUAGE_NAME.set_optional(False)
21+
CODEBASE_FILE_LANGUAGE_NAME.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
22+
23+
CODEBASE_FILE_RELATIVE_PATH = Property(
24+
lion_web_version=LW_REFERENCE_VERSION, name="relative_path",
25+
id="strumenta-codebase-file-relative-path")
26+
CODEBASE_FILE.add_feature(CODEBASE_FILE_RELATIVE_PATH)
27+
CODEBASE_FILE_RELATIVE_PATH.set_key("strumenta-codebase-file-relative-path")
28+
CODEBASE_FILE_RELATIVE_PATH.set_optional(False)
29+
CODEBASE_FILE_RELATIVE_PATH.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
30+
31+
CODEBASE_FILE_CODE = Property(
32+
lion_web_version=LW_REFERENCE_VERSION, name="code",
33+
id="strumenta-codebase-file-code")
34+
CODEBASE_FILE.add_feature(CODEBASE_FILE_CODE)
35+
CODEBASE_FILE_CODE.set_key("strumenta-codebase-file-code")
36+
CODEBASE_FILE_CODE.set_optional(False)
37+
CODEBASE_FILE_CODE.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
38+
39+
CODEBASE_FILE_AST = Containment(
40+
lion_web_version=LW_REFERENCE_VERSION, name="ast",
41+
id="strumenta-codebase-file-ast")
42+
CODEBASE_FILE.add_feature(CODEBASE_FILE_AST)
43+
CODEBASE_FILE_AST.set_key("strumenta-codebase-file-ast")
44+
CODEBASE_FILE_AST.set_optional(True)
45+
CODEBASE_FILE_AST.set_multiple(False)
46+
CODEBASE_FILE_AST.set_type(LionCoreBuiltins.get_node(LW_REFERENCE_VERSION))

pylasu/codebase/serialization.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from lionwebpython.serialization.json_serialization import JsonSerialization
2+
3+
from pylasu.codebase.codebase_file import CodebaseFile
4+
5+
6+
def _codebase_deserializer(
7+
classifier, serialized_instance,
8+
deserialized_instances_by_id, properties_values) -> CodebaseFile:
9+
language_name = properties_values[classifier.get_property_by_name('language_name')]
10+
relative_path = properties_values[classifier.get_property_by_name('relative_path')]
11+
code = properties_values[classifier.get_property_by_name('code')]
12+
return CodebaseFile(language_name=language_name, relative_path=relative_path, code=code, id=serialized_instance.id)
13+
14+
15+
def register_codebase_deserializers(jsonser: JsonSerialization):
16+
from pylasu.codebase.lwlanguage import CODEBASE_FILE
17+
jsonser.instantiator.register_custom_deserializer(CODEBASE_FILE.get_id(), _codebase_deserializer)

pylasu/emf/metamodel_builder.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from pylasu.reflection import get_type_annotations
1414
from pylasu.reflection.reflection import get_type_origin, is_enum_type, is_sequence_type, get_type_arguments
1515

16+
from deprecated import deprecated
1617

18+
19+
@deprecated(reason="EMF Support is going to be dropped")
1720
def resolve_bases(bases):
1821
"""Resolve MRO entries dynamically as specified by PEP 560."""
1922
if hasattr(types, "resolve_bases"):
@@ -38,6 +41,7 @@ def resolve_bases(bases):
3841
return tuple(new_bases)
3942

4043

44+
@deprecated(reason="EMF Support is going to be dropped")
4145
class MetamodelBuilder:
4246
def __init__(self, package_name: str, ns_uri: str, ns_prefix: str = None, resource: Resource = None,
4347
base_node_class: type = Node):
@@ -170,6 +174,7 @@ def generate(self):
170174
update_opposite = ECollection._update_opposite
171175

172176

177+
@deprecated(reason="EMF Support is going to be dropped")
173178
def update_opposite_if_not_none(self, owner, new_value, remove=False):
174179
if owner:
175180
update_opposite(self, owner, new_value, remove)

pylasu/emf/model.py

+6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
from pylasu.model import Node
77
from pylasu.support import extension_method
88

9+
from deprecated import deprecated
910

11+
12+
@deprecated(reason="EMF Support is going to be dropped")
1013
def find_eclassifier_in_resource(cls: type, resource: Resource):
1114
pkg_name = cls.__module__
1215
for p in resource.contents:
1316
if isinstance(p, EPackage) and p.name == pkg_name:
1417
return p.getEClassifier(cls.__name__)
1518

1619

20+
@deprecated(reason="EMF Support is going to be dropped")
1721
@extension_method(Resource)
1822
def find_eclassifier(self: Resource, cls: type):
1923
eclass = find_eclassifier_in_resource(cls, self)
@@ -27,6 +31,7 @@ def find_eclassifier(self: Resource, cls: type):
2731
return eclass
2832

2933

34+
@deprecated(reason="EMF Support is going to be dropped")
3035
@extension_method(Node)
3136
def to_eobject(self: Node, resource: Resource, mappings=None):
3237
if self is None:
@@ -50,6 +55,7 @@ def to_eobject(self: Node, resource: Resource, mappings=None):
5055
return eobject
5156

5257

58+
@deprecated(reason="EMF Support is going to be dropped")
5359
def translate_value(v, resource, mappings):
5460
if isinstance(v, Enum):
5561
enum_type = resource.find_eclassifier(type(v))

pylasu/lionweb/starlasu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from lionwebpython.language import Language, Concept
44
from lionwebpython.language.lioncore_builtins import LionCoreBuiltins
55
from lionwebpython.language.primitive_type import PrimitiveType
6-
from lionwebpython.lionweb_version import LionWebVersion
6+
from lionwebpython.lionweb_version import LionWebVersion # noqa: F401
77

88
from pylasu.model import Point, Position
99

0 commit comments

Comments
 (0)