
@K7]c           @   s  d  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 l m Z d d e e e d  Z d e d	  Z e d d d
  Z e d d d  Z e d d d  Z d e e e d d d d  Z e d d d  Z d   Z d d e d d  Z e j e e e e d  Z d e d e d e e e d  Z  d d  Z! e j e e e d d d  Z" e j d d  Z# e d  Z$ d   Z% d" d d d# d d d d d  Z& d e e e d d d d e e d d d  Z' d e d d e d  d!  Z( d S($   se  
This file defines the public API for conda-build.  Adding or removing functions,
or Changing arguments to anything in here should also mean changing the major
version number.

Design philosophy: put variability into config.  Make each function here accept kwargs,
but only use those kwargs in config.  Config must change to support new features elsewhere.
iN(   t   Configt   get_or_merge_configt   get_channel_urlst   DEFAULT_PREFIX_LENGTH(   t   ensure_list(   t   expand_globs(   t
   get_logger(   t
   expanduserc            si  d d l  m } m } d d l m }	 d d l m }
 d d l m } t	 | |  } | |  d | d | j
 d | d	 | d
 | } |   } x| D]\ } } } | j   s | j r x| j d
 | d | d |  D]v\ }     j   s | j r d | k s| d d k r| rf  j rfy |   d
 |   Wqf|	 |
 f k
 rb| sc  qcqfXn    j r  j j d  r  j d   _   j d =n    | | f |   j     j j j d  t   f d     j   D  f <qN  | | f | d j   j   j      j j j d  t   f d     j   D  f <q q Wq q Wt | j    S(   s   Given path to a recipe, return the MetaData object(s) representing that recipe, with jinja2
       templates evaluated.

    Returns a list of (metadata, needs_download, needs_reparse in env) tuplesi(   t   render_recipet   finalize_metadata(   t   DependencyNeedsBuildingError(   t   NoPackagesFoundError(   t   OrderedDictt   bypass_env_checkt   no_download_sourcet   configt   variantst   permit_unsatisfiable_variantst   permit_undefined_jinjat   typet   condat   outputst   target_platformc         3   s%   |  ] } |   j  j | f Vq d  S(   N(   R   t   variant(   t   .0t   var(   t   om(    s.   lib/python2.7/site-packages/conda_build/api.pys	   <genexpr>E   s   s   {}: {}c         3   s%   |  ] } |   j  j | f Vq d  S(   N(   R   R   (   R   R   (   R   (    s.   lib/python2.7/site-packages/conda_build/api.pys	   <genexpr>J   s   (   t   conda_build.renderR   R	   t   conda_build.exceptionsR
   t   conda_build.conda_interfaceR   t   collectionsR   R   R   t   skipt	   trim_skipt   get_output_metadata_sett   finalt   patht   metat   gett   parent_outputst   distR   R   t   tuplet   get_used_varst   formatR   t   namet   listt   values(   t   recipe_pathR   R   R   t   finalizeR   t   kwargsR   R	   R
   R   R   t   metadata_tuplest   output_metasR$   t   downloadt   render_in_envt   od(    (   R   s.   lib/python2.7/site-packages/conda_build/api.pyt   render   s>    				Pjc         C   s#   d d l  m } | |  | d | S(   sG   Save a rendered recipe in its final form to the path given by file_pathi(   t   output_yamlt   suppress_outputs(   R   R7   (   t   metadatat	   file_pathR8   R7   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR7   Q   s    c         K   s  d d l  m } d d l m } d d l m } t | |  } t |  d  r t |  |  r g  |  D]+ } t	 |  d k re t | d d  ^ qe }	 |	 r t
 |	  r |  }
 q8t d	 j |     no t |  |  rt |  d
 | d | d | d t | }
 n6 t |  d  s&t d j |     |  d d f g }
 g  } xL |
 D]D \ } } } | j   rv| j | |   qE| j | |   qEWt t t |    S(   s   Get output file paths for any packages that would be created by a recipe

    Both split packages (recipes with more than one output) and build matrices,
    created with variants, contribute to the list of file paths here.
    i(   t   bldpkg_path(   t   string_types(   t   get_skip_messaget   __iter__i   i    R   s    received mixed list of metas: {}R   R   R/   s"   Expecting metadata object - got {}N(   R   R;   R   R<   t   conda_build.utilsR=   R   t   hasattrt
   isinstancet   lent   allt
   ValueErrorR*   R6   t   Truet   AssertionErrort   NoneR   t   appendt   sortedR,   t   set(   t   recipe_path_or_metadataR   R   R   R0   R;   R<   R=   t   itemt   list_of_metasR9   t   outst   mt   _(    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   get_output_file_pathsW   s.    
+	c      	   K   s8   t  t  } | j d  t |  d | d | d | | S(   s   Get output file paths for any packages that would be created by a recipe

    Both split packages (recipes with more than one output) and build matrices,
    created with variants, contribute to the list of file paths here.
    s   deprecation warning: this function has been renamed to get_output_file_paths, to reflect that potentially multiple paths are returned.  This function will be removed in the conda-build 4.0 release.R   R   R   (   t   _get_loggert   __name__t   warnRQ   (   RK   R   R   R   R0   t   log(    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   get_output_file_path~   s
    	c         K   sA   t  | |  } t |  d | d | d | } t d   | D  S(   s   Check validity of input recipe path

    Verifies that recipe can be completely rendered, and that fields of the rendered recipe are
    valid fields, with some value checking.
    R   R   R   c         s   s   |  ] } | d  j    Vq d S(   i    N(   t   check_fields(   R   RO   (    (    s.   lib/python2.7/site-packages/conda_build/api.pys	   <genexpr>   s    (   R   R6   RC   (   R.   R   R   R   R0   R9   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   check   s    c         K   s  d d l  }	 d d l m }
 d d l m } d d l m } | d t t	 f k s] t
 d   t | |  } | s{ i  } n  t |   }  xJ |  D]B } t t | d  t | |  f  s t d j |    q q Wg  |  D] } t | |  r | ^ q } t | |	 j    } g  } x{ | D]s } |	 j j |  s`|	 j j |  r|	 j j |  d k ry | j | |   Wqt k
 rqqXqqWg  |  D] } t | d  r| ^ q} | j |  g  } x | D] } t | d  r| j |  q|	 j j |  s8|	 j j |	 j j |	 j   |   } n  |	 j j |  sbt d j |    n  | j |  qW| st d j |     n  |
 | | | d | d | d | d | d | S(   s   Run the build step.

    If recipe paths are provided, renders recipe before building.
    Tests built packages by default.  notest=True to skip test.iN(   t
   build_tree(   R<   (   t   find_recipes[   post must be boolean or None.  Remember, you must pass other arguments (config) by keyword.R   s)   Recipe passed was unrecognized object: {}s	   meta.yamls
   conda.yamls    Path to recipe did not exist: {}s$   No valid recipes found for input: {}t
   build_onlyt   postt   notestt   need_source_downloadR   (   s	   meta.yamls
   conda.yaml(   t   ost   conda_build.buildRY   R   R<   R?   RZ   RG   RE   t   FalseRF   R   t   _ensure_listt   anyR@   RA   RD   R*   t   _expand_globst   getcwdR#   t   isdirt   isfilet   basenameRH   t   IOErrort   extendt   isabst   normpatht   joint   exists(   t   recipe_paths_or_metadataR\   R^   R[   R]   R   R   t   statsR0   R_   RY   R<   RZ   t   recipet   pt   string_pathst   pathst   recipesRO   R9   t   absolute_recipes(    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   build   sL    !	$((*c         K   sx   d d l  m } t |  d  r+ |  j } n t | |  } | sI i  } n  | # | |  d | d | d | } Wd QX| S(   s   Run tests on either packages (.tar.bz2 or extracted) or recipe folders

    For a recipe folder, it renders the recipe enough to know what package to download, and obtains
    it from your currently configuured channels.i(   t   testR   t   move_brokenRp   N(   R`   Rx   R@   R   R   (   t    recipedir_or_package_or_metadataRy   R   Rp   R0   Rx   t   test_result(    (    s.   lib/python2.7/site-packages/conda_build/api.pyRx      s    	c          C   sa   d d l  }  |  j d g  } g  } x6 | D]. \ } } } | j d  s+ | j |  q+ q+ W| S(   s   List available skeletons for generating conda recipes from external sources.

    The returned list is generally the names of supported repositories (pypi, cran, etc.)iNs   conda_build/skeletonsRP   (   t   pkgutilt   iter_modulest
   startswithRH   (   R|   t   modulest   filesRP   R+   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   list_skeletons   s    t   .c   
         s  t    d |  } | r/ | j i | d 6 n  | rL | j i | d 6 n  | d k r{ t |  } | j i | d 6 n  t   |      j d  t |   }  t  t d d t   d t   d	 | g |  } | j	 j
 j     f d
   t    D } | j  f d   | j   D  x* t	 j
 j D] } | | k r1| | =q1q1W  / | j	 |  d | d | d | d   | }	 Wd QX|	 S(   s   Generate a conda recipe from an external repo.  Translates metadata from external
    sources into expected conda recipe format.t   versiont	   recursiveR   t
   output_dirt   skeletons   conda_build.skeletonst   globalst   localst   fromlistc            s.   i  |  ]$ } |  k r t    |  |  q S(    (   t   getattr(   R   R+   (   R   t	   func_args(    s.   lib/python2.7/site-packages/conda_build/api.pys
   <dictcomp>  s   	 c            s+   i  |  ]! \ } } |   k r | |  q S(    (    (   R   R+   t   value(   R   (    s.   lib/python2.7/site-packages/conda_build/api.pys
   <dictcomp>  s   	 R   N(   R   t   updateR   R   t   compute_build_idRb   t
   __import__R   R   t   skeletonizet   __code__t   co_varnamest   dirt   items(
   t   packagest   repoR   R   R   R   R0   t   modulet   argt   skeleton_return(    (   R   R   s.   lib/python2.7/site-packages/conda_build/api.pyR      s0    		#c         C   s5   d d l  m } t |   }  | |  | | | | |  S(   sj   Install a Python package in 'development mode'.

This works by creating a conda.pth file in site-packages.i   (   t   execute(   t   developR   Rb   (   t
   recipe_dirt   prefixt   no_pth_filet	   build_extt   cleant	   uninstallR   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   &  s    c	   
      C   s   d d l  m }	 t |  } |  j d  re |	 |  d | d | d | d | d | d	 | d
 | d | S|  j d  r t d   n t d |    d S(   s   Convert changes a package from one platform to another.  It applies only to things that are
    portable, such as pure python, or header-only C/C++ libraries.i   (   t   conda_converts   tar.bz2R   t   show_importst	   platformst   forcet   verboset   quiett   dry_runt   dependenciess   .whlsB   Conversion from wheel packages is not implemented yet, stay tuned.s   cannot convert: %sN(   t   convertR   Rb   t   endswitht   RuntimeError(
   t   package_fileR   R   R   R   R   R   R   R   R   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   0  s    t   defaultsc         C   s   d d l  m } | |   S(   sm   Check to make sure that packages in channel are installable.
    This is a consistency check for the channel.i   (   t   test_installable(   t   inspect_pkgR   (   t   channelR   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   A  s    t   packaget    c         C   sJ   d d l  m } t |   }  | |  d | d | d | d | d | d | S(	   Ni   (   t   inspect_linkagesR   t	   untrackedt   all_packagest
   show_filest   groupbyt   sysroot(   R   R   Rb   (   R   R   R   R   R   R   R   R   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   H  s    t   filenamec         C   s2   d d l  m } t |   }  | |  d | d | S(   Ni   (   t   inspect_objectsR   R   (   R   R   Rb   (   R   R   R   R   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   P  s    c         C   s   d d l  m } t d |  } t |   }  | |  |  } | rz d | GHx7 | j   D] \ } } d j | |  GHqV Wn	 d | GHt |  d k S(   Ni(   t   check_prefix_lengthst   prefix_lengths9   Packages with binary prefixes shorter than %d characters:s   {0} ({1} chars)sB   No packages found with binary prefixes shorter than %d characters.i    (   t   conda_build.tarcheckR   R    Rb   R   R*   RB   (   R   t   min_prefix_lengthR   R   t   prefix_lengthst   fnt   length(    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   inspect_prefix_lengthV  s    c         C   s   d d l  m } | |   S(   s   Return dictionaries of data that created the hash value (h????) for the provided package(s)

    Returns a dictionary with a key for each input package and a value of the dictionary loaded
    from the package's info/hash_input.json file
    i   (   t   get_hash_input(   R   R   (   R   R   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   inspect_hash_inputsf  s    i    c
         K   sb   d d l  m } t |	 |
  }	 | d |  d | d | d | d | d | d	 | d
 | d | d |	  
S(   Ni   (   t   create_metapackageR+   R   t   entry_pointst   build_stringt   build_numberR   t   homet   license_namet   summaryR   (   t   metapackageR   R   (   R+   R   R   R   R   R   R   R   R   R   R0   R   (    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   p  s    c         K   sH  d d  l  } d d l m } d d  l } d d l m } m } d d l m } d d l	 m
 } g  t |   D] } | j j |  ^ qk }  | s g  |  D] } | j |    ^ q }  n  t | |  r t |   } | j |  } Wd  QXn  xT |  D]L } | | d | d | d	 | d
 | d |	 d |
 d | d | |  d | 	q Wd  S(   Ni(   t   getpreferredencodingi   (   t   PY3R<   (   t   update_index(   R   t	   check_md5t   channel_namet   patch_generatort   threadsR   t   progresst   hotfix_source_repot   subdirst   current_index_versions(   t   yamlt   localeR   R_   t   conda_interfaceR   R<   t   conda_build.indexR   R?   R   Rb   R#   t   abspatht   decodeRA   t   opent	   safe_load(   t	   dir_pathsR   R   R   t   removeR   t   subdirR   R   R   R   R   R   R0   R   R   R_   R   R<   R   R   R#   t   f(    (    s.   lib/python2.7/site-packages/conda_build/api.pyR   {  s"    +(t   autoc   +         s  d d l  m  } d d l }	 d d l }
 d d l } d d l m } d d l m } m } d d l	 m
 } m } m } t } t | |  } i t d 6} t } g  |
 j j |   r |
 j |   n g  D]K } | j d  r |
 j j |
 j j |  |   r |
 j j |  |  ^ q } g  | D]< } |
 j j |
 j j | d	   r|
 j j | d	  ^ q} t |  } t |  rt } |  } n  | s|
 j j | j d
 j t | j   d    } n  t d | d | d | d d |  } t |  | _ g  } d } t |  |  r| rgx | D]D } d } d d l m } | | | i   } | j  | t t f  qWq|
 j j! |   d     st"   f d   | D  rt# |  d | | } qt } t } n |  } | rt$ |  } | }  | rkg  | D]' }! | |
 j j% |!  |  r|! ^ q}  t |   d k rJt& d j |     qk|  skt& d j |    qkn  t |   d k r| rt& d j |    n | }  | | j' |  d  d }" d |" j( _) n  | d k r(xM| D]B\ } }! }! |
 j j |
 j* d d d d d j | j+ d  | j+ d     }# |
 j j, | j-  }$ yw |
 j j, |#  }% y |
 j. |%  Wn t/ k
 rn Xy |
 j0 |#  Wn n Xd! j |# |$  GH|
 j1 |$ |#  Wqt2 k
 r}& t3 d" j |% t4 |&     qt3 k
 r }& t3 d# j |% t4 |&     qXqWn  | r4d$ n d%   | rL|   }' n | |	 j5 d  }' | rd&   }( d' j d( |" j( j6 d) | rd* n d) d+ |
 j j |" j( j6 |(   }) n| s2|'  | |" d, i  d- t Wd QXd&   }( d' j d( |" j( j6 d) | rd* n d) d+ |
 j j |" j( j6 |(   }) n | sGt& d.   n |  }* |' ! | |* d | d, i  d- t Wd QX|
 j j | j7 d/    }( d' j d( | j7 d) | rd* n d) d+ |
 j j | j7 |(   }) |) S(0   s   Set up either build/host or test environments, leaving you with a quick tool to debug
    your package's build or test phase.
    i(   t   fnmatchN(   R<   (   Rx   Rw   (   t   CONDA_TARBALL_EXTENSIONSt   on_wint   LoggingContextt   set_build_idt   works   metadata_conda_debug.yamls   debug_{}i  R   t   crootR   t   _prefix_lengthi
   R   t   symlink(   t   MetaDatai   c         3   s   |  ] }   | k Vq d  S(   N(    (   R   RP   (   t   ext(    s.   lib/python2.7/site-packages/conda_build/api.pys	   <genexpr>  s    s}   Specified --output-id matches more than one output ({}).  Please refine your output id so that only a single output is found.si   Specified --output-id did not match any outputs.  Available outputs are: {} Please check it and try againsx   More than one output found for this recipe ({}).  Please use the --output-id argument to filter down to a single output.i    t   usrt   localt   srcR   s   {}-{}s   package/names   package/versions*   Making debug info source symlink: {} => {}sL   You do not have the necessary permissions to create symlinks in {}
error: {}s/   Unknown error creating symlinks in {}
error: {}s   .bats   .sht   build_env_setups,   cd {work_dir} && {source} {activation_file}
t   work_dirt   sourcet   callt   activation_fileRp   t   provision_onlys   Debugging for test mode is only supported for package files that already exist. Please build your package first, then use it to create the debugging environment.t   conda_test_env_vars(8   R   t   loggingR_   t   timeR   R<   R`   Rx   Rw   R?   R   R   R   Ra   R   R#   Rf   t   listdirR~   Rm   Rg   RI   RB   RE   R   R*   t   intR   t   channel_urlsRA   t   conda_build.metadataR   RH   t   splitextRc   R6   RQ   Rh   RD   t   indexR   R   t   sept	   get_valuet   dirnamet	   meta_patht   makedirst   FileExistsErrort   unlinkR   t   PermissionErrort	   Exceptiont   strt   CRITICALR   t   test_dir(+   t)   recipe_or_package_path_or_metadata_tuplesR#   Rx   t	   output_idR   R   t   link_source_methodR0   R   R   R_   R   R<   t   run_testt	   run_buildR   R   R   t
   is_packaget   default_configt   argst   path_is_build_dirt   dt   workdirsR   t   metadatas_conda_debugR1   t   best_link_source_methodt   metadata_conda_debugR   R9   R   t   matched_outputsRP   t   target_metadatat   debug_source_loct   link_targett   dnt   et   log_contextR   t   activation_stringt
   test_input(    (   R   s.   lib/python2.7/site-packages/conda_build/api.pyt   debug  s    +<<	4	$	4				 
	!
	!"		(    (    ()   t   __doc__t   syst   _syst   conda_build.configR    R   R   R   R   R?   R   Rb   R   Rd   R   RR   t   os.pathR   RG   RE   Ra   R6   R7   RQ   RV   RX   Rw   Rx   R   R   R   R   R   R   R   R   R   R   R   R   R&  (    (    (    s.   lib/python2.7/site-packages/conda_build/api.pyt   <module>   sL   "	2&9		)			
		