o
    SDi,                     @   sX  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 d	d
lmZ d	dl mZ d	dlmZmZ ejddZe eZzd dlZW n eyf   dZ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#	d@d d!d"dd#ddd$d%eedf d&e$d'e%d(ed)ee%df d*e$d+e$d,ee$df d-eddfd.d/Z&e' 	d@d d!d"d#dd"d0d%eeedf ej(d1df d&ee$ej"d2df d'ee%ej"d3df d(eeej"d4df d*ee$ej"d5df d,eee$df ej"d6df d-eeej"d7df defd8d9Z)e' 	d@d:d!ddd#dd"d$d%eeedf ej(d1df d&ee$ej"d2df d'ee%ej"d3df d(eeej"d4df d)eee%df ej"d;df d*ee$ej"d5df d,eee$df ej"d6df d-eeej"d7df defd<d=Z*dAd>d?Z+dS )B    N)Path)AnyListUnion)print)Tree)	Annotated)get_import_data)FastAPICLIException   )__version__)setup_logging)get_rich_toolkitget_uvicorn_log_configrich)rich_markup_mode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   H/var/www/Datamplify/venv/lib/python3.10/site-packages/fastapi_cli/cli.pyversion_callback   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   "   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_tree9   s    


r,   z	127.0.0.1i@  T )hostportreloadworkers	root_pathappproxy_headerspathr.   r/   r0   r1   r2   commandr3   r4   c                C   s&  t  }	|dkrdnd}
|	jd|
 ddd |	  |	d zt| |d	}W n tyH } z|	  |	d
|  tjddd d }~ww t	d|j
j  t	d|j
j  |j
}|j}|	d|j  |	  t|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r|	  |	jdd d tstd!d |	  |	d" |	  tj|||||||t d# W d    d S 1 sw   Y  d S )$Ndevdevelopment
productionz	Starting u    server 🚀FastAPI)tagzYSearching for package file structure from directories with [blue]__init__.py[/blue] files)r5   app_namez[error]r   )codezImporting from zImporting module modulezIImporting the FastAPI app object from the module with the following code:r=   z[underline]from [bold]z[/bold] import [bold]z[/bold]zUsing import string: [blue]z[/]r3   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:)r3   r.   r/   r0   r1   r2   r4   
log_config)r   print_title
print_liner   r	   r
   r   r   loggerdebugmodule_dataextra_sys_pathmodule_import_strimport_stringr,   r"   r<   uvicornrunr   )r5   r.   r/   r0   r1   r2   r6   r3   r4   toolkitserver_typeimport_dataerH   rK   r(   urlurl_docsr   r   r   _runN   s   




$rT   )r.   r/   r0   r2   r3   r4   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.zEnable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development.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.zdEnable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to populate remote address info.c             
   C   s   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.
    r7   )r5   r.   r/   r0   r2   r3   r6   r4   NrT   )r5   r.   r/   r0   r2   r3   r4   r   r   r   r7      s   G
r7   z0.0.0.0zIUse multiple worker processes. Mutually exclusive with the --reload flag.c                C   s   t | ||||||d|d	 dS )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.
    rM   )	r5   r.   r/   r0   r1   r2   r3   r6   r4   NrU   )r5   r.   r/   r0   r1   r2   r3   r4   r   r   r   rM     s   M
rM   c                   C   s
   t   d S N)r3   r   r   r   r   main[  s   
rW   rV   )r   N),r   pathlibr   typingr   r   r   r   r   r   	rich.treer   typing_extensionsr   fastapi_cli.discoverr	   fastapi_cli.exceptionsr
   r-   r   r   	utils.clir   r   Typerr3   	getLogger__name__rF   rL   ImportErrorboolr   r   Optionr,   strintrT   r6   Argumentr7   rM   rW   r   r   r   r   <module>   s   




	

`
 
&,R

 &
,2Y