o
    ߥib                     @   s   d dl Z d dlmZmZmZ d dlm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 d d	lmZ e Z	dd
edeeeef  fddZddefddZdS )    N)DictOptionalUnion)urlparse)HubApiModelScopeConfig)	FILE_HASH)GitCommandWrapper)ModelFileSystemCache)compute_hash)
get_loggermodel_root_path
user_agentc                 C   s  zd}t jt j| dr-t }|| }|dr!|dd }t|}|jdd }nt| }|	 }dt
j|di}t
 }dt jv rH|ni |dd	i}	td
d}
z|
j||d\}}t|dkrj|d }nd}W n   d}Y |
j||d|	|d}|D ]M}|d dkrq|dur||rqtd|d  d| d  W dS t|v rtt j| |d }||t krqtd|d  d| d  W dS qW dS    Y dS )z`Check local model repo is latest.
    Check local model repo is same as hub latest version.
    Nz.git   z
user-agent)r   CI_TESTSnapshotTrueg      ?)timeout)model_iduse_cookiesr   masterT)r   revision	recursiveheadersr   TypetreezModel file Namez' is different from the latest version `zQ`,This is because you are using an older version or the file is updated manually.Path)ospathexistsjoinr	   get_repo_remote_urlendswithr   r
   get_model_idr   get_user_agentget_cookiesenvironr   get_model_branches_and_tagslenget_model_filesloggerinfor   r   )r   r   model_cachegit_cmd_wrappergit_urlu_parser   r   cookiessnapshot_header_api_	revisionslatest_revisionmodel_files
model_filelocal_file_hash r;   N/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/hub/check_model.pycheck_local_model_is_latest   s~   






r=   r   c                 C   sl   |d u r
t jd}| d u st j| rdS t }|d ur"|| z	|j| d W dS  ty5   Y dS w )NMODELSCOPE_API_TOKENF)r   T)	r   r(   getr    r!   r   login	get_model	Exception)r   tokenr4   r;   r;   r<   check_model_is_idb   s   
rD   )N)r   typingr   r   r   urllib.parser   modelscope.hub.apir   r   modelscope.hub.constantsr   modelscope.hub.gitr	   modelscope.hub.utils.cachingr
   modelscope.hub.utils.utilsr   modelscope.utils.loggerr   r,   strr=   rD   r;   r;   r;   r<   <module>   s"   
Q