
    AF[i-                    ^   d dl mZ d dlZd dlZd dlZd dlmZ d dl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 d dlmZ d dlmZmZ d dlmZ g dZdZ d Z!ddZ"	 	 	 	 ddZ#ddZ$ ed      dz  ddddd ed      ddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ%ddZ&y)     )annotationsN)Path)	Annotated)HfApi)Version)print)Console)Panel)ConfirmPrompt)parse)ArgumentOption)custom_component_analytics)redyellowgreenblueindigopurplepinkgrayz"https://pypi.org/account/register/c                    g }|D ]:  }d|v s#|j                  d      s|j                  d      s*|j                  |       < |S )N__pycache__distnode_modules)
startswithappend)_srcnamesignoredns       o/var/www/html/chatbot/moweb-chatbot/venv/lib/python3.12/site-packages/gradio/cli/commands/components/publish.py_ignorer$      sG    G Af!5n9UNN1 N    c                j    t        j                  d| j                        }|r|j                  d      S y )Nz-(\d+\.\d+\.\d+[a-zA-Z]*\d*)-   )researchnamegroup)	dist_filematchs     r#   _get_version_from_filer.   "   s+    II6	GE{{1~r%   c                    	 t        j                  |       S # t        $ r 	 t        |       cY S # t        $ r Y Y yw xY ww xY w)zCParse a version string, trying semantic_version first, then PEP440.N)semantic_versionr   
ValueErrorPEP440Version	Exception)version_strings    r#   _parse_versionr5   )   sI    ''77 	 00 		s     	?
.?	;?;?c                    g }| D ]0  }t        |      }|st        |      }|r|j                  |       0 y  |rt        t	        |            S d S )N)r.   r5   r   strmax)distribution_filesversionspversionparseds        r#   _get_max_versionr>   6   sY    H 	(+ #G,F'	 "*3s8}3t3r%   .r   T Fc           	     ~   t        dd |||	       t               }| j                         } | j                         st	        |  d      | j                         st	        |  d      t        |       j                  d      D cg c]!  }|j                  dv s|j                         # }}d>d}t        d |D        |	      }|st	        d
      d }|r|r|st        dt         d      }t        |       t        j                  d      }|rQt        j                         dz  j                         r,t        d       t!        t        j                         dz        }n9|r7t        d       t#        j                  d      }t#        j                  dd      }|r	 ddlm} ddlm} ddlm} |r|r |||      }n|r
 ||      }nt	        d      	 t5        |      }|D cg c]  }|r||j6                  v rt!        |       }}t        ddj9                  |              	  |||       	 |r|st        d       }t        |       t        j                  d!      }|rnt        d"      }t        |       t#        j                  d#t        d$      d%z         }|xs t!        t        d$      d%z        }t        |      j                         }|rd|	sbt        d&      }t        |       t        j                  d'      }	|	r5t#        j                  d(|       xs |}t        |      j                         }|r|d)z  }	 t?        |jA                               }|d*   d+   }|st	        d.      |j6                  jC                  d,      d d- \  }}tE        jF                         5 }tI        jJ                  t!        |      t!        |      d/       tI        jL                  t!        |d0z        t!        t        |      d0z               |	r;tI        jJ                  t!        |      t!        t        |      d1z        dtN        2       tI        jL                  t!        |d3z        t!        t        |      d3z               tQ        |4      } | jS                  |
xs |d5dd67      }!|!jT                  }
| jW                  |
|d58       |r(| jY                  |
t!        |      |j6                  d59       t        d:       | j[                  |
d|;       t        d<|
 d=       d d d        y y c c}w # t0        t2        f$ r}t	        d      |d }~ww xY wc c}w # |$ r}t	        d      |d }~ww xY w# t:        $ r |j=                          Y Pw xY w# t:        $ r% |j6                  jC                  d,      d d- \  }}Y Rw xY w# 1 sw Y   y xY w)?Npublish)upload_demoupload_pypiupload_sourcezQ does not exist. Run `gradio cc build` to create a wheel and source distribution.z is not a directory*>   .gz.whlc                    t        | j                        j                  d      d   }t        |      }|t	        d| d| j                         |S )N-r'   zCould not parse version z from )r7   r*   splitr5   r1   )pathversion_strr=   s      r#   _get_wheel_versionz$_publish.<locals>._get_wheel_version   sP    $))n**3/2,>7}F499+VWWr%   c              3  @   K   | ]  }|j                   d k(  s|  yw)rH   N)suffix).0r;   s     r#   	<genexpr>z_publish.<locals>.<genexpr>   s     =q!((f*<=s   )keyzgA wheel file was not found in the distribution directory. Run `gradio cc build` to create a wheel file.zIt is recommended to upload your component to pypi so that [bold][magenta]anyone[/][/] can install it with [bold][magenta]pip install[/][/].

A PyPi account is needed. If you do not have an account, register account here: [blue]z[/]z:snake: Upload to pypi?z.pypircz<:closed_lock_with_key: Found .pypirc file in home directory.zx:light_bulb: If you have Two Factor Authentication enabled, the username is __token__ and your password is your API key.z*:laptop_computer: Enter your pypi usernamez/:closed_lock_with_key: Enter your pypi passwordT)passwordr   )upload)InvalidDistribution)Settingsz^The twine library must be installed to publish to pypi.Install it with pip, pip install twine.)usernamerT   )config_filezBNo pypi username or password provided and no ~/.pypirc file found.zUploading files: ,zqInvalid distribution when uploading to pypi. Try upgrading 'pkginfo' with python -m pip install pkginfo --upgradezIt is recommended you upload a demo of your component to [blue]https://huggingface.co/spaces[/] so that anyone can try it from their browser.z:hugging_face: Upload demo?aX  Please provide the path to the [magenta]demo directory[/] for your custom component.

This directory should contain [magenta]all the files[/] it needs to run successfully.

Please make sure the gradio app is in an [magenta]space.py[/] file.

If you need additional python requirements, add a [magenta]requirements.txt[/] file to this directory.zR:roller_coaster: Please enter the path to the demo directory. Leave blank to use: r?   demozwIt is recommended that you share your [magenta]source code[/] so that others can learn from and improve your component.z1:books: Would you like to share your source code?zQ:file_folder: Please enter the path to the source directory. Leave blank to use: zpyproject.tomlprojectr*   rJ      zdemo_dir must be set)dirs_exist_okz
.gitignoresrc)r^   ignorez	README.md)tokenspacegradio)repo_id	repo_typeexist_ok	space_sdk)rd   folder_pathre   )rd   path_or_fileobjpath_in_repore   
)rd   factory_rebootra   z/Demo uploaded to https://huggingface.co/spaces/z !)rL   r   ).r   r	   resolveexistsr1   is_dirr   globrP   r8   r
   PYPI_REGISTER_URLr   r   askhomer7   r   twine.commands.uploadrU   twine.exceptionsrV   twine.settingsrW   ImportErrorModuleNotFoundErrorr>   r*   joinr3   print_exceptionr   	read_textrK   tempfileTemporaryDirectoryshutilcopytreecopyfiler$   r   create_repord   upload_folderupload_filerestart_space)"dist_dirrD   pypi_usernamepypi_passwordrC   demo_dir
source_dirra   prefer_localrE   rd   consoler;   r9   rN   
wheel_filerY   paneltwine_uploadrV   rW   etwine_settingsmax_versiontwine_files	demo_dir_source_dir_pyproject_toml_pathpyproject_tomlpackage_name_tempdirapirepo_urls"                                     r#   _publishr   E   s   R # iG!H??jij
 	
 ??H:%89::!(^005_9T		  =&=J <
 	
 KMeevdwwz|

 	ekk";<DIIK)3;;=PQdiikI56K K #JJ'STM"JJADM 	D</ ]%}}UN%+>NT 	&*+=>K ,#{aff'< AK 
 %chh{&;%<=>^[9 8<
 	ekk"?@yE %L

dfjknforxfxdz{I "<ScV);%<II..0H= F
 	e$WX

ghrgst  	  k*224J(+;;	?"#6#@#@#BCN))4V<L 344$////4Ra8a((* -	QgOOHG"
 OOJ-.DML01 
OW-."&"	 OOJ,-s4=;3N/O e$C/<!"	 ' H &&G#!  
 #$'
O!+%	    $Kgd%PCG9BOP[-	Q -	Q aZ 01 	: 	  '  [ 
  	&##%	&X  	? * 5 5c :2A >\1	?-	Q -	Qs   TTT! U" ""UU" $	U	 <!V E3V3!U0T<<UU" 	UUUU" "U?>U?*V0/V03V<c                    | j                         }|dz  j                         r|dz  S |dz  j                         r|dz  S t        d|  d      )Nzspace.pyzapp.pyz*Could not find "space.py" or "app.py" in "z".)rm   rn   FileNotFoundError)r   	_demo_dirs     r#   resolve_demor   +  sa      "IJ&&(:%%
h
	&	&	(8##8
"E
 	
r%   )r,   r   return
str | None)r4   r7   r   z/semantic_version.Version | PEP440Version | None)r9   z
list[Path]r   r   )r   z_Annotated[Path, Argument(help=f"Path to the wheel directory. Default is {Path('.') / 'dist'}")]rD   z:Annotated[bool, Option(help='Whether to upload to PyPI.')]r   z5Annotated[str, Option(help='The username for PyPI.')]r   z5Annotated[str, Option(help='The password for PyPI.')]rC   zFAnnotated[bool, Option(help='Whether to upload demo to HuggingFace.')]r   zBAnnotated[Path | None, Option(help='Path to the demo directory.')]r   zUAnnotated[Path, Option(help='Path to the source directory of the custom component.')]ra   zAnnotated[str | None, Option(help='HuggingFace token for uploading demo. Can be omitted if already logged in via huggingface cli.')]r   zvAnnotated[bool, Option(help='Install the package from the local wheel in the demo space, even if it exists on PyPi.')]rE   zwAnnotated[bool, Option(help='Whether to upload the source code of the custom component, to share with the community.')]rd   zAnnotated[str | None, Option(help='The repository id to upload the demo to. If not provided, a space will be created with the same name as the package in the HuggingFace account corresponding to the token.')])r   r   r   r   )'
__future__r   r(   r~   r|   pathlibr   typingr   r0   huggingface_hubr   packaging.versionr   r2   richr   rich.consoler	   
rich.panelr
   rich.promptr   r   tomlkitr   typerr   r   gradio.analyticsr   colorsrq   r$   r.   r5   r>   r   r    r%   r#   <module>r      s8   " 	      ! 6     '  " 7	O8 

4
4& 	S	FNRKMKM 	SW 	S	 	 	 	 	OcQcQ
 LcQ IcQ IcQcQ QcQcQ !cQ,-cQ89cQDEcQL	
r%   