o ƚRe9@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl m Z dgZ e eZedejZed ejejBZejdd ZGd ddeZdS) zu Class representing the list of files in a distribution. Equivalent to distutils.filelist, but fixes some problems. N)DistlibException)fsdecode convert_pathManifestz\\w* z#.*?(?= )| (?=$)c@seZdZdZdddZddZddZd d Zdd d ZddZ ddZ ddZ  dddZ  dddZ  dddZddZdS) rz~A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. NcCs>tjtj|p t|_|jtj|_d|_t |_ dS)zd Initialise an instance. :param base: The base directory to explore under. N) ospathabspathnormpathgetcwdbasesepprefixallfilessetfiles)selfrr/builddir/build/BUILDROOT/alt-python310-pip-21.3.1-3.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/distlib/manifest.py__init__*s zManifest.__init__cCsddlm}m}m}g|_}|j}|g}|j}|j}|rU|}t |} | D])} tj || } t| } | j } || rD|t | q'|| rP|| sP|| q'|sdSdS)zmFind all files under the base and set ``allfiles`` to the absolute pathnames of files found. r)S_ISREGS_ISDIRS_ISLNKN)statrrrrrpopappendr listdirr joinst_moder)rrrrrrootstackrpushnamesnamefullnamermoderrrfindall9s&    zManifest.findallcCs4||jstj|j|}|jtj|dS)zz Add a file to the manifest. :param item: The pathname to add. This can be relative to the base. N) startswithrr r rrraddr )ritemrrrr*Ts z Manifest.addcCs|D]}||qdS)z Add a list of files to the manifest. :param items: The pathnames to add. These can be relative to the base. N)r*)ritemsr+rrradd_many^s zManifest.add_manyFcsbfddtj}|r#t}|D] }|tj|q||O}ddtdd|DDS)z8 Return sorted files in directory order csN||td||jkr%tj|\}}|dvsJ||dSdS)Nzadd_dir added %s)/)r*loggerdebugrr r split)dirsdparent_add_dirrrrr8ls    z Manifest.sorted..add_dircSsg|]}tjj|qSr)r r r).0Z path_tuplerrr zsz#Manifest.sorted..css|] }tj|VqdSN)r r r2)r9r rrr {sz"Manifest.sorted..)rrr r dirnamesorted)rZwantdirsresultr3frr7rr>gs zManifest.sortedcCst|_g|_dS)zClear all collected files.N)rrr)rrrrclear}s zManifest.clearcCsp||\}}}}|dkr!|D]}|j|ddstd|qdS|dkr3|D] }|j|dd}q'dS|dkrK|D]}|j|ddsHtd|q9dS|d kr]|D] }|j|dd}qQdS|d krv|D]}|j||d sstd ||qcdS|d kr|D] }|j||d }q|dS|dkr|jd|d std|dSdS|dkr|jd|d std|dSdStd|)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 includeT)anchorzno files found matching %rexcludeglobal-includeFz3no files found matching %r anywhere in distributionglobal-excluderecursive-include)rz-no files found matching %r under directory %rrecursive-excludegraftNz no directories found matching %rprunez4no previously-included directories found matching %rzinvalid action %r)_parse_directive_include_patternr0warning_exclude_patternr)r directiveactionpatternsthedirZ dirpatternpatternfoundrrrprocess_directivesd zManifest.process_directivecCs|}t|dkr|ddvr|dd|d}d}}}|dvr ...cSg|]}t|qSrrr9wordrrrr:z-Manifest._parse_directive..)rGrHz*%r expects ...cSrVrrrWrrrr:rY)rIrJz!%r expects a single zunknown action %r)r2leninsertrr)rrOwordsrPrQrRZ dir_patternrrrrKs4        zManifest._parse_directiveTcCsPd}|||||}|jdur||jD]}||r%|j|d}q|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. FNT)_translate_patternrr(searchrr*)rrSrCris_regexrT pattern_rer%rrrrLs    zManifest._include_patterncCsBd}|||||}t|jD]}||r|j|d}q|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)rrSrCrr`rTrar@rrrrN)s   zManifest._exclude_patternc Cs|rt|tr t|S|Stdkr|dd\}}}|r5||}tdkr4||r2||s4Jnd}t t j |j d} |durtdkr\|d} ||dt|  } n||} | |rk| |smJ| t|t| t|} t j} t jdkrd} tdkrd| | | d|f}n3|t|t|t|}d || | | ||f}n|rtdkrd| |}n d || |t|df}t|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). )rZrr6r.N\z\\^z.*z%s%s%s%s.*%s%sz%s%s%s) isinstancestrrecompile_PYTHON_VERSION _glob_to_re partitionr)endswithescaper r rrr[r) rrSrCrr`startr6endrarZ empty_patternZ prefix_rerrrrr^=sH          zManifest._translate_patterncCs8t|}tj}tjdkrd}d|}td||}|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). rdz\\\\z\1[^%s]z((?rArUrKrLrNr^rkrrrrr%s(  O/ )  7)rxrqloggingr rhsysr.rcompatrutilr__all__ getLoggerrur0riMZ_COLLAPSE_PATTERNSZ_COMMENTED_LINE version_inforjobjectrrrrrs