U .e9@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@szeZdZdZdddZddZddZd d Zdd d ZddZ ddZ ddZ dddZ d ddZ d!ddZddZdS)"rz~A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. NcCs>tjtj|pt|_|jtj|_d|_t |_ dS)zd Initialise an instance. :param base: The base directory to explore under. N) ospathabspathnormpathgetcwdbasesepprefixallfilessetfiles)selfrr@/usr/lib/python3.8/site-packages/pip/_vendor/distlib/manifest.py__init__*szManifest.__init__cCsddlm}m}m}g|_}|j}|g}|j}|j}|r|}t |} | D]R} tj || } t| } | j } || r|t | qN|| rN|| sN|| qNq6dS)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^szManifest.add_manyFcsbfddtj}|rFt}|D]}|tj|q&||O}ddtdd|DDS)z8 Return sorted files in directory order cs>||td||jkr:tj|\}}||dS)Nzadd_dir added %s)r*loggerdebugrr r split)dirsdparent_add_dirrrrr6ls    z Manifest.sorted..add_dircSsg|]}tjj|qSr)r r r).0Z path_tuplerrr zsz#Manifest.sorted..css|]}tj|VqdS)N)r r r0)r7r rrr {sz"Manifest.sorted..)rrr r dirnamesorted)rZwantdirsresultr1frr5rr;gs zManifest.sortedcCst|_g|_dS)zClear all collected files.N)rrr)rrrrclear}szManifest.clearcCsj||\}}}}|dkrB|D]}|j|ddstd|qn$|dkrf|D]}|j|dd}qNn|dkr|D]}|j|ddsrtd|qrn|d kr|D]}|j|dd}qn|d kr|D] }|j||d std ||qn|d kr |D]}|j||d }qn\|dkr2|jd|d sftd|n4|dkrZ|jd|d sftd|n td|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 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_patternr.Zwarning_exclude_patternr)r directiveactionpatternsthedirZ dirpatternpatternfoundrrrprocess_directivesP   zManifest.process_directivecCs|}t|dkr,|ddkr,|dd|d}d}}}|dkrxt|dkr`td|d d |ddD}n~|d krt|d krtd |t|d}dd |ddD}n:|dkrt|dkrtd|t|d}n td|||||fS)z Validate a directive. :param directive: The directive to validate. :return: A tuple of action, patterns, thedir, dir_patterns rr)r?rArBrCrDrErFrGr?N)r?rArBrCrz$%r expects ...cSsg|] }t|qSrrr7Zwordrrrr8sz-Manifest._parse_directive..)rDrEz*%r expects ...cSsg|] }t|qSrrrRrrrr8s)rFrGz!%r expects a single zunknown action %r)r0leninsertrr)rrKZwordsrLrMrNZ dir_patternrrrrHs4       zManifest._parse_directiveTcCsPd}|||||}|jdkr&||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*)rrOr@ris_regexrP pattern_rer%rrrrIs    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)rVlistrrWremove)rrOr@rrXrPrYr=rrrrJ)s   zManifest._exclude_patternc Csv|rt|trt|S|Stdkr:|dd\}}}|rR||}tdkrVnd}ttj |j d} |dk r4tdkr|d} ||dt |  } n&||} | t |t | t |} tj } tj dkrd} tdkrd| | | d|f}n0|t |t |t |}d || | | ||f}n8|rltdkrRd| |}nd || |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). )rSrr4N\z\\^z.*z%s%s%s%s.*%s%sz%s%s%s) isinstancestrrecompile_PYTHON_VERSION _glob_to_re partitionescaper r rrrTr) rrOr@rrXstartr4endrYrZ empty_patternZ prefix_rerrrrrV=sF             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). r]z\\\\z\1[^%s]z((?rQrHrIrJrVrdrrrrr%s&   O/ )  7)roriZloggingr rasysr\rcompatrutilr__all__Z getLoggerrlr.rbMZ_COLLAPSE_PATTERNSZ_COMMENTED_LINE version_inforcobjectrrrrrs