‹“ReÛ9ã@sèdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dgZ ej eƒZejdejƒZejd ejejBƒZejdd …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ú‹/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_vendor/distlib/manifest.pyÚ__init__*s- zManifest.__init__cCsùddlm}m}m}g|_}|j}|g}|j}|j}x¥|rô|ƒ}tj |ƒ} x€| D]x} tj j || ƒ} tj| ƒ} | j } || ƒrÊ|jt | ƒƒqu|| ƒru|| ƒ ru|| ƒquWqPWdS)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Úfindall9s"          zManifest.findallcCsJ|j|jƒs*tjj|j|ƒ}|jjtjj|ƒƒdS)zz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N) Ú startswithrrr rr rÚaddr )rÚitemrrrr)Tsz 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_many^s zManifest.add_manyFcs‹‡‡fdd†‰tˆjƒ}|rgtƒ}x'|D]}ˆ|tjj|ƒƒq:W||O}dd„tdd„|DƒƒDƒS)z8 Return sorted files in directory order csg|j|ƒtjd|ƒ|ˆjkrctjj|ƒ\}}|dksVt‚ˆ||ƒdS)Nzadd_dir added %sÚú/)r-r.)r)ÚloggerÚdebugr rr ÚsplitÚAssertionError)ÚdirsÚdÚparentÚ_)Úadd_dirrrrr7ls  z Manifest.sorted..add_dircSs"g|]}tjj|Œ‘qSr)rr r)Ú.0Z path_tuplerrrú zs z#Manifest.sorted..css!|]}tjj|ƒVqdS)N)rr r1)r8r rrrú {sz"Manifest.sorted..)rrrr ÚdirnameÚsorted)rZwantdirsÚresultr3Úfr)r7rrr<gs    zManifest.sortedcCstƒ|_g|_dS)zClear all collected files.N)rrr)rrrrÚclear}s zManifest.clearcCs|j|ƒ\}}}}|dkr`xÚ|D]+}|j|ddƒs.tjd|ƒq.Wn¤|dkr•x•|D]}|j|ddƒ}qsWno|dkrÚx`|D]+}|j|ddƒs¨tjd|ƒq¨Wn*|d krx|D]}|j|ddƒ}qíWnõ|d krWxæ|D].}|j|d |ƒs"tjd ||ƒq"Wn­|d krŒxž|D]}|j|d |ƒ}qjWnx|dkrÀ|jdd |ƒstjd|ƒnD|dkrô|jdd |ƒstjd|ƒntd|ƒ‚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Úexcludezglobal-includeFz3no files found matching %r anywhere in distributionzglobal-excludezrecursive-includerz-no files found matching %r under directory %rzrecursive-excludeÚ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ÚpatternÚfoundrrrÚprocess_directive‚sD                    zManifest.process_directivec Csc|jƒ}t|ƒdkr>|ddkr>|jddƒ|d}d }}}|dkr¤t|ƒd kr„td |ƒ‚dd„|dd …Dƒ}n¯|dkrt|ƒdkrÒtd|ƒ‚t|dƒ}dd„|d d …Dƒ}nQ|dkrCt|ƒd kr0td|ƒ‚t|dƒ}ntd|ƒ‚||||fS)zŸ Validate a directive. :param directive: The directive to validate. :return: A tuple of action, patterns, thedir, dir_patterns rrr@rBúglobal-includeúglobal-excludeúrecursive-includeúrecursive-excluderCrDNrz$%r expects ...cSsg|]}t|ƒ‘qSr)r)r8Úwordrrrr9ês z-Manifest._parse_directive..éz*%r expects ...cSsg|]}t|ƒ‘qSr)r)r8rTrrrr9òs z!%r expects a single zunknown action %r)r@rBrPrQrRrSrCrD)r@rBrPrQ)rRrS)rCrD)r1ÚlenÚinsertrr)rrIÚwordsrJrKrLZ dir_patternrrrrEÑs:           zManifest._parse_directiveTcCstd}|j||||ƒ}|jdkr7|jƒx6|jD]+}|j|ƒrA|jj|ƒd}qAW|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))rrMrArÚis_regexrNÚ pattern_rer$rrrrFs  zManifest._include_patterncCsad}|j||||ƒ}x<t|jƒD]+}|j|ƒr.|jj|ƒd}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)rYÚlistrrZÚremove)rrMrArr[rNr\r>rrrrH)s  zManifest._exclude_patternc CsK|r&t|tƒr"tj|ƒS|Std krS|jdƒjdƒ\}}}|r›|j|ƒ}td kr¡|j|ƒr’|j|ƒs¡t ‚nd}tj t j j |jdƒƒ} |dk røtdkr |jdƒ} |j|ƒdt| ƒ …} nY|j|ƒ} | j|ƒr9| j|ƒs?t ‚| t|ƒt| ƒt|ƒ…} t j} t jdkrƒd} tdkr³d| | j | d |fƒ}q>|t|ƒt|ƒt|ƒ…}d || | | ||f}nF|r>tdkrd| |}n#d || |t|ƒd…f}tj|ƒ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). rUrr6r-Nú\z\\ú^z.*z%s%s%s%s.*%s%sz%s%s%s)rUr)rUr)rUr)rUr)rUr)Ú isinstanceÚstrÚreÚcompileÚ_PYTHON_VERSIONÚ _glob_to_reÚ partitionr(Úendswithr2Úescaperr rr rVr) rrMrArr[Ústartr6Úendr\r Z empty_patternZ prefix_rerrrrrY=sB   ! '!  #$&  & #zManifest._translate_patterncCsPtj|ƒ}tj}tjdkr-d}d|}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). r_z\\\\z\1[^%s]z((? s