3
Pf9 @ s d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z ddl
mZ dgZej
eZejdejZejd ejejB Zejdd
ZG dd deZdS )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 @ sz e Zd ZdZdddZdd Zdd Zd d
Zddd
Zdd Z dd Z
dd ZdddZd ddZ
d!ddZdd 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 jjt jj|pt j | _| jt j | _d| _t | _
dS )zd
Initialise an instance.
:param base: The base directory to explore under.
N)ospathabspathnormpathgetcwdbasesepprefixallfilessetfiles)selfr
r /usr/lib/python3.6/manifest.py__init__* s zManifest.__init__c C s ddl m}m}m} g | _}| j}|g}|j}|j}xv|r| }tj |} x\| D ]T}
tj
j||
}tj |}|j}
||
r|jt
| qR||
rR||
rR|| qRW q8W dS )zmFind all files under the base and set ``allfiles`` to the absolute
pathnames of files found.
r )S_ISREGS_ISDIRS_ISLNKN)statr r r r r
popappendr listdirr joinst_moder )r r r r r rootstackr pushnamesnamefullnamer moder r r findall9 s"
zManifest.findallc C s4 |j | jstjj| j|}| jjtjj| 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 x|D ]}| j | qW dS )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 sf fdd t j}|rJt }x|D ]} |tjj| q(W ||O }dd tdd |D D S )z8
Return sorted files in directory order
c s> | j | tjd| |jkr:tjj|\}} | | d S )Nzadd_dir added %s)r) loggerdebugr
r r split)dirsdparent_)add_dirr r r r4 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 jj|V qd S )N)r r r/ )r5 r r r r { s z"Manifest.sorted..)r r r r dirnamesorted)r Zwantdirsresultr0 fr )r4 r r r9 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 s | j |\}}}}|dkrFx&|D ]}| j|dds tjd| q W n<|dkrnx|D ]}| j|dd}qTW n|dkrx&|D ]}| j|dds|tjd| q|W n|d krx|D ]}| j|dd}qW n|d
k rx|D ] }| j||dstjd|| qW n|d
kr&xz|D ]}| j||d}qW n\|dkrN| jd|dstjd| n4|dkrv| jd|dstjd| 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 %rexcludezglobal-includeFz3no files found matching %r anywhere in distributionzglobal-excludezrecursive-include)r z-no files found matching %r under directory %rzrecursive-excludegraftNz no directories found matching %rprunez4no previously-included directories found matching %rzinvalid action %r)_parse_directive_include_patternr- Zwarning_exclude_patternr )r directiveactionpatternsthedirZ
dirpatternpatternfoundr r r process_directive sD
zManifest.process_directivec C s |j }t|dkr,|d dkr,|jdd |d }d } }}|dkrxt|dk r`td
| dd |dd D }n|dkrt|dk rtd| t|d }dd |dd D }n<|dk rt|dkrtd| 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= r? global-includeglobal-excluderecursive-includerecursive-excluder@ rA Nr z$%r expects ...c S s g | ]}t |qS r )r )r5 wordr r r r6 s z-Manifest._parse_directive.. z*%r expects ...c S s g | ]}t |qS r )r )r5 rP r r r r6 s z!%r expects a single zunknown action %r)r= r? rL rM rN rO r@ rA )r= r? rL rM )rN rO )r@ rA )r/ leninsertr r )r rE ZwordsrF rG rH Zdir_patternr r r rB s:
zManifest._parse_directiveTc C sT d}| j ||||}| jdkr&| j x(| jD ]}|j|r.| jj| d}q.W |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 rI r> r is_regexrJ
pattern_rer$ r r r rC s
zManifest._include_patternc C sF d}| j ||||}x,t| jD ]}|j|r | jj| d}q W |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)rT listr rU remove)r rI r> r rV rJ rW r; r r r rD ) s
zManifest._exclude_patternc
C sv |rt |trtj|S |S tdkr:| jdjd\}}}|rR| j|}td
krVnd}tjtj j
| jd} |dk r4tdkr| jd}
| j|dt|
}n&| j|}|t|t|t| }tj
}tj
dkrd}tdkrd| |j
|d | f }n0|t|t|t| }d
|| ||||f }n8|rltdkrRd| | }nd|| |t|d f }tj|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).
rQ r r3 N\z\\^z.*z%s%s%s%s.*%s%sz%s%s%s)rQ r )rQ r )rQ r )rQ r )rQ r )
isinstancestrrecompile_PYTHON_VERSION_glob_to_re partitionescaper r r r
rR r )
r rI r> r rV startr3 endrW r
Z
empty_patternZ prefix_rer r r r rT = s@
zManifest._translate_patternc C s8 t j|}tj}tjdkrd}d| }tjd||}|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((?