ó
r¦yMc        	   @   s«  d  Z  d d l Z d d l Z d d l m Z m Z m Z m Z d d l m	 Z	 d d l
 m Z d d l m Z d d d	 d
 d d d d d g	 Z d e f d „  ƒ  YZ d „  Z d „  Z d d „ Z d d d d d d d g Z d d d d  d! g Z d d l Z d" „  Z d# „  Z d d d$ „ Z d d d d d% „ Z d& d' „ Z d( e j f d) „  ƒ  YZ d* e j f d+ „  ƒ  YZ d, e j f d- „  ƒ  YZ d. e j f d/ „  ƒ  YZ d S(0   sm   
Distutils convenience functionality.

Don't use this outside of Twisted.

Maintainer: Christopher Armstrong
iÿÿÿÿN(   t   build_scriptst   install_datat	   build_extt   build_py(   t   CompileError(   t   core(   t	   Extensiont   concht   loret   mailt   namest   newst   pairt   runnert   webt   wordst   ConditionalExtensionc           B   s   e  Z d  Z d „  Z RS(   sj  
    An extension module that will only be compiled if certain conditions are
    met.

    @param condition: A callable of one argument which returns True or False to
        indicate whether the extension should be built. The argument is an
        instance of L{build_ext_twisted}, which has useful methods for checking
        things about the platform.
    c         O   s/   | j  d d „  ƒ |  _ t j |  | | Ž d  S(   Nt	   conditionc         S   s   t  S(   N(   t   True(   t   builder(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   <lambda>   s    (   t   popR   R   t   __init__(   t   selft   argst   kwargs(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR      s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR      s   	c          K   s   t  j t |      S(   s^  
    An alternative to distutils' setup() which is specially designed
    for Twisted subprojects.

    Pass twisted_subproject=projname if you want package and data
    files to automatically be found for you.

    @param conditionalExtensions: Extensions to optionally build.
    @type conditionalExtensions: C{list} of L{ConditionalExtension}
    (   R   t   setupt   get_setup_args(   t   kw(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR   $   s    c             sö  d |  k rá d t  j d ƒ k r0 t d ƒ ‚ n  |  d } t  j j d | ƒ } t | d d ƒ|  d <t | ƒ |  d <d | d	 } t  j j | ƒ rÁ |  j d
 g  ƒ j	 | j
 d d ƒ d  ƒ n  t | d d ƒ|  d <|  d =n[ d |  k r<g  } x# |  d D] } | j	 d | ƒ qþ W|  j d
 g  ƒ j | ƒ |  d =n  d |  k r‡i t d 6t d 6|  d <t j d  d k  r‡t |  d d <q‡n  d |  k rò|  d ‰  |  d =d |  k r½ˆ  |  d <n  d t f ‡  f d †  ƒ  Y} | |  j d i  ƒ d <n  |  S(   Nt   twisted_subprojectt   twistedt   .sC   Sorry, you need to run setup.py from the toplevel source directory.t   parentt   packagest   versions   twisted/plugins/twisted_s   .pyt
   py_modulest   /iýÿÿÿt
   data_filest   pluginss   twisted.plugins.t   cmdclassR   R    i   i   i    R   t   conditionalExtensionst   ext_modulest   my_build_extc              s   e  Z ˆ  Z RS(    (   R   R   R+   (    (   t
   extensions(    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR-   b   s   R   (   i   i   i    (   t   ost   listdirt   RuntimeErrort   patht   joint   getPackagest
   getVersiont   existst
   setdefaultt   appendt   replacet   getDataFilest   extendt   install_data_twistedt   build_scripts_twistedt   syst   version_infot   build_py_twistedt   build_ext_twisted(   R   t   projnamet   projdirt   pluginR&   t   plgR-   (    (   R.   s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR   1   sB    



	R!   c         C   sd   |  d k r$ t  j j | d ƒ } n t  j j | |  d ƒ } i d d 6} t | | ƒ | d j ƒ  S(   s÷   
    Extract the version number for a given project.

    @param proj: the name of the project. Examples are "core",
    "conch", "words", "mail".

    @rtype: str
    @returns: The version number of the project, as a string like
    "2.0.0".
    R   s   _version.pys   Nothing to see hereR   R%   (   R/   R2   R3   t   execfilet   base(   t   projRG   t   vfilet   ns(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR5   g   s    s   {arch}t   CVSs
   .cvsignoret   _darcst   RCSt   SCCSs   .svns	   *.py[cdo]s   *.s[ol]s   .#*s   *~s   *.pyc         C   sv   g  |  D] } | t  k r | ^ q }  xJ t D]B } g  |  D]/ } t j | | ƒ r9 | j d ƒ r9 | ^ q9 }  q, W|  S(   sJ   Given a list of file names, return those names that should be copied.
    s   .py(   t   EXCLUDE_NAMESt   EXCLUDE_PATTERNSt   fnmatcht   endswith(   R
   t   nt   pattern(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   _filterNames‚   s     c         C   s   t  j j |  ƒ } t  j j | ƒ } | j | ƒ ru | t | ƒ } | j t  j ƒ rb | d } n  t  j j |  | ƒ St d | | f ƒ ‚ d S(   s  
    Gets 'relativee' relative to 'basepath'.

    i.e.,

    >>> relativeTo('/home/', '/home/radix/')
    'radix'
    >>> relativeTo('.', '/home/radix/Projects/Twisted') # curdir is /home/radix
    'Projects/Twisted'

    The 'relativee' must be a child of 'basepath'.
    i   s   %s is not a subpath of %sN(   R/   R2   t   abspatht
   startswitht   lent   sepR3   t
   ValueError(   RG   t	   relativeet   basepatht   relative(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt
   relativeTo   s    c         C   s  | p	 d } | p g  } g  } xô t  j |  ƒ D]ã \ } } } g  } x* t D]" } | | k rJ | j | ƒ qJ qJ Wx* | D]" }	 |	 | k rw | j |	 ƒ qw qw Wx! t | ƒ D] }
 | j |
 ƒ qª W| r. | j t | | ƒ g  | D]$ }
 t | t  j j | |
 ƒ ƒ ^ qà f ƒ q. q. W| S(   s  
    Get all the data files that should be included in this distutils Project.

    'dname' should be the path to the package that you're distributing.

    'ignore' is a list of sub-packages to ignore.  This facilitates
    disparate package hierarchies.  That's a fancy way of saying that
    the 'twisted' package doesn't want to include the 'twisted.conch'
    package, so it will pass ['conch'] as the value.

    'parent' is necessary if you're distributing a subpackage like
    twisted.conch.  'dname' should point to 'twisted/conch' and 'parent'
    should point to 'twisted'.  This ensures that your data_files are
    generated correctly, only using relative paths for the first element
    of the tuple ('twisted/conch/*').
    The default 'parent' is the current working directory.
    R"   (	   R/   t   walkRO   t   removeRU   R8   R^   R2   R3   (   t   dnamet   ignoreR#   t   resultt	   directoryt   subdirectoriest	   filenamest   resultfilest   exnamet   igt   filename(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR:   ¦   s$    9c         C   sI  | p	 d } g  } | r$ | g } n  t  j j |  ƒ } | p? g  } | | k rR g  S| d k rg g  } n  | d k r| g  } n  t  j |  ƒ } g  | D] } t  j j |  | ƒ ^ q’ }	 d | k r#| j | | | g ƒ xI t t  j j |	 ƒ D]/ }
 t	 |
 d | | g d | d | d | ƒqí Wn  g  | D] } d j | ƒ ^ q*} | S(	   s¥   
    Get all packages which are under dname. This is necessary for
    Python 2.2's distutils. Pretty similar arguments to getDataFiles,
    including 'parent'.
    t    s   __init__.pyt   pkgnamet   resultsRb   R#   R"   N(
   R/   R2   t   basenamet   NoneR0   R3   R8   t   filtert   isdirR4   (   Ra   Rl   Rm   Rb   R#   t   prefixt   bnamet   subfilest   xt   abssubfilest   subdirRc   t   res(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR4   Ì   s,    		("Rk   c         C   s¸   t  j j | d |  ƒ } t  j j | ƒ sX t  j j | d ƒ } t  j j | ƒ sX g  Sn  t  j | ƒ } d | k rƒ | j d ƒ n  t t  j j g  | D] } t  j j | | ƒ ^ q– ƒ S(   sƒ   
    Returns a list of scripts for a Twisted subproject; this works in
    any of an SVN checkout, a project-specific tarball.
    t   bins   .svn(   R/   R2   R3   Rq   R0   R`   Rp   t   isfile(   RB   t   basedirt	   scriptdirt   thingiesRu   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt
   getScriptsë   s    R@   c           B   s   e  Z d  Z d „  Z RS(   sr   
    Changes behavior in Python 2.2 to support simultaneous specification of
    `packages' and `py_modules'.
    c         C   sI   |  j  r |  j ƒ  n  |  j r, |  j ƒ  n  |  j |  j d d ƒ ƒ d  S(   Nt   include_bytecodei    (   R&   t   build_modulesR$   t   build_packagest   byte_compilet   get_outputs(   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   run  s
    		(   R   R   R   R„   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR@      s   R=   c           B   s   e  Z d  Z d „  Z RS(   s2   Renames scripts so they end with '.py' on Windows.c         C   sÃ   t  j  j |  ƒ t j d k s# d  Sx™ t j |  j ƒ D]… } t j j |  j | ƒ } | j d ƒ s6 y t j	 | d ƒ Wn) t
 k
 r£ } | j d d k r¤ q¤ n Xt j | | d ƒ q6 q6 Wd  S(   Nt   nts   .pyi   s   No such file or directory(   R    R„   R/   t   nameR0   t	   build_dirR2   R3   RR   t   unlinkt   EnvironmentErrorR   t   rename(   R   t   ft   fpatht   e(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR„     s    (   R   R   R   R„   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR=     s   R<   c           B   s   e  Z d  Z d „  Z RS(   s>   I make sure data files are installed in the package directory.c         C   s$   |  j  d d ƒ t j j |  ƒ d  S(   Nt   installt   install_libt   install_dir(   R   R   (   t   set_undefined_optionsR   t   finalize_options(   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR’   #  s    	(   R   R   R   R’   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR<   !  s   RA   c           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sb   
    Allow subclasses to easily detect and customize Extensions to
    build at install-time.
    c         C   s€   t  j d k r d g |  _ n	 g  |  _ g  |  j D] } | j |  ƒ r1 | ^ q1 |  _ x$ |  j D] } | j j |  j ƒ q_ Wd S(   s  
        Prepare the C{self.extensions} attribute (used by
        L{build_ext.build_ext}) by checking which extensions in
        L{conditionalExtensions} should be built.  In addition, if we are
        building on NT, define the WIN32 macro to 1.
        R…   t   WIN32i   N(   R“   i   (   R/   R†   t   define_macrosR+   R   R.   R;   (   R   Ru   t   ext(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   prepare_extensions1  s    	c         C   s   |  j  ƒ  t j j |  ƒ d S(   sT   
        Check to see which extension modules to build and then build them.
        N(   R–   R   t   build_extensions(   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyR—   C  s    
c         C   s:   x3 d D]+ } y t  j | ƒ Wq t k
 r1 q Xq Wd  S(   Ns
   conftest.cs
   conftest.os   conftest.obj(   s
   conftest.cs
   conftest.os   conftest.obj(   R/   Rˆ   R‰   (   R   Rj   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   _remove_conftestK  s
    c         C   sr   t  d d ƒ } zQ | j | ƒ | j ƒ  y |  j j d g d d ƒWn t k
 rZ t SXt SWd  |  j ƒ  Xd  S(   Ns
   conftest.ct   wt
   output_dirRk   (	   t   opent   writet   closet   compilert   compileR   t   FalseR   R˜   (   R   t   contentt   conftest(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   _compile_helperS  s    
c         C   s(   |  j  j d | d ƒ |  j d | ƒ S(   s„   
        Check if the given header can be included by trying to compile a file
        that contains only an #include line.
        s   checking for %s ...i    s   #include <%s>
(   Rž   t   announceR£   (   R   t   header_name(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   _check_headerb  s    (   R   R   R   R–   R—   R˜   R£   R¦   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyRA   +  s   				(    R   R>   R/   t   distutils.commandR    R   R   R   t   distutils.errorsR   t	   distutilsR   t   distutils.coreR   t   twisted_subprojectsR   R   R   R5   RO   RP   RQ   RU   R^   Ro   R:   R4   R~   R@   R=   R<   RA   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   <module>   s2   "			6		&
