o
    "j~#                     @   s   d dl Z d dlZd dlZd dlZd dlmZ g ZdZdZdZ	e j
e j
dddd	Zd
d Zdd Zdd Zdd Zdd Zd%ddZdd Zdd Zdd Zd&dd Zd&d!d"Zd&d#d$ZdS )'    N)get_path_from_urlz~/.cachedependenciesz
hubconf.py~z.cacheZpaddleZhubc                 C   s8   t j| rt j| rt |  d S t|  d S d S )N)ospathexistsisfileremoveshutilrmtree)r    r   P/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddle/hapi/hub.py_remove_if_exists   s
   r   c                 C   sZ   t jd| zt| }t j|  W n ty$   t j| tdw t j| |S )Nr   zPPlease make sure config exists or repo error messages above fixed when importing)	sysr   insert
__import__modulespopImportErrorr	   RuntimeError)namerepo_dir
hub_moduler   r   r   _import_module&   s   r   c                 C   s:   |dkrd|  d| d| dS |dkrd | ||S d S )Ngithubzhttps://github.com//z	/archive/.zipgiteez1https://gitee.com/{}/{}/repository/archive/{}.zip)format)
repo_owner	repo_namebranchsourcer   r   r   _git_archive_link6   s   r#   c                 C   sD   |dkrdnd}d| v r|  d\}}n| }| d\}}|||fS )Nr   mainZmaster:r   )split)repor"   r!   Z	repo_infor   r    r   r   r   _parse_repo_infoA   s   
r(   c                 C   sD   zddl m} W n ty   ddlm} Y nw || jdd d S )Nr   )PathT)exist_ok)pathlibr)   r   Zpathlib2mkdir)dirnamer)   r   r   r   
_make_dirsK   s   r.   Tr   c                 C   s4  t }t| t| |\}}}|dd}tj|d|||g}	| o)tj|	}
|
r:|r8tj	
d|	 d |	S tj||d }t| t||||d}t||| dd}t|| t|}| d	 j}tj||}t| || W d    n1 sw   Y  t| t|	 t||	 |	S )
Nr   _zUsing cache found in 
r   r"   F)Zcheck_exist
decompressr   )HUB_DIRr.   r(   replacer   r   joinr   r   stderrwriter   r#   r   r
   movezipfileZipFileinfolistfilename
extractall)r'   force_reloadverboser"   Zhub_dirr   r    r!   Znormalized_brr   Z	use_cacheZcached_fileurlZfpathZcached_zipfileZextraced_repo_nameZextracted_repor   r   r   _get_cache_or_reloadS   s@   rA   c                 C   sB   t |ts	tdt| |d}|du st|std| d|S )zload entry from hubconfz5Invalid input: model should be a str of function nameNzCannot find callable z in hubconf)
isinstancestr
ValueErrorgetattrcallabler   )mr   funcr   r   r   _load_entry_from_hubconf   s   
rI   c                 C   s$   zt |  W dS  ty   Y dS w )NTF)r   r   )r   r   r   r   _check_module_exists   s   rJ   c                 C   sF   t | td }|d urdd |D }t|r!tdd|d S d S )Nc                 S   s   g | ]}t |s|qS r   )rJ   ).0pkgr   r   r   
<listcomp>   s
    z'_check_dependencies.<locals>.<listcomp>zMissing dependencies: {}z, )rE   VAR_DEPENDENCYlenr   r   r5   )rG   r   missing_depsr   r   r   _check_dependencies   s   rQ   Fc                    s^   |dvrt d| d|dv rt| |d|d} ttdd |   fd	d
t D }|S )a  
    List all entrypoints available in `github` hubconf.

    Args:
        repo_dir(str): Github or local path.

            - github path (str): A string with format "repo_owner/repo_name[:tag_name]" with an optional
              tag/branch. The default branch is `main` if not specified.
            - local path (str): Local repo path.

        source (str): `github` | `gitee` | `local`. Default is `github`.
        force_reload (bool, optional): Whether to discard the existing cache and force a fresh download. Default is `False`.

    Returns:
        entrypoints: A list of available entrypoint names.

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> paddle.hub.list('lyuwenyu/paddlehub_demo:main', source='github', force_reload=False)

    r   r   localUnknown source: "0". Allowed values: "github" | "gitee" | "local".r   r   Tr1   .r   c                    s(   g | ]}t t |r|d s|qS )r/   )rF   rE   
startswith)rK   fr   r   r   rM      s    zlist.<locals>.<listcomp>)rD   rA   r   MODULE_HUBCONFr&   dir)r   r"   r>   entrypointsr   rZ   r   list   s   

r^   c                 C   sT   |dvrt d| d|dv rt| |d|d} ttdd | }t||}|jS )	a  
    Show help information of model

    Args:
        repo_dir(str): Github or local path.

            - github path (str): A string with format "repo_owner/repo_name[:tag_name]" with an optional
              tag/branch. The default branch is `main` if not specified.
            - local path (str): Local repo path.

        model (str): Model name.
        source (str): `github` | `gitee` | `local`. Default is `github`.
        force_reload (bool, optional): Default is `False`.

    Returns:
        docs

    Examples:
        .. code-block:: python

            >>> import paddle

            >>> paddle.hub.help('lyuwenyu/paddlehub_demo:main', model='MM', source='github')

    rR   rT   rU   rV   Tr1   rW   r   )rD   rA   r   r[   r&   rI   __doc__)r   modelr"   r>   r   entryr   r   r   help   s   

rb   c                 K   sd   |dvrt d| d|dv rt| |d|d} ttdd | }t| t||}|d
i |S )a  
    Load model

    Args:
        repo_dir(str): Github or local path.

            - github path (str): A string with format "repo_owner/repo_name[:tag_name]" with an optional
              tag/branch. The default branch is `main` if not specified.
            - local path (str): Local repo path.

        model (str): Model name.
        source (str): `github` | `gitee` | `local`. Default is `github`.
        force_reload (bool, optional): Default is `False`.
        **kwargs: Parameters using for model.

    Returns:
        paddle model.

    Examples:
        .. code-block:: python

            >>> import paddle
            >>> paddle.hub.load('lyuwenyu/paddlehub_demo:main', model='MM', source='github')

    rR   rT   rU   rV   Tr1   rW   r   Nr   )rD   rA   r   r[   r&   rQ   rI   )r   r`   r"   r>   kwargsr   ra   r   r   r   load  s   

rd   )Tr   )r   F)r   r
   r   r9   Zpaddle.utils.downloadr   __all__ZDEFAULT_CACHE_DIRrN   r[   r   
expanduserr5   r3   r   r   r#   r(   r.   rA   rI   rJ   rQ   r^   rb   rd   r   r   r   r   <module>   s,   

7

.+