
    >9j0B                        U d dl Z d dlZd dlmZ d dlmZmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZ d d
lmZ ddlmZ ddl mZ ddlmZmZ  ej>                  ddddgi      Z  e jB                  e"      Z#ddddddZ$e%eez  e&f   e'd<   	 d dl(Z(	 d dl*m Z+ e jY                  e+       	 d dl-m Z. e jY                  e.       de/ddfdZ0e jc                         d ejd                  dd !      fd"ee/dz   ejd                  d#d$e0%      f   d&e/ddfd'       Z1d(e3e   defd)Z4	 dSd*d+d,ddd-dddddd.d/edz  d0e&d1e5d2e/d3e3e   dz  d4e5dz  d5e&d6e&d7e&dz  d8e&dz  d9e/d:e&dz  d;e&dz  ddfd<Z6e jo                         	 dSd*d+d,dd-ddd,dd=	d/eedz   ejp                  d>!      f   d0ee& ejd                  d?!      f   d1ee5 ejd                  d@dAB      f   d2ee/ ejd                  dC!      f   dDee3e   dz   ejd                  dE!      f   d5ee& ejd                  dF!      f   d7ee&dz   ejd                  dG!      f   d8ee&dz   ejd                  dHdIdJ!      f   d9ee/ ejd                  dK!      f   d:ee&dz   ejd                  dL!      f   defdM       Z9e jo                         	 dSdNd+ddd-ddd,ddO	d/eedz   ejp                  d>!      f   d0ee& ejd                  d?!      f   d1ee5 ejd                  d@dAB      f   d2ee/ ejd                  dC!      f   d4ee5dz   ejd                  dP!      f   d5ee& ejd                  dF!      f   d7ee&dz   ejd                  dG!      f   d8ee&dz   ejd                  dHdIdJ!      f   d9ee/ ejd                  dK!      f   d:ee&dz   ejd                  dL!      f   defdQ       Z:dTdRZ;y# e)$ r dZ(Y 9w xY w# e)$ r Y -w xY w# e)$ r Y !w xY w)U    N)Path)	AnnotatedAny)ValidationError)print)Syntax)Tree)FastAPIConfig)AppConfigSourceModuleConfigSourceget_import_data"get_import_data_from_import_string)FastAPICLIException   __version__)setup_logging)get_rich_toolkitget_uvicorn_log_configrichhelp_option_namesz-hz--help)rich_markup_modecontext_settingsz [blue]--entrypoint[/] CLI optionz.[blue]entrypoint[/] in [blue]pyproject.toml[/]z[blue]path[/] CLI argumentz[blue]--app[/] CLI optionauto-discovery)zentrypoint-optionzentrypoint-pyprojectzpath-argumentz
app-optionr   SOURCE_DESCRIPTIONSappvaluereturnc                     | r=t        dt         d       	 ddlm} t        d| d       t	        j
                         y # t        $ r Y t	        j
                         w xY w)NzFastAPI CLI version: [green]z[/green]r   r   z"FastAPI Cloud CLI version: [green])r   r   fastapi_cloud_cliImportErrortyperExit)r   cloud_cli_versions     O/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/fastapi_cli/cli.pyversion_callbackr'   C   sj    ,[MBC	 67H6IRS jjl   	jjl	s   A 	A A FzEnable verbose output)helpversionz	--versionzShow the version and exit.)r(   callbackverbosec                 `    |rt         j                  nt         j                  }t        |       y)u  
    FastAPI CLI - The [bold]fastapi[/bold] command line app. 😎

    Manage your [bold]FastAPI[/bold] projects, run your FastAPI apps, and more.

    Read more in the docs: [link=https://fastapi.tiangolo.com/fastapi-cli/]https://fastapi.tiangolo.com/fastapi-cli/[/link].
    )levelN)loggingDEBUGINFOr   )r)   r+   	log_levels      r&   r*   r*   R   s    $ ")gllI	"    module_pathsc                    | d   }|j                         rd|j                   nd|j                   }t        |      }|j                         r|j	                  d       |}| dd  D ]c  }|j                         rd|j                   nd|j                   }|j	                  |      }|j                         sS|j	                  d       e |S )Nr   u   🐍 u   📁 u   [dim]🐍 __init__.py[/dim]r   )is_filenamer	   is_diradd)r3   rootr6   	root_treetreesub_pathsub_names          r&   _get_module_treer>   i   s    ?D"&,,.U499+dii[6IDT
I{{}34D $ 4'/'7'7'9eHMM?#x}}o?V 	 xx!??HH234 r2   z	127.0.0.1i@  T )hostportreloadreload_dirsworkers	root_pathr   
entrypointproxy_headersforwarded_allow_ips
public_urlpathr@   rA   rB   rC   rD   rE   commandr   rF   rG   rH   rI   c                   t               5 }|dk(  rdnd}|j                  d| dd       |j                          |j                  d       |	rK| s|rG|j                          |j                  d	       |j                          t	        j
                  d
      	 t        j                  |	      }	 | s|rt        | |      }n7|j                  r!t        |j                  |j                        }n
t               }t         j#                  d|j$                  j&                          t         j#                  d|j$                  j(                          |j$                  }|j*                  }|j                  d|j&                          |j                          |j,                  r8t/        |j,                        }|j                  |d       |j                          |j                  dd       |j                          |j                  d|j(                   d|j0                   d       |j                          |j                  d| dd        t2        |j4                     }t2        |j6                     }|j                          |j                  d!d"       ||k(  r|j                  d#|        n(|j                  d$|        |j                  d%|        |j4                  d&k(  ru|j                          |j                  d'd(       |j                          |j                  t9        d)|j$                  j(                   d*|j0                   d+d,d-.             |r|j;                  d/      nd0| d*| }| d1}|j                          |j                  d2| d3| dd4| d3| dd5       |dk(  r#|j                          |j                  d6d(       t<        st        d7      d |j                          |j                  d8       |j                          t=        j>                  |||||r'|D cg c]  }tA        |j                                c}nd |||
|tC               9
       d d d        y # t        $ r}|j                          |j                  d       |j                          |j                         D ]7  }dj                  d |d   D              }|j                  d| d|d           9 |j                          t	        j
                  d
      d d }~ww xY w# t        $ r@}|j                          |j                  d|        t	        j
                  d
      d d }~ww xY wc c}w # 1 sw Y   y xY w):Ndevdevelopment
productionz	Starting u    server 🚀FastAPI)tagzYSearching for package file structure from directories with [blue]__init__.py[/blue] fileszD[error]Cannot use --entrypoint together with path or --app argumentsr   )code)rF   z/[error]Invalid configuration in pyproject.toml:.c              3   2   K   | ]  }t        |        y wN)str).0locs     r&   	<genexpr>z_run.<locals>.<genexpr>   s      BcS Bs   rX   u     [red]•[/red] z: msg)rJ   app_namez[error]zImporting from zImporting module modulezIImporting the FastAPI app object from the module with the following code:rR   z[underline]from [bold]z[/bold] import [bold]z[/bold]zUsing import string: [blue]z[/]r   zConfiguration sources:infou    • Import string: u    • Module: u    • App name: r   zMYou can configure an entrypoint in [blue]pyproject.toml[/] for this app with:tipz[tool.fastapi]
entrypoint = ":"toml
ansi_light)theme/zhttp://z/docszServer started at [link=]zDocumentation at [link=serverzERunning in development mode, for production use: [bold]fastapi run[/]z;Could not import Uvicorn, try running 'pip install uvicorn'zLogs:)
r   r@   rA   rB   rC   rD   rE   rG   rH   
log_config)"r   print_title
print_liner   r#   r$   r
   resolver   errorsjoinr   rF   r   from_pyprojectr   loggerdebugmodule_dataextra_sys_pathmodule_import_strimport_stringr3   r>   r[   r   module_config_sourceapp_name_config_sourcer   rstripuvicornrunrV   r   )rJ   r@   rA   rB   rC   rD   rE   rK   r   rF   rG   rH   rI   toolkitserver_typeconfigeerrorfieldimport_datarp   rs   r:   mod_source_descapp_source_descurlurl_docs	directorys                               r&   _runr   ~   sh     
	 S
w'.%'7m\i}LAyQg	
 43 MMV  **!$$	/"**jAF	/s-4#F""@%%v'<'< ./ 	{'>'>'M'M&NOP()@)@)R)R(STU!--#11(B(B'CDE##()A)ABIMM)M2 W 	 	
 	$[%B%B$CCXYdYmYmXnnuv	
 	)-< 	 	

 .k.N.NO-k.P.PQ.F;o-MM00ABCMMM/):;<MMOO+<=>++/?? MM_    MM))4)@)@)R)R(SSTU`UiUiTjjkm &	 )3j$'$q8OU%=&se1SE5%hZq
#> 	 	
 e MMW  
 %M 	g  <GGiY&&()G' 3-/	
IS
 S
(  	/ MMKL  K BU5\ BB 1%5<.IJK  **!$$.	/. # 	/ MMGA3-(**!$$.	/~ HUS
 S
s]   BU<Q82A	T+;L=U<8 U7U<8	T(B"T##T((U<+	U44;U//U44U<<V)	r@   rA   rB   
reload_dirrE   r   rF   rG   rH   zA path to a Python file or package directory (with [blue]__init__.py[/blue] files) containing a [bold]FastAPI[/bold] app. If not provided, a default set of paths will be tried.zThe host to serve on. For local development in localhost use [blue]127.0.0.1[/blue]. To enable public access, e.g. in a container, use all the IP addresses available with [blue]0.0.0.0[/blue].zThe port to serve on. You would normally have a termination proxy on top (another program) handling HTTPS on port [blue]443[/blue] and HTTP on port [blue]80[/blue], transferring the communication to your app.PORT)r(   envvarzEnable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development.r   zRSet reload directories explicitly, instead of using the current working directory.zThe root path is used to tell your app that it is being served to the outside world with some [bold]path prefix[/bold] set up in some termination proxy or similar.zThe name of the variable that contains the [bold]FastAPI[/bold] app in the imported module or package. If not provided, it is detected automatically.z--entrypointz-ezNThe FastAPI app import string in the format 'some.importable_module:app_name'.zdEnable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info.ziComma separated list of IP Addresses to trust with proxy headers. The literal '*' means trust everything.c       	         X    t        | |||||||d||	t        j                  d             y)u  
    Run a [bold]FastAPI[/bold] app in [yellow]development[/yellow] mode. 🧪

    This is equivalent to [bold]fastapi run[/bold] but with [bold]reload[/bold] enabled and listening on the [blue]127.0.0.1[/blue] address.

    It automatically detects the Python module or package that needs to be imported based on the file or directory path passed.

    If no path is passed, it tries with:

    - [blue]main.py[/blue]
    - [blue]app.py[/blue]
    - [blue]api.py[/blue]
    - [blue]app/main.py[/blue]
    - [blue]app/app.py[/blue]
    - [blue]app/api.py[/blue]

    It also detects the directory that needs to be added to the [bold]PYTHONPATH[/bold] to make the app importable and adds it.

    It detects the [bold]FastAPI[/bold] app object to use. By default it looks in the module or package for an object named:

    - [blue]app[/blue]
    - [blue]api[/blue]

    Otherwise, it uses the first [bold]FastAPI[/bold] app found in the imported module or package.
    rM   FASTAPI_PUBLIC_URL)rJ   r@   rA   rB   rC   rE   r   rF   rK   rG   rH   rI   Nr   osgetenv)
rJ   r@   rA   rB   r   rE   r   rF   rG   rH   s
             r&   rM   rM   $  s;    x 	#/9912r2   z0.0.0.0)	r@   rA   rB   rD   rE   r   rF   rG   rH   zIUse multiple worker processes. Mutually exclusive with the --reload flag.c       	         X    t        | |||||||d||	t        j                  d             y)u  
    Run a [bold]FastAPI[/bold] app in [green]production[/green] mode. 🚀

    This is equivalent to [bold]fastapi dev[/bold] but with [bold]reload[/bold] disabled and listening on the [blue]0.0.0.0[/blue] address.

    It automatically detects the Python module or package that needs to be imported based on the file or directory path passed.

    If no path is passed, it tries with:

    - [blue]main.py[/blue]
    - [blue]app.py[/blue]
    - [blue]api.py[/blue]
    - [blue]app/main.py[/blue]
    - [blue]app/app.py[/blue]
    - [blue]app/api.py[/blue]

    It also detects the directory that needs to be added to the [bold]PYTHONPATH[/bold] to make the app importable and adds it.

    It detects the [bold]FastAPI[/bold] app object to use. By default it looks in the module or package for an object named:

    - [blue]app[/blue]
    - [blue]api[/blue]

    Otherwise, it uses the first [bold]FastAPI[/bold] app found in the imported module or package.
    rx   r   )rJ   r@   rA   rB   rD   rE   r   rF   rK   rG   rH   rI   Nr   )
rJ   r@   rA   rB   rD   rE   r   rF   rG   rH   s
             r&   rx   rx     s;    x 	#/9912r2   c                      t                y rU   r    r2   r&   mainr     s    Er2   rU   )r   N)<r.   r   pathlibr   typingr   r   r#   pydanticr   r   r   rich.syntaxr   	rich.treer	   fastapi_cli.configr
   fastapi_cli.discoverr   r   r   r   fastapi_cli.exceptionsr   r?   r   r   	utils.clir   r   Typerr   	getLogger__name__rn   r   dictrV   __annotations__rw   r"   fastapi_cloud_cli.clir!   	add_typerfastapi_new.clifastapi_new_cliboolr'   r*   Optionlistr>   intr   rK   ArgumentrM   rx   r   r   r2   r&   <module>r      s    	  !  $    ,  7  " ?ekk/BT8DT.U 
		8	$ <L1-&H T,>CD 
	 MM#$
	 MM/"
D T   	 ELL-DE#t:EU	
	# # 
# #,4: $ , c
 %)!&*!c

+c
 c
 	c

 c
 dd"c
 4Zc
 c
 c
 
tc
 d
c
 c
 tc
 d
c
 
c
L  	h 	 	 	 	 	 	 	 	 	Ah
t D	
	h  T	
	h  d	
	h*  W	
	+h6 T
Te	
	7hB  w	
	ChN 
d
 i	
	
OhZ d
a	
	[hj w	
	khv #d
|	
	whB 	Ch hV  	h 	 	 	 	 	 	 	 	 	Ah
t D	
	h  T	
	h  d	
	h*  W	
	+h6 d
\	
	7hB  w	
	ChN 
d
 i	
	
OhZ d
a	
	[hj w	
	khv #d
|	
	whB 	Ch hV
c  G  		  		s6    O %O! =O- OO!O*)O*-O65O6