U
    ¨º|eW  ã                   @   s’   d Z ddlm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„ Zdd	„ Zd
d„ Zddd„ZG dd„ deƒZG dd„ deƒZdS )zE
Helpers for logging.

This module needs much love to become useful.
é    )Úprint_functionNé   )Úmkdirpc                 C   s"   t j d¡rtd| d ƒS | S dS )z¢Remove .1s to the time under Windows: this is the time it take to
    stat files. This is needed to make results similar to timings under
    Unix, for tests
    Úwinr   gš™™™™™¹?N)ÚsysÚplatformÚ
startswithÚmax©Út© r   úJ/var/www/website-v5/atlas_env/lib/python3.8/site-packages/joblib/logger.pyÚ_squeeze_time   s    r   c                 C   s   t | ƒ} d| | d f S )Nz%.1fs, %.1fminç      N@©r   r
   r   r   r   Úformat_time"   s    r   c                 C   s(   t | ƒ} | dkrd| d  S d|  S d S )Né<   z%4.1fminr   z %5.1fsr   r
   r   r   r   Úshort_format_time'   s    r   é   c                 C   sT   dt jkr,dd l}| ¡ }|jdddd� nd }tj| ||d�}|rP|jf |Ž |S )NÚnumpyr   é   é@   r   )Ú	precisionÚ	thresholdÚ	edgeitems)ÚdepthÚindent)r   Úmodulesr   Úget_printoptionsÚset_printoptionsÚpprintÚpformat)Úobjr   r   ÚnpZprint_optionsÚoutr   r   r   r!   /   s    
r!   c                   @   s<   e Zd ZdZddd„Zdd„ Zdd	„ Zd
d„ Zddd„ZdS )ÚLoggerz& Base class for logging messages.
    r   Nc                 C   s   || _ |r|nd| _dS )zì
            Parameters
            ----------
            depth: int, optional
                The depth of objects printed.
            name: str, optional
                The namespace to log to. If None, defaults to joblib.
        ÚjoblibN)r   Ú_name)Úselfr   Únamer   r   r   Ú__init__C   s    	zLogger.__init__c                 C   s   t  | j¡ d| |f ¡ d S ©Nz[%s]: %s)ÚloggingÚ	getLoggerr'   Úwarning©r(   Úmsgr   r   r   ÚwarnO   s    zLogger.warnc                 C   s   t  d| |f ¡ d S r+   )r,   Úinfor/   r   r   r   r2   R   s    zLogger.infoc                 C   s   t  | j¡ d| |f ¡ d S r+   )r,   r-   r'   Údebugr/   r   r   r   r3   U   s    zLogger.debugr   c                 C   s   t ||| jd�S )z2Return the formatted representation of the object.)r   r   )r!   r   )r(   r"   r   r   r   r   ÚformatY   s    zLogger.format)r   N)r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   r1   r2   r3   r4   r   r   r   r   r%   ?   s   
r%   c                   @   s$   e Zd ZdZd	dd„Zd
dd„ZdS )Ú	PrintTimez9 Print and log messages while keeping track of time.
    Nc              	   C   s  |d k	r|d k	rt dƒ‚t ¡ | _| j| _|d k	r@tj |d¡}|| _|d k	�rttj 	|¡ƒ tj 
|¡rÐtddƒD ]6}z$t |d|  |d|d   ¡ W qv   Y qvX qvzt ||d ¡ W n   Y nX z:t|dƒ�&}| d¡ | d	t | j¡ ¡ W 5 Q R X W n   Y nX d S )
Nz&Cannot specify both logfile and logdirz
joblib.logr   é	   z.%iz.1Úwz
Logging joblib python script
z

---%s---
)Ú
ValueErrorÚtimeÚ	last_timeÚ
start_timeÚosÚpathÚjoinÚlogfiler   ÚdirnameÚexistsÚrangeÚshutilÚmoveÚcopyÚopenÚwriteÚctime)r(   rC   ZlogdirÚir   r   r   r*   e   s6    

ÿ
$zPrintTime.__init__Ú Fc              	   C   s    |s$t   ¡ | j }d|t|ƒf }n t   ¡ | j }d|||d f }t|tjd� | jdk	r’z(t| jdƒ�}t||d� W 5 Q R X W n   Y nX t   ¡ | _dS )zr Print the time elapsed between the last call and the current
            call, with an optional message.
        z%s: %sz%s: %.2fs, %.1f minr   )ÚfileNÚa)	r=   r>   r   r?   Úprintr   ÚstderrrC   rJ   )r(   r0   ÚtotalZ
time_lapseZfull_msgÚfr   r   r   Ú__call__Š   s    ÿ
zPrintTime.__call__)NN)rN   F)r5   r6   r7   r8   r*   rU   r   r   r   r   r9   a   s   
%r9   )r   r   )r8   Ú
__future__r   r=   r   r@   rG   r,   r    Zdiskr   r   r   r   r!   Úobjectr%   r9   r   r   r   r   Ú<module>   s   

"