
    
_d5                         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m	Z	 ddl
mZ  G d d      Zd	 Z G d
 de      Zej                   fdZd ZddZy)zsdistutils.filelist

Provides the FileList class, used for poking about the filesystem
and building lists of files.
    N   )convert_path)DistutilsTemplateErrorDistutilsInternalError)logc                   v    e Zd ZdZddZd Zej                  fdZd Z	d Z
d Zd	 Zd
 Zd Zd ZddZddZy)FileLista  A list of files built by on exploring the filesystem and filtered by
    applying various patterns to what we find there.

    Instance attributes:
      dir
        directory from which files will be taken -- only used if
        'allfiles' not supplied to constructor
      files
        list of filenames currently being built/filtered/manipulated
      allfiles
        complete list of files under consideration (ie. without any
        filtering applied)
    Nc                      d | _         g | _        y N)allfilesfiles)selfwarndebug_prints      @/usr/lib/python3/dist-packages/setuptools/_distutils/filelist.py__init__zFileList.__init__    s     
    c                     || _         y r   )r   )r   r   s     r   set_allfileszFileList.set_allfiles&   s	     r   c                 $    t        |      | _        y r   )findallr   )r   dirs     r   r   zFileList.findall)   s    r   c                 ,    ddl m} |rt        |       yy)z~Print 'msg' to stdout if the global DEBUG (taken from the
        DISTUTILS_DEBUG environment variable) flag is true.
        r   )DEBUGN)distutils.debugr   print)r   msgr   s      r   r   zFileList.debug_print,   s     	*#J r   c                 :    | j                   j                  |       y r   )r   append)r   items     r   r   zFileList.append7   s    

$r   c                 :    | j                   j                  |       y r   )r   extend)r   itemss     r   r"   zFileList.extend:   s    

% r   c                     t        t        t        j                  j                  | j
                              }g | _        |D ]7  }| j
                  j                  t        j                  j                  |        9 y r   )sortedmapospathsplitr   r   join)r   sortable_files
sort_tuples      r   sortzFileList.sort=   sT    BGGMM4:: >?
( 	9JJJbggllJ78	9r   c                     t        t        | j                        dz
  dd      D ]2  }| j                  |   | j                  |dz
     k(  s&| j                  |= 4 y )Nr   r   )rangelenr   )r   is     r   remove_duplicateszFileList.remove_duplicatesF   sO    s4::*Ar2 	"Azz!}

1q5 11JJqM	"r   c                    |j                         }|d   }d x}x}}|dv r8t        |      dk  rt        d|z        |dd  D cg c]  }t        |       }}n|dv rFt        |      dk  rt        d|z        t        |d         }|dd  D cg c]  }t        |       }}n=|d	v r+t        |      dk7  rt        d
|z        t        |d         }nt        d|z        ||||fS c c}w c c}w )Nr   )includeexcludeglobal-includeglobal-exclude   z&'%s' expects <pattern1> <pattern2> ...r   )recursive-includerecursive-exclude   z,'%s' expects <dir> <pattern1> <pattern2> ...)graftprunez#'%s' expects a single <dir_pattern>zunknown action '%s')r)   r1   r   r   )r   linewordsactionpatternsr   dir_patternws           r   _parse_template_linezFileList._parse_template_lineN   s&   

q'+++3OO5zA~,<vE  27qr;AQ;H;AA5zA~,BVK  uQx(C16qr;AQ;H;))5zQ,9FB  'uQx0K()>)GHH#{33# < <s   C%C*c                    | j                  |      \  }}}}|dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d	|       . y |d
k(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  rU| j                  ddj                  |      z          |D ],  }| j                  |d      rt	        j
                  d|       . y |dk(  re| j                  dj                  |dj                  |                   |D ]/  }| j                  ||      rd}t	        j
                  |||       1 y |dk(  rc| j                  dj                  |dj                  |                   |D ]-  }| j                  ||      rt	        j
                  d||       / y |dk(  r?| j                  d|z          | j                  d |      st	        j
                  d|       y y |dk(  r?| j                  d|z          | j                  d |      st	        j
                  d|       y y t        d|z        )Nr5   zinclude  r   )anchorz%warning: no files found matching '%s'r6   zexclude z9warning: no previously-included files found matching '%s'r7   zglobal-include r   z>warning: no files found matching '%s' anywhere in distributionr8   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr:   zrecursive-include {} {})prefixz:warning: no files found matching '%s' under directory '%s'r;   zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'r=   zgraft z+warning: no directories found matching '%s'r>   zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')	rE   r   r*   include_patternr   warningexclude_patternformatr   )r   r?   rA   rB   r   rC   patternr   s           r   process_template_linezFileList.process_template_linel   s    04/H/H/N,3
 YZ#((8*<<=# R++GA+>KK GQR y Z#((8*<<=# ++GA+>KK2   ''.(1CCD# ++GA+>KK7   ''.(1CCD# ++GA+>KKB   **6==c388HCUVW# 3++GC+@W  KKWc23 **6==c388HCUVW# 	++GC+@KK>  	 wX34''['AI;W B wX34''['AP B )9FB r   c                 B   d}t        ||||      }| j                  d|j                  z         | j                  | j	                          | j                  D ]E  }|j                  |      s| j                  d|z          | j                  j                  |       d}G |S )a  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, False otherwise.
        Fz%include_pattern: applying regex r'%s'z adding T)translate_patternr   rN   r   r   searchr   r   )r   rN   rH   rI   is_regexfiles_found
pattern_renames           r   rJ   zFileList.include_pattern   s    4 &wI
@:CUCUUV == LLNMM 	#D  &  d!23

!!$'"		#
 r   c                 P   d}t        ||||      }| j                  d|j                  z         t        t	        | j
                        dz
  dd      D ]Q  }|j                  | j
                  |         s"| j                  d| j
                  |   z          | j
                  |= d}S |S )a  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, False otherwise.
        Fz%exclude_pattern: applying regex r'%s'r   r/   z
 removing T)rQ   r   rN   r0   r1   r   rR   )r   rN   rH   rI   rS   rT   rU   r2   s           r   rL   zFileList.exclude_pattern   s     &wI
@:CUCUUVs4::*B3 	#A  A/  

1!=>JJqM"		#
 r   )NNr   Nr   )__name__
__module____qualname____doc__r   r   r'   curdirr   r   r   r"   r-   r3   rE   rO   rJ   rL    r   r   r	   r	      sO    ! )) % !9"4<Z|'Rr   r	   c                     t         j                  t        j                  | d            }d |D        }t        t        j                  j
                  |      S )z%
    Find all files under 'path'
    T)followlinksc              3   r   K   | ]/  \  }}}|D ]$  }t         j                  j                  ||       & 1 y wr   )r'   r(   r*   ).0basedirsr   files        r   	<genexpr>z#_find_all_simple.<locals>.<genexpr>  s=      %6T4QVIMT4  s   57)_UniqueDirsfilterr'   walkr(   isfile)r(   
all_uniqueresultss      r   _find_all_simplerm     sE     ##BGGDd$CDJ:DG "''..'**r   c                   &    e Zd ZdZd Zed        Zy)rg   z
    Exclude previously-seen dirs from walk results,
    avoiding infinite recursion.
    Ref https://bugs.python.org/issue44497.
    c                     |\  }}}t        j                  |      }|j                  |j                  f}|| v }|r|dd= | j	                  |       | S )z
        Given an item from an os.walk result, determine
        if the item represents a unique dir for this instance
        and if not, prevent further traversal.
        N)r'   statst_devst_inoadd)r   	walk_itemrc   rd   r   rp   	candidatefounds           r   __call__z_UniqueDirs.__call__  sW     &dEwwt}KK,	T!Qyr   c                 $    t         |        |      S r   )rh   )clsr#   s     r   rh   z_UniqueDirs.filter)  s    ceU##r   N)rY   rZ   r[   r\   rw   classmethodrh   r^   r   r   rg   rg     s      $ $r   rg   c                     t        |       }| t        j                  k(  r;t        j                  t        j
                  j                  |       }t        ||      }t        |      S )z
    Find all files under 'dir' and return the list of full filenames.
    Unless dir is '.', return full filenames with dir prepended.
    )start)	rm   r'   r]   	functoolspartialr(   relpathr&   list)r   r   make_rels      r   r   r   .  sJ    
 S!E
bii$$RWW__C@He$;r   c                     t        j                  |       }t        j                  }t        j                  dk(  rd}d|z  }t	        j
                  d||      }|S )zTranslate 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).
    \z\\\\z\1[^%s]z((?<!\\)(\\\\)*)\.)fnmatch	translater'   sepresub)rN   rU   r   escapeds       r   
glob_to_rer   :  sT     ""7+J &&C	vv~ 3G-w
CJr   c                    |r't        | t              rt        j                  |       S | S t	        d      j                  d      \  }}}| r/t	        |       }|j                  |      r|j                  |      sJ d}|t	        |      }|j                  |      r|j                  |      sJ |t        |      t        |      t        |      z
   }t        j                  }	t        j                  dk(  rd}	|t        |      t        |      t        |      z
   }dj                  |||	||      }n |rdj                  ||t        |      d       }t        j                  |      S )a  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).
    _ Nr   z\\z{}\A{}{}.*{}{}z{}\A{})
isinstancestrr   compiler   	partition
startswithendswithr1   r'   r   rM   )
rN   rH   rI   rS   r|   r   endrU   	prefix_rer   s
             r   rQ   rQ   Q  s@    gs#::g&&N sO--c2ME1c(
$$U+
0C0CC0HHH
v&	##E*y/A/A#/FFFc%j3y>CH+DE	ff66T>CE
S_s3x-GH
&--eYZQTU
"))%CJL1IJJ::j!!r   rX   )r\   r'   r   r   r}   utilr   errorsr   r   _logr   r	   rm   setrg   r]   r   r   rQ   r^   r   r   <module>r      sW    
 	    B q qn+$# $6 		 	.""r   