B
    XM\Y                 @   s0  d Z ddlZddl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 d6d
dZd7ddZd8ddZd9ddZd:ddZd;ddZd<ddZdd Zd=ddZejd	d	d	d	fddZd>dd Zd?d"d#Zejd	d	d	d$d%fd&d'Zejd(fd)d*Zefd+d,Z d-d. Z!d@d0d1Z"dAd2d3Z#dBd4d5Z$dS )Cae  
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.
    N)Configget_or_merge_configDEFAULT_PREFIX_LENGTH)ensure_list)expand_globs)
get_logger)
expanduserTFc                s  ddl m}m} ddlm}	 ddlm}
 ddlm} t	|f|}|| ||j
|||d}| }xR|D ]H\}}}| r~|jsdx,|j|| |dD ]\}   r|jsd|ks|d d	krh|r jsy| |d
 W n" |	|
fk
r   | s Y nX  js. jdr. jd  _ jd=  ||f|   jjdt fdd  D f< q ||f|d j   jjdt fdd  D f< qW qdW t| S )zGiven 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) tuplesr   )render_recipefinalize_metadata)DependencyNeedsBuildingError)NoPackagesFoundError)OrderedDict)bypass_env_checkno_download_sourceconfigvariantspermit_unsatisfiable_variants)r   Zpermit_undefined_jinjar   typeZconda)r   outputsZtarget_platformc             3   s   | ]}| j j| fV  qd S )N)r   variant).0var)om .lib/python3.7/site-packages/conda_build/api.py	<genexpr>D   s   zrender.<locals>.<genexpr>z{}: {}c             3   s   | ]}| j j| fV  qd S )N)r   r   )r   r   )r   r   r   r   I   s   )conda_build.renderr	   r
   Zconda_build.exceptionsr   conda_build.conda_interfacer   collectionsr   r   r   skipZ	trim_skipZget_output_metadata_setfinalpathmetagetZparent_outputsZdistr   r   tupleZget_used_varsformatr   namelistvalues)recipe_pathr   r   r   finalizer   kwargsr	   r
   r   r   r   metadata_tuplesZoutput_metasr"   ZdownloadZrender_in_envZodr   )r   r   render   s>    :Jr-   c             C   s   ddl m} || ||dS )zGSave a rendered recipe in its final form to the path given by file_pathr   )output_yaml)suppress_outputs)r   r.   )metadataZ	file_pathr/   r.   r   r   r   r.   P   s    r.   c             K   s  ddl m} ddlm} ddlm} t|f|}t| drtt| |stdd | D }|rdt	|rd| }	qt
d| nJt| |rt| f|||d	d
|}	n$t| dstd| | ddfg}	g }
x8|	D ]0\}}}| r|
|| q|
|| qW ttt|
S )zGet 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.
    r   )bldpkg_path)string_types)get_skip_message__iter__c             S   s&   g | ]}t |d krt|d dqS )   r   r   )lenhasattr)r   itemr   r   r   
<listcomp>d   s    z)get_output_file_paths.<locals>.<listcomp>z received mixed list of metas: {}T)r   r   r   r*   r   z"Expecting metadata object - got {}N)r   r1   r   r2   conda_build.utilsr3   r   r7   
isinstanceall
ValueErrorr%   r-   AssertionErrorr   appendsortedr'   set)recipe_path_or_metadatar   r   r   r+   r1   r2   r3   Zlist_of_metasr0   Zoutsm_r   r   r   get_output_file_pathsV   s,    
rE   c             K   s*   t t}|d t| f|||d|S )zGet 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.
    zdeprecation 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   )_get_logger__name__warnrE   )rB   r   r   r   r+   logr   r   r   get_output_file_path}   s
    
rJ   c             K   s.   t |f|}t| |||d}tdd |D S )zCheck 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    V  qdS )r   N)Zcheck_fields)r   rC   r   r   r   r      s    zcheck.<locals>.<genexpr>)r   r-   r<   )r)   r   r   r   r+   r0   r   r   r   check   s    
rK   c          
      s  ddl }	ddlm}
 ddlm  ddlm} |dks<tdt|f|}|sPi }t	| } x2| D ]*}t
t|dt| fs^td	|q^W  fd
d| D }t||	 }g }x`|D ]X}|	j|s|	j|r|	j|dkry||| W q tk
r   wY qX qW dd | D }|| g }xt|D ]l}t|drP|| nN|	j|sx|	j|	j|	 |}|	j|std||| q4W |std| |
||||||||dS )zRun the build step.

    If recipe paths are provided, renders recipe before building.
    Tests built packages by default.  notest=True to skip test.r   N)
build_tree)r2   )find_recipe)NTFz[post must be boolean or None.  Remember, you must pass other arguments (config) by keyword.r   z)Recipe passed was unrecognized object: {}c                s   g | ]}t | r|qS r   )r;   )r   p)r2   r   r   r9      s    zbuild.<locals>.<listcomp>)z	meta.yamlz
conda.yamlc             S   s   g | ]}t |d r|qS )r   )r7   )r   rC   r   r   r   r9      s    z Path to recipe did not exist: {}z$No valid recipes found for input: {})
build_onlypostnotestneed_source_downloadr   )osconda_build.buildrL   r   r2   r:   rM   r>   r   _ensure_listanyr7   r;   r=   r%   _expand_globsgetcwdr!   isdirisfilebasenamer?   IOErrorextendisabsnormpathjoinexists)Zrecipe_paths_or_metadatarP   rR   rO   rQ   r   r   statsr+   rS   rL   rM   ZrecipeZstring_pathspathsZrecipesr0   Zabsolute_recipesr   )r2   r   build   sL    



rd   c          	   K   sV   ddl m} t| dr| j}nt|f|}|s2i }| || |||d}W dQ R X |S )zRun 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.r   )testr   )r   move_brokenrb   N)rT   re   r7   r   r   )Z recipedir_or_package_or_metadatarf   r   rb   r+   re   Ztest_resultr   r   r   re      s    
re   c              C   sD   ddl } | dg}g }x&|D ]\}}}|ds|| qW |S )zList available skeletons for generating conda recipes from external sources.

    The returned list is generally the names of supported repositories (pypi, cran, etc.)r   Nzconda_build/skeletonsrD   )pkgutiliter_modules
startswithr?   )rg   modulesfilesrD   r&   r   r   r   list_skeletons   s    
rl   .c       
   	      s  t  d|}|r|d|i |r0|d|i |dkrNt|}|d|i t f|  d t| } t tdt t |gd|}|j	j
j fdd	t D }|fd
d	| D  xt	j
jD ]}||kr||= qW  " |j	| f||| d|}	W dQ R X |	S )zGenerate a conda recipe from an external repo.  Translates metadata from external
    sources into expected conda recipe format.version	recursiverm   
output_dirZskeletonzconda_build.skeletons)globalslocalsfromlistc                s    i | ]}|krt  ||qS r   )getattr)r   r&   )r   	func_argsr   r   
<dictcomp>  s    zskeletonize.<locals>.<dictcomp>c                s   i | ]\}}| kr||qS r   r   )r   r&   value)ru   r   r   rv     s    )rp   rn   ro   r   N)rt   updater   r   Zcompute_build_idrU   
__import__rq   rr   skeletonize__code__co_varnamesdiritems)
packagesZreporp   rn   ro   r   r+   moduleargZskeleton_returnr   )r   ru   r   rz      s0    


rz   c             C   s&   ddl m} t| } || |||||S )zjInstall a Python package in 'development mode'.

This works by creating a conda.pth file in site-packages.   )execute)developr   rU   )Z
recipe_dirprefixZno_pth_fileZ	build_extZcleanZ	uninstallr   r   r   r   r   %  s    r   c	       
      C   s\   ddl m}	 t|}| dr8|	| ||||||||d	S | drLtdntd|  dS )	zConvert 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.r   )conda_convertztar.bz2)rp   show_imports	platformsforceverbosequietdry_rundependenciesz.whlzBConversion from wheel packages is not implemented yet, stay tuned.zcannot convert: %sN)convertr   rU   endswithRuntimeError)
Zpackage_filerp   r   r   r   r   r   r   r   r   r   r   r   r   /  s    



r   defaultsc             C   s   ddl m} || S )zmCheck to make sure that packages in channel are installable.
    This is a consistency check for the channel.r   )test_installable)inspect_pkgr   )Zchannelr   r   r   r   r   @  s    r   package c          	   C   s*   ddl m} t| } || ||||||dS )Nr   )inspect_linkages)r   	untrackedall_packages
show_filesgroupbysysroot)r   r   rU   )r   r   r   r   r   r   r   r   r   r   r   r   G  s    
r   filenamec             C   s"   ddl m} t| } || ||dS )Nr   )inspect_objects)r   r   )r   r   rU   )r   r   r   r   r   r   r   r   O  s    r   c             C   sx   ddl m} t|d}t| } || |}|r`td|  x2| D ]\}}td|| qBW ntd|  t|dkS )Nr   )check_prefix_lengths)prefix_lengthz9Packages with binary prefixes shorter than %d characters:z{0} ({1} chars)zBNo packages found with binary prefixes shorter than %d characters.)Zconda_build.tarcheckr   r   rU   printr~   r%   r6   )r   Zmin_prefix_lengthr   r   Zprefix_lengthsfnlengthr   r   r   inspect_prefix_lengthU  s    

r   c             C   s   ddl m} || S )zReturn 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
    r   )get_hash_input)r   r   )r   r   r   r   r   inspect_hash_inputse  s    r   r   c
             K   s4   ddl m} t|	f|
}	|| |||||||||	d
S )Nr   )create_metapackage)
r&   rn   entry_pointsbuild_stringbuild_numberr   homelicense_namesummaryr   )Zmetapackager   r   )r&   rn   r   r   r   r   r   r   r   r   r+   r   r   r   r   r   o  s    r   c                s   ddl m  dd lddlm} ddlm} ddlm} fddt	| D } |sd fd	d| D } x*| D ]"}|||||||	|
|||d
	 qjW d S )Nr   )getpreferredencodingr   )PY3)update_index)r   c                s   g | ]} j |qS r   )r!   abspath)r   r!   )rS   r   r   r9     s    z update_index.<locals>.<listcomp>c                s   g | ]}|   qS r   )decode)r   r!   )r   r   r   r9     s    )	check_md5channel_namepatch_generatorthreadsr   progresshotfix_source_repoZsubdirs)
Zlocaler   rS   Zconda_interfacer   Zconda_build.indexr   r:   r   rU   )Z	dir_pathsr   r   r   remover   Zsubdirr   r   r   r   r   r+   r   r   r   r!   r   )r   rS   r   r   z  s    
r   c          	      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} d}t|f|}ddi}|sj|jd	t| d
 }tf |||dd|}g }t| |	rj| d   rt fdd|D st| fd|i|}nd}d}n| }|rt|}|}rhfdd|D }t|dkrTtd|n|shtd|t|dkrtd|n|}|||d  d }d|j_|rdnd |r| }n||jd }|s,| ||i dd W dQ R X d  }dj|jj|rdndj|jj|d}np|s<tdn| }| |
||i dd  W dQ R X j|jd!  }dj|j|rdndj|j|d}|S )"zSet up either build/host or test environments, leaving you with a quick tool to debug
    your package's build or test phase.
    r   )fnmatchN)r2   )re   rd   )CONDA_TARBALL_EXTENSIONSon_winLoggingContextFZset_build_idzdebug_{}i  
   )r   crootr   _prefix_lengthr   c             3   s   | ]} |kV  qd S )Nr   )r   rD   )extr   r   r     s    zdebug.<locals>.<genexpr>r   Tc                s"   g | ]} j |r|qS r   )r!   r[   )r   rD   )r   rS   	output_idr   r   r9     s    zdebug.<locals>.<listcomp>z}Specified --output-id matches more than one output ({}).  Please refine your output id so that only a single output is found.ziSpecified --output-id did not match any outputs.  Available outputs are: {} Please check it and try againzxMore than one output found for this recipe ({}).  Please use the --output-id argument to filter down to a single output.z.batz.sh)rb   provision_onlyZbuild_env_setupz,cd {work_dir} && {source} {activation_file}
Zcallsource)work_dirr   activation_filezDebugging 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.)r   rb   r   Zconda_test_env_vars) r   loggingrS   timer   r2   rT   re   rd   r:   r   r   r   r   r!   r`   r   r%   intr;   splitextrV   r-   rE   r6   r=   indexr   r   ZCRITICALr   Ztest_dir)Z)recipe_or_package_path_or_metadata_tuplesr!   re   r   r   r   r+   r   r   r2   Zrun_testZ	run_buildr   r   r   
is_packageZdefault_configargsr,   r   Zmatched_outputsZtarget_metadataZlog_contextr   Zactivation_stringZ
test_inputr   )r   r   rS   r   r   debug  sz    "


r   )NNTTF)NF)FNN)FNN)FNN)NTFFNNN)TNN)rm   NFN)rm   FNFNFTF)r   )r   Nr   r   NNNN)NFFFNNNNFFN)NFNNT)%__doc__sys_sysZconda_build.configr   r   r   r   r:   r   rU   r   rW   r   rF   os.pathr   r-   r.   rE   rJ   rK   rd   re   rl   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sL    
2
 
& 

 
9
 
)	 


  
	  
 