o
    niI'                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d	d
lmZ eeZG dd dZdS )    N)copyfile)AnyDictListOptional)unquote)SettingsStatic)
filesystem)CONDA_ENVIRONMENTS_FNAME
DIFF_FNAMEMETADATA_FNAME)GitRepo   )	Interfacec                   @   s   e Zd ZdededdfddZdddZdd	d
Zdee	e
f dee	e
f fddZdee	e
f fddZdddZdeddfddZdS )
SystemInfosettings	interfacereturnNc                 C   sf   t d || _tj| jjt| _|| _	t
| jj| jj| jj| jjd| _d | _g | _t d d S )NzSystem info init)rootremote
remote_urlcommitzSystem info init done)loggerdebugr   ospathjoin	files_dirr   metadata_file_namebackend_interfacer   git_root
git_remotegit_remote_url
git_commitgitsaved_programsaved_patches)selfr   r    r(   c/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/sdk/internal/system/system_info.py__init__   s   
zSystemInfo.__init__c              	   C   s   t d | jjst d d S | jjpt }| jj}t	
tj| jjdtj| tj||}tj|sDt d| d S tj| jjd|}|| _tj|s\t|| t d d S )NzSaving codez.unable to save code -- program entry not foundcodez$unable to save code -- can't find {}zSaving code done)r   r   r   program_relpathwarningr$   r   r   getcwdr	   mkdir_exists_okr   r   r   dirnameexistsformatr%   r   )r'   r   program_relativeprogram_absoluter%   r(   r(   r)   
_save_code+   s,   


zSystemInfo._save_codec           
   
   C   s  | j jsdS td z| j j}ddg}| j jr|d | j jrYtj	
| jjt}t|d"}tj|dg ||dd	 | jtj	j|| jjd
 W d   n1 sTw   Y  | j  }|r|| j jjjkr|j}tj	
| jjd| d}t|d"}tj||g ||dd	 | jtj	j|| jjd
 W d   n1 sw   Y  W n ttjtjfy }	 ztd|	 W Y d}	~	nd}	~	ww td dS )a  Save the current state of this repository to one or more patches.

        Makes one patch against HEAD and another one against the most recent
        commit that occurs in an upstream branch. This way we can be robust
        to history editing as long as the user never does "push -f" to break
        history on an upstream branch.

        Writes the first patch to <files_dir>/<DIFF_FNAME> and the second to
        <files_dir>/upstream_diff_<commit_id>.patch.

        NzSaving git patchesr$   diffz--submodule=diffwbHEAD   )stdoutcwdtimeout)startupstream_diff_z.patchzError generating diff: {}zSaving git patches done)r$   enabledr   r   r   has_submodule_diffappenddirtyr   r   r   r   r   r   open
subprocess
check_callr&   relpathget_upstream_fork_pointrepoheadr   hexsha
ValueErrorCalledProcessErrorTimeoutExpirederrorr2   )
r'   r   	diff_args
patch_pathpatchupstream_commitshaupstream_patch_pathupstream_patcher(   r(   r)   _save_patchesE   sX   


	zSystemInfo._save_patchesdatac                 C   s   | j js| j jr
|S | jjs| jjr|S td | jj| jj	d|d< | jj
|d< | jjp6|dp6t |d< td |S )NzProbing git)r   r   r$   emailr   zProbing git done)r   disable_gitx_disable_machine_infor$   r?   autor   r   r   last_commitrY   r   getr   r.   )r'   rX   r(   r(   r)   
_probe_git   s   


zSystemInfo._probe_gitc                 C   s  t d t }| jj|d< | jj|d< tj  |d< | jj	r+tj
| jj	 nd|d< | jj|d< t| jjp;d|d	< d
|d< | jjdurU| jj|d< | jj|d< | jjs| jjs| jjrh| jj|d< n9| jjr| jjrw| jj|d< n*| jjr| jjdrt| jj}d| |d< | jj|d< n| jj|d< | jj|d< | |}| jjdkr| jj|d< | jj|d< tj|d< n| dd | dd t d |S )z?Probe the system for information about the current environment.zProbing systemr   pythonheartbeatAtN	startedAtdockerr(   argsrunningstateprogramcodePathLocalcodePathzfileId=z+https://colab.research.google.com/notebook#colabr   truehostusername
executablerY   zProbing system done)!r   r   dictr   _os_pythondatetimeutcnow	isoformatx_start_timeutcfromtimestamprc   tuple_argsrg   _code_path_localdisable_coder[   r,   _jupyternotebook_namex_jupyter_path
startswithr   x_jupyter_namex_jupyter_rootr_   	anonymousrl   rm   sysrn   pop)r'   rX   	unescapedr(   r(   r)   probe   sL   


zSystemInfo.probec              
   C   s   t jt jtjd}|sd S td z*tt j| j	j
td}tjg d|tjdd W d    n1 s9w   Y  W n tyY } ztd|  W Y d }~nd }~ww td d S )	Nz
conda-metazDSaving list of conda packages installed into the current environmentw)condaenvexport   )r:   stderrr<   zError saving conda packages: zSaving conda packages done)r   r   r1   r   r   prefixr   r   rC   r   r   r
   rD   callDEVNULL	Exception	exception)r'   current_shell_is_condafrV   r(   r(   r)   _save_conda   s0   	zSystemInfo._save_condasystem_infoc                 C   s   | j jr|   | j jr|   |   t| jd}tj	|dd}|
| |
d W d    n1 s6w   Y  tj| j}t|dfgd}| jratjd| j}|d t|df | jD ]}|d t|df qd| j| d S )	Nr      )indent
now)filesr+   r   )r   x_save_requirementsr   	save_coder5   rW   rC   r   jsondumpswriter   r   basenamero   r%   r   rA   globescaper&   r   publish_files)r'   r   r   s	base_namer   r%   rQ   r(   r(   r)   publish   s$   

zSystemInfo.publish)r   N)__name__
__module____qualname__r   r   r*   r5   rW   r   strr   r_   r   r   ro   r   r(   r(   r(   r)   r      s    

";
8r   ) rr   r   r   loggingr   rD   r   shutilr   typingr   r   r   r   urllib.parser   "wandb.sdk.internal.settings_staticr   wandb.sdk.libr	   wandb.sdk.lib.filenamesr
   r   r   wandb.sdk.lib.gitlibr   assets.interfacesr   	getLoggerr   r   r   r(   r(   r(   r)   <module>   s"   
