qdZddlmZddlZddlZddlZddlZddlmZddl m Z m Z ddl m Z ddlmZmZdd lmZGd d Zd ZGd deZejfddZdZddZdS)zsdistutils.filelist Provides the FileList class, used for poking about the filesystem and building lists of files. ) annotationsN)Iterable)Literaloverload)log)DistutilsInternalErrorDistutilsTemplateError convert_pathc<eZdZdZd/d0dZd1d Zejfd2dZd3dZ d4dZ d5dZ d6dZ d6dZ dZd7dZe d8d9d$Ze d:d;d'Zed;d(Z d8ds %     rctttjj|j}g|_|D]-}|jtjj|.dSr)sortedmapospathsplitrr+join)rsortable_files sort_tuples rsortz FileList.sortAsaBGM4: > >?? ( 9 9J J  bglJ7 8 8 8 8 9 9rctt|jdz ddD])}|j||j|dz kr|j|=*dS)Nrr)rangelenr)ris rremove_duplicateszFileList.remove_duplicatesJsZs4:*Ar22 " "Az!} 1q5 111JqM " "rc|}|d}dx}x}}|dvr;t|dkrtd|dd|ddD}n|dvrPt|d krtd|d t|d}d |ddD}nS|d vr ...c,g|]}t|Sr .0ws r z1FileList._parse_template_line..];;;A Q;;;rr)recursive-includerecursive-excludez)' expects ...c,g|]}t|SrGr rHs rrKz1FileList._parse_template_line..drLr)graftprunez ' expects a single zunknown action ')r4r<r r )rlinewordsactionpatternsr dir_patterns r_parse_template_linezFileList._parse_template_lineRse q'+++3 O O O5zzA~~,CCCC<;qrr;;;HH A A A5zzA~~,IIIIuQx((C;;qrr;;;HH ) ) )5zzQ,@@@@'uQx00KK()EF)E)E)EFF F#{33rrSc||\}}}}|dkr^|dd|z|D].}||dst jd|/dS|dkr^|dd|z|D].}||dst jd |/dS|d kr^|d d|z|D].}||d st jd |/dS|dkr^|dd|z|D].}||d st jd|/dS|dkrr|d|d||D]1}|||sd}t j|||2dS|dkrp|d|d||D]/}|||st jd||0dS|dkrH|d|z|d|st jd|dSdS|dkrH|d|z|d|st jd|dSdStd|d) Nr@zinclude  T)anchorz%warning: no files found matching '%s'rAzexclude z9warning: no previously-included files found matching '%s'rBzglobal-include Fz>warning: no files found matching '%s' anywhere in distributionrCzglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionrMzrecursive-include {} {})prefixz:warning: no files found matching '%s' under directory '%s'rNzrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'rQzgraft z+warning: no directories found matching '%s'rRzprune z6no previously-included directories found matching '%s'z$this cannot happen: invalid action 'rE) rXrr5include_patternrwarningexclude_patternformatr )rrSrUrVrrWpatternr#s rprocess_template_linezFileList.process_template_linepsI 04/H/H/N/N,3 Y     Z#((8*<*<< = = =# R R++GD+AARK GQQQ R Ry   Z#((8*<*<< = = =#  ++GD+AAKS  ' ' '   .(1C1CC D D D#  ++GE+BBK7   ' ' '   .(1C1CC D D D#  ++GE+BBKB   * * *   6==c388HCUCUVV W W W# 3 3++GC+@@3VCKWc222 3 3 * * *   6==c388HCUCUVV W W W#  ++GC+@@K>    w     X 3 4 4 4''['AA X I;WWWWW X Xw     X 3 4 4 4''['AA  M   )@v@@@ rTFrar[boolr\ str | Noneis_regexLiteral[False]cdSrrGrrar[r\res rr]zFileList.include_pattern srstr | re.Pattern[str] Literal[True]cdSrrGrhs rr]zFileList.include_pattern srcdSrrGrhs rr]zFileList.include_patternrirstr | re.PatterncFd}t||||}|d|jd|j||jD]K}||r4|d|z|j|d}L|S)aSelect 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'rENz adding T)translate_patternrrarr"searchrr+)rrar[r\re files_found pattern_renames rr]zFileList.include_patterns@ &wII  Sj>PSSSTTT = LLNNNM # #D  && #  d!2333 !!$'''" rcdSrrGrhs rr_zFileList.exclude_patternrircdSrrGrhs rr_zFileList.exclude_patternrmrcdSrrGrhs rr_zFileList.exclude_pattern!rircVd}t||||}|d|jdtt |jdz ddD]O}||j|r-|d|j|z|j|=d}P|S)aRemove 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'rErr:z removing T)rqrrar;r<rrr)rrar[r\rersrtr=s rr_zFileList.exclude_pattern)s &wII  Sj>PSSSTTTs4:*B33 # #A  A// #   1 !=>>>JqM" r)NN)rrrrrr)rrrr)rr rr)r#rrr)r(r)rr)r,rrr)rr)rSr)rrTNF) rar)r[rcr\rdrerfrrc)TN) rarjr[rcr\rdrerkrrc) raror[rcr\rdrercrrc)__name__ __module__ __qualname____doc__rrr2curdirr"rr+r.r8r>rXrbrr]r_rGrrrrs:  ##### !!!!57I%%%%%    !!!!9999""""444z#_find_all_simple..Is^%6T4QVIM T4  r) _UniqueDirsfilterr2walkr3isfile)r3 all_uniqueresultss r_find_all_simplerDsZ##BGDd$C$C$CDDJ:DG "'.' * **rc.eZdZdZdZedZdS)rz Exclude previously-seen dirs from walk results, avoiding infinite recursion. Ref https://bugs.python.org/issue44497. c|\}}}tj|}|j|jf}||v}|r|dd=||| 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)r2statst_devst_inoadd)r walk_itemrrrr candidatefounds r__call__z_UniqueDirs.__call__Vsb &dEwt}}K, T!  QQQ yrc2t||Sr)r)clsr,s rrz_UniqueDirs.filterescceeU###rN)r{r|r}r~r classmethodrrGrrrrOsH   $$[$$$rrrr ct|}|tjkr5tjtjj|}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) rr2r functoolspartialr3relpathr1list)rrmake_rels rr"r"jsR S ! !E bi$RW_C@@@He$$ ;;rctj|}tj}tjdkrd}d|d}t jd||}|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[^]z((?>CHH+DDE f 6T>>CE S__s3xx-G GH EE)ESEEJEEE  A"@@jU&>@@J :j ! !!r)rr rz)r~ __future__rrrr2rcollections.abcrtypingrr_logrerrorsr r utilr rrsetrrr"rrqrGrrrsg #""""" $$$$$$$$$$$$$$BBBBBBBBiiiiiiii^ +++$$$$$#$$$6+-)     .""""""""""""r