2
2
import shutil
3
3
from enum import Enum
4
4
from dotenv import dotenv_values
5
- from create_fastapi_project .helpers .install import add_configuration_to_pyproject , install_dependencies
5
+ from create_fastapi_project .helpers .install import (
6
+ add_configuration_to_pyproject ,
7
+ install_dependencies ,
8
+ )
9
+
6
10
7
11
class ITemplate (str , Enum ):
8
12
basic = "basic"
9
13
langchain_basic = "langchain_basic"
10
- full = "full"
14
+ full = "full"
15
+
11
16
12
17
def install_template (root : str , template : ITemplate , app_name : str ):
13
18
print (f"Initializing project with template: { template } " )
@@ -32,45 +37,107 @@ def install_template(root: str, template: ITemplate, app_name: str):
32
37
dirs_exist_ok = True ,
33
38
)
34
39
35
-
36
40
poetry_path = ""
37
41
if template == ITemplate .full or template == ITemplate .langchain_basic :
38
42
# TODO: CHECK PATHS IN MACOS AND WINDOWS | (os.path.join)
39
43
poetry_path = os .path .join (root , "backend" , "app" )
44
+ poetry_frontend_path = os .path .join (root , "frontend" , "app" )
40
45
41
46
else :
42
47
poetry_path = os .path .join (root , "app" )
43
-
48
+
44
49
has_pyproject = add_configuration_to_pyproject (poetry_path )
45
50
46
51
if has_pyproject :
47
- dependencies = ["fastapi[all]" , "fastapi-pagination[sqlalchemy]@^0.12.7" , "asyncer@^0.0.2" , "httpx@^0.24.1" ]
52
+ dependencies = [
53
+ "fastapi[all]" ,
54
+ "fastapi-pagination[sqlalchemy]@^0.12.7" ,
55
+ "asyncer@^0.0.2" ,
56
+ "httpx@^0.24.1" ,
57
+ ]
58
+ dev_dependencies = [
59
+ "pytest@^7.4.0" ,
60
+ "mypy@^1.5.0" ,
61
+ "ruff@^0.0.284" ,
62
+ "black@^23.7.0" ,
63
+ ]
48
64
if template == ITemplate .langchain_basic :
49
65
langchain_dependencies = [
50
66
"langchain@^0.0.265" ,
51
67
"openai@^0.27.8" ,
52
68
"adaptive-cards-py@^0.0.7" ,
53
- "google-search-results@^2.4.2"
69
+ "google-search-results@^2.4.2" ,
70
+ ]
71
+ frontend_dependencies = [
72
+ "streamlit" ,
73
+ "websockets" ,
54
74
]
55
75
dependencies [0 ] = "fastapi[all]@^0.99.1"
56
76
dependencies .extend (langchain_dependencies )
57
- dev_dependencies = ["pytest@^5.2" , "mypy@^1.5.0" , "ruff@^0.0.284" , "black@^23.7.0" ]
77
+ if template == ITemplate .full :
78
+ full_dependencies = [
79
+ "alembic@^1.10.2" ,
80
+ "asyncpg@^0.27.0" ,
81
+ "sqlmodel@^0.0.8" ,
82
+ "python-jose@^3.3.0" ,
83
+ "cryptography@^38.0.3" ,
84
+ "passlib@^1.7.4" ,
85
+ "SQLAlchemy-Utils@^0.38.3" ,
86
+ "SQLAlchemy@^1.4.40" ,
87
+ "minio@^7.1.13" ,
88
+ "Pillow@^9.4.0" ,
89
+ "watchfiles@^0.18.1" ,
90
+ "asyncer@^0.0.2" ,
91
+ "httpx@^0.23.1" ,
92
+ "pandas@^1.5.3" ,
93
+ "openpyxl@^3.0.10" ,
94
+ "redis@^4.5.1" ,
95
+ "fastapi-async-sqlalchemy@^0.3.12" ,
96
+ "oso@^0.26.4" ,
97
+ "celery@^5.2.7" ,
98
+ "transformers@^4.28.1" ,
99
+ "requests@^2.29.0" ,
100
+ "wheel@^0.40.0" ,
101
+ "setuptools@^67.7.2" ,
102
+ "langchain@^0.0.262" ,
103
+ "openai@^0.27.5" ,
104
+ "celery-sqlalchemy-scheduler@^0.3.0" ,
105
+ "psycopg2-binary@^2.9.5" ,
106
+ "fastapi-limiter@^0.1.5 " ,
107
+ "fastapi-pagination[sqlalchemy]@^0.11.4 " ,
108
+ "fastapi-cache2[redis]@^0.2.1 " ,
109
+ ]
110
+ full_dev_dependencies = [
111
+ "pytest-asyncio@^0.21.1" ,
112
+ ]
113
+ dependencies [0 ] = "fastapi[all]@^0.95.2"
114
+ dependencies .extend (full_dependencies )
115
+ dev_dependencies .extend (full_dev_dependencies )
116
+
58
117
print ("- Installing main packages. This might take a couple of minutes." )
59
118
install_dependencies (poetry_path , dependencies )
60
119
print ("- Installing development packages. This might take a couple of minutes." )
61
120
install_dependencies (poetry_path , dev_dependencies , dev = True )
121
+
122
+ if template == ITemplate .langchain_basic :
123
+ add_configuration_to_pyproject (poetry_frontend_path )
124
+ print (
125
+ "- Installing frontend packages. This might take a couple of minutes."
126
+ )
127
+ install_dependencies (poetry_frontend_path , frontend_dependencies )
128
+
62
129
# Set your dynamic environment variables
63
-
130
+
64
131
# Load variables from .env.example
65
132
example_env = dotenv_values (".env.example" )
66
133
example_env ["PROJECT_NAME" ] = app_name
67
134
68
135
# Write modified environment variables to .env and .env.example file
69
- with open (".env" , "w" ) as env_file , open (".env.example" , "w" ) as example_env_file :
136
+ with open (".env" , "w" ) as env_file , open (
137
+ ".env.example" , "w"
138
+ ) as example_env_file :
70
139
for key , value in example_env .items ():
71
140
env_file .write (f"{ key } ={ value } \n " )
72
141
example_env_file .write (f"{ key } ={ value } \n " )
73
142
74
143
return has_pyproject
75
-
76
-
0 commit comments