o
    h{1                     @  s  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
Z
ddlm  mZ ddlm  mZ ddlmZ ddlmZmZ ddlmZ erNddlmZ d	Zd
ZdcddZddddZe	dedef dZdeddZ dfddZ!e
j"dd id!e
j#d"d#e
$ed$e
j%d%d&dgd(d)Z&e&'d*d+d* Z(e&'d,d-d. Z)e&'d/d0d1 Z*e&'d2e d3d4 Z+e&'d5e e
j,d6d#d7d8e
j,d9d:d;dhdid<d=Z-djd?d@Z.		dkdldDdEZ/e&"dFdGdF Z0e0'dHdIdJ Z1e&"dKdLdK Ze'dMe dNdO Z2e&j"dPd#dQe
j3dRdP Z4e4'dSdTdU Z5e&j"dVd#dWdXdV Z6e6'dYdZd[ Z7e&'d\e
j,d]d^d_dhdmd`daZ8e9dbkrJe&  dS dS )nz=A script which is run when the Streamlit package is executed.    )annotationsN)TYPE_CHECKINGAnyCallableTypeVar)config)Credentialscheck_credentials)$create_default_cache_storage_manager)ConfigOption)pypy3)errorwarninginfodebugconfig_optionr   returndict[str, Any]c                 C  sb   d| j  }| j dd}| j}| jr%|du rd}|d| j d| j 7 }||| j|| j| jdS )	z>Composes given config option options as options for click lib.z--._N z
 z - )paramdescriptiontypeoptionenvvarmultiple)	keyreplacer   
deprecateddeprecation_textexpiration_dater   env_varr   )r   r   r   r    r$   E/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/web/cli.py&_convert_config_option_to_click_option*   s    r&   c                   s   d	 fdd}|S )
N_ctxclick.Context_paramclick.Parameterr   Nonec                   s$   |d u rd S t d jd j)NzSetting zn option using the CLI flag is not allowed. Set this option in the configuration file or environment variable: )
SystemExitr   r#   )r'   r)   	cli_valuer   r$   r%   callbackC   s   
z1_make_sensitive_option_callback.<locals>.callback)r'   r(   r)   r*   r   r+   r$   )r   r/   r$   r.   r%   _make_sensitive_option_callbackB   s   	r0   F.)boundfuncc                 C  s   t tj D ]8\}}t|}|jrdddt|d}nd|d d}tj|d |d f|d |d	 |d
 d|}|| } q| S )z;Decorator that adds config param keys to click dynamically.FT)expose_valuehiddenis_eagerr/   r   )show_envvarr   r   r   r   r   r   )helpr   r   )	reversed_config_config_options_templateitemsr&   	sensitiver0   clickr   )r3   r   valueparsed_parameterclick_option_kwargsr   r$   r$   r%   configurator_optionsR   s.   
rB   main_script_pathstrurl_pathr+   c                 C  s   ddl }t| d4}z||}|  ||j W n |jjy4 } zt	d| d| d}~ww W d   dS 1 s@w   Y  dS )z2Fetch remote file at url_path to main_script_path.r   NwbzUnable to fetch z.
)
requestsopengetraise_for_statuswritecontent
exceptionsRequestExceptionr>   BadParameter)rC   rE   rG   fpresper$   r$   r%   _download_remotep   s   
"rS   auto_envvar_prefix	STREAMLIT)context_settingsz--log_levelT)show_defaultr   	Streamlit	prog_namer   c                 C  s*   | rddl m} |t}|d dS dS )zTry out a demo with:

        $ streamlit hello

    Or use the line below to run your own script:

        $ streamlit run your_script.py
    r   )
get_loggerzSetting the log level using the --log_level flag is unsupported.
Use the --logger.level flag (after your streamlit command) instead.N)streamlit.loggerr[   __name__r   )	log_levelr[   LOGGERr$   r$   r%   main}   s   r`   r8   c                   C  s0   t   ttjdksJ dtjd< tdd dS )zPrint this help message.   z--help   	streamlitrY   N)_get_command_line_as_stringlensysargvr`   r$   r$   r$   r%   r8      s   
versionc                  C  s4   ddl } t  t| jdksJ d| jd< t  dS )z!Print Streamlit's version number.r   Nra   z	--versionrb   )rf   rd   re   rg   r`   )rf   r$   r$   r%   main_version   s
   

ri   docsc                  C  s$   t d ddlm}  | d dS )zShow help in browser.zShowing help page in browser...r   cli_utilzhttps://docs.streamlit.ioN)r>   echorc   rl   open_browserrk   r$   r$   r%   	main_docs   s   
ro   helloc                  K  s.   ddl m} tj| d |j}t|| d dS )zRuns the Hello World script.r   )streamlit_appflag_optionsN)streamlit.hellorq   	bootstrapload_config_options__file__	_main_run)kwargsrq   filenamer$   r$   r%   
main_hello   s   r{   runtargetSTREAMLIT_RUN_TARGET)requiredr   args)nargsc                 K  s,  ddl m} tj|d tj| \}}|dd tvr2|dd dkr)t	dt	d| d	|
| rdd
lm} | 5}ddlm} || j}	tj||	dddd }
|| } t|
|  t|
||d W d   dS 1 sxw   Y  dS tj| std|  t| ||d dS )zRun a Python script, piping stderr to Streamlit.

    The script can be local or it can be an url. In the latter case, Streamlit
    will download the script to a temporary file and runs this file.

    r   )url_utilrr   rb   Nr   zStreamlit requires raw Python (.py) files, but the provided file has no extension.
For more information, please see https://docs.streamlit.ioz/Streamlit requires raw Python (.py) files, not z<.
For more information, please see https://docs.streamlit.io)TemporaryDirectory)urlparse/r   zFile does not exist: )rc   r   ru   rv   ospathsplitextACCEPTED_FILE_EXTENSIONSr>   BadArgumentUsageis_urlstreamlit.temporary_directoryr   urllib.parser   joinstriprsplitprocess_gitblob_urlrS   rx   existsrO   )r}   r   ry   r   r   	extensionr   temp_dirr   r   rC   r$   r$   r%   main_run   s4   




"r   
str | Nonec                  C  sV   dd l } t j}|d u rd S d|jv rtd|jg}|tjdd   | 	|S )Nr   zstreamlit.cliz}Running streamlit via `python -m streamlit.cli <command>` is unsupported. Please use `python -m streamlit <command>` instead.rb   )

subprocessr>   get_current_contextparentcommand_pathRuntimeErrorextendrf   rg   list2cmdline)r   r   cmd_line_as_listr$   r$   r%   rd      s   


rd   list[str] | Noners   dict[str, Any] | Nonec                 C  s<   |d u rg }|d u ri }t  dk}t  t| ||| d S )Nzstreamlit hello)rd   r	   ru   r|   )filer   rs   is_hellor$   r$   r%   rx     s   
rx   cachec                   C     dS )zManage the Streamlit cache.Nr$   r$   r$   r$   r%   r        clearc                  C  s   t  } |   tj  dS )z1Clear st.cache_data and st.cache_resource caches.N)r
   	clear_allcachingcache_resourcer   )cache_storage_managerr$   r$   r%   cache_clear   s   	r   r   c                   C  r   )z#Manage Streamlit's config settings.Nr$   r$   r$   r$   r%   r   1  r   showc                  K  s   t j| d t  dS )z(Show all of Streamlit's config settings.rr   N)ru   rv   r:   show_config)ry   r$   r$   r%   config_show7  s   r   activate)invoke_without_commandc                 C  s   | j st   dS dS )z*Activate Streamlit by entering your email.N)invoked_subcommandr   get_currentr   )ctxr$   r$   r%   r   D  s   resetc                   C  s   t    dS )zReset Activation Credentials.N)r   r   r   r$   r$   r$   r%   activate_resetL  s   r   test)r5   c                   C  r   )zuInternal-only commands used for testing.

    These commands are not included in the output of `streamlit help`.
    Nr$   r$   r$   r$   r%   r   U  s   rZ   c                  C  s.   t   t j} | dusJ | jdksJ dS )zAssert that the program name is set to `streamlit test`.

    This is used by our cli-smoke-tests to verify that the program name is set
    to `streamlit ...` whether the streamlit binary is invoked directly or via
    `python -m streamlit ...`.
    Nzstreamlit test)rd   r>   r   r   r   )r   r$   r$   r%   test_prog_name^  s   

r   init	directoryF)r   c              
   C  s   ddl m} | r|| n| }z	|jddd W n ty- } ztd| d}~ww |d d |d	 d
 | rBt| nd}tj	ddd tj	| dd tj
ddd tj	d| ddd tjdddr}|d	 }t
d tt| dS dS )zInitialize a new Streamlit project.

    If DIRECTORY is specified, create it and initialize the project there.
    Otherwise use the current directory.
    r   )PathT)exist_okparentszFailed to create directory: Nzrequirements.txtz
streamlit
zstreamlit_app.pyu   import streamlit as st

st.title("🎈 My new app")
st.write(
    "Let's start building! For help and inspiration, head over to [docs.streamlit.io](https://docs.streamlit.io/)."
)
r   u!   ✨ Created new Streamlit app in F)nlblue)fgu   🚀 Run it with: zstreamlit run z/streamlit_app.pyu   ❓ Run the app now?)defaultz
Starting Streamlit...)pathlibr   cwdmkdirOSErrorr>   ClickException
write_textrD   sechorm   confirmrx   )r   r   project_dirrR   rel_path_strapp_pathr$   r$   r%   	main_initp  s(   
r   __main__)r   r   r   r   )r   r   )r3   r1   r   r1   )rC   rD   rE   rD   r   r+   )r   )N)r}   rD   )r   r   )NN)r   r   rs   r   r   r+   )r   r   ):__doc__
__future__r   r   rf   typingr   r   r   r   r>   streamlit.runtime.cachingruntimer   streamlit.web.bootstrapwebru   rc   r   r:   streamlit.runtime.credentialsr   r	   *streamlit.web.cache_storage_manager_configr
   streamlit.config_optionr   r   
LOG_LEVELSr&   r0   r1   rB   rS   groupr   Choiceversion_optionr`   commandr8   ri   ro   r{   argumentr   rd   rx   r   r   r   pass_contextr   r   r   r   r   r]   r$   r$   r$   r%   <module>   s   







	
*






(
