
    xhe^                       d Z ddlmZ ddl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mZmZmZmZmZmZmZ 	 	 	 	 	 d'dZd(dZ	 	 	 d)dZ	 	 	 d)dZd)dZ	 	 	 	 	 	 	 d*dZ	 	 	 d+dZ d Z!	 d,dZ"ej#        ddddfdZ$	 	 	 	 	 	 	 	 d-dZ%d.dZ&ej#        dddddfdZ'ej#        dfdZ(efdZ)d  Z*	 	 	 	 	 	 	 	 d/d"Z+	 	 	 	 	 	 d0d1d&Z,dS )2ae  
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.
    )annotationsN)dirname
expanduserjoin)Path   )DEFAULT_PREFIX_LENGTH)Configget_channel_urlsget_or_merge_config)CONDA_PACKAGE_EXTENSIONSLoggingContextensure_listexpand_globsfind_recipe
get_loggerget_skip_messageon_winTFc                   ddl m} ddlm} ddlm}	 ddlm}
m} t          |fi |} || ||j
        |||          } |            }|D ]\  }}}|                                r|j        sw|                    || |          D ]\\  }                                r|j        s:d	|vs|d	         d
k    r|r&j        s	  |
|          n# |	|f$ r |s Y nw xY wj        s&                    d          x}r|_        j        d= ||f|                                j        j                            d          t/          fd                                D                       f<   ||f|j         d                                 j        j                            d          t/          fd                                D                       f<   ^t7          |                                          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   )OrderedDictr   )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>\   F       " "$' "%bi&7&< =" " " " " "    z: c              3  @   K   | ]}|j         j        |         fV  d S r&   r'   r)   s     r-   r.   zrender.<locals>.<genexpr>e   r/   r0   )collectionsr   conda_interfacer   
exceptionsr   renderr   r   r   r   skip	trim_skipget_output_metadata_setfinalpathget_sectionparent_outputsmetadistr   r(   gettupleget_used_varsr!   namelistvalues)recipe_pathr   r   r   finalizer   kwargsr   r   r   r   r   metadata_tuplesoutput_metasr=   downloadrender_in_envodr#   r,   s                      @r-   r5   r5   #   s    ('''''55555588888888888888 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 3r~~i7P7P,PG 307B- "	 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)r5   rN   )metadata	file_pathrO   rN   s       r-   rN   rN   n   s,    ######;x=MNNNNr0   c                   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 ][\  }	}
}
|		                                r#|
                    t          |	                     =|
                     ||	                     \t          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__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&&~~r0   zreceived mixed list of metas: T)r   r   r   rF   r   z Expecting metadata object - got N)r5   rT   r   rY   
isinstancestrall
ValueErrorr   r6   appendr   sortedrC   set)recipe_path_or_metadatar   r   r   rG   rT   list_of_metasrP   outsm_s              r-   get_output_file_pathsrh   u   s    $##### 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//"""r0   c                v    t          t                    }|                    d           t          | f|||d|S )rS   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   )r   __name__warnrh   )rc   r   r   r   rG   logs         r-   get_output_file_pathrn      s`     X

CHH	2  
 !-	 
   r0   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.
    rj   c              3  J   K   | ]}|d                                           V  dS )r   N)check_fields)r*   rf   s     r-   r.   zcheck.<locals>.<genexpr>   s2      55qqt  ""555555r0   )r   r5   r^   )rE   r   r   r   rG   rP   s         r-   checkrr      sX     !22622F-	  H 55H555555r0   c           	        ddl m}	 |dv s
J d            g }
t          |           D ]}t          |t                    r[t          |t          j                              D ]8}	 t          |          }n# t          $ r Y w xY w|

                    |           9rt          |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   )
build_tree)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   )buildrt   r   r\   r]   r   osgetcwdr   OSErrorr`   rY   r_   r   )recipe_paths_or_metadatarw   need_source_downloadrv   rx   r   r   ru   rG   rt   recipesrecipes               r-   ry   ry      s    "!!!!!&&&&	/ '&&
 G677 Q Qfc"" 
	Q&vry{{;; ' '(00FF   Hv&&&&' VX&& 	QNN6""""OvOOPPP 
K1IKK
 
 	
 :"644V44 kr
 
 
 
s   !A11
A>=A>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)ry   r   rY   r   r   ) recipedir_or_package_or_metadatar   r   ru   rG   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	skeletonsrg   )pkgutiliter_modulesr   r   __file__
startswithr`   )r   modulesfilesrg   rB   s        r-   list_skeletonsr   1  s{    
 NNN""D):):K$H$H#IJJGE  
4s## 	LLLr0   .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*   rB   r   	func_argss     r-   
<dictcomp>zskeletonize.<locals>.<dictcomp>b  s/    WWWdTYEVEVdGFD))EVEVEVr0   c                $    i | ]\  }}|v 	||S r   r   )r*   rB   valuer   s      r-   r   zskeletonize.<locals>.<dictcomp>c  s)    VVV;4DIDUDU4DUDUDUr0   )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   rG   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'''8$$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   t  s=     !     Z((J7:v{IuiPPPr0   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     '&&&&&I&&IY'' @}!%%

 

 

 
	
 
		v	&	& @P
 
 	
 /,>???r0   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$$$r0   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     .-----8$$H!   r0   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    ,,,,,,8$$H?8FGDDDDr0   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.r   )tarcheckr   r
   r   printr   rX   )r   min_prefix_lengthr   r   prefix_lengthsfnlengths          r-   inspect_prefix_lengthr     s    ......"3444F8$$H))(F;;N 
G 	
 	
 	
 )..00 	, 	,JBR**6***++++	, 	P 	
 	
 	
 ~!##r0   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&     ,+++++>(###r0   r   c
                R    ddl m} t          |	fi |
}	 || |||||||||	
  
        S )Nr   )create_metapackage)
rB   r   entry_pointsbuild_stringbuild_numberr   homelicense_namesummaryr   )metapackager   r   )rB   r   r   r   r   r   r   r   r   r   rG   r   s               r-   r   r     sc     0///// 22622F!!!!!   r0   autor   boolc                x   #$ ddl }ddl}	ddlm$ ddlm}
 ddlm} ddlm} d}t          |fi |}d	di}d} fd
t          j	        
                               rt          j                   ng D             }d |D             }t          |          }t          |          rd} }|sJt          j	                            |j        dt!          |	                                dz                       }t          d1|||dd|}t#          |          |_        g }d}t'           t(                    r|r-|D ])}d} |||i           }|                    |ddf           *n^t          j	                                       d         ##r t/          #fdt0          D                       st3           fd|i|}nd}d}n }|rt5          |          }|}rJ$fd|D             }t          |          dk    rt7          d| d          |st7          d| d          t          |          dk    r|st7          d| d          |}||                    |d                            d         }d|j        _        |dk    rx|D ]t\  }}}t          j	                            t          j        dz   ddd|                                  d |!                                           }t          j	        "                    |j#                  }	 t          j	        "                    |          }	 t          j$        |           n# tJ          $ r Y nw xY w	 t          j&        |           n#  Y nxY wtO          d!| d"|            t          j(        ||           # tR          $ r'}tU          d#| d$t)          |                     d}~wtT          $ r'}tU          d%| d$t)          |                     d}~ww xY wtV          rd&nd'#|rtY                      }ntY          |j-        dz             }|rZd(#z   } d).                    |j        j/        tV          rd*nd+t          j	                            |j        j/        |           ,          }!n0|s|5   |
|i d-           ddd           n# 1 swxY w Y   d(#z   } d).                    |j        j/        tV          rd*nd+t          j	                            |j        j/        |           ,          }!n|st7          d.           }"|5   ||"|i d/           ddd           n# 1 swxY w Y   t          j	                            |j0        d0#z             } d).                    |j0        tV          rd*nd+t          j	                            |j0        |           ,          }!|!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)fnmatchr   )ry   r   )MetaDataFset_build_idc                    g | ]t}|                     d           t          j                            t          j                            |                    Tt          j                            |          uS )work)r   rz   r:   isdirr   )r*   d)recipe_or_package_path_or_metadata_tupless     r-   r[   zdebug.<locals>.<listcomp>&  s|        LL   FJJ 
>BB  r0   c                    g | ]_}t           j                            t           j                            |d                     ?t           j                            |d           `S )zmetadata_conda_debug.yaml)rz   r:   isfiler   )r*   fs     r-   r[   zdebug.<locals>.<listcomp>4  s^       7>>"',,q*EFFGG
Q344  r0   Tdebug_i  
   )r   crootr   _prefix_lengthr6   symlinkc              3      K   | ]}|v V  	d S r&   r   )r*   rg   exts     r-   r.   zdebug.<locals>.<genexpr>P  s'      !M!Mq#(!M!M!M!M!M!Mr0   r   c                f    g | ]-} t           j                            |                    +|.S r   )rz   r:   basename)r*   rg   r   	output_ids     r-   r[   zdebug.<locals>.<listcomp>_  sJ       ggbg.>.>q.A.A9&M&M  r0   z4Specified --output-id matches more than one output (zF). Please refine your output id so that only a single output is found.zHSpecified --output-id did not match any outputs. Available outputs are: z Please check it and try againz,More than one output found for this recipe (zI). Please use the --output-id argument to filter down to a single output.usrlocalsrcr"   -z"Making debug info source symlink: z => z@You do not have the necessary permissions to create symlinks in z
error: z#Unknown error creating symlinks in 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   )1loggingtimer   ry   r   rP   r   r   rz   r:   r   listdirra   rX   r   r   intr   channel_urlsr\   r]   r`   splitextanyr   r5   rh   r_   indexr   r   seprB   r   r   	meta_pathmakedirsFileExistsErrorunlinkr   r   PermissionError	Exceptionr   r   CRITICALformatr	  test_dir)%r   r:   r   r  r   r   link_source_methodrG   r  r  	run_buildrun_testr   
is_packagedefault_configargspath_is_build_dirworkdirsmetadatas_conda_debugrH   best_link_source_methodmetadata_conda_debugrP   r#   matched_outputstarget_metadatarg   debug_source_loclink_targetdnelog_contextr
  activation_string
test_inputr   r   s%   `  `                               @@r-   debugr3    sG    NNNKKK))))))''''''""""""J(::6::NE"D    w}}FGGBJ@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9;O$;SAA D 	"(= @ @$*3'#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'' Z? Z Z Z   %  4_f 4 4 4   !##,=#Yw Y Y Y  
 &O)'--8J*K*KLQO/1,)++- 	 	NHa!w||==??99X%5%5%7%799    '//(*<==KW__%566KOOOO&   DI.////D\9I\\{\\   
;(89999"   lWYlldghidjdjll      O"OOs1vvOO   
%&&C ;$&&$W%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   
N*L?>N?
M	NMNM%$N%M)'/N
O8""OO8"O33O8R))R-0R-"T>>UU)NNTTF)NF)FNN)NTFFNNN)TNN)r   NFN)r   FNFNFTF)r   )r   Nr   r   NNNN)NFNNTr   )r   r   )-__doc__
__future__r   rz   sysos.pathr   r   r   pathlibr   r   r	   r   r
   r   r   utilsr   r   r   r   r   r   r   r   r5   rN   rh   rn   rr   ry   r   r   r   r   r   r   r   r   r   r   r   r   r3  r   r0   r-   <module>r:     s\    # " " " " " 
			 



 - - - - - - - - - -       < ; ; ; ; ; A A A A A A A A A A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "&H' H' H' H'VO O O O 	3# 3# 3# 3#p 	   66 6 6 6$ 

3 3 3 3p 
	" " " "J    KO1 1 1 1l :
Q Q Q Q& 

!@ !@ !@ !@H% % % % :   . &)Z E E E E 7E $ $ $ $*$ $ $ 	   @ 
	x x x x x x xr0   