î “Re¹4ã@sÉdZddlZddlZddlZddlZddlmZddlmZddl m Z dgZ ej e ƒZejdejƒZejd ejejBƒZGd d„deƒZdS) zu Class representing the list of files in a distribution. Equivalent to distutils.filelist, but fixes some problems. éNé)ÚDistlibException)Úfsdecode)Ú convert_pathÚManifestz\\w* z#.*?(?= )| (?=$)c@sÇeZdZdZddd„Zdd„Zdd„Zd d „Zd d d „Zdd„Z dd„Z dd„Z ddd dd„Z ddd dd„Z ddd dd„Zdd„ZdS)rz~A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. NcCsYtjjtjj|p!tjƒƒƒ|_|jtj|_d|_t ƒ|_ dS)zd Initialise an instance. :param base: The base directory to explore under. N) ÚosÚpathÚabspathÚnormpathÚgetcwdÚbaseÚsepÚprefixÚallfilesÚsetÚfiles)Úselfr ©rú7/tmp/pip-ztkk0jow-build/pip/_vendor/distlib/manifest.pyÚ__init__#s- zManifest.__init__cCsüddlm}m}m}g|_}|j}|g}|j}|j}x¨|r÷|ƒ}tj |ƒ} xƒ| D]{} tj j || ƒ} tj| ƒ} | j } || ƒrÊ|jt | ƒƒqu|| ƒru|| ƒ ru|| ƒququWqPWdS)zmFind all files under the base and set ``allfiles`` to the absolute pathnames of files found. r)ÚS_ISREGÚS_ISDIRÚS_ISLNKN)Ústatrrrrr ÚpopÚappendrÚlistdirrÚjoinÚst_moder)rrrrrÚrootÚstackrÚpushÚnamesÚnameÚfullnamerÚmoderrrÚfindall2s"          zManifest.findallcCsM|j|jƒs-tjj|j|ƒ}n|jjtjj|ƒƒdS)zz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N) Ú startswithrrrrr rÚaddr )rÚitemrrrr(Msz Manifest.addcCs"x|D]}|j|ƒqWdS)z† Add a list of files to the manifest. :param items: The pathnames to add. These can be relative to the base. N)r()rÚitemsr)rrrÚadd_manyWs zManifest.add_manyFcsއ‡fdd†‰tˆjƒ}|rjtƒ}x'|D]}ˆ|tjj|ƒƒq:W||O}ndd„tdd„|DƒƒDƒS)z8 Return sorted files in directory order csj|j|ƒtjd|ƒ|ˆjkrftjj|ƒ\}}|dksVt‚ˆ||ƒndS)Nzadd_dir added %sÚú/)r,r-)r(ÚloggerÚdebugr rrÚsplitÚAssertionError)ÚdirsÚdÚparentÚ_)Úadd_dirrrrr6es  z Manifest.sorted..add_dircSs"g|]}tjj|Œ‘qSr)rrr)Ú.0Z path_tuplerrrú ss z#Manifest.sorted..css!|]}tjj|ƒVqdS)N)rrr0)r7rrrrú tsz"Manifest.sorted..)rrrrÚdirnameÚsorted)rZwantdirsÚresultr2Úfr)r6rrr;`s    zManifest.sortedcCstƒ|_g|_dS)zClear all collected files.N)rrr)rrrrÚclearvs zManifest.clearcCsS|j|ƒ\}}}}|dkrcx%|D].}|j|ddƒs.tjd|ƒq.q.Wnì|dkr«xÝ|D].}|j|ddƒsvtjd|ƒqvqvWn¤|dkróx•|D].}|j|ddƒs¾tjd |ƒq¾q¾Wn\|d kr;xM|D].}|j|ddƒstjd |ƒqqWn|d kr†x|D]1}|j|d |ƒsNtjd||ƒqNqNWnÉ|dkrÑxº|D]1}|j|d |ƒs™tjd||ƒq™q™Wn~|dkr|jdd |ƒsOtjd|ƒqOnG|dkr?|jdd |ƒsOtjd|ƒqOntd|ƒ‚dS)av 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 ÚincludeÚanchorTzno files found matching %rÚexcludez.no previously-included files found matching %rzglobal-includeFz3no files found matching %r anywhere in distributionzglobal-excludezGno previously-included files matching %r found anywhere in distributionzrecursive-includerz-no files found matching %r under directory %rzrecursive-excludezAno previously-included files matching %r found under directory %rÚgraftNz no directories found matching %rÚprunez4no previously-included directories found matching %rzinvalid action %r)Ú_parse_directiveÚ_include_patternr.ÚwarningÚ_exclude_patternr)rÚ directiveÚactionÚpatternsÚthedirZ dirpatternÚpatternrrrÚprocess_directive{sP                       zManifest.process_directivec Cso|jƒ}t|ƒdkrA|ddkrA|jddƒn|d}d }}}|dkrªt|ƒd krŠtd |ƒ‚ndd„|dd …Dƒ}nµ|dkr t|ƒdkrÛtd|ƒ‚nt|dƒ}dd„|d d …Dƒ}nT|dkrOt|ƒd kr<td|ƒ‚nt|dƒ}ntd|ƒ‚||||fS)zŸ Validate a directive. :param directive: The directive to validate. :return: A tuple of action, patterns, thedir, dir_patterns rrr?rAúglobal-includeúglobal-excludeúrecursive-includeúrecursive-excluderBrCNéz$%r expects ...cSsg|]}t|ƒ‘qSr)r)r7Úwordrrrr8às z-Manifest._parse_directive..éz*%r expects ...cSsg|]}t|ƒ‘qSr)r)r7rSrrrr8ès z!%r expects a single zunknown action %r)úincludeúexcluderNrOrPrQúgraftúprune)rUrVrNrO)rPrQ)rWrX)r0ÚlenÚinsertrr)rrHÚwordsrIrJrKZ dir_patternrrrrDÇs:        zManifest._parse_directiveTcCszd}|j||||ƒ}|jdkr:|jƒnx9|jD].}|j|ƒrD|jj|ƒd}qDqDW|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. FNT)Ú_translate_patternrr&Úsearchrr()rrLr@rÚis_regexÚfoundÚ pattern_rer#rrrrEös  zManifest._include_patterncCsdd}|j||||ƒ}x?t|jƒD].}|j|ƒr.|jj|ƒd}q.q.W|S)atRemove 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 FT)r\Úlistrr]Úremove)rrLr@rr^r_r`r=rrrrGs  zManifest._exclude_patternc Cs |r)t|tƒr"tj|ƒS|Sn|rA|j|ƒ}nd}tjtjj|j dƒƒ}|dk rè|jdƒ}|j|ƒdt |ƒ …}tj } tj dkrÄd} nd|| j|d|fƒ}n|rÿd||}ntj|ƒS)aTranslate 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,Nú\z\\ú^z.*) Ú isinstanceÚstrÚreÚcompileÚ _glob_to_reÚescaperrrr rYr ) rrLr@rr^r`r Z empty_patternZ prefix_rer rrrr\3s&  !    zManifest._translate_patterncCsStj|ƒ}tj}tjdkr0d}nd|}tjd||ƒ}|S)z÷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). rcz\\\\z\1[^%s]z((?rMrDrErGr\rirrrrrs     L /(#)rrrkÚloggingrrgr,rÚcompatrÚutilrÚ__all__Ú getLoggerror.rhÚMZ_COLLAPSE_PATTERNÚSZ_COMMENTED_LINEÚobjectrrrrrÚ s