o
    *i:                     @   s  d dl Z d dlmZ d dlmZ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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dZe eZzd dl Z W n e!ys   dZ Y nw zd dl"mZ# e$e# W n	 e!y   Y nw zd dl%mZ& e$e& W n	 e!y   Y nw de'ddfddZ(e) dej*dddfdeee'df ej*dde(df de'ddfd d!Z)d"e+e defd#d$Z,	dQd%d&d'ddd(ddddd)
d*eedf d+e-d,e.d-e'd.ee+e df d/ee.df d0e-d1e-d2ee-df d3ee-df d4e'd5ee-df ddfd6d7Z/e0 	dQd%d&d'dd(ddd'dd8	d*eeedf ej1d9df d+ee-ej*d:df d,ee.ej*d;d<d=f d-ee'ej*d>df d?eee+e df ej*d@df d0ee-ej*dAdf d2eee-df ej*dBdf d3eee-df ej*dCdDdEdf d4ee'ej*dFdf d5eee-df ej*dGdf defdHdIZ2e0 	dQdJd&ddd(ddd'ddK	d*eeedf ej1d9df d+ee-ej*d:df d,ee.ej*d;d<d=f d-ee'ej*d>df d/eee.df ej*dLdf d0ee-ej*dAdf d2eee-df ej*dBdf d3eee-df ej*dCdDdEdf d4ee'ej*dFdf d5eee-df ej*dGdf defdMdNZ3dRdOdPZ4dS )S    N)Path)	AnnotatedAnyUnion)ValidationError)print)Tree)FastAPIConfig)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_settingsappvaluereturnc                 C   s    | rt dt d t d S )NzFastAPI CLI version: [green]z[/green])r   r   typerExit)r    r   L/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/fastapi_cli/cli.pyversion_callback3   s   r   FzEnable verbose output)helpversionz	--versionzShow the version and exit.)r   callbackverbosec                 C   s   |rt jnt j}t|d dS )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_levelr   r   r   r!   9   s   r!   module_pathsc                 C   s   | d }|  rd|j nd|j }t|}| r!|d |}| dd  D ] }|  r5d|j nd|j }||}| rI|d q)|S )Nr   u   🐍 u   📁 u   [dim]🐍 __init__.py[/dim]r   )is_filenamer   is_diradd)r(   rootr*   	root_treetreesub_pathsub_namer   r   r   _get_module_treeP   s    


r2   z	127.0.0.1i@  T )
hostportreloadreload_dirsworkers	root_pathr   
entrypointproxy_headersforwarded_allow_ipspathr4   r5   r6   r7   r8   r9   commandr   r:   r;   r<   c                C   s6  t  }|dkrdnd}|jd| ddd |  |d |	r:| s'|r:|  |d	 |  tjd
dztj|	d}W nD ty } z8|  |d |  |	 D ]}d
dd |d D }|d| d|d   q[|  tjd
dd d }~ww z| s|rt| |d}n|jrt|j}nt }W n ty } z|  |d|  tjd
dd d }~ww td|jj  td|jj  |j}|j}|d|j  |  |jrt|j}|j|dd |  |jddd |  |d|j d|j d |  |jd| d d!d d"| d#| }| d$}|  |jd%| d&| d d'| d&| d d(d |dkrY|  |jd)d*d tsatd+d |  |d, |  tj|||||r~d-d. |D nd |||
|t d/
 W d    d S 1 sw   Y  d S )0N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)r:   z/[error]Invalid configuration in pyproject.toml:.c                 s   s    | ]}t |V  qd S N)str).0locr   r   r   	<genexpr>   s    z_run.<locals>.<genexpr>rI   u     [red]•[/red] z: msg)r=   app_namez[error]zImporting from zImporting module modulezIImporting the FastAPI app object from the module with the following code:rD   z[underline]from [bold]z[/bold] import [bold]z[/bold]zUsing import string: [blue]z[/]r   zhttp://:z/docszServer started at [link=]zDocumentation at [link=serverzERunning in development mode, for production use: [bold]fastapi run[/]tipz;Could not import Uvicorn, try running 'pip install uvicorn'zLogs:c                 S   s   g | ]}t | qS r   )rG   resolve)rH   	directoryr   r   r   
<listcomp>   s    z_run.<locals>.<listcomp>)
r   r4   r5   r6   r7   r8   r9   r;   r<   
log_config)r   print_title
print_liner   r   r   r	   rR   r   errorsjoinr
   r:   r   r   loggerdebugmodule_dataextra_sys_pathmodule_import_strimport_stringr(   r2   rL   uvicornrunr   )r=   r4   r5   r6   r7   r8   r9   r>   r   r:   r;   r<   toolkitserver_typeconfigeerrorfieldimport_datar\   r_   r.   urlurl_docsr   r   r   _rune   s   






$rk   )	r4   r5   r6   
reload_dirr9   r   r:   r;   r<   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.rl   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       	   
      C   "   t | |||||||d||	d dS )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.
    r?   )r=   r4   r5   r6   r7   r9   r   r:   r>   r;   r<   Nrk   )
r=   r4   r5   r6   rl   r9   r   r:   r;   r<   r   r   r   r?         \
r?   z0.0.0.0)	r4   r5   r6   r8   r9   r   r:   r;   r<   zIUse multiple worker processes. Mutually exclusive with the --reload flag.c       	   
      C   ro   )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.
    ra   )r=   r4   r5   r6   r8   r9   r   r:   r>   r;   r<   Nrp   )
r=   r4   r5   r6   r8   r9   r   r:   r;   r<   r   r   r   ra   W  rq   ra   c                   C   s
   t   d S rF   r   r   r   r   r   main  s   
rr   rF   )r   N)5r$   pathlibr   typingr   r   r   r   pydanticr   r   r   	rich.treer   fastapi_cli.configr	   fastapi_cli.discoverr
   r   fastapi_cli.exceptionsr   r3   r   r   	utils.clir   r   Typerr   	getLogger__name__rZ   r`   ImportErrorfastapi_cloud_cli.clifastapi_cloud_cli	add_typerfastapi_new.clifastapi_new_cliboolr   r!   Optionlistr2   rG   intrk   r>   Argumentr?   ra   rr   r   r   r   r   <module>   sB   



	




 
!'
-
5;
Aj

!'
-
5;
Aj