ž
7’Re¹4 c @ sÉ d Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m
Z
d g Z e j e
ƒ Z e j d e j ƒ Z e j d e j e j Bƒ Z Gd
d „ d e ƒ Z d S( uu
Class representing the list of files in a distribution.
Equivalent to distutils.filelist, but fixes some problems.
i Ni ( u DistlibException( u fsdecode( u convert_pathu Manifestu \\w*
u #.*?(?=
)|
(?=$)c B sË | Ee Z d Z d Z d d d „ Z d d „ Z d d „ Z d d „ Z d d
d „ Z
d d
„ Z d d „ Z d d „ Z
d d d d d „ Z d d d d d „ Z d d d d d „ Z d d „ Z d S( u Manifestu~ A list of files built by on exploring the filesystem and filtered by
applying various patterns to what we find there.
c C sY t j j t j j | p! t j ƒ ƒ ƒ | _ | j t j | _ d | _ t
ƒ | _ d S( ud
Initialise an instance.
:param base: The base directory to explore under.
N( u osu pathu abspathu normpathu getcwdu baseu sepu prefixu Noneu allfilesu setu files( u selfu base( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu __init__# s - u Manifest.__init__c C sü d d l m } m } m } g | _ } | j } | g } | j } | j } x¨ | r÷ | ƒ } t j | ƒ } xƒ | D]{ }
t j
j | |
ƒ } t j | ƒ } | j }
| |
ƒ rÊ | j t
| ƒ ƒ qu | |
ƒ ru | |
ƒ ru | | ƒ qu qu WqP Wd S( um Find all files under the base and set ``allfiles`` to the absolute
pathnames of files found.
i ( u S_ISREGu S_ISDIRu S_ISLNKN( u statu S_ISREGu S_ISDIRu S_ISLNKu allfilesu baseu popu appendu osu listdiru pathu joinu st_modeu fsdecode( u selfu S_ISREGu S_ISDIRu S_ISLNKu allfilesu rootu stacku popu pushu namesu nameu fullnameu statu mode( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu findall2 s"
u Manifest.findallc C sM | j | j ƒ s- t j j | j | ƒ } n | j j t j j | ƒ ƒ d S( uz
Add a file to the manifest.
:param item: The pathname to add. This can be relative to the base.
N( u
startswithu prefixu osu pathu joinu baseu filesu addu normpath( u selfu item( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu addM s u Manifest.addc C s" x | D] } | j | ƒ q Wd S( u†
Add a list of files to the manifest.
:param items: The pathnames to add. These can be relative to the base.
N( u add( u selfu itemsu item( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu add_manyW s
u Manifest.add_manyc sŽ ‡ ‡ f d d † ‰ t ˆ j ƒ } | rj t ƒ } x' | D] } ˆ | t j j | ƒ ƒ q: W| | O} n d d „ t d d „ | Dƒ ƒ Dƒ S( u8
Return sorted files in directory order
c sj | j | ƒ t j d | ƒ | ˆ j k rf t j j | ƒ \ } } | d k sV t ‚ ˆ | | ƒ n d S( Nu add_dir added %su u /( u u /( u addu loggeru debugu baseu osu pathu splitu AssertionError( u dirsu du parentu _( u add_diru self( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu add_dire s
u Manifest.sorted..add_dirc S s" g | ] } t j j | Œ ‘ q S( ( u osu pathu join( u .0u
path_tuple( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu
s s u# Manifest.sorted..c s s! | ] } t j j | ƒ Vq d S( N( u osu pathu split( u .0u path( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu t s u" Manifest.sorted..( u setu filesu osu pathu dirnameu sorted( u selfu wantdirsu resultu dirsu f( ( u add_diru selfu5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu sorted` s
u Manifest.sortedc C s t ƒ | _ g | _ d S( u Clear all collected files.N( u setu filesu allfiles( u self( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu clearv s u Manifest.clearc C sS | j | ƒ \ } } } } | d k rc x%| D]. } | j | d d ƒs. t j d | ƒ q. q. Wnì| d k r« xÝ| D]. } | j | d d ƒsv t j d | ƒ qv qv Wn¤| d k ró x•| D]. } | j | d d ƒs¾ t j d | ƒ q¾ q¾ Wn\| d k r;xM| D]. } | j | d d ƒst j d | ƒ qqWn| d
k r†x| D]1 } | j | d | ƒsNt j d | | ƒ qNqNWnÉ | d
k rÑxº | D]1 } | j | d | ƒs™t j d | | ƒ q™q™Wn~ | d k r| j d d | ƒsOt j d | ƒ qOnG | d k r?| j d d | ƒsOt j d | ƒ qOn t d | ƒ ‚ d S( uv
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
u includeu anchoru no files found matching %ru excludeu. no previously-included files found matching %ru global-includeu3 no files found matching %r anywhere in distributionu global-excludeuG no previously-included files matching %r found anywhere in distributionu recursive-includeu prefixu- no files found matching %r under directory %ru recursive-excludeuA no previously-included files matching %r found under directory %ru graftu no directories found matching %ru pruneu4 no previously-included directories found matching %ru invalid action %rNTF( u _parse_directiveu _include_patternu Trueu loggeru warningu _exclude_patternu Falseu Noneu DistlibException( u selfu directiveu actionu patternsu thediru
dirpatternu pattern( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu process_directive{ sP
u Manifest.process_directivec
C so | j ƒ } t | ƒ d k rA | d d k rA | j d d ƒ n | d } d } } } | d k rª t | ƒ d k rŠ t d | ƒ ‚ n d
d „ | d d … Dƒ } nµ | d k rt | ƒ d k rÛ t d | ƒ ‚ n t | d ƒ } d d „ | d d … Dƒ } nT | d k rOt | ƒ d k r<t d | ƒ ‚ n t | d ƒ } n t d | ƒ ‚ | | | | f S( uŸ
Validate a directive.
:param directive: The directive to validate.
:return: A tuple of action, patterns, thedir, dir_patterns
i i u includeu excludeu global-includeu global-excludeu recursive-includeu recursive-excludeu graftu prunei u$ %r expects ...c S s g | ] } t | ƒ ‘ q S( ( u convert_path( u .0u word( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu
à s u- Manifest._parse_directive..Ni u* %r expects ...c S s g | ] } t | ƒ ‘ q S( ( u convert_path( u .0u word( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu
è s u! %r expects a single u unknown action %r( u includeu excludeu global-includeu global-excludeu recursive-includeu recursive-excludeu graftu prune( u includeu excludeu global-includeu global-exclude( u recursive-includeu recursive-exclude( u graftu prune( u splitu lenu insertu Noneu DistlibExceptionu convert_path( u selfu directiveu wordsu actionu patternsu thediru dir_pattern( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu _parse_directiveÇ s:
u Manifest._parse_directivec C sz d } | j | | | | ƒ } | j d k r: | j ƒ n x9 | j D]. } | j | ƒ rD | j j | ƒ d } qD qD W| S( u… 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( u Falseu _translate_patternu allfilesu Noneu findallu searchu filesu addu True( u selfu patternu anchoru prefixu is_regexu foundu
pattern_reu name( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu _include_patternö s
u Manifest._include_patternc C sd d } | j | | | | ƒ } x? t | j ƒ D]. } | j | ƒ r. | j j | ƒ d } q. q. W| S( ut 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( u Falseu _translate_patternu listu filesu searchu removeu True( u selfu patternu anchoru prefixu is_regexu foundu
pattern_reu f( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu _exclude_pattern s
u Manifest._exclude_patternc
C s | r) t | t ƒ r" t j | ƒ S| Sn | rA | j | ƒ } n d } t j t j j | j d ƒ ƒ } | d k rè | j d ƒ } | j | ƒ d t | ƒ … } t j } t j d k rÄ d } n d | | j | d | f ƒ } n | rÿ d | | } n t j | ƒ S( u 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).
u Nu \u \\u ^u .*(
u
isinstanceu stru reu compileu _glob_to_reu escapeu osu pathu joinu baseu Noneu lenu sep(
u selfu patternu anchoru prefixu is_regexu
pattern_reu baseu
empty_patternu prefix_reu sep( ( u5 /tmp/pip-zej_zi-build/pip/_vendor/distlib/manifest.pyu _translate_pattern3 s&