ó
è¾bc           @   s”   d  Z  d 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	 d d l
 m Z d d l m Z d	 e f d
 „  ƒ  YZ d S(   sH   distutils.command.build_py

Implements the Distutils 'build_py' command.s   $Id$iÿÿÿÿN(   t   glob(   t   Command(   t   DistutilsOptionErrort   DistutilsFileError(   t   convert_path(   t   logt   build_pyc           B   sê   e  Z d  Z d# d$ d& d' d( g Z d d g Z i d d 6Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d  „  Z d! „  Z d" „  Z RS()   s5   "build" pure Python modules (copy to build directory)s
   build-lib=t   ds   directory to "build" (copy) tot   compilet   cs   compile .py to .pycs
   no-compiles!   don't compile .py files [default]s	   optimize=t   Osl   also compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0]t   forcet   fs2   forcibly build everything (ignore file timestamps)c         C   sL   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d |  _ d |  _ d  |  _ d  S(   Ni    (	   t   Nonet	   build_libt
   py_modulest   packaget   package_datat   package_dirR   t   optimizeR   (   t   self(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   initialize_options!   s    							c         C   s  |  j  d d d ƒ |  j j |  _ |  j j |  _ |  j j |  _ i  |  _ |  j j rŽ x6 |  j j j ƒ  D] \ } } t | ƒ |  j | <qh Wn  |  j ƒ  |  _	 t
 |  j t ƒ sy; t |  j ƒ |  _ d |  j k oÞ d k n sé t ‚ Wqt t f k
 rt d ƒ ‚ qXn  d  S(	   Nt   buildR   R   i    i   s   optimize must be 0, 1, or 2(   R   R   (   R   R   (   t   set_undefined_optionst   distributiont   packagesR   R   R   t   itemsR   t   get_data_filest
   data_filest
   isinstanceR   t   intt   AssertionErrort
   ValueErrorR   (   R   t   namet   path(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   finalize_options+   s"    		)c         C   sS   |  j  r |  j ƒ  n  |  j r6 |  j ƒ  |  j ƒ  n  |  j |  j d d ƒ ƒ d  S(   Nt   include_bytecodei    (   R   t   build_modulesR   t   build_packagest   build_package_datat   byte_compilet   get_outputs(   R   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   runD   s    		
c         C   sÀ   g  } |  j  s | Sx¦ |  j  D]› } |  j | ƒ } t j j |  j g | j d ƒ Œ  } d } | rv t | ƒ d } n  g  |  j | | ƒ D] } | | ^ q‰ } | j	 | | | | f ƒ q W| S(   s?   Generate list of '(package,src_dir,build_dir,filenames)' tuplest   .i    i   (
   R   t   get_package_dirt   osR"   t   joinR   t   splitt   lent   find_data_filest   append(   R   t   dataR   t   src_dirt	   build_dirt   plent   filet	   filenames(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR   b   s    	%)c         C   s¢   |  j  j d g  ƒ |  j  j | g  ƒ } g  } xm | D]e } t t j j | t | ƒ ƒ ƒ } | j g  | D]* } | | k ri t j j | ƒ ri | ^ qi ƒ q5 W| S(   s6   Return filenames for package's data files in 'src_dir't    (	   R   t   getR    R-   R"   R.   R   t   extendt   isfile(   R   R   R4   t   globst   filest   patternt   filelistt   fn(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR1   z   s    !#c         C   sˆ   x |  j  D]v \ } } } } xa | D]Y } t j j | | ƒ } |  j t j j | ƒ ƒ |  j t j j | | ƒ | d t ƒq# Wq
 Wd S(   s$   Copy data files into build directoryt   preserve_modeN(   R   R-   R"   R.   t   mkpatht   dirnamet	   copy_filet   False(   R   R   R4   R5   R8   t   filenamet   target(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR'   ‡   s    c         C   s   | j  d ƒ } |  j s5 | r. t j j | Œ  Sd SnÇ g  } x¾ | r° y |  j d j | ƒ } Wn, t k
 rŒ | j d | d ƒ | d =q> X| j d | ƒ t j j | Œ  Sq> W|  j j d ƒ } | d k	 râ | j d | ƒ n  | rø t j j | Œ  Sd Sd S(   s½   Return the directory, relative to the top of the source
           distribution, where package 'package' should be found
           (at least according to the 'package_dir' option, if any).R+   R9   i    iÿÿÿÿN(	   R/   R   R-   R"   R.   t   KeyErrort   insertR:   R   (   R   R   R"   t   tailt   pdir(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR,      s(    			c         C   s¥   | d k rY t  j j | ƒ s1 t d | ƒ ‚ n  t  j j | ƒ sY t d | ƒ ‚ qY n  | r¡ t  j j | d ƒ } t  j j | ƒ rŠ | St j d d | ƒ n  d  S(   NR9   s%   package directory '%s' does not exists>   supposed package directory '%s' exists, but is not a directorys   __init__.pys!   package init file '%s' not found s   (or not a regular file)(
   R-   R"   t   existsR   t   isdirR.   R<   R   t   warnR   (   R   R   R   t   init_py(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   check_package¸   s    	c         C   s1   t  j j | ƒ s) t j d | | ƒ t St Sd  S(   Ns!   file %s (for module %s) not found(   R-   R"   R<   R   RO   RF   t   True(   R   t   modulet   module_file(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   check_moduleÓ   s    c   	      C   sÈ   |  j  | | ƒ t t j j | d ƒ ƒ } g  } t j j |  j j ƒ } xx | D]p } t j j | ƒ } | | k r¯ t j j t j j	 | ƒ ƒ d } | j
 | | | f ƒ qP |  j d | ƒ qP W| S(   Ns   *.pyi    s   excluding %s(   RQ   R    R-   R"   R.   t   abspathR   t   script_namet   splitextt   basenameR2   t   debug_print(	   R   R   R   t   module_filest   modulest   setup_scriptR   t   abs_fRS   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   find_package_modulesÚ   s    "c         C   s!  i  } g  } x|  j  D]} | j d ƒ } d j | d d !ƒ } | d } y | | \ } } Wn& t k
 r‡ |  j | ƒ } d } n X| sÒ |  j | | ƒ }	 | d f | | <|	 rÒ | j | d |	 f ƒ qÒ n  t j j | | d ƒ }
 |  j	 | |
 ƒ sq n  | j | | |
 f ƒ q W| S(   sÈ  Finds individually-specified Python modules, ie. those listed by
        module name in 'self.py_modules'.  Returns a list of tuples (package,
        module_base, filename): 'package' is a tuple of the path through
        package-space to the module; 'module_base' is the bare (no
        packages, no dots) module name, and 'filename' is the path to the
        ".py" file (relative to the distribution root) that implements the
        module.
        R+   i    iÿÿÿÿi   t   __init__s   .py(
   R   R/   R.   RI   R,   RQ   R2   R-   R"   RU   (   R   R   R\   RS   R"   R   t   module_baseR   t   checkedRP   RT   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   find_modulesé   s*    

c         C   sw   g  } |  j  r% | j |  j ƒ  ƒ n  |  j rs xB |  j D]4 } |  j | ƒ } |  j | | ƒ } | j | ƒ q8 Wn  | S(   s4  Compute the list of all modules that will be built, whether
        they are specified one-module-at-a-time ('self.py_modules') or
        by whole packages ('self.packages').  Return a list of tuples
        (package, module, module_file), just like 'find_modules()' and
        'find_package_modules()' do.(   R   R;   Rc   R   R,   R_   (   R   R\   R   R   t   m(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   find_all_modules  s    		c         C   s!   g  |  j  ƒ  D] } | d ^ q S(   Niÿÿÿÿ(   Re   (   R   RS   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   get_source_files-  s    c         C   s.   | g t  | ƒ | d g } t j j | Œ  S(   Ns   .py(   t   listR-   R"   R.   (   R   R5   R   RS   t   outfile_path(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   get_module_outfile0  s    i   c         C   sõ   |  j  ƒ  } g  } x” | D]Œ \ } } } | j d ƒ } |  j |  j | | ƒ } | j | ƒ | r |  j r | j | d ƒ n  |  j d k r¥ | j | d ƒ q¥ q q W| g  |  j D]4 \ } } }	 }
 |
 D] } t j	 j
 |	 | ƒ ^ qÌ q¶ 7} | S(   NR+   R	   i    t   o(   Re   R/   Ri   R   R2   R   R   R   R-   R"   R.   (   R   R$   R\   t   outputsR   RS   RT   RG   R4   R5   R8   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR)   4  s     	)c         C   s’   t  | t ƒ r! | j d ƒ } n$ t  | t t f ƒ sE t d ƒ ‚ n  |  j |  j | | ƒ } t j	 j
 | ƒ } |  j | ƒ |  j | | d d ƒS(   NR+   s:   'package' must be a string (dot-separated), list, or tupleRB   i    (   R   t   strR/   Rg   t   tuplet	   TypeErrorRi   R   R-   R"   RD   RC   RE   (   R   RS   RT   R   t   outfilet   dir(    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   build_moduleI  s    c         C   s=   |  j  ƒ  } x* | D]" \ } } } |  j | | | ƒ q Wd  S(   N(   Rc   Rq   (   R   R\   R   RS   RT   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR%   X  s    c         C   sx   xq |  j  D]f } |  j | ƒ } |  j | | ƒ } x< | D]4 \ } } } | | k sY t ‚ |  j | | | ƒ q8 Wq
 Wd  S(   N(   R   R,   R_   R   Rq   (   R   R   R   R\   t   package_RS   RT   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR&   b  s    c      
   C   sË   t  j r |  j d ƒ d  Sd d l m } |  j } | d t j k rV | t j } n  |  j rŠ | | d d d |  j	 d | d |  j
 ƒn  |  j d k rÇ | | d |  j d |  j	 d | d |  j
 ƒn  d  S(	   Ns%   byte-compiling is disabled, skipping.iÿÿÿÿ(   R(   R   i    R   t   prefixt   dry_run(   t   syst   dont_write_bytecodeRO   t   distutils.utilR(   R   R-   t   sepR   R   Rt   R   (   R   R>   R(   Rs   (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR(   w  s    			(   s
   build-lib=R   s   directory to "build" (copy) to(   R   R	   s   compile .py to .pycN(   s
   no-compileNs!   don't compile .py files [default](   s	   optimize=R
   sl   also compile with optimization: -O1 for "python -O", -O2 for "python -OO", and -O0 to disable [default: -O0](   R   R   s2   forcibly build everything (ignore file timestamps)(   t   __name__t
   __module__t   descriptionR   t   user_optionst   boolean_optionst   negative_optR   R#   R*   R   R1   R'   R,   RQ   RU   R_   Rc   Re   Rf   Ri   R)   Rq   R%   R&   R(   (    (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyR      s8    		
							(				4					
	(   t   __doc__t   __revision__R-   Ru   R    t   distutils.coreR   t   distutils.errorsR   R   Rw   R   t	   distutilsR   R   (    (    (    s0   /usr/lib/python2.7/distutils/command/build_py.pyt   <module>   s   