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,97 @@ 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" )
40
44
41
45
else :
42
46
poetry_path = os .path .join (root , "app" )
43
-
47
+
44
48
has_pyproject = add_configuration_to_pyproject (poetry_path )
45
49
46
50
if has_pyproject :
47
- dependencies = ["fastapi[all]" , "fastapi-pagination[sqlalchemy]@^0.12.7" , "asyncer@^0.0.2" , "httpx@^0.24.1" ]
51
+ dependencies = [
52
+ "fastapi[all]" ,
53
+ "fastapi-pagination[sqlalchemy]@^0.12.7" ,
54
+ "asyncer@^0.0.2" ,
55
+ "httpx@^0.24.1" ,
56
+ ]
57
+ dev_dependencies = [
58
+ "pytest@^7.4.0" ,
59
+ "mypy@^1.5.0" ,
60
+ "ruff@^0.0.284" ,
61
+ "black@^23.7.0" ,
62
+ ]
48
63
if template == ITemplate .langchain_basic :
49
64
langchain_dependencies = [
50
65
"langchain@^0.0.265" ,
51
66
"openai@^0.27.8" ,
52
67
"adaptive-cards-py@^0.0.7" ,
53
- "google-search-results@^2.4.2"
68
+ "google-search-results@^2.4.2" ,
54
69
]
55
70
dependencies [0 ] = "fastapi[all]@^0.99.1"
56
71
dependencies .extend (langchain_dependencies )
57
- dev_dependencies = ["pytest@^5.2" , "mypy@^1.5.0" , "ruff@^0.0.284" , "black@^23.7.0" ]
72
+ if template == ITemplate .full :
73
+ full_dependencies = [
74
+ "alembic@^1.10.2" ,
75
+ "asyncpg@^0.27.0" ,
76
+ "sqlmodel@^0.0.8" ,
77
+ "python-jose@^3.3.0" ,
78
+ "cryptography@^38.0.3" ,
79
+ "passlib@^1.7.4" ,
80
+ "SQLAlchemy-Utils@^0.38.3" ,
81
+ "SQLAlchemy@^1.4.40" ,
82
+ "minio@^7.1.13" ,
83
+ "Pillow@^9.4.0" ,
84
+ "watchfiles@^0.18.1" ,
85
+ "asyncer@^0.0.2" ,
86
+ "httpx@^0.23.1" ,
87
+ "pandas@^1.5.3" ,
88
+ "openpyxl@^3.0.10" ,
89
+ "redis@^4.5.1" ,
90
+ "fastapi-async-sqlalchemy@^0.3.12" ,
91
+ "oso@^0.26.4" ,
92
+ "celery@^5.2.7" ,
93
+ "transformers@^4.28.1" ,
94
+ "requests@^2.29.0" ,
95
+ "wheel@^0.40.0" ,
96
+ "setuptools@^67.7.2" ,
97
+ "langchain@^0.0.262" ,
98
+ "openai@^0.27.5" ,
99
+ "celery-sqlalchemy-scheduler@^0.3.0" ,
100
+ "psycopg2-binary@^2.9.5" ,
101
+ "fastapi-limiter@^0.1.5 " ,
102
+ # fastapi-pagination {extras ["sqlalchemy"], version "^0.11.4"},
103
+ "fastapi-pagination[sqlalchemy]@^0.11.4 " ,
104
+ # fastapi-cache2 {extras ["redis"], version "^0.2.1"},
105
+ "fastapi-cache2[redis]@^0.2.1 " ,
106
+ # torch [ {url "https://download.pytorch.org/whl/cpu/torch-2.0.0%2Bcpu-cp310-cp310-linux_x86_64.whl", markers "sys_platform 'linux'"},{url "https://download.pytorch.org/whl/cpu/torch-2.0.0%2Bcpu-cp310-cp310-win_amd64.whl", markers "sys_platform 'win32'"}],
107
+ ]
108
+ full_dev_dependencies = [
109
+ "pytest-asyncio@^0.21.1" ,
110
+ ]
111
+ dependencies [0 ] = "fastapi[all]@^0.95.2"
112
+ dependencies .extend (full_dependencies )
113
+ dev_dependencies .extend (full_dev_dependencies )
114
+
58
115
print ("- Installing main packages. This might take a couple of minutes." )
59
116
install_dependencies (poetry_path , dependencies )
60
117
print ("- Installing development packages. This might take a couple of minutes." )
61
118
install_dependencies (poetry_path , dev_dependencies , dev = True )
62
119
# Set your dynamic environment variables
63
-
120
+
64
121
# Load variables from .env.example
65
122
example_env = dotenv_values (".env.example" )
66
123
example_env ["PROJECT_NAME" ] = app_name
67
124
68
125
# 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 :
126
+ with open (".env" , "w" ) as env_file , open (
127
+ ".env.example" , "w"
128
+ ) as example_env_file :
70
129
for key , value in example_env .items ():
71
130
env_file .write (f"{ key } ={ value } \n " )
72
131
example_env_file .write (f"{ key } ={ value } \n " )
73
132
74
133
return has_pyproject
75
-
76
-
0 commit comments