16
16
17
17
from fastapi_fastkit .core .exceptions import CLIExceptions
18
18
from fastapi_fastkit .core .settings import FastkitConfig
19
- from fastapi_fastkit .utils .inspector import delete_project
20
19
from fastapi_fastkit .utils .logging import setup_logging
21
20
from fastapi_fastkit .utils .transducer import copy_and_convert_template
22
21
25
24
create_info_table ,
26
25
inject_project_metadata ,
27
26
print_error ,
27
+ print_info ,
28
28
print_success ,
29
29
print_warning ,
30
30
validate_email ,
@@ -234,19 +234,13 @@ def startup(
234
234
prompt = "Enter project name" ,
235
235
help = "Name of the new FastAPI project" ,
236
236
)
237
- @click .option (
238
- "--stack" ,
239
- type = click .Choice (["minimal" , "standard" , "full" ]),
240
- prompt = "Select stack" ,
241
- help = "Project stack configuration" ,
242
- )
243
- def startproject (project_name : str , stack : str ) -> None :
237
+ def startproject (project_name : str ) -> None :
244
238
"""
245
239
Start a new FastAPI project.
246
- Dependencies will be automatically installed based on the selected stack.
240
+ This command will automatically create a new FastAPI project directory and a python virtual environment.
241
+ Dependencies will be automatically installed based on the selected stack at venv.
247
242
248
243
:param project_name: Project name
249
- :param stack: Project stack configuration
250
244
:return: None
251
245
"""
252
246
settings = FastkitConfig ()
@@ -256,28 +250,43 @@ def startproject(project_name: str, stack: str) -> None:
256
250
print_error (f"Error: Project '{ project_name } ' already exists." )
257
251
return
258
252
253
+ dependencies = {
254
+ "minimal" : ["fastapi" , "uvicorn" ],
255
+ "standard" : ["fastapi" , "uvicorn" , "sqlalchemy" , "alembic" , "pytest" ],
256
+ "full" : [
257
+ "fastapi" ,
258
+ "uvicorn" ,
259
+ "sqlalchemy" ,
260
+ "alembic" ,
261
+ "pytest" ,
262
+ "redis" ,
263
+ "celery" ,
264
+ "docker-compose" ,
265
+ ],
266
+ }
267
+
268
+ console .print ("\n [bold]Available Stacks and Dependencies:[/bold]" )
269
+ for stack_name , deps in dependencies .items ():
270
+ table = create_info_table (
271
+ f"{ stack_name .upper ()} Stack" ,
272
+ {f"Dependency { i + 1 } " : dep for i , dep in enumerate (deps )},
273
+ )
274
+ console .print (table )
275
+ console .print ("\n " )
276
+
277
+ stack = click .prompt (
278
+ "Select stack" ,
279
+ type = click .Choice (["minimal" , "standard" , "full" ]),
280
+ show_choices = True ,
281
+ )
282
+
259
283
try :
260
284
os .makedirs (project_dir )
261
285
262
286
table = create_info_table (
263
- f"Creating Project: { project_name } " , {"Component" : "Status " }
287
+ f"Creating Project: { project_name } " , {"Component" : "Collected " }
264
288
)
265
289
266
- dependencies = {
267
- "minimal" : ["fastapi" , "uvicorn" ],
268
- "standard" : ["fastapi" , "uvicorn" , "sqlalchemy" , "alembic" , "pytest" ],
269
- "full" : [
270
- "fastapi" ,
271
- "uvicorn" ,
272
- "sqlalchemy" ,
273
- "alembic" ,
274
- "pytest" ,
275
- "redis" ,
276
- "celery" ,
277
- "docker-compose" ,
278
- ],
279
- }
280
-
281
290
with open (os .path .join (project_dir , "requirements.txt" ), "w" ) as f :
282
291
for dep in dependencies [stack ]:
283
292
f .write (f"{ dep } \n " )
@@ -287,15 +296,31 @@ def startproject(project_name: str, stack: str) -> None:
287
296
288
297
with console .status ("[bold green]Setting up project environment..." ):
289
298
console .print ("[yellow]Creating virtual environment...[/yellow]" )
290
- subprocess .run (["python" , "-m" , "venv" , os .path .join (project_dir , "venv" )])
299
+ venv_path = os .path .join (project_dir , "venv" )
300
+ subprocess .run (["python" , "-m" , "venv" , venv_path ], check = True )
301
+
302
+ if os .name == "nt" : # Windows
303
+ pip_path = os .path .join (venv_path , "Scripts" , "pip" )
304
+ else : # Linux/Mac
305
+ pip_path = os .path .join (venv_path , "bin" , "pip" )
291
306
292
307
console .print ("[yellow]Installing dependencies...[/yellow]" )
293
308
subprocess .run (
294
- ["pip" , "install" , "-r" , "requirements.txt" ], cwd = project_dir
309
+ [pip_path , "install" , "-r" , "requirements.txt" ],
310
+ cwd = project_dir ,
311
+ check = True ,
295
312
)
296
313
297
314
print_success (f"Project '{ project_name } ' has been created successfully!" )
298
315
316
+ if os .name == "nt" :
317
+ activate_venv = f" { os .path .join (venv_path , 'Scripts' , 'activate.bat' )} "
318
+ else :
319
+ activate_venv = f" source { os .path .join (venv_path , 'bin' , 'activate' )} "
320
+ print_info (
321
+ "To activate the virtual environment, run:\n \n " + activate_venv ,
322
+ )
323
+
299
324
except Exception as e :
300
325
print_error (f"Error during project creation: { e } " )
301
326
shutil .rmtree (project_dir , ignore_errors = True )
@@ -353,7 +378,7 @@ def deleteproject(ctx: Context, project_name: str) -> None:
353
378
return
354
379
355
380
try :
356
- delete_project (project_dir )
381
+ shutil . rmtree (project_dir )
357
382
print_success (f"Project '{ project_name } ' has been deleted successfully!" )
358
383
359
384
except Exception as e :
0 commit comments