o
    `^hW                     @   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 )zRemove .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   K/home/air/shanriGPT/back/venv/lib/python3.10/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 )N<   z%4.1fminr   z %5.1fsr   r
   r   r   r   short_format_time'   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 )	Nnumpyr      @   r   )	precision	threshold	edgeitems)depthindentr   )r   modulesr   get_printoptionsset_printoptionspprintpformat)objr   r   np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
|| _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__C   s   	zLogger.__init__c                 C      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.   infor1   r   r   r   r4   R   s   zLogger.infoc                 C   r,   r-   )r.   r/   r(   debugr1   r   r   r   r5   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+   r3   r4   r5   r6   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 ur|d urt dt | _| j| _|d ur tj|d}|| _|d urt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 sw   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)   rE   logdirir   r   r   r+   e   s:   

&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 )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   rA   printr   stderrrE   rL   )r)   r2   total
time_lapsefull_msgfr   r   r   __call__   s"   
zPrintTime.__call__)NN)rQ   F)r7   r8   r9   r:   r+   rZ   r   r   r   r   r;   a   s    
%r;   )r   r   )r:   
__future__r   r?   r   rB   rI   r.   r    diskr   r   r   r   r!   objectr&   r;   r   r   r   r   <module>   s    

"