
    ujy                         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
edefdZ	 	 dd
edeeeef                  dee         fdZddedee         fdZdS )    N)DictOptionalUnion)urlparse)HubApiModelScopeConfig)	FILE_HASH)GitCommandWrapper)ModelFileSystemCache)compute_hash)
get_loggermodel_root_pathreturnc                    d }t           j                            t           j                            | d                    rat	                      }|                    |           }|                    d          r
|d d         }t          |          }|j        dd          }n#t          |           }|	                                }|S )N.git   )
ospathexistsjoinr
   get_repo_remote_urlendswithr   r   get_model_id)r   model_cachegit_cmd_wrappergit_urlu_parsemodel_ids         j/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/hub/check_model.pyget_model_id_from_cacher!      s    K	w~~bgll?F;;<< 	.+--!55oFFF## 	#crclG7##<#*?;;++--O    
user_agenttokenc                    	 t          |           }|                    dd          }dt          j        |          i}t	          d|          }|                                }dt          j        v r|ni |dd	i}	 |                    ||
          \  }}	t          |	          dk    r	|	d         }
nd}
n	#  d}
Y nxY w|
                    ||
d||          }d}t          j                            t          j                            | d                    st          |           }|D ]}|d         dk    r|@|                    |          r't                              d|d          d|
 d            dS t"          |v rot%          t          j                            | |d                             }||t"                   k    rt                              d|d          d|
 d            dS dS #  Y dS xY w)z`Check local model repo is latest.
    Check local model repo is same as hub latest version.
    ___.z
user-agent)r#      )timeoutr$   CI_TESTSnapshotTrue)r   use_cookiesr   masterT)r   revision	recursiveheadersr-   Nr   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)r!   replacer   get_user_agentr   get_cookiesr   environget_model_branches_and_tagslenget_model_filesr   r   r   r   loggerinfor	   r   )r   r#   r$   r   r1   _apicookiessnapshot_header_	revisionslatest_revisionmodel_filesr   
model_filelocal_file_hashs                  r    check_local_model_is_latestrH   !   s   @*?;;##E3// +zDDD
 b...""$$%."*%<%<'' C
C
 FC
	';;!w < 8 8LAy9~~!!"+A,"*	'&OOO**$# + 
 
 w~~bgll?FCCDD 	@.??K% 	 	J&!V++&%%j11 KKkj&8 k kap k k k   EE
**&2_j6HII'K 'KO&*Y*??? o*V*< o oet o o o    +	 	2s2   A9G4 <8B5 4G4 5B;9B>G4 9A6G4 1G4 4G9r   c                     | t           j                            |           rdS t                      }|                    |           	 |                    |            dS # t          $ r Y dS w xY w)NF)r   T)r   r   r   r   login	get_model	Exception)r   r$   r?   s      r    check_model_is_idrM   l   s{    27>>(33uxx

5	NNHN///4 	 	 	55	s   A   
A.-A.)NN)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!   rH   rM    r"   r    <module>rX      sj   
			 ( ( ( ( ( ( ( ( ( ( ! ! ! ! ! ! 7 7 7 7 7 7 7 7 . . . . . . 0 0 0 0 0 0 = = = = = = 3 3 3 3 3 3 . . . . . .	S s    $ .2H HHtSy)*H C=H H H HV
 
 
HSM 
 
 
 
 
 
r"   