î
½1kd!  ã               @   sÅ   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	 y d  d l
 m Z Wn% e k
 r› Gd d „  d ƒ Z Yn XGd d	 „  d	 e e ƒ Z d
 d „  Z d S)é    N)Úbuild_py)Úconvert_path)Úglob)Ú	Mixin2to3c               @   s   e  Z d  Z d d d „ Z d S)r   Tc             C   s   d S)z
do nothingN© )ÚselfÚfilesZdoctestsr   r   úQ/var/www/pythonscrapper/code/venv/build/setuptools/setuptools/command/build_py.pyÚrun_2to3   s    zMixin2to3.run_2to3N)Ú__name__Ú
__module__Ú__qualname__r
   r   r   r   r	   r      s   r   c               @   sÓ   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d d „  Z d d „  Z e j d k  rŸ d d d „ Z n  d d „  Z d d „  Z d d „  Z d d „  Z d  S)!r   aX  Enhanced 'build_py' command that includes data files with packages

    The data files are specified via a 'package_data' argument to 'setup()'.
    See 'setuptools.dist.Distribution' for more details.

    Also, this version of the 'build_py' command allows you to specify both
    'py_modules' and 'packages' in the same setup operation.
    c             C   sc   t  j |  ƒ |  j j |  _ |  j j p+ i  |  _ d |  j k rM |  j d =n  g  |  _ g  |  _ d  S)NÚ
data_files)Ú	_build_pyÚfinalize_optionsÚdistributionÚpackage_dataÚexclude_package_dataÚ__dict__Ú_build_py__updated_filesÚ_build_py__doctests_2to3)r   r   r   r	   r      s     	zbuild_py.finalize_optionsc             C   s§   |  j  r |  j r d S|  j  r. |  j ƒ  n  |  j rN |  j ƒ  |  j ƒ  n  |  j |  j d ƒ |  j |  j d ƒ |  j |  j d ƒ |  j t	 j
 |  d d ƒƒ d S)z?Build modules, packages, and copy data files to build directoryNFTÚinclude_bytecoder   )Ú
py_modulesÚpackagesZbuild_modulesZbuild_packagesÚbuild_package_datar
   r   r   Úbyte_compiler   Úget_outputs)r   r   r   r	   Úrun!   s    		
zbuild_py.runc             C   s3   | d k r# |  j  ƒ  |  _ } | St j |  | ƒ S)Nr   )Ú_get_data_filesr   r   Ú__getattr__)r   Úattrr   r   r   r	   r   5   s    zbuild_py.__getattr__c             C   sA   t  j |  | | | ƒ \ } } | r7 |  j j | ƒ n  | | f S)N)r   Úbuild_moduler   Úappend)r   ÚmoduleZmodule_fileÚpackageÚoutfileÚcopiedr   r   r	   r!   ;   s    zbuild_py.build_modulec                s°   |  j  ƒ  g  } x™ |  j p f  D]ˆ } |  j | ƒ } t j j |  j g | j d ƒ Œ  } t | ƒ d ‰  ‡  f d d †  |  j	 | | ƒ Dƒ } | j
 | | | | f ƒ q  W| S)z?Generate list of '(package,src_dir,build_dir,filenames)' tuplesÚ.é   c                s    g  |  ] } | ˆ  d  … ‘ q S)Nr   )Ú.0Úfile)Úplenr   r	   ú
<listcomp>Q   s   	 z,build_py._get_data_files.<locals>.<listcomp>)Úanalyze_manifestr   Úget_package_dirÚosÚpathÚjoinÚ	build_libÚsplitÚlenÚfind_data_filesr"   )r   Údatar$   Úsrc_dirÚ	build_dirÚ	filenamesr   )r+   r	   r   A   s    
%%zbuild_py._get_data_filesc             C   s“   |  j  j d g  ƒ |  j  j | g  ƒ } |  j j | g  ƒ d d … } x6 | D]. } | j t t j j | t | ƒ ƒ ƒ ƒ qN W|  j	 | | | ƒ S)z6Return filenames for package's data files in 'src_dir'Ú N)
r   ÚgetÚmanifest_filesÚextendr   r/   r0   r1   r   Úexclude_data_files)r   r$   r7   Úglobsr   Úpatternr   r   r	   r5   V   s    ,zbuild_py.find_data_filesc       
      C   sÍ   xÆ |  j  D]» \ } } } } x¦ | D]ž } t j j | | ƒ } |  j t j j | ƒ ƒ t j j | | ƒ } |  j | | ƒ \ } }	 t j j | ƒ } |	 r# | |  j j	 k r# |  j
 j | ƒ q# q# Wq
 Wd S)z$Copy data files into build directoryN)r   r/   r0   r1   ÚmkpathÚdirnameÚ	copy_fileÚabspathr   Zconvert_2to3_doctestsr   r"   )
r   r$   r7   r8   r9   ÚfilenameÚtargetÚsrcfileÚoutfr&   r   r   r	   r   `   s    zbuild_py.build_package_datac             C   s\  i  |  _  } |  j j s d  Si  } x0 |  j p2 f  D] } | | t |  j | ƒ ƒ <q3 W|  j d ƒ |  j d ƒ } xã | j j	 D]Õ } t
 j j t | ƒ ƒ \ } } d  } | }	 xU | r| | k r| | k r| } t
 j j | ƒ \ } }
 t
 j j |
 | ƒ } q² W| | k r | j d ƒ r4| |	 k r4q n  | j | | g  ƒ j | ƒ q q Wd  S)NÚegg_infoz.py)r<   r   Zinclude_package_datar   Úassert_relativer.   Úrun_commandÚget_finalized_commandÚfilelistr   r/   r0   r3   r1   ÚendswithÚ
setdefaultr"   )r   ZmfZsrc_dirsr$   Zei_cmdr0   ÚdÚfÚprevZoldfZdfr   r   r	   r-   l   s(    !zbuild_py.analyze_manifestc             C   s   d  S)Nr   )r   r   r   r	   Úget_data_files„   s    zbuild_py.get_data_filesz2.4r(   c             C   s$   t  j |  | ƒ d d „  |  j Dƒ S)aj  Return complete list of files copied to the build directory

            This includes both '.py' files and data files, as well as '.pyc'
            and '.pyo' files if 'include_bytecode' is true.  (This method is
            needed for the 'install_lib' command to do its job properly, and to
            generate a correct installation manifest.)
            c             S   s>   g  |  ]4 \ } } } } | D] } t  j j | | ƒ ‘ q q Sr   )r/   r0   r1   )r)   r$   r7   r8   r9   rE   r   r   r	   r,   �   s   	z(build_py.get_outputs.<locals>.<listcomp>)r   r   r   )r   r   r   r   r	   r   ‡   s    	zbuild_py.get_outputsc             C   s÷   y |  j  | SWn t k
 r# Yn Xt j |  | | ƒ } | |  j  | <| sZ |  j j r^ | Sx; |  j j D]) } | | k s� | j | d ƒ rk Pqk qk W| St | d ƒ } d j ƒ  | j	 ƒ  k ré d d l
 m } | d | f ƒ ‚ n  | j ƒ  | S)z8Check namespace packages' __init__ for declare_namespacer'   ZrbUÚdeclare_namespacer   )ÚDistutilsErrorzÀNamespace package problem: %s is a namespace package, but its
__init__.py does not call declare_namespace()! Please fix it.
(See the setuptools manual under "Namespace Packages" for details.)
)Úpackages_checkedÚKeyErrorr   Úcheck_packager   Znamespace_packagesÚ
startswithÚopenÚencodeÚreadÚdistutils.errorsrU   Úclose)r   r$   Úpackage_dirZinit_pyÚpkgrQ   rU   r   r   r	   rX   •   s(    
zbuild_py.check_packagec             C   s   i  |  _  t j |  ƒ d  S)N)rV   r   Úinitialize_options)r   r   r   r	   ra   ´   s    	zbuild_py.initialize_optionsc             C   sA   t  j |  | ƒ } |  j j d  k	 r= t j j |  j j | ƒ S| S)N)r   r.   r   Zsrc_rootr/   r0   r1   )r   r$   Úresr   r   r	   r.   ¸   s    zbuild_py.get_package_dirc                sœ   |  j  j d g  ƒ |  j  j | g  ƒ } g  ‰  x< | D]4 } ˆ  j t j | t j j | t | ƒ ƒ ƒ ƒ q5 Wt	 j
 ˆ  ƒ ‰  i  ‰ ‡  ‡ f d d †  | Dƒ S)z6Filter filenames for package's data files in 'src_dir'r:   c                s@   g  |  ]6 } | ˆ  k r | ˆ k r ˆ j  | d  ƒ r | ‘ q S)r(   )rO   )r)   rQ   )ÚbadÚseenr   r	   r,   Ì   s   	 z/build_py.exclude_data_files.<locals>.<listcomp>)r   r;   r=   ÚfnmatchÚfilterr/   r0   r1   r   ÚdictÚfromkeys)r   r$   r7   r   r?   r@   r   )rc   rd   r	   r>   ¾   s    &zbuild_py.exclude_data_filesN)r   r   r   Ú__doc__r   r   r   r!   r   r5   r   r-   rS   ÚsysÚversionr   rX   ra   r.   r>   r   r   r   r	   r      s    
r   c             C   sO   t  j j |  ƒ s |  Sd d l m } t j d ƒ j ƒ  |  } | | ƒ ‚ d  S)Nr   )ÚDistutilsSetupErrorzÓ
        Error: setup script specifies an absolute path:

            %s

        setup() arguments must *always* be /-separated paths relative to the
        setup.py directory, *never* absolute paths.
        )r/   r0   Úisabsr]   rl   ÚtextwrapÚdedentÚlstrip)r0   rl   Úmsgr   r   r	   rJ   Ñ   s    rJ   )r/   rj   re   rn   Zdistutils.command.build_pyr   r   Údistutils.utilr   r   Zsetuptools.lib2to3_exr   ÚImportErrorrJ   r   r   r   r	   Ú<module>   s   Á