o
    i                     @   s  d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	 d dl
Z
d dlmZmZ ddlmZmZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ ededddedddddeddddddedddddedddddfdee deded ed!ef
d"d#Z	d5dd$ddd%dee deded eee  d!ed&e	eef fd'dZ d&eeef fd(d)Z!d$d*deded&eeef fd+d,Z"ded&ee fd-d.Z#ded&eeef fd/d0Z$		d6d1eeef d2ee d eee  d&efd3d4Z%dS )7    N)Path)AnyDictListOptionalUnion)MarkdownRendererPrinter   )aboututil)importlib_metadata   )ArgOptappstring_to_list)get_latest_versionget_model_filenameinfoz Optional loadable spaCy pipeline)helpFz
--markdownz-mdz#Generate Markdown for GitHub issuesz--silentz-sz-Sz"Don't print anything (just return)labelsz	--excludez-ez2Comma-separated keys to exclude from the print-outz--urlz-uzLPrint the URL to download the most recent compatible version of the pipelinemodelmarkdownsilentexcludeurlc                 C   s   t |}t| ||||d dS )aa  
    Print info about spaCy installation. If a pipeline is specified as an argument,
    print its meta information. Flag --markdown prints details in Markdown for easy
    copy-pasting to GitHub issues.

    Flag --url prints only the download URL of the most recent compatible
    version of the pipeline.

    DOCS: https://spacy.io/api/cli#info
    r   r   r   r   N)r   r   )r   r   r   r   r    r   B/home/ubuntu/.local/lib/python3.10/site-packages/spacy/cli/info.pyinfo_cli   s   
r    Tr   returnc                   s  t || d} sg  |r+| d ur#d|  d}t| }t|d  |S |jddd n| r:d|  d}t| |d	}nd
}t }dd | D }d|v rct|d trcd	dd |d  D |d< t
|| d}	|rt|srt|	 |	S |s fdd| D }
|j|
|d |S )Nno_printprettyzDownload info for pipeline ''download_urlz%--url option requires a pipeline namer   exitszInfo about pipeline 'r   zInfo about spaCyc                 S   s"   i | ]\}}|  d d|qS ) _)lowerreplace.0kvr   r   r   
<dictcomp>F   s   " zinfo.<locals>.<dictcomp>	Pipelinesz, c                 s   s$    | ]\}}| d | dV  qdS )z ()Nr   )r/   nr1   r   r   r   	<genexpr>H   s    
zinfo.<locals>.<genexpr>)titler   c                    s   i | ]\}}| vr||qS r   r   r.   r   r   r   r2   Q   s    )r7   )r	   info_model_urlprintfail
info_model
info_spacyitems
isinstancedictjoinget_markdowntable)r   r   r   r   r   msgr7   dataraw_datamarkdown_data
table_datar   r8   r   r   -   s:   

c                  C   sR   i } t  D ]}|dd}t || |< qtjtttj	j	t

 t
 | dS )z\Generate info about the current spaCy intallation.

    RETURNS (dict): The spaCy info.
    -r+   )zspaCy versionLocationPlatformzPython versionr3   )r   get_installed_modelsr-   get_package_versionr   __version__strr   __file__parentplatformpython_version)
all_modelspkg_namepackager   r   r   r=   V   s   r=   r)   c                C   s   t || d}t| rt| }nt| }|d }| s&|jd|dd t|}|	 |kr:t
|	 |d< nt
||d< t| }|rJ||d< dd	 | D S )
zGenerate info about a specific model.

    model (str): Model name of path.
    silent (bool): Don't print anything, just return.
    RETURNS (dict): The model meta.
    r"   z	meta.jsonzCan't find pipeline meta.jsonr   r'   sourcer&   c                 S   s   i | ]\}}|d vr||qS ))accuracyperformancespeedr   r.   r   r   r   r2      s    zinfo_model.<locals>.<dictcomp>)r	   r   
is_packageget_package_pathr   is_filer;   srsly	read_jsonresolverO   info_installed_model_urlr>   )r   r   rD   
model_path	meta_pathmetar&   r   r   r   r<   h   s"   

r<   c                 C   sN   zt | }|d}t|trt|}|d W S W dS  ty&   Y dS w )zGiven a pipeline name, get the download URL if available, otherwise
    return None.

    This is only available for pipelines installed as modules that have
    dist-info available.
    zdirect_url.jsonr   N)r   distribution	read_textr?   rO   jsonloads	Exception)r   disttextrE   r   r   r   ra      s   




ra   c                 C   s<   t | }t| |}tjd | }d}|j| |d}||dS )z=Return the download URL for the latest version of a pipeline./z>https://github.com/explosion/spacy-models/releases/tag/{m}-{v})mr1   )r&   release_url)r   r   r   __download_url__format)r   versionfilenamer&   release_tplrn   r   r   r   r9      s   

r9   rE   r7   c              	   C   s   t  }|r||d| g }|  D ]7\}}|r||v rqt|tr;zt| }W n ty7   d}Y nw |r;q|	|
| d d|  q||| d|j dS )a  Get data in GitHub-flavoured Markdown format for issues etc.

    data (Dict[str, Any]): Label/value pairs.
    title (str): Optional title, will be rendered as headline 2.
    exclude (List[str]): Names of keys to exclude.
    RETURNS (str): The Markdown string.
    r
   F:r*   
)r   addr7   r>   r?   rO   r   existsri   appendboldlistrk   )rE   r7   r   mdr>   keyvalueexisting_pathr   r   r   rB      s$   
"rB   )N)NN)&rg   rR   pathlibr   typingr   r   r   r   r   r^   wasabir   r	    r   r   compatr   _utilr   r   r   r   downloadr   r   commandrO   boolr    r@   r   r=   r<   ra   r9   rB   r   r   r   r   <module>   sz    



)$

