ó
¦V]c           @@  sÑ  d  Z  d d l m Z e Z d d l Z d d l Z d d l m Z d d „ Z	 e j
 ƒ  Z e	 d ƒ Z e	 d ƒ Z e	 d	 ƒ Z e	 d
 ƒ Z e e k r¡ d Z n e j j e d ƒ d Z e	 d e j j d d ƒ ƒ Z e	 d ƒ d e j j d d ƒ Z e	 d e j j d e ƒ ƒ Z e	 d ƒ Z e	 d ƒ Z e	 d ƒ Z e j	 d ƒ Z d „  Z d „  Z e d „ Z d „  Z d „  Z d d „ Z  d  d „ Z! d! e" d „ Z# d „  Z$ e% d k rÍe$ e j& d ƒ n  d S("   sÆ   
Compile a Python script into an executable that embeds CPython and run it.
Requires CPython to be built as a shared library ('libpythonX.Y').

Basic usage:

    python cythonrun somefile.py [ARGS]
i    (   t   absolute_importN(   t	   sysconfigt    c         C@  s   t  j |  ƒ p | S(   N(   R   t   get_config_var(   t   namet   default(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyR      s    t   LIBDIRt   LIBPLt   LIBRARYt	   LDLIBRARYi   t   CCt   CFLAGSt    t   LINKCCt   LINKFORSHAREDt   LIBSt   SYSLIBSt   EXEc         G@  s4   t  r0 | r |  | }  n  t j j |  d ƒ n  d  S(   Ns   
(   t   DEBUGt   syst   stderrt   write(   t   msgt   args(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   _debug)   s    c           C@  s    t  d t ƒ t  d t ƒ t  d t ƒ t  d t ƒ t  d t ƒ t  d t ƒ t  d t ƒ t  d t ƒ t  d	 t	 ƒ t  d
 t
 ƒ t  d t ƒ t  d t ƒ d  S(   Ns
   INCDIR: %ss   LIBDIR1: %ss   LIBDIR2: %ss	   PYLIB: %ss   PYLIB_DYN: %ss   CC: %ss
   CFLAGS: %ss
   LINKCC: %ss   LINKFORSHARED: %ss   LIBS: %ss   SYSLIBS: %ss   EXE_EXT: %s(   R   t   INCDIRt   LIBDIR1t   LIBDIR2t   PYLIBt	   PYLIB_DYNR
   R   R   R   R   R   t   EXE_EXT(    (    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   dump_config/   s    c         C@  s—   | r" d j  |  ƒ }  t |  ƒ n t d j  |  ƒ ƒ y d d  l } Wn  t k
 rg t j |  ƒ } n X| j |  d | ƒ} | r“ t j | ƒ n  d  S(   NR   i    t   shell(	   t   joinR   t
   subprocesst   ImportErrort   ost   systemt   callR   t   exit(   t   cmdR    R"   t
   returncode(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   runcmd=   s    c         C@  st   t  t d |  t |  d d t d t g t r8 d t pJ t j j t t	 ƒ g t
 j ƒ  t j ƒ  t j ƒ  ƒ d  S(   Ns   -os   .os   -Ls   -l(   R*   R   R   R   R   R   R$   t   pathR!   R   R   t   splitR   R   (   t   basename(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   clinkN   s    c         C@  s6   t  t d d |  d |  d d t g t j ƒ  ƒ d  S(   Ns   -cs   -os   .os   .cs   -I(   R*   R
   R   R   R,   (   R-   (    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   ccompileS   s    c         C@  s   d d l  m } m } m } | j t | p. d ƒ d |  g ƒ \ } } t d | j |  ƒ | j | | ƒ } | j	 d k r‹ t
 j d ƒ n  d  S(   Ni   (   t   Versiont   CmdLinet   Mains   --embeds   Using Cython %s to compile %si    i   (    (   t   CompilerR0   R1   R2   t   parse_command_linet   listR   t   versiont   compilet
   num_errorsR   R'   (   t
   input_filet   optionsR0   R1   R2   t   sourcest   result(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt	   cycompileV   s    +c         C@  s-   t  t j j |  ƒ g t | ƒ d t ƒd  S(   NR    (   R*   R$   R+   t   abspathR5   t   False(   t   program_nameR   (    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt	   exec_file^   s    c         C@  sß   t  j j |  ƒ d } | t } | rZ t  j j | ƒ t  j j |  ƒ k rZ t d ƒ ‚ n  | rº t  j j | ƒ rº t  j j |  ƒ rº t  j j |  ƒ t  j j | ƒ k rº t d | ƒ | St	 |  | ƒ t
 | ƒ t | ƒ | S(   si   
    Build an executable program from a Cython module.

    Returns the name of the executable file.
    i    s?   Input and output file names are the same, refusing to overwrites'   File is up to date, not regenerating %s(   R$   R+   t   splitextR   R>   t
   ValueErrort   existst   getmtimeR   R=   R/   R.   (   R9   t   compiler_argst   forceR-   t   exe_file(    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   builda   s    
++$

c         C@  s«   g  } d } x| t |  ƒ D]b \ } } | j d ƒ rD | j | ƒ n1 | d k r` | j | ƒ n | } |  | d }  P| } q Wt d ƒ ‚ t | | ƒ } t | |  ƒ d S(   s›   
    Build an executable program from a Cython module and runs it.

    Arguments after the module name will be passed verbatimely to the
    program.
    t   -s   -Xs   --directivei   s   no input file providedN(   s   -Xs   --directive(   t   Nonet	   enumeratet
   startswitht   appendRC   RI   RA   (   R   t   cy_argst   last_argt   it   argR9   R@   (    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   build_and_runt   s    
t   __main__i   (    (    (    ('   t   __doc__t
   __future__R    t   TrueR   R   R$   t	   distutilsR   R   t   get_python_incR   R   R   R   R   R+   RB   t   environt   getR
   R   R   R   R   R   R   R   R   R*   R.   R/   R=   RA   R?   RI   RS   t   __name__t   argv(    (    (    s;   lib/python2.7/site-packages/Cython/Build/BuildExecutable.pyt   <module>   s@   	#					