ó
î–+[c           @€  s±  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z y d d l Z Wn e	 k
 ru d d l Z n Xd d l
 Z
 d d l Z d d l Z d d l Z y d d l Z Wn; e	 k
 ró y d d l Z Wn e	 k
 rï e Z n Xn Xd d l m Z d d l m Z m Z m Z d d l m Z m Z d d l m Z d d	 l m Z m Z d
 Z d „  Z  d e! f d „  ƒ  YZ" d e f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d S(   so   
A context object for caching a function's return value each time it
is called with the same input arguments.

iÿÿÿÿ(   t   with_statementNi   (   t   hash(   t   get_func_codet   get_func_namet   filter_args(   t   Loggert   format_time(   t   numpy_pickle(   t   mkdirpt
   rm_subdirss   # first line:c         C€  s^   |  j  t ƒ rN |  j d ƒ }  t |  d t t ƒ ƒ } d j |  d ƒ }  n d } |  | f S(   sZ    Extract the first line information from the function code
        text if available.
    s   
i    i   iÿÿÿÿ(   t
   startswitht   FIRST_LINE_TEXTt   splitt   intt   lent   join(   t	   func_codet
   first_line(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   extract_first_line9   s    t   JobLibCollisionWarningc           B€  s   e  Z d  Z RS(   sF    Warn that there might be a collision between names of functions.
    (   t   __name__t
   __module__t   __doc__(    (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR   F   s   t   MemorizedFuncc           B€  s­   e  Z d  Z d d e d d d „ Z d „  Z d „  Z e d „ Z	 d „  Z
 d „  Z d d	 „ Z e d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s"   Callable object decorating a function for caching its return value
        each time it is called.

        All values are cached on the filesystem, in a deep directory
        structure. Methods are provided to inspect the cache or clean it.

        Attributes
        ----------
        func: callable
            The original, undecorated, function.
        cachedir: string
            Path to the base cache directory of the memory context.
        ignore: list or None
            List of variable names to ignore when choosing whether to
            recompute.
        mmap_mode: {None, 'r+', 'r', 'w+', 'c'}
            The memmapping mode used when loading from cache
            numpy arrays. See numpy.load for the meaning of the
            arguments.
        compress: boolean
            Whether to zip the stored data on disk. Note that compressed
            arrays cannot be read by memmapping.
        verbose: int, optional
            The verbosity flag, controls messages that are issued as
            the function is revaluated.
    i   c   	      C€  s  t  j |  ƒ | |  _ | |  _ | |  _ | |  _ | |  _ | rb | d k	 rb t j	 d d d ƒn  | d k r} t
 j
 ƒ  } n  | |  _ | d k r› g  } n  | |  _ t |  j ƒ y t j |  | ƒ Wn n Xt j | ƒ rt j ƒ  j | ƒ j d d d ƒ } n	 | j } d | |  _ d S(	   sU  
            Parameters
            ----------
            func: callable
                The function to decorate
            cachedir: string
                The path of the base directory to use as a data store
            ignore: list or None
                List of variable names to ignore.
            mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional
                The memmapping mode used when loading from cache
                numpy arrays. See numpy.load for the meaning of the
                arguments.
            verbose: int, optional
                Verbosity flag, controls the debug messages that are issued
                as functions are revaluated. The higher, the more verbose
            timestamp: float, optional
                The reference time from which times in tracing messages
                are reported.
        s&   Compressed results cannot be memmappedt
   stackleveli   s   
s   

i   s   Memoized version of %sN(   R   t   __init__t   _verboset   cachedirt   funct	   mmap_modet   compresst   Nonet   warningst   warnt   timet	   timestampt   ignoreR   t	   functoolst   update_wrappert   inspectt
   isfunctiont   pydoct   TextDoct   documentt   replaceR   (	   t   selfR   R   R$   R   R   t   verboseR#   t   doc(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR   m   s2    					
				c         O€  su  |  j  | | Ž  \ } } |  j d d ƒ o9 t j j | ƒ s |  j d k r} t |  j ƒ \ } } |  j d | | | f ƒ n  |  j	 | | Ž  Sy t
 j
 ƒ  } |  j | ƒ } |  j d k rt
 j
 ƒ  | }	 t |  j ƒ \ } } d | t |	 ƒ f }
 t d d t |
 ƒ ƒ d	 |
 GHn  | SWnQ t k
 rp|  j d
 | | t j ƒ  f ƒ t j | d t ƒ|  j	 | | Ž  SXd  S(   NR   i   i
   s3   Computing func %s, argument hash %s in directory %si   s   %s cache loaded - %si    iP   t   _s<   Exception while loading results for (args=%s, kwargs=%s)
 %st   ignore_errors(   t   get_output_dirt   _check_previous_func_codet   ost   patht   existsR   R   R   R!   t   callR"   t   load_outputR   t   maxR   t	   Exceptiont	   tracebackt
   format_exct   shutilt   rmtreet   True(   R-   t   argst   kwargst
   output_dirt   argument_hashR0   t   namet   t0t   outt   tt   msg(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   __call__Ÿ   s,    	#	c         C€  s1   |  j  |  j |  j |  j |  j |  j |  j f f S(   s¤    We don't store the timestamp when pickling, to avoid the hash
            depending from it.
            In addition, when unpickling, we run the __init__
        (   t	   __class__R   R   R$   R   R   R   (   R-   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt
   __reduce__¿   s    c         C€  sQ   t  |  j ƒ \ } } | j | ƒ t j j |  j | Œ } | rM t | ƒ n  | S(   sT    Get the directory corresponding to the cache for the
            function.
        (   R   R   t   appendR4   R5   R   R   R   (   R-   t   mkdirt   moduleRD   t   func_dir(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   _get_func_dirË   s    c         O€  sa   |  j  d k	 } t t |  j |  j | | ƒ d | ƒ} t j j |  j	 |  j ƒ | ƒ } | | f S(   sÊ    Returns the directory in which are persisted the results
            of the function corresponding to the given arguments.

            The results can be loaded using the .load_output method.
        t   coerce_mmapN(
   R   R   R   R   R   R$   R4   R5   R   RP   (   R-   R@   RA   RQ   RC   RB   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR2   Ö   s    		c         C€  s<   d t  | | f } t | d ƒ  } | j | ƒ Wd QXd S(   s=    Write the function code and the filename to a file.
        s   %s %i
%st   wN(   R   t   opent   write(   R-   t   filenameR   R   RF   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   _write_func_codeä   s    i   c         C€  s_  t  |  j ƒ \ } } } |  j ƒ  } t j j | d ƒ } y1 t | ƒ  } t | j ƒ  ƒ \ } }	 Wd QXWn% t	 k
 r‘ |  j
 | | | ƒ t SX| | k r¢ t S|	 | k o¹ d k n r't |  j d t d t ƒ\ }
 } | d k sd | | | f } n | } t j t d | ƒ d | ƒn  |	 | k r| d k	 rt j j | ƒ rt |  j d t ƒ\ }
 } t | j d	 ƒ ƒ } t | ƒ j ƒ  |	 d
 |	 d
 | d
 !} d j | ƒ } | j ƒ  | j ƒ  k rt j t d | | |	 | | | f ƒ d | ƒqn  |  j d k rKt |  j d t ƒ\ }
 } |  j d | | f ƒ n  |  j d t ƒ t S(   s€   
            stacklevel is the depth a which this function is called, to
            issue useful warnings to the user.
        s   func_code.pyNiÿÿÿÿt   resolv_aliast   win_characterss
   %s (%s:%i)s/   Cannot detect name collisions for function '%s'R   s   
i   t    sH   Possible name collisions between functions '%s' (%s:%i) and '%s' (%s:%i)i
   s'   Function %s (stored in %s) has changed.R!   (   R   R   RP   R4   R5   R   RS   R   t   readt   IOErrorRV   t   FalseR?   R   R    R!   R   R   R6   R   R   t   filet	   readlinest   rstripR   t   clear(   R-   R   R   t   source_fileR   RO   t   func_code_filet   infilet   old_func_codet   old_first_lineR0   t	   func_namet   func_descriptiont	   num_linest   on_disk_func_code(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR3   ë   sR    "				c         C€  s«   |  j  d t ƒ } |  j r5 | r5 |  j d | ƒ n  t j j | ƒ r] t j | d t	 ƒn  t
 | ƒ t |  j ƒ \ } } } t j j | d ƒ } |  j | | | ƒ d S(   s%    Empty the function's cache.
        RM   s   Clearing cache %sR1   s   func_code.pyN(   RP   R\   R   R!   R4   R5   R6   R=   R>   R?   R   R   R   R   RV   (   R-   R!   RO   R   R0   R   Rb   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR`   .  s    
c         O€  sÎ   t  j  ƒ  } |  j | | Ž  \ } } |  j rA |  j | | Ž  GHn  |  j | | Ž  } |  j | | ƒ t  j  ƒ  | } |  j rÊ t |  j ƒ \ } }	 d |	 t | ƒ f }
 t d d t	 |
 ƒ ƒ d |
 GHn  | S(   sq    Force the execution of the function with the given arguments and
            persist the output values.
        s   %s - %si    iP   R0   (
   R"   R2   R   t   format_callR   t   _persist_outputR   R   R9   R   (   R-   R@   RA   t
   start_timeRB   RC   t   outputt   durationR0   RD   RH   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR7   ;  s    		#c         O€  s9   |  j  |  j | | Ž \ } } d d d | | f } | S(   sq    Returns a nicely formatted statement displaying the function
            call with the given arguments.
        s   %s
[Memory] Calling %s...
%siP   R0   (   t   format_signatureR   (   R-   R@   t   kwdsR5   t	   signatureRH   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyRj   M  s    c         O€  sN  t  | ƒ \ } } g  | D] } | r | ^ q } | rV | j | ƒ d j | ƒ } n | } t ƒ  } d }	 xx | D]p }
 |  j |
 d d ƒ}
 t |
 ƒ d k r° d |
 d  }
 n  |	 d k rÉ d	 |
 }
 n  t |
 ƒ }	 | j |
 ƒ qr W| j g  | j ƒ  D]% \ } } d
 | |  j | ƒ f ^ qù ƒ d j | ƒ } d | | f } | | f S(   Nt   .i    t   indenti   iÜ  s   %s...i¼  iP   s   
%ss   %s=%ss   , s   %s(%s)(   R   RL   R   t   listt   formatR   t   extendt	   iteritems(   R-   R   R@   Rp   RN   RD   t   mt   module_patht   arg_strt   previous_lengtht   argt   vt   iRq   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyRo   X  s*    		6c         C€  so   yW t  | ƒ t j j | d ƒ } t j | | d |  j ƒ|  j d k rV d | GHn  Wn t k
 rj n Xd S(   s:    Persist the given output tuple in the directory.
        s
   output.pklR   i
   s   Persisting in %sN(	   R   R4   R5   R   R   t   dumpR   R   t   OSError(   R-   Rm   t   dirRU   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyRk   u  s    
c         O€  sŠ   t  |  j |  j | | ƒ } t d „  | j ƒ  Dƒ ƒ } t d k	 r† y6 t | ƒ t j | t	 t
 j j | d ƒ d ƒ ƒ Wq† q† Xn  | S(   sa    Save a small summary of the call using json format in the
            output directory.
        c         s€  s'   |  ] \ } } | t  | ƒ f Vq d  S(   N(   t   repr(   t   .0t   kR}   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pys	   <genexpr>ˆ  s    s   input_args.jsonRR   N(   R   R   R$   t   dictRw   t   jsonR   R   R   R]   R4   R5   R   (   R-   RB   R@   RA   t   argument_dictt
   input_repr(    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   _persist_input  s    
#c         C€  s¯   |  j  d k r„ t j ƒ  |  j } |  j  d k  rY d t | ƒ |  j |  j ƒ d f GHq„ d t | ƒ |  j |  j ƒ d | f GHn  t j j | d ƒ } t	 j
 | d |  j ƒS(   se    Read the results of a previous calculation from the directory
            it was cached in.
        i   i
   s   [Memory]% 16s: Loading %s...i    s!   [Memory]% 16s: Loading %s from %ss
   output.pklR   (   R   R"   R#   R   Ro   R   R4   R5   R   R   t   loadR   (   R-   RB   RG   RU   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR8   –  s    		c         C€  s#   d |  j  j |  j t |  j ƒ f S(   Ns   %s(func=%s, cachedir=%s)(   RJ   R   R   R‚   R   (   R-   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   __repr__±  s    	N(   R   R   R   R   R\   R   RI   RK   R?   RP   R2   RV   R3   R`   R7   Rj   Ro   Rk   R‰   R8   R‹   (    (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR   N   s"   1	 			C						t   Memoryc           B€  s\   e  Z d  Z d e d d „ Z d d d e d „ Z e d „ Z d „  Z	 d „  Z
 d „  Z RS(	   sø    A context object for caching a function's return value each time it
        is called with the same input arguments.

        All values are cached on the filesystem, in a deep directory
        structure.

        see :ref:`memory_reference`
    i   c         C€  s    t  j |  ƒ | |  _ | |  _ t j ƒ  |  _ | |  _ | r_ | d k	 r_ t j	 d d d ƒn  | d k rw d |  _
 n% t j j | d ƒ |  _
 t |  j
 ƒ d S(   s;  
            Parameters
            ----------
            cachedir: string or None
                The path of the base directory to use as a data store
                or None. If None is given, no caching is done and
                the Memory object is completely transparent.
            mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional
                The memmapping mode used when loading from cache
                numpy arrays. See numpy.load for the meaning of the
                arguments.
            compress: boolean
                Whether to zip the stored data on disk. Note that
                compressed arrays cannot be read by memmapping.
            verbose: int, optional
                Verbosity flag, controls the debug messages that are issued
                as functions are revaluated.
        s&   Compressed results cannot be memmappedR   i   t   joblibN(   R   R   R   R   R"   R#   R   R   R    R!   R   R4   R5   R   R   (   R-   R   R   R   R.   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR   É  s    			
c         C€  s·   | d k r" t j |  j d | ƒS|  j d k r5 | S| d k rM |  j } n  | t k re |  j } n  t | t	 ƒ r€ | j
 } n  t	 | d |  j d | d | d |  j d | d |  j ƒS(   s{   Decorates the given function func to only compute its return
            value for input arguments not cached on disk.

            Parameters
            ----------
            func: callable, optional
                The function to be decorated
            ignore: list of strings
                A list of arguments name to ignore in the hashing
            verbose: integer, optional
                The verbosity mode of the function. By default that
                of the memory object is used.
            mmap_mode: {None, 'r+', 'r', 'w+', 'c'}, optional
                The memmapping mode used when loading from cache
                numpy arrays. See numpy.load for the meaning of the
                arguments. By default that of the memory object is used.

            Returns
            -------
            decorated_func: MemorizedFunc object
                The returned object is a MemorizedFunc object, that is
                callable (behaves like a function), but offers extra
                methods for cache lookup and management. See the
                documentation for :class:`joblib.memory.MemorizedFunc`.
        R$   R   R   R   R.   R#   N(   R   R%   t   partialt   cacheR   R   R\   R   t
   isinstanceR   R   R   R#   (   R-   R   R$   R.   R   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR   ë  s     	c         C€  s'   | r |  j  d ƒ n  t |  j ƒ d S(   s-    Erase the complete cache directory.
        s   Flushing completely the cacheN(   R!   R	   R   (   R-   R!   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR`     s    c         O€  s2   |  j  d k r | | | Ž  S|  j | ƒ | | Ž  S(   s   Eval function func with arguments `*args` and `**kwargs`,
            in the context of the memory.

            This method works similarly to the builtin `apply`, except
            that the function is called only if the cache is not
            up to date.

        N(   R   R   R   (   R-   R   R@   RA   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   eval   s    	c         C€  s   d |  j  j t |  j ƒ f S(   Ns   %s(cachedir=%s)(   RJ   R   R‚   R   (   R-   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyR‹   1  s    	c         C€  sD   |  j  d k	 r |  j  d  n d } |  j | |  j |  j |  j f f S(   s¤    We don't store the timestamp when pickling, to avoid the hash
            depending from it.
            In addition, when unpickling, we run the __init__
        iùÿÿÿN(   R   R   RJ   R   R   R   (   R-   R   (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyRK   7  s    "	N(   R   R   R   R   R\   R   R   R?   R`   R‘   R‹   RK   (    (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyRŒ   ¼  s   "	-		(%   R   t
   __future__R    R4   R=   R"   R)   t   cPicklet   picklet   ImportErrorR%   R;   R    R'   R†   t
   simplejsonR   t   hashingR   t   func_inspectR   R   R   t   loggerR   R   RY   R   t   diskR   R	   R   R   t   UserWarningR   R   RŒ   (    (    (    sU   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/memory.pyt   <module>   s>   	ÿ o