Skip to content

basic and unfinished python compiler #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 29, 2021
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# App architect

### Python Compiler
There is no faster way for understanding than trying it yourself.
you can execute the next command in the root of the project (this folder) and a simple code wil be generated.
```sh
python .\compiler\compiler.py c "python.json.v1" ./blueprints/examples/calculator/v2/services/processing/operations/sum.code.json code.py
```

You can check the base blueprint for this project in the route examples/calculator/v2/services/processing/operations/sum.code.json

```py
def sum(number_a:int, number_b:int, *, debug:bool=False)->int:
result:str = number_a+number_b
if debug:
print(result)
return result
```
This is the expected answer, a simple function with all that we specified in the code.json file and ready to be used.

#### What is so special about this?
This is a basic format for you to generate code in any language, in any framework as long as the correct compiler is available.

### Current roadmap for this project

- Finish the basic Python compiler
- Add tests
- Work in the JS Express compiler
- Create a UI from where to Edit code and generate the proper code.json, then you can choose from your saved snippets or those that other people had made public
### App Compiler
Design your application in a json like structure, this way the resulting project is going to be easily understood both by human and by machine.

This json like structure will let you:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
"endpoints": {
"sum":{
"request":{"a":{"type":"int"}, "b":{"type":"int"}},
"response":{"a":{"type":"int"}, "b":{"type":"int"}},
"response":{"result":{"type":"int"}},
"processing":{
"from": "processing.operations.sum",
"number_a": "a",
"number_b": "b",
"message": "calculating sum"
"__extends":{
"__from": "processing.operations.sum"
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
{
"engine": "python3.8",
"__description": "what seams like a simple sum",
"__constructor":{
"description": "what seams like a simple sum",
"number_a":{"type":"str", "default":"number_a"},
"number_b":{"type":"str", "default":"number_b"},
"message":{"type":"str", "default":"adding {__number_a} to {__number_b}"}
"message":{"type":"str", "default":"adding {__number_a} to {__number_b}"},
"function_name":{"type":"str", "default":"sum"}
},
"inputs":{
"__number_a":{"type":"str", "required":true},
"__number_b":{"type":"str", "required":true}
"type": "function",
"name": "__function_name",
"args":{
"__number_a":{"type":"int", "required":true},
"__number_b":{"type":"int", "required":true}
},
"kwargs":{
"debug":{"type":"bool", "default":false}
},
"outputs":{
"result":{"type":"int", "required":true}
},
"code": [
{
"type": "function",
"name": "print",
"args": ["f\"__message\""]
},
{
"type": "variable",
"variable_type": "str",
"name": "sum_result",
"equals": ["__number_a+number_b"]
"name": "result",
"expression": "__number_a+number_b"
},
{
"type": "conditional",
"condition": "debug",
"code": [
{
"type": "function_call",
"function":"print",
"args": ["result"]
}
]
},
{
"type": "return",
"args": ["sum_result"]
"args": ["result"]
}
]
}
26 changes: 21 additions & 5 deletions blueprints/examples/facebook/main.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@
"name": "facebook",
"models": {
"user":"global.utils.auth.user.models.user",
"conversation":"global.communication.chat.models.conversation",
"message":"global.communication.chat.feed.models.message"
"conversation":{"__extends":{
"__from":"global.communication.chat.models.conversation",
"user":"user"
}},
"message":{"__extends":{
"__from":"global.communication.chat.feed.models.message",
"user":"user"
}}
},
"services": {
"user":"global.utils.services.user",
"conversation":"global.communication.chat.services.conversation",
"message":"global.communication.chat.services.message"
"user":{"__extends":{
"__from":"global.utils.auth.user.services.user",
"user":"user"
}},
"conversation":{"__extends":{
"__from":"global.communication.chat.services.conversation",
"user":"user",
"conversation":"conversation"
}},
"message":{"__extends":{
"__from":"global.communication.chat.services.message",
"user":"user"
}}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"__constructor":{
"user":{
"description":"user to be used"
}
"description":"user model to be used",
"type":"str"
}
},
"attributes":{
"id": {"type":"id"},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"__constructor":{
"user":{
"description":"user to be used"
}
"description":"user model to be used",
"type":"str"
}
},
"__extends":{
"__from":"global.communication.chat.models.message",
"user":"__user"
},
"attributes":{
"feed":{"type":"feed", "required":true, "user":"__user"}
},
"__extends":{
"__from":"global.communication.chat.models.message"
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"__constructor":{
"user":{
"description":"user to be used"
}
"description":"user model to be used",
"type":"str"
}
},
"attributes":{
"id": {"type":"id"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"__constructor":{
"user":{
"description":"user model to be used",
"default":"global.auth.user.models.user"
"type":"str"
}
},
"attributes":{
Expand All @@ -23,8 +23,8 @@
},
"get":{
"__extends":{
"__from":"create",
"__excludes":[ "id"]
"__from":"attributes",
"__excludes":["id"]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"__constructor":{
"user":{
"type":"str",
"description":"route to user to be used"
"description":"user model to be used",
"type":"str"
}
},
"attributes":{
Expand All @@ -25,7 +25,7 @@
},
"get":{
"__extends":{
"__from":"create",
"__from":"attributes",
"__excludes":[ "id"]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"__constructor":{
"conversation":{
"description":"conversation model to be used",
"default":"global.communication.chat.models.conversation"
"type": "str"
}
},
"endpoints":{
Expand Down
6 changes: 3 additions & 3 deletions blueprints/global/utils/auth/user/models/user.model.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
"list":{
"response":{
"__extends":{
"from":"attributes",
"__from":"attributes",
"__excludes":["password"]
}
}
},
"get":{
"request":{
"__extends":{
"from":"attributes",
"__from":"attributes",
"__includes":["id"]
}
},
"response":{
"__extends":{
"from":"attributes",
"__from":"attributes",
"__excludes":["id"]
}
}
Expand Down
3 changes: 3 additions & 0 deletions blueprints/global/utils/auth/user/services/user.service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
40 changes: 30 additions & 10 deletions compiler/compiler.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
from json_compiler.Compiler import Compiler as json_compiler
import json
import sys
COMPILERS = {
"django-postgres.v1": "under development",
"flask-mongo.v1": "under development",
"nodejs-mongo.v1": "under development",
from json_compiler.Compiler import Compiler as json_compiler
from django_compiler.Compiler import Compiler as django_compiler
from python_compiler.Compiler import Compiler as python_compiler

COMPILERS = { # "framework.language.version: compiler"
"django.json.v1": django_compiler,
"python.json.v1": python_compiler,
"flask.json.v1": "under development",
"nodejs.json.v1": "under development",
"json.v1": json_compiler
}
def compile(compiler_name, project_name):
compiler = COMPILERS[compiler_name](project_name)
compiler.compile()
compiler = COMPILERS[compiler_name](main_file=project_name)
compiled_project = compiler.compile()
print(compiled_project)
# TODO: propper file extension and format saving
'''
with open(f"./{sys.argv[4]}", "w") as f:
json.dump(compiled_project, f, indent=4)
'''
OPTIONS = {
"compile": compile,
"c": compile
}
def main():
# 1 action
# 2 compiler
# 3 project
# 4 destination folder
OPTIONS[sys.argv[1]](sys.argv[2], sys.argv[3])
return

main()
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/import.app.json
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/construct.app.json
# python .\compiler.py c "json.v1" ../blueprints/examples/facebook/main.app.json build
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/import.app.json build
# python .\compiler.py c "json.v1" ./sample_blueprints/samples/construct.app.json build
# python .\compiler.py c "json.v1" ../blueprints/examples/calculator/v2/main.app.json build

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

Loading