1
1
import os
2
2
from pathlib import Path
3
+ from typing import Optional
3
4
4
5
from pydantic import BaseModel
5
6
10
11
start_worker_sh_template ,
11
12
)
12
13
from bridge .console import console
14
+ from bridge .framework .base import Framework
13
15
from bridge .utils .filesystem import (
14
16
resolve_dot_bridge ,
15
17
resolve_project_dir ,
16
18
set_executable ,
17
19
)
18
20
19
21
22
+ def detect_framework () -> Framework :
23
+ # TODO: auto-detect framework (assuming Django)
24
+ return Framework .DJANGO
25
+
26
+
27
+ def detect_django_settings_module (project_name : str = "" ) -> str :
28
+ settings_path = f"{ project_name } /settings.py"
29
+ if os .path .exists (settings_path ):
30
+ return f"{ project_name } .settings"
31
+ else :
32
+ # TODO: validate input
33
+ return console .input (
34
+ "Please provide the path to your"
35
+ " Django settings module (ex: myapp.settings):\n > "
36
+ )
37
+
38
+
20
39
def detect_application_callable (project_name : str = "" ) -> str :
21
40
wsgi_path = f"{ project_name } /wsgi.py"
22
41
asgi_path = f"{ project_name } /asgi.py"
@@ -25,34 +44,48 @@ def detect_application_callable(project_name: str = "") -> str:
25
44
elif os .path .exists (asgi_path ):
26
45
return f"{ project_name } .asgi:application"
27
46
else :
47
+ # TODO: validate input
28
48
return console .input (
29
49
"Please provide the path to your WSGI or ASGI application callable "
30
50
"(ex: myapp.wsgi:application):\n > "
31
51
)
32
52
33
53
54
+ class DjangoConfig (BaseModel ):
55
+ settings_module : str
56
+
57
+
34
58
class RenderPlatformInitConfig (BaseModel ):
59
+ framework : Framework = Framework .DJANGO
35
60
project_name : str
36
61
app_path : str
37
62
bridge_path : str
63
+ django_config : Optional [DjangoConfig ] = None
38
64
39
65
40
66
def build_render_init_config () -> RenderPlatformInitConfig :
41
67
# NOTE: this method may request user input directly on the CLI
42
68
# to determine configuration when it cannot be auto-detected
69
+ framework = detect_framework ()
43
70
project_name = resolve_project_dir ().name
44
71
app_path = detect_application_callable (project_name = project_name )
45
- # May be able to remove this call since all scripts, YAML have moved to root
46
72
bridge_path = resolve_dot_bridge ()
47
- return RenderPlatformInitConfig (
73
+ init_config = RenderPlatformInitConfig (
48
74
project_name = project_name , app_path = app_path , bridge_path = str (bridge_path )
49
75
)
50
76
77
+ # Provide framework-specific configuration
78
+ if framework == Framework .DJANGO :
79
+ settings_module = detect_django_settings_module (project_name = project_name )
80
+ init_config .django_config = DjangoConfig (settings_module = settings_module )
81
+
82
+ return init_config
83
+
51
84
52
85
def initialize_render_platform (config : RenderPlatformInitConfig ):
53
86
build_sh_path = Path ("./render-build.sh" )
54
87
with build_sh_path .open (mode = "w" ) as f :
55
- f .write (build_sh_template ())
88
+ f .write (build_sh_template (framework = config . framework ))
56
89
set_executable (build_sh_path )
57
90
58
91
start_sh_path = Path ("./render-start.sh" )
@@ -62,13 +95,17 @@ def initialize_render_platform(config: RenderPlatformInitConfig):
62
95
63
96
start_worker_sh_path = Path ("./render-start-worker.sh" )
64
97
with start_worker_sh_path .open (mode = "w" ) as f :
65
- f .write (start_worker_sh_template ())
98
+ f .write (start_worker_sh_template (framework = config . framework ))
66
99
set_executable (start_worker_sh_path )
67
100
68
101
with open ("render.yaml" , "w" ) as f :
69
102
f .write (
70
103
render_yaml_template (
104
+ framework = config .framework ,
71
105
service_name = config .project_name ,
72
106
database_name = f"{ config .project_name } _db" ,
107
+ django_settings_module = config .django_config .settings_module
108
+ if config .django_config
109
+ else "" ,
73
110
)
74
111
)
0 commit comments