o
    ³ôjÂ  ã                   @   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 )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š™™™™™¹?)ÚsysÚplatformÚ
startswithÚmax©Út© r   ú`/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/joblib/logger.pyÚ_squeeze_time   s   r   c                 C   s   t | ƒ} d| | d f S )a/  Format a duration in seconds as a human-readable string.

    Returns both seconds and minutes, e.g. ``'12.3s, 0.2min'``.

    Parameters
    ----------
    t : float
        Duration in seconds.

    Returns
    -------
    str
        Formatted string showing the duration in seconds and minutes.
    z%.1fs, %.1fminç      N@©r   r
   r   r   r   Úformat_time"   s   r   c                 C   s$   t | ƒ} | dkrd| d  S d|  S )a]  Format a duration in seconds as a compact human-readable string.

    Returns minutes for durations over 60 seconds, otherwise seconds.

    Parameters
    ----------
    t : float
        Duration in seconds.

    Returns
    -------
    str
        Formatted string: ``'  42.0s'`` for short durations or
        ``' 1.2min'`` for longer ones.
    é<   z%4.1fminr   z %5.1fsr   r
   r   r   r   Úshort_format_time5   s   r   é   c                 C   sX   dt jv rddl}| ¡ }|jdddd� nd}tj| ||d�}|r*|jd	i |¤Ž |S )
a7  Return a pretty-printed string representation of an object.

    Uses :func:`pprint.pformat` with numpy print options temporarily
    reduced to keep output concise when numpy is available.

    Parameters
    ----------
    obj : object
        The object to format.
    indent : int, optional
        Indentation level passed to :func:`pprint.pformat`. Default is 0.
    depth : int, optional
        Maximum nesting depth passed to :func:`pprint.pformat`. Default is 3.

    Returns
    -------
    str
        Pretty-printed string representation of ``obj``.
    Únumpyr   Né   é@   r   )Ú	precisionÚ	thresholdÚ	edgeitems)ÚdepthÚindentr   )r   Úmodulesr   Úget_printoptionsÚset_printoptionsÚpprintÚpformat)Úobjr   r   ÚnpZprint_optionsÚoutr   r   r   r!   L   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
|| _dS 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__s   s   	zLogger.__init__c                 C   ó   t  | j¡ d| |f ¡ d S ©Nz[%s]: %s)ÚloggingÚ	getLoggerr'   Úwarning©r(   Úmsgr   r   r   Úwarn   s   zLogger.warnc                 C   s   t  d| |f ¡ d S r,   )r-   Úinfor0   r   r   r   r3   ‚   s   zLogger.infoc                 C   r+   r,   )r-   r.   r'   Údebugr0   r   r   r   r4   …   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   Úformat‰   s   zLogger.format)r   N)r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   r2   r3   r4   r5   r   r   r   r   r%   p   s    
r%   c                   @   s$   e Zd ZdZd	dd„Zd
dd„ZdS )Ú	PrintTimez3Print and log messages while keeping track of time.Nc                 C   s,  |d ur|d urt dƒ‚t ¡ | _| j| _|d ur tj |d¡}|| _|d ur”ttj 	|¡ƒ tj 
|¡rctddƒD ]}zt |d|  |d|d   ¡ W q:   Y q:z
t ||d ¡ W n   Y z*t|dƒ�}| d¡ | d	t | j¡ ¡ W d   ƒ W d S 1 s†w   Y  W d S    Y d S 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(   rD   ZlogdirÚir   r   r   r*   ”   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urQzt| jdƒ�}t||d� W d  ƒ n1 sFw   Y  W n   Y t   ¡ | _dS )zmPrint 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   ÚstderrrD   rK   )r(   r1   ÚtotalZ
time_lapseÚfull_msgÚfr   r   r   Ú__call__¸   s   
ÿ€zPrintTime.__call__)NN)rO   F)r6   r7   r8   r9   r*   rW   r   r   r   r   r:   ‘   s    
$r:   )r   r   )r9   Ú
__future__r   r-   rA   r    rH   r   r>   Údiskr   r   r   r   r!   Úobjectr%   r:   r   r   r   r   Ú<module>   s    

$!