3
LY                 @   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mZmZ ddlZddlmZ ddlmZmZ ddlmZ d	d
lmZ dddddddgZejjZdZdZdgZG dd deZ G dd de Z!e j"Z#ej$j%Z%ej&ej$j'Z(G dd de(Z'dd Z)ej*fddZ+ej,  dS )z@Extensions to the 'distutils' for large or complex distributions    N)convert_path)fnmatchcase)filterfilterfalsemap)	Extension)DistributionFeature)Require   )monkeysetupr   r	   Commandr   r
   find_packagesTzlib2to3.fixesc               @   sH   e Zd ZdZedf dfddZedd Zedd	 Zed
d Z	dS )PackageFinderzI
    Generate a list of all Python packages found within a directory
    .*c             C   s&   t | jt|| jd| | j| S )a	  Return a list all Python packages found within directory 'where'

        'where' is the root directory which will be searched for packages.  It
        should be supplied as a "cross-platform" (i.e. URL-style) path; it will
        be converted to the appropriate local path syntax.

        'exclude' is a sequence of package names to exclude; '*' can be used
        as a wildcard in the names, such that 'foo.*' will exclude all
        subpackages of 'foo' (but not 'foo' itself).

        'include' is a sequence of package names to include.  If it's
        specified, only the named packages will be included.  If it's not
        specified, all found packages will be included.  'include' can contain
        shell style wildcard patterns just like 'exclude'.
        ez_setup*__pycache__)r   r   )list_find_packages_iterr   _build_filter)clswhereexcludeinclude r   m/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/setuptools/setuptools/__init__.pyfind'   s    zPackageFinder.findc             c   s   xt j|ddD ]\}}}|dd }g |dd< xp|D ]h}t jj||}	t jj|	|}
|
jt jjd}d|ks8| j|	 r~q8||r|| r|V  |j| q8W qW dS )zy
        All the packages found in 'where' that pass the 'include' filter, but
        not the 'exclude' filter.
        T)followlinksNr   )	oswalkpathjoinrelpathreplacesep_looks_like_packageappend)r   r   r   r   rootdirsfilesZall_dirsdir	full_pathrel_pathpackager   r   r   r   >   s    
z!PackageFinder._find_packages_iterc             C   s   t jjt jj| dS )z%Does a directory look like a package?z__init__.py)r    r"   isfiler#   )r"   r   r   r   r'   Z   s    z!PackageFinder._looks_like_packagec                 s    fddS )z
        Given a list of patterns, return a callable that will be true only if
        the input matches at least one of the patterns.
        c                s   t  fddD S )Nc             3   s   | ]}t  |d V  qdS ))patN)r   ).0r1   )namer   r   	<genexpr>e   s    z@PackageFinder._build_filter.<locals>.<lambda>.<locals>.<genexpr>)any)r3   )patterns)r3   r   <lambda>e   s    z-PackageFinder._build_filter.<locals>.<lambda>r   )r6   r   )r6   r   r   _   s    zPackageFinder._build_filterN)r   )
__name__
__module____qualname____doc__classmethodr   r   staticmethodr'   r   r   r   r   r   r   "   s   r   c               @   s   e Zd Zedd ZdS )PEP420PackageFinderc             C   s   dS )NTr   )r"   r   r   r   r'   i   s    z'PEP420PackageFinder._looks_like_packageN)r8   r9   r:   r=   r'   r   r   r   r   r>   h   s   r>   c               @   s(   e Zd ZejZdZdd ZdddZdS )	r   Fc             K   s   t j| | t| j| dS )zj
        Construct the command for dist, updating
        vars(self) with any keyword parameters.
        N)_Command__init__varsupdate)selfdistkwr   r   r   r@   z   s    zCommand.__init__r   c             K   s    t j| ||}t|j| |S )N)r?   reinitialize_commandrA   rB   )rC   commandreinit_subcommandsrE   cmdr   r   r   rF      s    zCommand.reinitialize_commandN)r   )r8   r9   r:   r?   r;   Zcommand_consumes_argumentsr@   rF   r   r   r   r   r   u   s   c             C   s&   dd t j| ddD }tt jj|S )z%
    Find all files under 'path'
    c             s   s,   | ]$\}}}|D ]}t jj||V  qqd S )N)r    r"   r#   )r2   baser*   r+   filer   r   r   r4      s   z#_find_all_simple.<locals>.<genexpr>T)r   )r    r!   r   r"   r0   )r"   resultsr   r   r   _find_all_simple   s    rM   c             C   s6   t | }| tjkr.tjtjj| d}t||}t|S )z
    Find all files under 'dir' and return the list of full filenames.
    Unless dir is '.', return full filenames with dir prepended.
    )start)	rM   r    curdir	functoolspartialr"   r$   r   r   )r,   r+   Zmake_relr   r   r   findall   s
    

rR   )-r;   r    rP   distutils.core	distutilsdistutils.filelistdistutils.utilr   fnmatchr   Zsetuptools.extern.six.movesr   r   r   Zsetuptools.version
setuptoolsZsetuptools.extensionr   Zsetuptools.distr   r	   Zsetuptools.dependsr
    r   __all__version__version__Zbootstrap_install_fromZrun_2to3_on_doctestsZlib2to3_fixer_packagesobjectr   r>   r   r   corer   Zget_unpatchedr   r?   rM   rO   rR   Z	patch_allr   r   r   r   <module>   s6   F