Skip to content

Commit 38d14ba

Browse files
committed
Linting
1 parent 967036f commit 38d14ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1573
-697
lines changed

.github/workflows/pythonapp.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
# stop the build if there are Python style violations
3131
flake8 . --count --show-source --statistics
3232
flake8 tests --config tests/.flake8 --count --show-source --statistics
33+
ruff check pylasu/ tests/
3334
- name: Generate test parsers
3435
run: ./generate-test-parsers.sh
3536
working-directory: tests

pylasu/StrumentaLanguageSupport/StrumentaLanguageSupport.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
"""Definition of meta model 'StrumentaLanguageSupport'."""
2+
23
from functools import partial
3-
import pyecore.ecore as Ecore
4-
from pyecore.ecore import *
54

5+
import pyecore.ecore as Ecore
6+
from pyecore.ecore import (EAttribute, EDataType, EEnum, EInt, EObject,
7+
EPackage, EReference, EString, MetaEClass, abstract)
68

7-
name = 'StrumentaLanguageSupport'
8-
nsURI = 'https://strumenta.com/kolasu/v2'
9-
nsPrefix = ''
9+
name = "StrumentaLanguageSupport"
10+
nsURI = "https://strumenta.com/kolasu/v2"
11+
nsPrefix = ""
1012

1113
eClass = EPackage(name=name, nsURI=nsURI, nsPrefix=nsPrefix)
1214

1315
eClassifiers = {}
1416
getEClassifier = partial(Ecore.getEClassifier, searchspace=eClassifiers)
15-
IssueType = EEnum('IssueType', literals=['LEXICAL', 'SYNTACTIC', 'SEMANTIC'])
17+
IssueType = EEnum("IssueType", literals=["LEXICAL", "SYNTACTIC", "SEMANTIC"])
1618

17-
IssueSeverity = EEnum('IssueSeverity', literals=['ERROR', 'WARNING', 'INFO'])
19+
IssueSeverity = EEnum("IssueSeverity", literals=["ERROR", "WARNING", "INFO"])
1820

1921

20-
BigDecimal = EDataType('BigDecimal', instanceClassName='java.math.BigDecimal')
22+
BigDecimal = EDataType("BigDecimal", instanceClassName="java.math.BigDecimal")
2123

22-
BigInteger = EDataType('BigInteger', instanceClassName='java.math.BigInteger')
24+
BigInteger = EDataType("BigInteger", instanceClassName="java.math.BigInteger")
2325

2426

2527
class LocalDate(EObject, metaclass=MetaEClass):
@@ -175,7 +177,9 @@ class Issue(EObject, metaclass=MetaEClass):
175177

176178
type = EAttribute(eType=IssueType, unique=True, derived=False, changeable=True)
177179
message = EAttribute(eType=EString, unique=True, derived=False, changeable=True)
178-
severity = EAttribute(eType=IssueSeverity, unique=True, derived=False, changeable=True)
180+
severity = EAttribute(
181+
eType=IssueSeverity, unique=True, derived=False, changeable=True
182+
)
179183
position = EReference(ordered=True, unique=True, containment=True, derived=False)
180184

181185
def __init__(self, *, type=None, message=None, severity=None, position=None):
@@ -232,7 +236,9 @@ def __init__(self, *, name=None, referenced=None):
232236
class Result(EObject, metaclass=MetaEClass):
233237

234238
root = EReference(ordered=True, unique=True, containment=True, derived=False)
235-
issues = EReference(ordered=True, unique=True, containment=True, derived=False, upper=-1)
239+
issues = EReference(
240+
ordered=True, unique=True, containment=True, derived=False, upper=-1
241+
)
236242

237243
def __init__(self, *, root=None, issues=None):
238244
# if kwargs:

pylasu/StrumentaLanguageSupport/__init__.py

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
2-
from .StrumentaLanguageSupport import getEClassifier, eClassifiers
3-
from .StrumentaLanguageSupport import name, nsURI, nsPrefix, eClass
4-
from .StrumentaLanguageSupport import BigDecimal, BigInteger, LocalDate, LocalTime, LocalDateTime, Point, Position, Origin, Destination, NodeDestination, TextFileDestination, ASTNode, Statement, Expression, EntityDeclaration, IssueType, IssueSeverity, Issue, PossiblyNamed, Named, ReferenceByName, Result
5-
6-
71
from . import StrumentaLanguageSupport
2+
from .StrumentaLanguageSupport import (ASTNode, BigDecimal, BigInteger,
3+
Destination, EntityDeclaration,
4+
Expression, Issue, IssueSeverity,
5+
IssueType, LocalDate, LocalDateTime,
6+
LocalTime, Named, NodeDestination,
7+
Origin, Point, Position, PossiblyNamed,
8+
ReferenceByName, Result, Statement,
9+
TextFileDestination, eClass,
10+
eClassifiers)
811

9-
__all__ = ['BigDecimal', 'BigInteger', 'LocalDate', 'LocalTime', 'LocalDateTime', 'Point', 'Position', 'Origin', 'Destination', 'NodeDestination', 'TextFileDestination',
10-
'ASTNode', 'Statement', 'Expression', 'EntityDeclaration', 'IssueType', 'IssueSeverity', 'Issue', 'PossiblyNamed', 'Named', 'ReferenceByName', 'Result']
12+
__all__ = [
13+
"BigDecimal",
14+
"BigInteger",
15+
"LocalDate",
16+
"LocalTime",
17+
"LocalDateTime",
18+
"Point",
19+
"Position",
20+
"Origin",
21+
"Destination",
22+
"NodeDestination",
23+
"TextFileDestination",
24+
"ASTNode",
25+
"Statement",
26+
"Expression",
27+
"EntityDeclaration",
28+
"IssueType",
29+
"IssueSeverity",
30+
"Issue",
31+
"PossiblyNamed",
32+
"Named",
33+
"ReferenceByName",
34+
"Result",
35+
]
1136

1237
eSubpackages = []
1338
eSuperPackage = None

pylasu/codebase/__init__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from .codebase_file import CodebaseFile
2-
from .lwlanguage import CODEBASE_LANGUAGE, CODEBASE_FILE
2+
from .lwlanguage import CODEBASE_FILE, CODEBASE_LANGUAGE
33
from .serialization import register_codebase_deserializers
44

5-
__all__ = ["CodebaseFile", "CODEBASE_LANGUAGE", "CODEBASE_FILE", "register_codebase_deserializers"]
5+
__all__ = [
6+
"CodebaseFile",
7+
"CODEBASE_LANGUAGE",
8+
"CODEBASE_FILE",
9+
"register_codebase_deserializers",
10+
]

pylasu/codebase/codebase_file.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22

3-
from lionwebpython.model.classifier_instance_utils import ClassifierInstanceUtils
3+
from lionwebpython.model.classifier_instance_utils import \
4+
ClassifierInstanceUtils
45
from lionwebpython.model.impl.dynamic_node import DynamicNode
56
from lionwebpython.model.node import Node
67

@@ -13,31 +14,31 @@ class CodebaseFile(DynamicNode):
1314

1415
@property
1516
def language_name(self):
16-
return ClassifierInstanceUtils.get_property_value_by_name(self, 'language_name')
17+
return ClassifierInstanceUtils.get_property_value_by_name(self, "language_name")
1718

1819
@language_name.setter
1920
def language_name(self, value):
20-
ClassifierInstanceUtils.set_property_value_by_name(self, 'language_name', value)
21+
ClassifierInstanceUtils.set_property_value_by_name(self, "language_name", value)
2122

2223
@property
2324
def relative_path(self):
24-
return ClassifierInstanceUtils.get_property_value_by_name(self, 'relative_path')
25+
return ClassifierInstanceUtils.get_property_value_by_name(self, "relative_path")
2526

2627
@relative_path.setter
2728
def relative_path(self, value):
28-
ClassifierInstanceUtils.set_property_value_by_name(self, 'relative_path', value)
29+
ClassifierInstanceUtils.set_property_value_by_name(self, "relative_path", value)
2930

3031
@property
3132
def code(self):
32-
return ClassifierInstanceUtils.get_property_value_by_name(self, 'code')
33+
return ClassifierInstanceUtils.get_property_value_by_name(self, "code")
3334

3435
@code.setter
3536
def code(self, value):
36-
ClassifierInstanceUtils.set_property_value_by_name(self, 'code', value)
37+
ClassifierInstanceUtils.set_property_value_by_name(self, "code", value)
3738

3839
@property
3940
def ast(self):
40-
containment = self.get_classifier().get_containment_by_name('ast')
41+
containment = self.get_classifier().get_containment_by_name("ast")
4142
children = self.get_children(containment=containment)
4243
if len(children) == 0:
4344
return None
@@ -46,7 +47,7 @@ def ast(self):
4647

4748
@ast.setter
4849
def ast(self, value):
49-
containment = self.get_classifier().get_containment_by_name('ast')
50+
containment = self.get_classifier().get_containment_by_name("ast")
5051
children = self.get_children(containment=containment)
5152
if value is None:
5253
if len(children) != 0:
@@ -56,11 +57,20 @@ def ast(self, value):
5657
self.remove_child(child=children[0])
5758
self.add_child(containment=containment, child=value)
5859

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
60+
def __init__(
61+
self,
62+
language_name: str,
63+
relative_path: str,
64+
code: str,
65+
ast: Optional[Node] = None,
66+
id: Optional[str] = None,
67+
):
6268
from pylasu.codebase.lwlanguage import CODEBASE_FILE
63-
super().__init__(id or f"codebase_file_{to_lionweb_identifier(relative_path)}", CODEBASE_FILE)
69+
from pylasu.lionweb.utils import to_lionweb_identifier
70+
71+
super().__init__(
72+
id or f"codebase_file_{to_lionweb_identifier(relative_path)}", CODEBASE_FILE
73+
)
6474
self.language_name = language_name
6575
self.relative_path = relative_path
6676
self.code = code

pylasu/codebase/lwlanguage.py

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
1-
from lionwebpython.language import Language, Concept, Property, Containment
1+
from lionwebpython.language import Concept, Containment, Language, Property
22
from lionwebpython.language.lioncore_builtins import LionCoreBuiltins
33

44
from pylasu.lionweb.utils import LW_REFERENCE_VERSION
55

66
CODEBASE_LANGUAGE = Language(
7-
lion_web_version=LW_REFERENCE_VERSION, name="Codebase",
8-
id="strumenta-codebase", version="1", key="strumenta-codebase")
7+
lion_web_version=LW_REFERENCE_VERSION,
8+
name="Codebase",
9+
id="strumenta-codebase",
10+
version="1",
11+
key="strumenta-codebase",
12+
)
913

1014
CODEBASE_FILE = Concept(
11-
lion_web_version=LW_REFERENCE_VERSION, name="CodebaseFile",
12-
id="strumenta-codebase-file", key="strumenta-codebase-file")
15+
lion_web_version=LW_REFERENCE_VERSION,
16+
name="CodebaseFile",
17+
id="strumenta-codebase-file",
18+
key="strumenta-codebase-file",
19+
)
1320
CODEBASE_LANGUAGE.add_element(CODEBASE_FILE)
1421

1522
CODEBASE_FILE_LANGUAGE_NAME = Property(
16-
lion_web_version=LW_REFERENCE_VERSION, name="language_name",
17-
id="strumenta-codebase-file-language-name")
23+
lion_web_version=LW_REFERENCE_VERSION,
24+
name="language_name",
25+
id="strumenta-codebase-file-language-name",
26+
)
1827
CODEBASE_FILE.add_feature(CODEBASE_FILE_LANGUAGE_NAME)
1928
CODEBASE_FILE_LANGUAGE_NAME.set_key("strumenta-codebase-file-language-name")
2029
CODEBASE_FILE_LANGUAGE_NAME.set_optional(False)
2130
CODEBASE_FILE_LANGUAGE_NAME.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
2231

2332
CODEBASE_FILE_RELATIVE_PATH = Property(
24-
lion_web_version=LW_REFERENCE_VERSION, name="relative_path",
25-
id="strumenta-codebase-file-relative-path")
33+
lion_web_version=LW_REFERENCE_VERSION,
34+
name="relative_path",
35+
id="strumenta-codebase-file-relative-path",
36+
)
2637
CODEBASE_FILE.add_feature(CODEBASE_FILE_RELATIVE_PATH)
2738
CODEBASE_FILE_RELATIVE_PATH.set_key("strumenta-codebase-file-relative-path")
2839
CODEBASE_FILE_RELATIVE_PATH.set_optional(False)
2940
CODEBASE_FILE_RELATIVE_PATH.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
3041

3142
CODEBASE_FILE_CODE = Property(
32-
lion_web_version=LW_REFERENCE_VERSION, name="code",
33-
id="strumenta-codebase-file-code")
43+
lion_web_version=LW_REFERENCE_VERSION,
44+
name="code",
45+
id="strumenta-codebase-file-code",
46+
)
3447
CODEBASE_FILE.add_feature(CODEBASE_FILE_CODE)
3548
CODEBASE_FILE_CODE.set_key("strumenta-codebase-file-code")
3649
CODEBASE_FILE_CODE.set_optional(False)
3750
CODEBASE_FILE_CODE.set_type(LionCoreBuiltins.get_string(LW_REFERENCE_VERSION))
3851

3952
CODEBASE_FILE_AST = Containment(
40-
lion_web_version=LW_REFERENCE_VERSION, name="ast",
41-
id="strumenta-codebase-file-ast")
53+
lion_web_version=LW_REFERENCE_VERSION, name="ast", id="strumenta-codebase-file-ast"
54+
)
4255
CODEBASE_FILE.add_feature(CODEBASE_FILE_AST)
4356
CODEBASE_FILE_AST.set_key("strumenta-codebase-file-ast")
4457
CODEBASE_FILE_AST.set_optional(True)

pylasu/codebase/serialization.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44

55

66
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)
7+
classifier, serialized_instance, deserialized_instances_by_id, properties_values
8+
) -> 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(
13+
language_name=language_name,
14+
relative_path=relative_path,
15+
code=code,
16+
id=serialized_instance.id,
17+
)
1318

1419

1520
def register_codebase_deserializers(jsonser: JsonSerialization):
1621
from pylasu.codebase.lwlanguage import CODEBASE_FILE
17-
jsonser.instantiator.register_custom_deserializer(CODEBASE_FILE.get_id(), _codebase_deserializer)
22+
23+
jsonser.instantiator.register_custom_deserializer(
24+
CODEBASE_FILE.get_id(), _codebase_deserializer
25+
)

0 commit comments

Comments
 (0)