σ
@K7]c           @` sύ   d  d l  m Z m Z m Z d  d l m Z m Z m Z m Z m	 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 m Z d  d l m Z d	   Z d
   Z d   Z d   Z d   Z d   Z e j e e e e d  Z d S(   i    (   t   absolute_importt   divisiont   print_function(   t   joint   isdirt   abspatht
   expandusert   existsNi   (   t   string_types(   t   mk_relative_osx(   t   check_call_envt   rec_globt   get_site_packages(   t   find_executablec         C` sP   t  |  d g  } x7 | D]/ } t j d k r> t | |  q t d  q Wd S(   sμ  
    invokes functions in post module to relink to libraries in conda env

    :param pkg_path: look for shared objects to relink in pkg_path
    :param build_prefix: path to conda environment which contains lib/. to find
        runtime libraries.

    .. note:: develop mode builds the extensions in place and makes a link to
        package in site-packages/. The build_prefix points to conda environment
        since runtime libraries should be loaded from environment's lib/. first
    s   .sot   darwins"   Nothing to do on Linux or Windows.N(   R   t   syst   platformR	   t   print(   t   pkg_patht   build_prefixt	   bin_filest   b_file(    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   relink_sharedobjects   s
    c      	   C` s   t  |  d  } t | d  k } t | d   } | j   } Wd QX| d | k rf t d |  n | j | d  t d |  Wd QXd S(   s  
    Append pkg_path to conda.pth in site-packages directory for current
    environment. Only add path if it doens't already exist.

    :param sp_dir: path to site-packages/. directory
    :param pkg_path: the package path to append to site-packes/. dir.
    s	   conda.ptht   at   rNs   
s   path exists, skipping s   added (   R   t   opent	   readlinesR   t   write(   t   sp_dirR   t   c_filet   ft   cft   pkgs_in_dev_mode(    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   write_to_conda_pth)   s    c         C` s8   t  |  d  } t |  s4 t j d j |    n  | S(   s3    Return full path to setup.py or exit if not found s   setup.pys"   No setup.py found in {0}. Exiting.(   R   R   R   t   exitt   format(   t   path_t   setup_py(    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   get_setup_pyA   s    c         C` s>   d |  d g } t  |  t d d j |   t d  d S(   sZ   
    This invokes:
    $ python setup.py clean

    :param setup_py: path to setup.py
    t   pythont   cleans   Completed: t    s/   ===============================================N(   R
   R   R   (   R%   t   cmd(    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   _cleanL   s    
c         C` sA   d |  d d g } t  |  t d d j |   t d  d S(   sΛ   
    Define a develop function - similar to build function
    todo: need to test on win32 and linux

    It invokes:
    $ python setup.py build_ext --inplace

    :param setup_py: path to setup.py
    R'   t	   build_exts	   --inplaces   Completed: R)   s/   ===============================================N(   R
   R   R   (   R%   R*   (    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt
   _build_extZ   s    
c         C` sΞ   t  |  d  } t  |  d  } t } t | d  d } t | d  L } xB | D]: } | | d k ru | j |  qO t d |  t } qO WWd QXWd QX| sΊ t d |  t d	  n  t j | |  d S(
   s@  
    Look for pkg_path in conda.pth file in site-packages directory and remove
    it. If pkg_path is not found in conda.pth, it means package is not
    installed in 'development mode' via conda develop.

    :param sp_dir: path to site-packages/. directory
    :param pkg_path: the package path to be uninstalled.
    s	   conda.pths   conda.pth.tempt   wR   s   
s   uninstalled: Ns!   conda.pth does not contain path: s'   package not installed via conda develop(   R   t   FalseR   R   R   t   Truet   shutilt   move(   R   R   t   o_c_ptht   n_c_ptht   foundt   new_ct   orig_ct   line(    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt
   _uninstalll   s    	c   
      C` sF  t  |  s  t j d |  n  t d d | s8 t  t | d j t t j j	  t t j j
  f   } t |   t k r |  g }  n  x³ |  D]« } t t |   } | rΒ t | |  d  S| sΞ | rt |  }	 | rχ t |	  | sχ d  Sn  | rt |	  qn  | s#t | |  n  t | |  t d |  q Wd  S(   Ns_   Error: environment does not exist: %s
#
# Use 'conda create' to create the environment first.
#R'   t   prefixt   .s   completed operation for: (   R   R   R"   R   t   AssertionErrorR   R   t   strt   version_infot   majort   minort   typeR   R   R   R9   R&   R+   R-   R!   R   R   (
   t   recipe_dirsR:   t   no_pth_fileR,   R(   t	   uninstallR   t   pathR   R%   (    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   execute   s2    
(   t
   __future__R    R   R   t   os.pathR   R   R   R   R   R1   R   t   conda_interfaceR   t   conda_build.postR	   t   conda_build.utilsR
   R   R   t   conda_build.os_utils.externalR   R   R!   R&   R+   R-   R9   R:   R/   RF   (    (    (    s2   lib/python2.7/site-packages/conda_build/develop.pyt   <module>   s   (							