Skip to content

Commit fcefff1

Browse files
committed
Linting
1 parent fb9156e commit fcefff1

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

pylasu/codebase/lionweb.py

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
import base64
21
import re
32
from typing import Optional
43

54
from lionwebpython.language import Language, Concept, Property, Containment
6-
from lionwebpython.language.classifier import Classifier
75
from lionwebpython.language.lioncore_builtins import LionCoreBuiltins
6+
from lionwebpython.lionweb_version import LionWebVersion
87
from lionwebpython.model.classifier_instance_utils import ClassifierInstanceUtils
98
from lionwebpython.model.impl.dynamic_node import DynamicNode
109
from lionwebpython.model.node import Node
11-
from lionwebpython.lionweb_version import LionWebVersion
1210
from lionwebpython.serialization.json_serialization import JsonSerialization
1311

1412
LW_REFERENCE_VERSION = LionWebVersion.V2023_1
1513

16-
CODEBASE_LANGUAGE = Language(lion_web_version=LW_REFERENCE_VERSION, name="Codebase",
17-
id="strumenta-codebase", version="1", key="strumenta-codebase")
14+
CODEBASE_LANGUAGE = Language(
15+
lion_web_version=LW_REFERENCE_VERSION, name="Codebase",
16+
id="strumenta-codebase", version="1", key="strumenta-codebase")
1817

19-
CODEBASE_FILE = Concept(lion_web_version=LW_REFERENCE_VERSION, name="CodebaseFile",
20-
id="strumenta-codebase-file", key="strumenta-codebase-file")
18+
CODEBASE_FILE = Concept(
19+
lion_web_version=LW_REFERENCE_VERSION, name="CodebaseFile",
20+
id="strumenta-codebase-file", key="strumenta-codebase-file")
2121
CODEBASE_LANGUAGE.add_element(CODEBASE_FILE)
2222

23-
CODEBASE_FILE_LANGUAGE_NAME = Property(lion_web_version=LW_REFERENCE_VERSION, name="language_name",
24-
id="strumenta-codebase-file-language-name")
23+
CODEBASE_FILE_LANGUAGE_NAME = Property(
24+
lion_web_version=LW_REFERENCE_VERSION, name="language_name",
25+
id="strumenta-codebase-file-language-name")
2526
CODEBASE_FILE.add_feature(CODEBASE_FILE_LANGUAGE_NAME)
2627
CODEBASE_FILE_LANGUAGE_NAME.set_key("strumenta-codebase-file-language-name")
2728
CODEBASE_FILE_LANGUAGE_NAME.set_optional(False)
2829
CODEBASE_FILE_LANGUAGE_NAME.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
2930

30-
CODEBASE_FILE_RELATIVE_PATH = Property(lion_web_version=LW_REFERENCE_VERSION, name="relative_path",
31-
id="strumenta-codebase-file-relative-path")
31+
CODEBASE_FILE_RELATIVE_PATH = Property(
32+
lion_web_version=LW_REFERENCE_VERSION, name="relative_path",
33+
id="strumenta-codebase-file-relative-path")
3234
CODEBASE_FILE.add_feature(CODEBASE_FILE_RELATIVE_PATH)
3335
CODEBASE_FILE_RELATIVE_PATH.set_key("strumenta-codebase-file-relative-path")
3436
CODEBASE_FILE_RELATIVE_PATH.set_optional(False)
3537
CODEBASE_FILE_RELATIVE_PATH.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
3638

37-
CODEBASE_FILE_CODE = Property(lion_web_version=LW_REFERENCE_VERSION, name="code",
38-
id="strumenta-codebase-file-code")
39+
CODEBASE_FILE_CODE = Property(
40+
lion_web_version=LW_REFERENCE_VERSION, name="code",
41+
id="strumenta-codebase-file-code")
3942
CODEBASE_FILE.add_feature(CODEBASE_FILE_CODE)
4043
CODEBASE_FILE_CODE.set_key("strumenta-codebase-file-code")
4144
CODEBASE_FILE_CODE.set_optional(False)
4245
CODEBASE_FILE_CODE.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
4346

44-
CODEBASE_FILE_AST = Containment(lion_web_version=LW_REFERENCE_VERSION, name="ast",
45-
id="strumenta-codebase-file-ast")
47+
CODEBASE_FILE_AST = Containment(
48+
lion_web_version=LW_REFERENCE_VERSION, name="ast",
49+
id="strumenta-codebase-file-ast")
4650
CODEBASE_FILE.add_feature(CODEBASE_FILE_AST)
4751
CODEBASE_FILE_AST.set_key("strumenta-codebase-file-ast")
4852
CODEBASE_FILE_AST.set_optional(True)
@@ -76,6 +80,7 @@ def to_lionweb_identifier(s: str) -> str:
7680
# Ensure the identifier is not empty
7781
return s if s else "_"
7882

83+
7984
class CodebaseFile(DynamicNode):
8085
language_name: str
8186
relative_path: str
@@ -127,21 +132,23 @@ def ast(self, value):
127132
self.remove_child(child=children[0])
128133
self.add_child(containment=containment, child=value)
129134

130-
def __init__(self, language_name: str, relative_path: str, code: str, ast: Optional[Node] = None, id: Optional[str] = None):
135+
def __init__(self, language_name: str, relative_path: str, code: str, ast: Optional[Node] = None,
136+
id: Optional[str] = None):
131137
super().__init__(id or f"codebase_file_{to_lionweb_identifier(relative_path)}", CODEBASE_FILE)
132138
self.language_name = language_name
133139
self.relative_path = relative_path
134140
self.code = code
135141
self.ast = ast
136142

137143

138-
def codebase_deserializer(classifier, serialized_instance,
139-
deserialized_instances_by_id, properties_values) -> CodebaseFile:
144+
def codebase_deserializer(
145+
classifier, serialized_instance,
146+
deserialized_instances_by_id, properties_values) -> CodebaseFile:
140147
language_name = properties_values[classifier.get_property_by_name('language_name')]
141148
relative_path = properties_values[classifier.get_property_by_name('relative_path')]
142149
code = properties_values[classifier.get_property_by_name('code')]
143150
return CodebaseFile(language_name=language_name, relative_path=relative_path, code=code, id=serialized_instance.id)
144151

145152

146153
def register_codebase_deserializers(jsonser: JsonSerialization):
147-
jsonser.instantiator.register_custom_deserializer(CODEBASE_FILE.get_id(), codebase_deserializer)
154+
jsonser.instantiator.register_custom_deserializer(CODEBASE_FILE.get_id(), codebase_deserializer)

pylasu/lionweb/ast_generation.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def _generate_constructor(concept: Concept) -> ast.FunctionDef:
133133
ast.arg(arg="concept", annotation=ast.Name(id="Concept", ctx=ast.Load()))
134134
],
135135
kwonlyargs=[], kw_defaults=[],
136-
defaults = [
137-
ast.Name(id=to_snake_case(concept.get_name()).upper())
138-
]
136+
defaults=[ast.Name(id=to_snake_case(concept.get_name()).upper())]
139137
),
140138
body=[
141139
# super().__init__(id=id, position=position, concept=concept)
@@ -194,7 +192,8 @@ def _generate_constructor(concept: Concept) -> ast.FunctionDef:
194192
def _generate_from_concept(classifier: Concept) -> ClassDef:
195193
bases = []
196194
if classifier.get_extended_concept().id == StarLasuBaseLanguage.get_astnode(LionWebVersion.V2023_1).id:
197-
if len([i for i in classifier.get_implemented() if i.get_language().get_name() != 'com.strumenta.StarLasu']) == 0:
195+
if len([i for i in classifier.get_implemented() if i.get_language().get_name()
196+
!= 'com.strumenta.StarLasu']) == 0:
198197
bases.append('ASTNode')
199198
else:
200199
bases.append(classifier.get_extended_concept().get_name())
@@ -282,7 +281,8 @@ def ast_generation(click, language: Language, output, language_name=str):
282281
# from rpg.language import CONTROL_SPECIFICATION
283282
import_concepts = ast.ImportFrom(
284283
module=f"{language_name.lower()}.language",
285-
names=[ast.alias(name=to_snake_case(e.get_name()).upper(), asname=None)for e in language.get_elements() if isinstance(e, Concept)],
284+
names=[ast.alias(name=to_snake_case(e.get_name()).upper(),
285+
asname=None)for e in language.get_elements() if isinstance(e, Concept)],
286286
level=0
287287
)
288288
module = ast.Module(body=[import_abc, import_dataclass, import_typing, import_enum, import_starlasu, import_node,

pylasu/lionweb/language_generation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ def language_generation(click, language: Language, output, language_name: str):
310310
value=ast.Call(func=ast.Name(id="_load_language", ctx=ast.Load()), args=[], keywords=[])
311311
)
312312

313-
314313
module = ast.Module(
315314
body=imports + [
316315
load_starlasu_func,
@@ -356,4 +355,4 @@ def language_generation(click, language: Language, output, language_name: str):
356355
output_path.mkdir(parents=True, exist_ok=True)
357356
click.echo(f"📂 Saving language to: {output}")
358357
with Path(f"{output}/language.py").open("w", encoding="utf-8") as f:
359-
f.write(generated_code)
358+
f.write(generated_code)

pylasu/lwmodel/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .astnode import ASTNode
22

3-
__all__ = ["ASTNode"]
3+
__all__ = ["ASTNode"]

pylasu/lwmodel/astnode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88

99
class ASTNode(DynamicNode):
10-
11-
def __init__(self, id: str, concept: Concept, position: Optional[Position]=None):
10+
11+
def __init__(self, id: str, concept: Concept, position: Optional[Position] = None):
1212
super().__init__(id=id, concept=concept)
1313
if position:
14-
self.set_property_value(property=concept.get_property_by_name('position'), value=position)
14+
self.set_property_value(property=concept.get_property_by_name('position'), value=position)

0 commit comments

Comments
 (0)