U
ÀÒ.eÛ9 ã @ s¤ d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ dgZe
e¡Ze dej¡Ze d ejejB ¡Zejdd
… ZG dd„ 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 @ sz e Zd ZdZddd„Zdd„ Zdd„ Zd d
„ Zddd
„Zdd„ Z dd„ Z
dd„ Zddd„Zd dd„Z
d!dd„Zdd„ ZdS )"r z~A list of files built by on exploring the filesystem and filtered by
applying various patterns to what we find there.
Nc C s> t j t j |pt ¡ ¡¡| _| jt j | _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 ú@/usr/lib/python3.8/site-packages/pip/_vendor/distlib/manifest.pyÚ__init__* s zManifest.__init__c C s¨ ddl m}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_ISREGÚS_ISDIRÚS_ISLNKN)Ústatr r r r r ÚpopÚappendr Úlistdirr
ÚjoinÚst_moder )r r r r r ÚrootÚstackr ÚpushÚnamesÚnameÚfullnamer Úmoder r r Úfindall9 s"
zManifest.findallc C s4 | | j¡stj | j|¡}| j tj |¡¡ dS )zz
Add a file to the manifest.
:param item: The pathname to add. This can be relative to the base.
N) Ú
startswithr r r
r r r Úaddr )r Úitemr r r r* T s zManifest.addc C s |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* )r Úitemsr+ r r r Úadd_many^ s zManifest.add_manyFc sb ‡ ‡fdd„‰ t ˆjƒ}|rFt ƒ }|D ]}ˆ |tj |¡ƒ q&||O }dd„ tdd„ |D ƒƒD ƒS )z8
Return sorted files in directory order
c s> | |¡ t d|¡ |ˆjkr:tj |¡\}}ˆ | |ƒ d S )Nzadd_dir added %s)r* ÚloggerÚdebugr r r
Úsplit)ÚdirsÚdÚparentÚ_©Úadd_dirr r r r6 l s
z Manifest.sorted..add_dirc S s g | ]}t jj|Ž ‘qS r )r r
r )Ú.0Z
path_tupler r r Ú
z s z#Manifest.sorted..c s s | ]}t j |¡V qd S )N)r r
r0 )r7 r
r r r Ú { s z"Manifest.sorted..)r r r r
ÚdirnameÚsorted)r ZwantdirsÚresultr1 Úfr r5 r r; g s
ÿzManifest.sortedc C s t ƒ | _g | _dS )zClear all collected files.N)r r r )r r r r Úclear} s zManifest.clearc C sj | |¡\}}}}|dkrB|D ]}| j|dd�st d|¡ q�n$|dkrf|D ]}| j|dd�}qN�n |dkr”|D ]}| j|dd�srt d|¡ qrnÒ|d kr¶|D ]}| j|dd�}q n°|d
kræ|D ] }| j||d�sÂt d||¡ qÂn€|d
k�r
|D ]}| j||d�}qôn\|dk�r2| jd|d��sft d|¡ n4|dk�rZ| jd|d��sft d|¡ 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
ÚincludeT)Úanchorzno files found matching %rÚexcludeúglobal-includeFz3no files found matching %r anywhere in distributionúglobal-excludeúrecursive-include)r z-no files found matching %r under directory %rúrecursive-excludeÚgraftNz no directories found matching %rÚprunez4no previously-included directories found matching %rzinvalid action %r)Ú_parse_directiveÚ_include_patternr. ZwarningÚ_exclude_patternr )r Ú directiveÚactionÚpatternsÚthedirZ
dirpatternÚpatternÚfoundr r r Úprocess_directive‚ sP ÿ ÿ
ÿ
ÿÿzManifest.process_directivec C s | ¡ }t|ƒdkr,|d dkr,| dd¡ |d }d } }}|dkrxt|ƒdk r`td| ƒ‚d d
„ |dd… D ƒ}n~|dkr¼t|ƒdk r˜td
| ƒ‚t|d ƒ}dd
„ |dd… D ƒ}n:|dkrêt|ƒdkrÜtd| ƒ‚t|d ƒ}ntd| ƒ‚||||fS )zŸ
Validate a directive.
:param directive: The directive to validate.
:return: A tuple of action, patterns, thedir, dir_patterns
r r )r? rA rB rC rD rE rF rG r? N)r? rA rB rC r z$%r expects ...c S s g | ]}t |ƒ‘qS r r ©r7 Zwordr r r r8 ê s z-Manifest._parse_directive..)rD rE é z*%r expects ...c S s g | ]}t |ƒ‘qS r r rR r r r r8 ò s )rF rG z!%r expects a single zunknown action %r)r0 ÚlenÚinsertr r )r rK ZwordsrL rM rN Zdir_patternr r r rH Ñ s4 ÿÿÿzManifest._parse_directiveTc C sP d}| ||||¡}| jdkr&| ¡ | jD ]}| |¡r,| j |¡ d}q,|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_patternr r( Úsearchr r* )r rO r@ r Úis_regexrP Ú
pattern_rer% r r r rI s
zManifest._include_patternc C sB d}| ||||¡}t| jƒD ]}| |¡r| j |¡ d}q|S )at Remove 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)rV Úlistr rW Úremove)r rO r@ r rX rP rY r= r r r rJ ) s
zManifest._exclude_patternc
C sv |rt |tƒrt |¡S |S tdkr:| d¡ d¡\}}}|rR| |¡}tdkrVnd}t tj
| jd¡¡} |dk �r4tdkr¢| d¡}
| |¡dt|
ƒ … }n&| |¡}|t|ƒt|ƒt|ƒ … }tj
}tj
dkrÜd}tdk�rd| |
|d| f¡ }n0|t|ƒt|ƒt|ƒ … }d || ||||f }n8|�rltdk�rRd| | }nd
|| |t|ƒd… f }t |¡S )a Translate 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).
)rS r r4 Ú Nú\z\\ú^z.*z%s%s%s%s.*%s%sz%s%s%s)Ú
isinstanceÚstrÚreÚcompileÚ_PYTHON_VERSIONÚ_glob_to_reÚ partitionÚescaper r
r r rT r )
r rO r@ r rX Ústartr4 ÚendrY r Z
empty_patternZ prefix_rer r r r rV = sF
ÿ
ÿ
zManifest._translate_patternc C s8 t |¡}tj}tjdkrd}d| }t d||¡}|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((?