o
    ۷i                     @  s   d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	Z	d dl
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mZmZ eddddddddfd1ddZ	d2d3d/d0ZdS )4    )annotationsN)Path)	AnnotatedAny)ArgumentOption)custom_component_analytics)LivePanelDisplay   )css)extract_docstringsget_deepmake_markdown
make_space.TFpathHAnnotated[Path, Argument(help='The directory of the custom component.')]demo_dirBAnnotated[Path | None, Option(help='Path to the demo directory.')]	demo_name<Annotated[str | None, Option(help='Name of the demo file.')]readme_pathBAnnotated[Path | None, Option(help='Path to the README.md file.')]	space_urlKAnnotated[str | None, Option(help='URL of the Space to use for the demo.')]generate_spacebAnnotated[bool, Option(help='Create a documentation space for the custom compone.', is_flag=True)]generate_readme_Annotated[bool, Option(help='Create a README.md file for the custom component.', is_flag=True)]suppress_demo_checkPAnnotated[bool, Option(help='Suppress demo warnings and errors.', is_flag=True)]c                 C  sh  t ddddd t|  }|rt| ntd }	|r |nd}
|	|
 }|r.t| n|d }|s:|s:tdt m}|jdt|j dd	d
 |d| d |d  sctd| dt	|d dd}t
| }W d   n1 s}w   Y  t|ddg}t|tstdt||||||d||	|||d W d   dS 1 sw   Y  dS )z!Runs the documentation generator.docsNdemozapp.pyz	README.mdz-Must generate at least one of space or readmez7:page_facing_up: Generating documentation for [orange3][/]g?)	add_sleepz.:eyes: Reading project metadata from [orange3]z/pyproject.toml[/]
zpyproject.tomlz,Cannot find pyproject.toml file in [orange3]utf-8encodingprojectnamez Name not found in pyproject.tomlsimple)liver)   r   pyproject_tomlr   r   	type_mode
_demo_path	_demo_dir_readme_pathr   _component_dir)r   r   resolve
ValueErrorr	   updatestrr)   existsopentomlloadsreadr   
isinstancerun_command)r   r   r   r   r   r   r   r   r1   r/   
_demo_namer.   r0   r+   fdatar)    r@   Y/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/cli/commands/components/docs.py_docs   s`   


"rB   r+   r	   r)   r5   r,   dict[str, Any]boolr-   r.   r   r/   r0   
str | Noner1   r*   c                 C  s  t |dd}| }W d    n1 sw   Y  td| dj}|dkp)d}t|ddg}tt|dd	gp:d
}t|g d}|
rG|
nt|g d}|sZ|sZtd| dt	|}t
|\}}|r|sn| d t||||d u rx|nt|||d u r|nt||d u r|nt|||d	}t |d ddd}|| |s| d| d W d    n1 sw   Y  t |d ddd}|t W d    n1 sw   Y  |r5|s| d t||||||||}t|	 }t |	ddd0}td|}|d ur|d | d  | }|| |s%| d|	 d W d    n	1 s0w   Y  |rTt|	|}t|d |}| d| d| d |dkr`| d d S d S ) Nr%   r&   zhttps://pypi.org/pypi/z/json   Fr(   versiondescription )r(   urls
repository)r(   rJ   spacez>Cannot find version in pyproject.toml or on PyPI for [orange3]zQ[/].
If you have just published to PyPI, please wait a few minutes and try again.z%:computer: [blue]Generating space.[/])	r!   r)   rH   local_versionr"   rL   repopypi_existsr   zspace.pywz-:white_check_mark: Space created in [orange3]z/space.py[/]
zcss.cssz$:pencil: [blue]Generating README.[/]z,(?:^|[
])---[
]+([\S\s]*?)[
]+---([
]|$)z0:white_check_mark: README generated in [orange3]r#   z7:white_check_mark: Documentation generated in [orange3]z[/] and [orange3]z;[/]. Pass --no-generate-docs to disable auto documentation.r*   z
:orange_circle: [red]The docs were generated in simple mode. Updating python to a more recent version will result in richer documentation.[/])r7   r:   httpxgetstatus_coder   r5   r3   	importlibimport_moduler   r4   r   writer   r   r   	read_textresearchspanrelative_to)r+   r)   r,   r   r   r   r-   r.   r/   r0   r   r1   r*   r>   r"   rO   rM   rH   rN   rL   moduler!   sourcereadmereadme_content
yaml_regexshort_readme_pathshort_demo_pathr@   r@   rA   r<   k   s   










r<   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    )F)r+   r	   r)   r5   r,   rC   r   rD   r   rD   r   rD   r-   r5   r.   r   r/   r   r0   r   r   rE   r1   r   r*   rD   )
__future__r   rU   rY   pathlibr   typingr   r   rR   tomlkitr8   typerr   r   gradio.analyticsr   gradio.cli.commands.displayr	   _docs_assetsr   _docs_utilsr   r   r   r   rB   r<   r@   r@   r@   rA   <module>   s.    e