o
    Þ­j¨9  ã                   @   sZ  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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 yq   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&dB 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dB d+e,d,e-d-e&d.e*e dB d/e-dB d0e,d1e,d2e,dB d3e,dB d4e&d5e,dB ddfd6d7„Z.e /¡ 	dQd%d&d'dd(ddd'dd8œ	d*eedB ej0d9d�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B ej)d@d�f d0ee,ej)dAd�f d2ee,dB ej)dBd�f d3ee,dB ej)dCdDdEd�f d4ee&ej)dFd�f d5ee,dB ej)dGd�f defdHdI„ƒZ1e /¡ 	dQdJd&ddd(ddd'ddKœ	d*eedB ej0d9d�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-dB ej)dLd�f d0ee,ej)dAd�f d2ee,dB ej)dBd�f d3ee,dB ej)dCdDdEd�f d4ee&ej)dFd�f d5ee,dB ej)dGd�f defdMdN„ƒZ2dRdOdP„Z3dS )Sé    N)ÚPath)Ú	AnnotatedÚAny)Ú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/var/www/html/CropPilot/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    
ÿ

€r1   z	127.0.0.1i@  TÚ )
ÚhostÚportÚreloadÚreload_dirsÚworkersÚ	root_pathr   Ú
entrypointÚproxy_headersÚforwarded_allow_ipsÚpathr3   r4   r5   r6   r7   r8   Úcommandr   r9   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Œ|r“t| |d�}n|jrœt|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rú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�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 �s”w   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)r9   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>rH   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:rC   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   )rF   Úresolve)rG   Ú	directoryr   r   r   Ú
<listcomp>à   s    z_run.<locals>.<listcomp>)
r   r3   r4   r5   r6   r7   r8   r:   r;   Ú
log_config)r   Úprint_titleÚ
print_liner   r   r   r   rQ   r   ÚerrorsÚjoinr	   r9   r
   r   ÚloggerÚdebugÚmodule_dataÚextra_sys_pathÚmodule_import_strÚimport_stringr'   r1   rK   ÚuvicornÚrunr   )r<   r3   r4   r5   r6   r7   r8   r=   r   r9   r:   r;   ÚtoolkitÚserver_typeÚconfigÚeÚerrorÚfieldÚimport_datar[   r^   r-   ÚurlÚurl_docsr   r   r   Ú_rune   sÊ   
ÿÿ
€õ€€ý
þÿ
þ
ý
þÿþ
ÿò$šrj   )	r3   r4   r5   Ú
reload_dirr8   r   r9   r:   r;   z°A 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.zÀThe 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].zÐThe 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   ÚenvvarzƒEnable auto-reload of the server when (code) files change. This is [bold]resource intensive[/bold], use it only during development.rk   zRSet reload directories explicitly, instead of using the current working directory.z£The 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.z•The 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<   r3   r4   r5   r6   r8   r   r9   r=   r:   r;   N©rj   )
r<   r3   r4   r5   rk   r8   r   r9   r:   r;   r   r   r   r>   ì   ó   \
õr>   z0.0.0.0)	r3   r4   r5   r7   r8   r   r9   r:   r;   zIUse multiple worker processes. Mutually exclusive with the --reload flag.c       	   
      C   rn   )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.
    r`   )r<   r3   r4   r5   r7   r8   r   r9   r=   r:   r;   Nro   )
r<   r3   r4   r5   r7   r8   r   r9   r:   r;   r   r   r   r`   W  rp   r`   c                   C   s
   t ƒ  d S rE   r   r   r   r   r   ÚmainÂ  s   
rq   rE   )r   N)4r#   Úpathlibr   Útypingr   r   r   Úpydanticr   r   r   Ú	rich.treer   Úfastapi_cli.configr   Úfastapi_cli.discoverr	   r
   Úfastapi_cli.exceptionsr   r2   r   r   Ú	utils.clir   r   ÚTyperr   Ú	getLoggerÚ__name__rY   r_   ÚImportErrorÚfastapi_cloud_cli.cliÚfastapi_cloud_cliÚ	add_typerÚfastapi_new.cliÚfastapi_new_cliÚboolr   r    ÚOptionÚlistr1   rF   Úintrj   r=   ÚArgumentr>   r`   rq   r   r   r   r   Ú<module>   sB   ÿ
ÿÿÿùÿÿÿÿùøÿóÿýüû
úùø	÷
öõôó
ò úÀÿÿÿÿÿÿÿøþÿÿòÿÿÿë
ÿÿÿå!ÿÿÿß'ÿÿÿÙ-ýÿÿÓ5ÿÿÿË;ÿÿÿÅA¿júÀÿÿÿÿÿÿÿøþÿÿòÿÿÿëÿÿÿå!ÿÿÿß'ÿÿÿÙ-ýÿÿÓ5ÿÿÿË;ÿÿÿÅA¿j