Skip to content

Commit d0a9eef

Browse files
python engines structure
1 parent 628b16d commit d0a9eef

File tree

5 files changed

+46
-14
lines changed

5 files changed

+46
-14
lines changed

compiler/compiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
COMPILERS = { # "framework.language.version: compiler"
88
"django.json.v1": django_compiler,
9-
"python.json.v1": django_compiler,
9+
"python.json.v1": python_compiler,
1010
"flask.json.v1": "under development",
1111
"nodejs.json.v1": "under development",
1212
"json.v1": json_compiler
1313
}
1414
def compile(compiler_name, project_name):
15-
compiler = COMPILERS[compiler_name](project_name)
15+
compiler = COMPILERS[compiler_name](main_file=project_name)
1616
compiled_project = compiler.compile()
1717
with open(f"./{sys.argv[4]}/{compiled_project.get('name', 'project')}.build.json", "w") as f:
1818
json.dump(compiled_project, f, indent=4)
@@ -35,5 +35,5 @@ def main():
3535
# python .\compiler.py c "json.v1" ../blueprints/examples/calculator/v2/main.app.json build
3636

3737
# python .\compiler.py c "django.json.v1" ../blueprints/examples/facebook/main.app.json build
38-
# python .\compiler.py c "python.json.v1" ../blueprints/examples/facebook/main.app.json build
38+
# python .\compiler.py c "python.json.v1" ../blueprints/examples/calculator/v2/services/processing/operations/sum.code.json build
3939

compiler/django_compiler/Compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def compile_model(model_name:str, model_dict:dict, model_names:list, *, base_fol
8686
class Compiler:
8787
blueprint: dict = {}
8888

89-
def __init__(self, main_file) -> None:
89+
def __init__(self, *, main_file) -> None:
9090
self.main_folder = Path(os.path.dirname(main_file))
9191
self.main_file = Path(main_file)
9292

@@ -112,7 +112,7 @@ def compile_services(self, build):
112112
build[SEVICES_FIELD] = services
113113
return build
114114

115-
def compile(self):
115+
def compile(self) -> dict:
116116
build = self.compile_models(self.blueprint)
117117
#build = self.compile_services(build)
118118
#print(build)

compiler/json_compiler/Compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def json_global_compile(json_dict, *, args = {}, base_folder=None, base_dict={},
148148
class Compiler:
149149
blueprint: dict = {}
150150

151-
def __init__(self, main_file) -> None:
151+
def __init__(self, *, main_file) -> None:
152152
self.main_folder = Path(os.path.dirname(main_file))
153153
self.main_file = Path(main_file)
154154
self.blueprint = load_json_as_dict(self.main_file)
@@ -196,7 +196,7 @@ def compile_services(self, build):
196196
build[SEVICES_FIELD] = services
197197
return build
198198

199-
def compile(self):
199+
def compile(self) -> dict:
200200
build = json_global_compile(self.blueprint, base_folder=self.main_folder)
201201
build = self.compile_models(build)
202202
build = self.compile_services(build)

compiler/python_compiler/Compiler.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
import os
22
import json
33

4-
from json_compiler.Compiler import Compiler as json_compiler, special_flags_processing, load_json_as_dict, object_route_join
4+
from json_compiler.Compiler import Compiler as json_compiler, special_flags_processing, load_json_as_dict
5+
from .engines.py3_8.Compiler import compile as py3_9_compiler
56
from utils.CustomLogging import CustomLogging
67

8+
FLAG_ENGINE = "engine"
9+
ENGINES = {
10+
"python3.8":py3_9_compiler
11+
}
712
class Compiler:
813
blueprint: dict = {}
914

1015
def __init__(self, *, main_file:str = "", blueprint:dict = {}) -> None:
11-
if blueprint:
12-
self.blueprint = blueprint
1316
if main_file:
14-
if not blueprint:
15-
self.blueprint = load_json_as_dict(main_file)
1617
self.main_folder = os.path.dirname(main_file)
1718
self.main_file = main_file
19+
if not blueprint:
20+
raw_blueprint = load_json_as_dict(main_file)
21+
self.blueprint = special_flags_processing(raw_blueprint, base_folder=self.main_folder)
22+
if blueprint:
23+
self.blueprint = special_flags_processing(blueprint, base_folder=self.main_folder)
1824

19-
def compile(self):
20-
return
25+
def compile(self) -> dict:
26+
build = {}
27+
if engine_type := self.blueprint.get(FLAG_ENGINE):
28+
if engine_compiler := ENGINES.get(engine_type):
29+
build = engine_compiler(self.blueprint)
30+
else:
31+
CustomLogging.error(f"Compiler {engine_type} does not exists")
32+
else:
33+
CustomLogging.error(f"Flag {FLAG_ENGINE} not defined")
34+
return build
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from utils.CustomLogging import CustomLogging
2+
FLAG_FRAGMENT_TYPE = "type"
3+
FRAGMENT_TYPES={
4+
"function":print,
5+
"class":print,
6+
"variable":print,
7+
"conditional":print
8+
}
9+
def compile(blueprint:dict):
10+
build = {}
11+
if fragment_type := blueprint.get(FLAG_FRAGMENT_TYPE):
12+
if fragment_compiler := FRAGMENT_TYPES[fragment_type]:
13+
build = fragment_compiler(blueprint)
14+
else:
15+
CustomLogging.error(f"Fragment type {fragment_type} does not exists")
16+
else:
17+
CustomLogging.error(f"Flag {FLAG_FRAGMENT_TYPE} not defined in blueprint")
18+
return build

0 commit comments

Comments
 (0)