o
    5tio                     @   sl   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 d dlmZ ddl	m
Z
 dd Zd	d
 Zdd ZdS )    N)datetime)Path)FileLock   )__version__c              	   K   s   t  }t| |}| |d< t |d< t|d< tj|d< tj|d< t	t
|d # t|d}t|| W d   n1 sAw   Y  W d   n1 sPw   Y  ztt
|d  W |S  tyk   Y |S w )	aC  
    Saves results to a JSON file. Also saves system information such as current time, current commit
    hash if inside a repository, and Python system information.

    Args:
        path_or_file (`str`):
            Path or file to store the file. If only a folder is provided
            the results file will be saved in the format `"result-%Y_%m_%d-%H_%M_%S.json"`.

    Example:
        ```py
        >>> import evaluate
        >>> result = {"bleu": 0.7}
        >>> params = {"model": "gpt-2"}
        >>> evaluate.save("./results/", **result, **params)
        ```
    
_timestamp_git_commit_hash_evaluate_version_python_version_interpreter_pathz.lockwN)r   now_setup_path	isoformatr   r   sysversion
executabler   stropenjsondumposremoveFileNotFoundError)path_or_filedatacurrent_time	file_pathf r   C/home/ubuntu/.local/lib/python3.10/site-packages/evaluate/saving.pysave   s(   



r!   c                 C   sT   t | } t| jdk}|r| j}| j}n| }d|d d }|jddd || S )Nr   zresult-z%Y_%m_%d-%H_%M_%Sz.jsonT)parentsexist_ok)r   lensuffixparentnamestrftimemkdir)r   r   is_filefolder	file_namer   r   r    r   6   s   r   c                  C   sT   t jd dt jd} | j  dkr(t jd t t jd} | j  S d S )Nz#git rev-parse --is-inside-work-treez./)cwdstdouttruezgit rev-parse HEAD)	
subprocessrunsplitPIPEr.   decodestripr   getcwd)resr   r   r    r   C   s
   r   )r   r   r0   r   r   pathlibr   datasets.utils.filelockr    r   r!   r   r   r   r   r   r    <module>   s    )