11import os
22import re
33import time
4- import subprocess
54
65import argparse
6+ import subprocess
77import importlib .metadata
88
99from typing import cast
1515 success_print ,
1616 warning_print ,
1717 clone_repository ,
18+ display_intro_text ,
1819)
1920
2021
21- def intro_text () -> None :
22- intro_message = """
23- ______________________________________________________________
24-
25- ███████╗ █████╗ ███████╗████████╗ █████╗ ██████╗ ██╗
26- ██╔════╝██╔══██╗██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██║
27- █████╗ ███████║███████╗ ██║ ███████║██████╔╝██║
28- ██╔══╝ ██╔══██║╚════██║ ██║ ██╔══██║██ ██║
29- ██║ ██║ ██║███████║ ██║ ██║ ██║██║ ║██║
30- ╚═╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚╝╚╝
31-
32- ██████╗ ██████╗ ██████╗ ███████╗███████╗ ██████ ████████╗
33- ██╔══██╗██╔══██╗██╔═══██╗ ════██╗██╔════╝██╔════╝ ╚══██╔══╝
34- ██████╔╝██████╔╝██║ ██║ ██║█████╗ ██║ ██║
35- ██╔═══╝ ██╔══██╗██║ ██║███ ██║██╔══╝ ██║ ██║
36- ██║ ██║ ██║╚██████╔╝██████╔╝███████╗╚██████╗ ██║
37- ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝
38-
39- ██████╗ ███████╗███╗ ██╗ █████╗
40- ██╔════╝ ██╔════╝████╗ ██║██╔══██╗
41- ██║ ███╗█████╗ ██╔██╗ ██║ █████╔╝
42- ██║ ██║██╔══╝ ██║╚██╗██║██╔══██╗
43- ╚██████╔╝███████╗██║ ╚████║ █████╔╝
44- ╚═════╝ ╚══════╝╚═╝ ╚╝ ╚════╝
45- ______________________________________________________________
22+ def generate_default_project_details () -> dict [str , str | int | tuple ]:
4623 """
47- print (intro_message )
48- description = """
49- Generate a fully structured FastAPI projects instantly.
50- Boilerplate code, ready-to-run endpoints, and project scaffolding
51- all in one simple command. Kickstart your backend in seconds!
24+ Generates Default Project Details
5225
53- Provide Project Details to each prompt and press Enter complete project setup
54- Values placed within square brackets ([My Awesome FastAPI Project]) are defaults values for the project details
55- If you do not provide a value, those values are used instead
56- _____________________________________________________________________________________________________
57- """
58- # FUN 🚀
26+ For Single Value Constant Details like name, description etc
27+ The values are provided to the dictionary as simple String values
28+ But for Enumerated Values like open_source_license type
29+ the options are passed as a list of tuples where the the first item in tuple
30+ if the enumerate for the item and the second item is the actual value to be stored,
31+
32+ like so
5933
60- # How Fast Can you Complete your FastAPI project setup?
61- # Blaze through the steps to make the global leaderboard for projects generated with FastAPI Project Gen8.
62- # In Order to qualify for this leaderboard, you have to make sure to input every project detail and not use defaults
63- # even though the defaults match your project attribute .
64- # Current Best Record: {get_current_best_record()[0]} seconds - Title: [{get_current_best_record()[1]}]
65- print ( description )
34+ open_source_license: (
35+ "<default_enumeration>", [
36+ (<enumeration>, "<actual_value>"),
37+ .. .
38+ ]
39+ )
6640
41+ """
42+ return {
43+ "name" : "My Awesome FastAPI Project" ,
44+ "slug_name" : "my_awesome_fastapi_project" ,
45+ "description" : "FastAPI Project Description" ,
46+ "author(s)" : ("John Doe" , "Jane Doe" ),
47+ "virtual_env_folder_name" : "venv" ,
48+ "version" : "0.1.0" ,
49+ "email" : "brianobot9@gmail.com" ,
50+ "repository_link" : "" ,
51+ "open_source_license" : ("1" , [
52+ (1 , "MIT" ),
53+ (2 , "BSD" ),
54+ (3 , "GPLv3" ),
55+ (4 , "Apache Software License 2.0" ),
56+ (5 , "Not open source" ),
57+ ]),
58+ }
59+
6760
6861def get_project_detail (
6962 attr : str ,
7063 default : str | int | tuple [str , ...],
7164 project_detail : dict [str , str | int | tuple ]
7265) -> str | int | tuple [str , ...]:
73- # Process the display for collecting the detail
74- if "_" in attr :
75- attr = attr .lower ()
76- if attr == "slug_name" :
77- # Update the slug name to match the project nanme
78- default = slugify (str (project_detail ['name' ]))
79- if attr == "description" :
80- # Include the Project name in the default description for better suggestion
81- print ("About to Update the Description" )
82- default = cast (str , default ) + f" for { project_detail ['name' ]} "
83-
84- if attr not in {"open_source_license" , "username_type" }:
66+ """
67+ This functions gets a project detail from the user via the command line interface, if nothing is provided
68+ the default value is used for the project detail value.
69+ """
70+
71+ # Tuples Attrs means the detail have options, so process them differently
72+ if not isinstance (attr , tuple ):
8573 detail = input (f"Enter Project { attr } ['{ default } ']: " )
8674 else :
8775 count = 0
@@ -120,7 +108,7 @@ def get_project_detail(
120108
121109 # Process the value provided by the user
122110 if attr == "slug_name" :
123- detail = slugify (cast (str , detail ))
111+ detail = slugify (cast (str , detail )) if detail else None
124112 if attr == "authors" :
125113 detail = tuple (cast (str , detail ).split ("," ))
126114 return detail if detail else default
@@ -155,7 +143,7 @@ def apply_project_metadata(project_detail: dict[str, str]) -> None:
155143 target .write_text (content )
156144
157145
158- def generate_project (project_detail : dict [str , str ]):
146+ def generate_project_scaffold (project_detail : dict [str , str ]):
159147 # Clone The Default Project Template into Folder with Project Slug Name
160148 # check if the project already exist
161149
@@ -207,6 +195,9 @@ def generate_project(project_detail: dict[str, str]):
207195
208196
209197def main ():
198+ """
199+ Main entry point to interacting with the Command Line Utility of the Generator Library
200+ """
210201 parser = argparse .ArgumentParser (
211202 prog = "fastapi-gen8" ,
212203 description = "Generate clean, production-ready FastAPI project scaffolds" ,
@@ -220,36 +211,13 @@ def main():
220211
221212 _args = parser .parse_args ()
222213
223- intro_text ()
224-
225- project_details : dict [str , str | int | tuple ] = {
226- "name" : "My Awesome FastAPI Project" ,
227- "slug_name" : "my_awesome_fastapi_project" ,
228- "description" : "FastAPI Backend Project" ,
229- "author(s)" : ("John Doe" , "Jane Doe" ),
230- "virtual_env_folder_name" : "venv" ,
231- "version" : "0.1.0" ,
232- "email" : "brianobot9@gmail.com" ,
233- "repository_link" : "" ,
234- "open_source_license" : ("1" , [
235- (1 , "MIT" ),
236- (2 , "BSD" ),
237- (3 , "GPLv3" ),
238- (4 , "Apache Software License 2.0" ),
239- (5 , "Not open source" ),
240- ]),
241- # "username_type": ("1", [
242- # (1, "email"),
243- # (2, "username"),
244- # (3, "email + username"),
245- # (4, "None"),
246- # ]),
247- }
214+ display_intro_text ()
215+ project_details = generate_default_project_details ()
248216
249- start_time = time .time ()
217+ start_time = time .time () # this is an internal metric to track the duration for each project generation
250218 for attr , default_value in project_details .items ():
251219 detail = get_project_detail (attr .title (), default_value , project_details )
252- project_details [attr ] = detail
220+ project_details [attr ] = detail # update the default project detail with the provided one
253221 success_print (f"Project { attr .title ()} = { detail } " )
254222
255223
@@ -259,7 +227,7 @@ def main():
259227 print ("----------------------------------------------" )
260228
261229 # Generate Projects with the Details Provided by the User
262- generate_project (cast (dict [str , str ], project_details ))
230+ generate_project_scaffold (cast (dict [str , str ], project_details ))
263231
264232
265233if __name__ == "__main__" :
0 commit comments