ó
^†êWc           @   sÉ   d  Z  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 g Z e j e ƒ Z e j d e j ƒ Z e j d	 e j e j Bƒ Z d e f d
 „  ƒ  YZ d S(   su   
Class representing the list of files in a distribution.

Equivalent to distutils.filelist, but fixes some problems.
iÿÿÿÿNi   (   t   DistlibException(   t   fsdecode(   t   convert_patht   Manifests   \\w*
s   #.*?(?=
)|
(?=$)c           B   s›   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z e d „ Z	 d „  Z
 d „  Z d „  Z e d e d	 „ Z e d e d
 „ Z e d e d „ Z d „  Z RS(   s~   A list of files built by on exploring the filesystem and filtered by
    applying various patterns to what we find there.
    c         C   sY   t  j j t  j j | p! t  j ƒ  ƒ ƒ |  _ |  j t  j |  _ d |  _	 t
 ƒ  |  _ d S(   sd   
        Initialise an instance.

        :param base: The base directory to explore under.
        N(   t   ost   patht   abspatht   normpatht   getcwdt   baset   sept   prefixt   Nonet   allfilest   sett   files(   t   selfR	   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   __init__#   s    -	c         C   sü   d d l  m } m } m } g  |  _ } |  j } | g } | j } | j } x¨ | r÷ | ƒ  } t j	 | ƒ }	 xƒ |	 D]{ }
 t j
 j | |
 ƒ } t j  | ƒ } | j } | | ƒ rÊ | j t | ƒ ƒ qu | | ƒ ru | | ƒ ru | | ƒ qu qu WqP Wd S(   sm   Find all files under the base and set ``allfiles`` to the absolute
        pathnames of files found.
        iÿÿÿÿ(   t   S_ISREGt   S_ISDIRt   S_ISLNKN(   t   statR   R   R   R   R	   t   popt   appendR   t   listdirR   t   joint   st_modeR   (   R   R   R   R   R   t   roott   stackR   t   pusht   namest   namet   fullnameR   t   mode(    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   findall2   s"    							c         C   sM   | j  |  j ƒ s- t j j |  j | ƒ } n  |  j j t j j | ƒ ƒ d S(   sz   
        Add a file to the manifest.

        :param item: The pathname to add. This can be relative to the base.
        N(	   t
   startswithR   R   R   R   R	   R   t   addR   (   R   t   item(    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR$   M   s    c         C   s"   x | D] } |  j  | ƒ q Wd S(   s†   
        Add a list of files to the manifest.

        :param items: The pathnames to add. These can be relative to the base.
        N(   R$   (   R   t   itemsR%   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   add_manyW   s    c            sš   ‡  ‡ f d †  ‰  t  ˆ j ƒ } | rg t  ƒ  } x' | D] } ˆ  | t j j | ƒ ƒ q7 W| | O} n  g  t d „  | Dƒ ƒ D] } t j j | Œ  ^ q~ S(   s8   
        Return sorted files in directory order
        c            sj   |  j  | ƒ t j d | ƒ | ˆ j k rf t j j | ƒ \ } } | d k sV t ‚ ˆ  |  | ƒ n  d  S(   Ns   add_dir added %st    t   /(   R(   R)   (   R$   t   loggert   debugR	   R   R   t   splitt   AssertionError(   t   dirst   dt   parentt   _(   t   add_dirR   (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR2   e   s    c         s   s!   |  ] } t  j j | ƒ Vq d  S(   N(   R   R   R,   (   t   .0R   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pys	   <genexpr>t   s    (   R   R   R   R   t   dirnamet   sortedR   (   R   t   wantdirst   resultR.   t   ft
   path_tuple(    (   R2   R   sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR5   `   s    	c         C   s   t  ƒ  |  _ g  |  _ d S(   s   Clear all collected files.N(   R   R   R   (   R   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   clearv   s    c         C   s  |  j  | ƒ \ } } } } | d k rc xé| D]. } |  j | d t ƒs. t j d | ƒ q. q. Wn°| d k r˜ x¡| D] } |  j | d t ƒ} qv Wn{| d k rà xl| D]. } |  j | d t ƒs« t j d | ƒ q« q« Wn3| d k rx$| D] } |  j | d t ƒ} qó Wnþ | d k r`xï | D]1 } |  j | d	 | ƒs(t j d
 | | ƒ q(q(Wn³ | d k r•x¤ | D] } |  j | d	 | ƒ} qsWn~ | d k rÌ|  j d d	 | ƒst j d | ƒ qnG | d k r|  j d d	 | ƒst j d | ƒ qn t d | ƒ ‚ d S(   sv  
        Process a directive which either adds some files from ``allfiles`` to
        ``files``, or removes some files from ``files``.

        :param directive: The directive to process. This should be in a format
                     compatible with distutils ``MANIFEST.in`` files:

                     http://docs.python.org/distutils/sourcedist.html#commands
        t   includet   anchors   no files found matching %rt   excludes   global-includes3   no files found matching %r anywhere in distributions   global-excludes   recursive-includeR   s-   no files found matching %r under directory %rs   recursive-excludet   grafts    no directories found matching %rt   prunes4   no previously-included directories found matching %rs   invalid action %rN(	   t   _parse_directivet   _include_patternt   TrueR*   t   warningt   _exclude_patternt   FalseR   R    (   R   t	   directivet   actiont   patternst   thedirt
   dirpatternt   patternt   found(    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   process_directive{   sD    				c      	   C   s{  | j  ƒ  } t | ƒ d k rA | d d k rA | j d d ƒ n  | d } d } } } | d k r° t | ƒ d k  rŠ t d | ƒ ‚ n  g  | d D] } t | ƒ ^ q• } n» | d k rt | ƒ d k  rá t d | ƒ ‚ n  t | d ƒ } g  | d D] } t | ƒ ^ qü } nT | d k r[t | ƒ d k rHt d | ƒ ‚ n  t | d ƒ } n t d | ƒ ‚ | | | | f S(   sŸ   
        Validate a directive.
        :param directive: The directive to validate.
        :return: A tuple of action, patterns, thedir, dir_patterns
        i   i    R;   R=   s   global-includes   global-excludes   recursive-includes   recursive-excludeR>   R?   i   s$   %r expects <pattern1> <pattern2> ...i   s*   %r expects <dir> <pattern1> <pattern2> ...s!   %r expects a single <dir_pattern>s   unknown action %r(   s   includes   excludes   global-includes   global-excludes   recursive-includes   recursive-excludes   grafts   pruneN(   s   includes   excludes   global-includes   global-exclude(   s   recursive-includes   recursive-exclude(   s   grafts   prune(   R,   t   lent   insertR   R    R   (   R   RF   t   wordsRG   RH   RI   t   dir_patternt   word(    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR@   Ê   s:        	
	&&c         C   sz   t  } |  j | | | | ƒ } |  j d k r: |  j ƒ  n  x9 |  j D]. } | j | ƒ rD |  j j | ƒ t } qD qD W| S(   s…  Select strings (presumably filenames) from 'self.files' that
        match 'pattern', a Unix-style wildcard (glob) pattern.

        Patterns are not quite the same as implemented by the 'fnmatch'
        module: '*' and '?'  match non-special characters, where "special"
        is platform-dependent: slash on Unix; colon, slash, and backslash on
        DOS/Windows; and colon on Mac OS.

        If 'anchor' is true (the default), then the pattern match is more
        stringent: "*.py" will match "foo.py" but not "foo/bar.py".  If
        'anchor' is false, both of these will match.

        If 'prefix' is supplied, then only filenames starting with 'prefix'
        (itself a pattern) and ending with 'pattern', with anything in between
        them, will match.  'anchor' is ignored in this case.

        If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and
        'pattern' is assumed to be either a string containing a regex or a
        regex object -- no translation is done, the regex is just compiled
        and used as-is.

        Selected strings will be added to self.files.

        Return True if files are found.
        N(	   RE   t   _translate_patternR   R   R"   t   searchR   R$   RB   (   R   RK   R<   R   t   is_regexRL   t
   pattern_reR   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyRA   ù   s    c         C   sd   t  } |  j | | | | ƒ } x? t |  j ƒ D]. } | j | ƒ r. |  j j | ƒ t } q. q. W| S(   st  Remove strings (presumably filenames) from 'files' that match
        'pattern'.

        Other parameters are the same as for 'include_pattern()', above.
        The list 'self.files' is modified in place. Return True if files are
        found.

        This API is public to allow e.g. exclusion of SCM subdirs, e.g. when
        packaging source distributions
        (   RE   RS   t   listR   RT   t   removeRB   (   R   RK   R<   R   RU   RL   RV   R8   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyRD   "  s    c   
      C   s  | r) t  | t ƒ r" t j | ƒ S| Sn  | rA |  j | ƒ } n d } t j t j j |  j	 d ƒ ƒ } | d k	 râ |  j d ƒ } |  j | ƒ t | ƒ  } t j }	 t j d k r¾ d }	 n  d | |	 j | d | f ƒ } n | rù d | | } n  t j | ƒ S(   s  Translate a shell-like wildcard pattern to a compiled regular
        expression.

        Return the compiled regex.  If 'is_regex' true,
        then 'pattern' is directly compiled to a regex (if it's a string)
        or just returned as-is (assumes it's a regex object).
        R(   s   \s   \\t   ^s   .*N(   t
   isinstancet   strt   ret   compilet   _glob_to_ret   escapeR   R   R   R	   R   RN   R
   (
   R   RK   R<   R   RU   RV   R	   t   empty_patternt	   prefix_reR
   (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyRS   6  s&    	!		c         C   sS   t  j | ƒ } t j } t j d k r0 d } n  d | } t j d | | ƒ } | S(   s÷   Translate a shell-like glob pattern to a regular expression.

        Return a string containing the regex.  Differs from
        'fnmatch.translate()' in that '*' does not match "special characters"
        (which are platform-specific).
        s   \s   \\\\s   \1[^%s]s   ((?<!\\)(\\\\)*)\.(   t   fnmatcht	   translateR   R
   R\   t   sub(   R   RK   RV   R
   t   escaped(    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR^   Z  s    		
N(   t   __name__t
   __module__t   __doc__R   R   R"   R$   R'   RE   R5   R:   RM   R@   RB   RA   RD   RS   R^   (    (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyR      s    		
				O	/(#(   Rh   Rb   t   loggingR   R\   R(   R    t   compatR   t   utilR   t   __all__t	   getLoggerRf   R*   R]   t   Mt   _COLLAPSE_PATTERNt   St   _COMMENTED_LINEt   objectR   (    (    (    sm   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/distlib/manifest.pyt   <module>
   s   	