ó
'ØNc        	   @   sŲ  d  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 l Z d d l Z d d l Z d d l 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"   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  e e d0  Z! e!   Z" d1   Z# d S(2   sm   
Distutils convenience functionality.

Don't use this outside of Twisted.

Maintainer: Christopher Armstrong
i’’’’(   t   build_scriptst   install_datat	   build_extt   build_py(   t   CompileError(   t   core(   t	   ExtensionNt   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-   h   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   7   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   n   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(   sO   
    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 |  } x3 d d d g D]" } | | k rw | j |  qw qw Wt 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   .svns   _preamble.pys   _preamble.pyc(   R/   R2   R3   Rq   R0   R`   Rp   t   isfile(   RB   t   basedirt	   scriptdirt   thingiest   specialExclusionRu   (    (    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_extensions:  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   L  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_conftestT  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_helper\  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_headerk  s    (   R   R   R   R   R   R   R¤   R§   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyRA   4  s   				c         C   st   y | j    d k SWnY t k
 ro y  |  j \ } } } | d k SWn t k
 rW n Xd |  j k rk t St SXd S(   s¦  
    Checks if this implementation is CPython.

    On recent versions of Python, will use C{platform.python_implementation}.
    On 2.5, it will try to extract the implementation from sys.subversion. On
    older versions (currently the only supported older version is 2.4), checks
    if C{__pypy__} is in C{sys.modules}, since PyPy is the implementation we
    really care about. If it isn't, assumes CPython.

    This takes C{sys} and C{platform} kwargs that by default use the real
    modules. You shouldn't care about these -- they are for testing purposes
    only.

    @return: C{False} if the implementation is definitely not CPython, C{True}
        otherwise.
    t   CPythont   __pypy__N(   t   python_implementationt   AttributeErrort
   subversiont   modulesR”   R   (   R>   t   platformt   implementationt   _(    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   _checkCPythonu  s    c         C   s   |  j  d  S(   s   
    Checks if the header for building epoll (C{sys/epoll.h}) is available.

    @return: C{True} if the header is available, C{False} otherwise.
    s   sys/epoll.h(   R§   (   R   (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt	   _hasEpoll  s    ($   R   t   distutils.commandR    R   R   R   t   distutils.errorsR   t	   distutilsR   t   distutils.coreR   RQ   R/   R®   R>   t   twisted_subprojectsR   R   R   R5   RO   RP   RU   R^   Ro   R:   R4   R   R@   R=   R<   RA   R±   t
   _isCPythonR²   (    (    (    s7   /usr/lib/python2.7/dist-packages/twisted/python/dist.pyt   <module>   s<   "			7		'
A#	