
    8xde                        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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Zd-dZ	 	 	 d.dZ	 	 	 d.dZd.dZ	 	 	 	 	 	 	 d/dZ	 	 	 d0dZd Z	 d1dZ ej!        ddddfdZ"	 	 	 	 	 	 	 	 d2dZ#d3dZ$ej!        dddddfdZ%ej!        dfd Z&efd!Z'd" Z(	 	 	 	 	 	 	 	 d4d$Z) ed%d&d'(          	 	 	 	 	 	 	 	 	 	 	 	 d5d)            Z*	 	 	 	 	 	 d6d+Z+dS )7ae  
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)dirname
expanduserjoin)Path)DEFAULT_PREFIX_LENGTH)Configget_channel_urlsget_or_merge_configensure_list)expand_globs)
get_logger   )
deprecatedTFc                 ,   ddl m} ddlm} ddlm}	 ddlm}
m} t          |fi |} || ||j
        |||          } |            }|D ]\  }}}|                                r|j        s|                    || |          D ]j\  }                                r|j        sHd|vs|d         d	k    r|r&j        s	  |
|
          n# |	|f$ r |s Y nw xY wj        s4j                            d          rj        d         _        j        d= ||f|                                j        j                            d          t-          fd                                D                       f<   ||f|j         d                                 j        j                            d          t-          fd                                D                       f<   lt5          |                                          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   )OrderedDict)NoPackagesFoundError)DependencyNeedsBuildingError)finalize_metadatarender_recipe)bypass_env_checkno_download_sourceconfigvariantspermit_unsatisfiable_variants)r   permit_undefined_jinjar   typeconda)r   outputstarget_platformc              3   @   K   | ]}|j         j        |         fV  d S Nr   variant.0varoms     /lib/python3.11/site-packages/conda_build/api.py	<genexpr>zrender.<locals>.<genexpr>V   F       " "$' "%bi&7&< =" " " " " "    z: c              3   @   K   | ]}|j         j        |         fV  d S r"   r#   r%   s     r)   r*   zrender.<locals>.<genexpr>_   r+   r,   )collectionsr   conda_build.conda_interfacer   conda_build.exceptionsr   conda_build.renderr   r   r
   r   skip	trim_skipget_output_metadata_setfinalpathmetagetparent_outputsdistr   r$   tupleget_used_varsr   namelistvalues)recipe_pathr   r   r   finalizer   kwargsr   r   r   r   r   metadata_tuplesoutput_metasr7   downloadrender_in_envodr(   s                     @r)   renderrH      s    ('''''@@@@@@CCCCCCCCCCCCCC 22622F#m)!4&C  O ;==L)8 (: (:%hyy{{ '	:&"2 '	:66.K+3|!1 7   &: &:B
 wwyy !:(8 !:R''2f:+@+@# *BH **%6%6$&B_&" &" &" %ABV#W * * *'D !*$)!* !**
  "w 327;;y+A+A 302	0BB- "	 2  =9 %GGIII-112CDD! " " " "+-+;+;+=+=" " "      =9 %!w55"''))55I-112CDD! " " " "+-+;+;+=+=" " "   ##%%&&&s   C
CCc                 *    ddl m}  || ||          S )zGSave a rendered recipe in its final form to the path given by file_pathr   )output_yaml)suppress_outputs)r1   rJ   )metadata	file_pathrK   rJ   s       r)   rJ   rJ   h   s,    ......;x=MNNNNr,   c                    ddl m} ddlm} t	          |fi |}t          | d          rGt          | t                    s2d | D             }|rt          |          r| }ndt          d|            t          | t          t          f          rt          | f|||dd|}n#t          | d	          sJ d
|              | ddfg}g }	|D ]W\  }
}}|
                                r|	                     ||
                     9|	                     ||
                     Xt          t          t!          |	                              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.
    r   )bldpkg_path)get_skip_message__iter__c                 `    g | ]+}t          |          d k    t          |d         d          ,S )   r   r   )lenhasattr)r&   items     r)   
<listcomp>z)get_output_file_paths.<locals>.<listcomp>   s=     
 
 
4yyA~~ DGX&&~~r,   zreceived mixed list of metas: T)r   r   r   rA   r   z Expecting metadata object - got N)r1   rP   conda_build.utilsrQ   r
   rV   
isinstancestrall
ValueErrorr   rH   r2   appendsortedr>   set)recipe_path_or_metadatar   r   r   rB   rP   rQ   list_of_metasrL   outsm_s               r)   get_output_file_pathsrf   o   s    /.....222222 22622F&
33 ;J= = ;
 
/
 
 
  	YS// 	Y.HHW>UWWXXX	+c4[	9	9 ;#
1
 
 
 
 #X
 
 	H 	HG.EGG	H 	H 	H -dD9:D ( (1a6688 	(KK((++,,,,KKA''''$s4yy//"""r,   c                 v    t          t                    }|                    d           t          | f|||d|S )rO   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__warnrf   )ra   r   r   r   rB   logs         r)   get_output_file_pathrm      s`     h

CHH	2  
 !-	 
   r,   c                 t    t          |fi |}t          | |||          }t          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.
    rh   c              3   J   K   | ]}|d                                           V  dS )r   N)check_fields)r&   rd   s     r)   r*   zcheck.<locals>.<genexpr>   s2      55qqt  ""555555r,   )r
   rH   r\   )r@   r   r   r   rB   rL   s         r)   checkrq      sX     !22622F-	  H 55H555555r,   c           	         ddl }	ddlm}
 ddlm} |dv s
J d            g }t          |           D ]}t          |t                    rXt          ||		                                          D ]4}	  ||          }n# t          $ r Y w xY w|                    |           5ot          |d          r|                    |           t          d|           |st          d	|             |
|t          |fi ||pi ||||
          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)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: z"No valid recipes found for input: )r   stats
build_onlypostnotestr   )osconda_build.buildrs   rY   rt   _ensure_listrZ   r[   _expand_globsgetcwdOSErrorr^   rV   r]   r
   )recipe_paths_or_metadatarw   need_source_downloadrv   rx   r   r   ru   rB   ry   rs   rt   recipesrecipes                 r)   buildr      s    III,,,,,,------&&&&	/ '&&
 G788 Q Qfc"" 
	Q'		<< ' '([00FF   Hv&&&&' VX&& 	QNN6""""OvOOPPP 
K1IKK
 
 	
 :"644V44 kr
 
 
 
s   ,A88
BBc                     ddl m} t          | d          r| j        }nt	          |fi |}|si }|5   || |||          }ddd           n# 1 swxY w Y   |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_brokenru   N)rz   r   rV   r   r
   ) recipedir_or_package_or_metadatar   r   ru   rB   r   test_results          r)   r   r   
  s     '&&&&&/:: 718$V66v66  	 

 


 d,#	
 
 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 s   AAAc                      ddl } |                     t          t          t                    d          g          }g }|D ]0\  }}}|                    d          s|                    |           1|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   N	skeletonsre   )pkgutiliter_modulesr   r   __file__
startswithr^   )r   modulesfilesre   r=   s        r)   list_skeletonsr   /  s{    
 NNN""D):):K$H$H#IJJGE  
4s## 	LLLr,   .c           	        
 t          d|          }|r|                    d|i           |r|                    d|i           |dk    r&t          |          }|                    d|i           t          fi |                    d           t          |           } t          t          dt                      t                      |g          |          }|j	        j
        j        

fdt                    D             }|                    
fd	|                                D                        t          j
        j        D ]	}||v r||= 
5   |j	        | f|||d
|}	ddd           n# 1 swxY w Y   |	S )zGenerate a conda recipe from an external repo.  Translates metadata from external
    sources into expected conda recipe format.version	recursiver   
output_dirskeletonzconda_build.skeletons)globalslocalsfromlistc                 :    i | ]}|v |t          |          S  )getattr)r&   r=   r   	func_argss     r)   
<dictcomp>zskeletonize.<locals>.<dictcomp>`  s/    WWWdTYEVEVdGFD))EVEVEVr,   c                 $    i | ]\  }}|v 	||S r   r   )r&   r=   valuer   s      r)   r   zskeletonize.<locals>.<dictcomp>a  s)    VVV;4DIDUDU4DUDUDUr,   )r   r   r   r   N)r   updater   r
   compute_build_idr{   
__import__r   r   skeletonize__code__co_varnamesdiritems)packagesrepor   r   r   r   rB   moduleargskeleton_returnr   s        `    @r)   r   r   >  s    fi11G ,y'*+++ 0{I.///S
++
|Z0111 !22622F
J'''H%%H #WYYvxxSWRX	
 	
 	
 		 F "+7IWWWWWc&kkWWWF
MMVVVV&,,..VVVWWW#/  &==s	 
 
,&,
!
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 s   E::E>E>c                 L    ddl m} t          |           }  || |||||          S )znInstall a Python package in 'development mode'.

    This works by creating a conda.pth file in site-packages.r   )execute)developr   r{   )
recipe_dirprefixno_pth_file	build_extclean	uninstallr   s          r)   r   r   r  s=     !     j))J7:v{IuiPPPr,   c	                     ddl m}	 t          |          }|                     d          r |	| ||||||||	  	        S |                     d          rt	          d          t	          d| z            )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)r   show_imports	platformsforceverbosequietdry_rundependenciesz.whlzBConversion from wheel packages is not implemented yet, stay tuned.zcannot convert: %s)convertr   r{   endswithRuntimeError)
package_filer   r   r   r   r   r   r   r   r   s
             r)   r   r     s     '&&&&&Y''IY'' @}!%%

 

 

 
	
 
		v	&	& @S
 
 	
 /,>???r,   defaultsc                 $    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   )channelr   s     r)   r   r     s'     .-----G$$$r,   package c           	      P    ddl m} t          |           }  || ||||||          S )Nr   )inspect_linkages)r   	untrackedall_packages
show_filesgroupbysysroot)r   r   r{   )r   r   r   r   r   r   r   r   s           r)   r   r     sR     .-----H%%H!   r,   filenamec                 H    ddl m} t          |           }  || ||          S )Nr   )inspect_objects)r   r   )r   r   r{   )r   r   r   r   s       r)   r   r     s8    ,,,,,,H%%H?8FGDDDDr,   c                 6   ddl m} t          |          }t          |           }  || |          }|rBt	          d|z             |                                D ]\  }}t	          | d| d           nt	          d|z             t          |          dk    S )Nr   )check_prefix_lengths)prefix_lengthz9Packages with binary prefixes shorter than %d characters:z (z chars)zBNo packages found with binary prefixes shorter than %d characters.)conda_build.tarcheckr   r   r{   printr   rU   )r   min_prefix_lengthr   r   prefix_lengthsfnlengths          r)   inspect_prefix_lengthr     s    999999"3444FH%%H))(F;;N 
G 	
 	
 	
 )..00 	, 	,JBR**6***++++	, 	P 	
 	
 	
 ~!##r,   c                 $    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   s     r)   inspect_hash_inputsr     s&     ,+++++>(###r,   r   c
                 R    ddl m} t          |	fi |
}	 || |||||||||	
  
        S )Nr   )create_metapackage)
r=   r   entry_pointsbuild_stringbuild_numberr   homelicense_namesummaryr   )metapackager   r
   )r=   r   r   r   r   r   r   r   r   r   rB   r   s               r)   r   r     sc     0///// 22622F!!!!!   r,   z3.25.0z4.0.0zUse standalone conda-index.)addendumc                 v   dd l dd l}ddlm} ddlm} fdt          |           D             } t          |t                    r<t          |          5 }|
                    |          }d d d            n# 1 swxY w Y   | D ]4} |||||||	|
 ||          ||                    dd           
  
         5d S )Nr   )update_indexr   c                 D    g | ]}j                             |          S r   )r6   abspath)r&   r6   ry   s     r)   rX   z update_index.<locals>.<listcomp>#  s'    KKK4&&KKKr,   
index_file)		check_md5channel_namepatch_generatorthreadsr   progresssubdirscurrent_index_versionsr   )ry   yamlconda_build.indexr   rY   r   r{   rZ   r[   open	safe_loadr8   )	dir_pathsr   r   r   remover   subdirr   r   r   r   hotfix_source_repor   rB   r   legacy_update_indexr   fr6   ry   s                      @r)   r   r     sR   " IIIKKKEEEEEE------KKKK<	3J3JKKKI(#.. 7()) 	7Q%)^^A%6%6"	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7  
 
%+K''#9zz,55	
 	
 	
 	
 	

 
s   A77A;>A;autoc                    &'( ddl }ddl(ddl}	ddlm' ddlm}
 ddlm} ddlm}m	}m
} d}t          |fi |}ddi}d}( fd	(j                                       r(                               ng D             }(fd
|D             }t          |          }t!          |          rd} }|sE(j                            |j        dt'          |	                                dz                       }t          d1|||dd|}t)          |          |_        g }d}t-           t.                    r|r3|D ]/}d}ddlm}  |||i           }|                    |ddf           0nT(j                                       d         &&rt9          &fd|D                       st;           fd|i|}nd}d}n }|rt=          |          }|}rZ'(fd|D             }t!          |          dk    r"t?          d                     |                    |st?          d| d          t!          |          dk    r$|s"t?          d                     |                    |}||!                    |d                            d         }d|j"        _#        |dk    r|D ]\  }}}(j                            (j$        dz   dddd                     |%                    d           |%                    d!                              }(j        &                    |j'                  }	 (j        &                    |          } 	 ((                    |            n# tR          $ r Y nw xY w	 (*                    |           n#  Y nxY wtW          d"| d#|            (,                    ||           # tZ          $ r5}!t]          d$                     | t/          |!                              d}!~!wt\          $ r5}!t]          d%                     | t/          |!                              d}!~!ww xY w|rd&nd'&|r |            }"n ||j/        dz             }"|rPd(&z   }#d)                     |j"        j0        |rd*nd+(j                            |j"        j0        |#          ,          }$n|sw|"5   |
|i d-           ddd           n# 1 swxY w Y   d(&z   }#d)                     |j"        j0        |rd*nd+(j                            |j"        j0        |#          ,          }$n|st?          d.           }%|"5   ||%|i d/           ddd           n# 1 swxY w Y   (j                            |j1        d0&z             }#d)                     |j1        |rd*nd+(j                            |j1        |#          ,          }$|$S )2zSet up either build/host or test environments, leaving you with a quick tool to debug
    your package's build or test phase.
    r   N)fnmatch)r   r   )CONDA_PACKAGE_EXTENSIONSLoggingContexton_winFset_build_idc                     g | ]e}|                     d           j                            j                            |                    Jj                            |          fS )work)r   r6   isdirr   )r&   dry   )recipe_or_package_path_or_metadata_tupless     r)   rX   zdebug.<locals>.<listcomp>R  s|        LL   FJJ 
>BB  r,   c                     g | ]P}j                             j                             |d                     5j                             |d           QS )zmetadata_conda_debug.yaml)r6   isfiler   )r&   r  ry   s     r)   rX   zdebug.<locals>.<listcomp>`  s_       7>>"',,q*EFFGG
Q344  r,   Tdebug_i  
   )r   crootr   _prefix_lengthr2   symlink)MetaDatar   c              3       K   | ]}|v V  	d S r"   r   )r&   re   exts     r)   r*   zdebug.<locals>.<genexpr>~  s'      !M!Mq#(!M!M!M!M!M!Mr,   r   c                 \    g | ](} j                             |                    &|)S r   )r6   basename)r&   re   r  ry   	output_ids     r)   rX   zdebug.<locals>.<listcomp>  sJ       ggbg.>.>q.A.A9&M&M  r,   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: z 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.usrlocalsrcr   z{}-{}zpackage/namezpackage/versionz"Making debug info source symlink: z => zLYou do not have the necessary permissions to create symlinks in {}
error: {}z/Unknown error creating symlinks in {}
error: {}z.batz.shbuild_env_setupz,cd {work_dir} && {source} {activation_file}
callsource)work_dirr"  activation_file)ru   provision_onlyzDebugging 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   ru   r%  conda_test_env_varsr   )2loggingry   timer  rz   r   r   rY   r  r  r	  r
   r6   r  listdirr_   rU   r   r  intr	   channel_urlsrZ   r[   conda_build.metadatar  r^   splitextanyrH   rf   r]   formatindexr   r   sep	get_valuer   	meta_pathmakedirsFileExistsErrorunlinkr   r  PermissionError	ExceptionCRITICALr#  test_dir))r  r6   r   r  r   r   link_source_methodrB   r'  r(  	run_buildrun_testr  r  r	  
is_packagedefault_configargspath_is_build_dirworkdirsmetadatas_conda_debugrC   best_link_source_methodmetadata_conda_debugr  rL   r   matched_outputstarget_metadatare   debug_source_loclink_targetdnelog_contextr$  activation_string
test_inputr  r  ry   s)   `  `                                  @@@r)   debugrO  8  s    NNNIIIKKK444444222222RRRRRRRRRRJ(::6::NE"D     w}}FGGBJJ@AAA  H     
 ##899
 !! 9 8 Vw||N02T3tyy{{T?Q;R;R2T2TUU  T72 QU F +622FO$;SAA D 	"(= @ @$*3'999999#8$8&"EE&&%'>????@ '""#LMMaPC "c!M!M!M!M4L!M!M!MMM ""(=# #FL#PV# #
 !

C 2'88! 	     "  O ?##a'' 0060G0G   %   H`g  H  H  H   !##,=#&&,fWoo  
 &O)'--8J*K*KLQO/1,)++- %	 %	NHa!w||&&~66&&'899 	  	  '//(*<==KW__%566KKOOOO&   DII.////D\9I\\{\\   

;(89999"   cjjCFF   
    FMMCFF    
%&&C ;$n&&$nW%5%9:: %
+c1KRR$+4#166GLL&/  S 
 
  
 	F 	FIoREEEE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F+c1KRR$+4#166GLL&/  S 
 
  	Cd  
 CJ  	O 	OHZbNNNN	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O 	O',,v8MPS8STTKRR_#166GLL/JJ S 
 

 s   *N6MN6
M(%N6'M((N6,NN6N0N66
P2 0O00P2=0P--P21SSS;UUU)NNTTF)NF)FNN)NTFFNNN)TNN)r   NFN)r   FNFNFTF)r   )r   Nr   r   NNNN)NFFFNNNNFFNN)NFNNTr  ),__doc__sys_sysos.pathr   r   r   pathlibr   conda_build.configr   r  r   r	   r
   rY   r   r{   r   r|   r   ri   deprecationsr   rH   rJ   rf   rm   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO  r   r,   r)   <module>rW     s}        . - - - - - - - - -       G F F F F F L L L L L L L L L L 9 9 9 9 9 9 ; ; ; ; ; ; 7 7 7 7 7 7 $ $ $ $ $ $
 "&H' H' H' H'VO O O O 	4# 4# 4# 4#r 	   66 6 6 6$ 

6 6 6 6v 
	" " " "J    KO1 1 1 1l ;
Q Q Q Q& 

!@ !@ !@ !@H% % % % ;   . &*[* E E E E 7E $ $ $ $*$ $ $ 	   < Hg(EFFF 
)
 )
 )
 GF)
\ 
	A A A A A Ar,   