o
    xi                     @  s   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 dZ
dZd	Zed
ZG dd deZdddZeG dd dZdS )zVSupport for parsing GitHub URLs (which might be user provided) into constituent parts.    )annotationsN)	dataclass)IntEnum)LaunchErrorzhttps://zgit@z.gitz[0-9a-f]{40}c                   @  s   e Zd ZdZdZdS )ReferenceType      N)__name__
__module____qualname__BRANCHCOMMIT r   r   R/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/launch/git_reference.pyr      s    r   netlocstrreturn"tuple[str | None, str | None, str]c                 C  sf   |  dd}t|dkrdd|d fS |\}}| dd}t|dkr*|d d|fS |d |d |fS )zParse netloc into username, password, and host.

    github.com => None, None, "@github.com"
    username@github.com => "username", None, "github.com"
    username:password@github.com => "username", "password", "github.com"
    @r   Nr   :)splitlen)r   partsauthhostr   r   r   _parse_netloc   s   r   c                   @  s0   e Zd Zdddd	Zedd
dZdddZdS )GitReferenceNremoter   ref
str | Noner   Nonec                 C  s   || _ || _dS )zInitialize a reference from a remote and ref.

        Arguments:
            remote: A remote URL or URI.
            ref: A branch, tag, or commit hash.
        N)urir   )selfr   r   r   r   r   __init__+   s   
zGitReference.__init__c                 C  s   | j S N)r!   )r"   r   r   r   url5   s   zGitReference.urldst_dirc           
   
   C  s`  ddl }|j|}|j| _|d| jpd}z|  W n |jj	y6 } zt
d| j d| d}~ww | jr[| j|jv rG|j| j }n| j}|| j|}|  |jj| _nLd}|jD ]$}t|drhq`|j}	|	drv|	d	d }	|	d
kr~d
} n|	dkrd}q`|st
d| j || _|| _|||j| }|  |jj| _|jddd dS )zHFetch the repo into dst_dir and refine githubref based on what we learn.r   Norigin z+Unable to fetch from git remote repository z:
tagzorigin/   mainmasterz6Unable to determine branch or commit to checkout from T)init	recursive)gitRepor-   working_dirpathcreate_remoter!   fetchexcGitCommandErrorr   r%   r   refscreate_headcheckoutcommithexshacommit_hash
referenceshasattrname
startswithdefault_branchsubmodule_update)
r"   r&   r/   repor'   er   headrA   refnamer   r   r   r4   9   sT   




zGitReference.fetchr$   )r   r   r   r   r   r    )r   r   )r&   r   r   r    )r	   r
   r   r#   propertyr%   r4   r   r   r   r   r   )   s
    
r   )r   r   r   r   )__doc__
__future__r   redataclassesr   enumr   wandb.sdk.launch.errorsr   PREFIX_HTTPS
PREFIX_SSH
SUFFIX_GITcompileGIT_COMMIT_REGEXr   r   r   r   r   r   r   <module>   s    

