
    8xd                       d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZmZ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mZ d dlmZ d d	lmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) d
dl*m+Z+m,Z,m-Z- d
dl.m/Z/  e%e0          Z1e&rd dlm2Z2 ej3        d          dk    rd dl4m5Z5 nd dl6m5Z5  ej7        d          Z8 ej7        d          Z9d Z:d9dZ;d Z<	 	 	 d:dZ=d Z>d Z?	 	 	 	 d;dZ@d<dZAd=dZBd ZC	 d>d ZDd! ZE ej7        d"          ZF ej7        d#          ZGd?d@d*ZHd?d@d+ZIdAd1ZJd2 ZKd3 ZLd4 ZM	 d?d5ZNd?d6ZOd?d7ZPd8 ZQdS )B    )annotationsN)abspathbasenameexists
expanduserisdirisfilejoinnormpath)Path)CalledProcessError)Iterable)CondaHTTPErrorurl_path)external)LoggingContextcheck_call_envcheck_output_env convert_path_for_cygwin_or_msys2	copy_intodecompressible_extsensure_list
get_loggeron_winrm_rfsafe_print_unicodetar_xf   )TemporaryDirectorydownloadhashsum_file)MissingDependency)convert_unix_path_to_win   )urljoinz(?:.+)\.(.+)\.(?:.+)\s(.+)z(.*?)(\.(?:tar\.)?[^.]+)$c                P    t                               d|d d          d|           S )Nz\1_
   z\2)ext_resub)fn
hash_values     2lib/python3.11/site-packages/conda_build/source.pyappend_hash_to_fnr-   2   s*    ::0Z_000"555    Fc                   |rt                               d| z             t          |           s3t          j                            |           st          j        |            |d         }t          |t                    s|g}d|v r|d         nt          |d                   x}}d}dD ]?}||v r9||         dv rt          d| d	|           t          |||                   }d
} n.@t                               d                    |                     t          | |          }	t          |	          r!|rt                               d|z             nQ|rt                               d|z             |D ]}
d|
vr|
                    d          rt#          |
          }
t          j                            |
          s=t          j                            t          j                            ||
                    }
t)          |
          }
nC|
                    d          r.dt#          |
dd                                       dd          z   }
	 |rt                               d|
z             t-                      5  t/          |
|	           ddd           n# 1 swxY w Y   |rt                               d            n# t0          $ rV}t                               dt3          |                                          z             t7          |	           Y d}~d}~wt8          $ rV}t                               dt3          |                                          z             t7          |	           Y d}~d}~ww xY wt7          |	           t9          d|
z            d}dD ]k}||v re||         }t;          |	|          }||k    rEt7          |	           t9          d                    |                                ||                     nl|sX|st;          |	d          }t          |	|          }t          j                            |          st?          j         |	|           |}	|	|fS )z%Download a source to the local cache.zSource cache directory is: %surlr*   r   F)md5sha1sha256)N zEmpty z hash provided for TznNo hash (md5, sha1, sha256) provided for {}.  Source download forced.  Add hash to recipe to use source cache.zFound source in cache: %szDownloading source to cache: %s://~z	file:///~zfile:///   N\/zDownloading %sSuccessz	Error: %szCould not download %sz{} mismatch: '{}' != '{}'r3   )!loginfor   ospathislinkmakedirs
isinstancelistr   
ValueErrorr-   warnformatr
   r	   
startswithr   isabsr   r   replacer   r    r   strstripr   RuntimeErrorr!   uppershutilmove)cache_folderrecipe_pathsource_dictverbosesource_urlsunhashed_fnr*   
hash_added	hash_typer>   r0   ehashedtpexpected_hash	dest_paths                   r,   download_to_cacher\   6   s    A0<?@@@ "rw~~l'C'C "
L!!!e$Kk4(( $"m![00Dh{1~6N6NK" J. 
 
	##9%33 !L)!L!L!L!LMMM"2{9'=>>BJE $ 	66<f[6I6I	
 	
 	
 b!!Dd|| "> 	7HH025666 	=HH6;<<< 	> 	>CC>>#&& *$S//Cw}}S)) K'**27<<S+I+IJJCsmm>>+.. N$z#abb'':':'B'B4'M'MMC 5HH-3444#%% ( (S$'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (  (HHY''' "   s1vv||~~5666d   s1vv||~~5666d $KKK6<===F'  'OM!$++F&&d"/66

FM   
 E    	2!$11F%dF33	w~~i(( 	)Ki(((sJ   -K?JKJ 	 K#J 	$K
NAL  N-AM>>Nc           	     2   t           j                            |           }t          j        |           }t	                      5 }|D ]S}t          j        t           j                            | |          t           j                            ||                     Tt          |            |D ]S}t          j        t           j                            ||          t           j                            ||                     T	 ddd           dS # 1 swxY w Y   dS )zMoves all files/folders one level up.

    This is for when your archive extracts into its own folder, so that we don't need to
    know exactly what that folder is called.N)	r=   r>   dirnamelistdirr   rM   rN   r
   r   )nested_folderparentflisttmpdirentrys        r,   hoist_single_extracted_folderre      sG   
 W__]++FJ}%%E			 R 	Y 	YEK]E::BGLLQV<W<WXXXXm 	R 	REKVU33RW\\&%5P5PQQQQ	R	R R R R R R R R R R R R R R R R R Rs   B<DDD  Tc           	     0   t          ||| |          \  }}	t          |          st          j        |           |rt	          d           t          |          5 }
t          j                            |
|	          }|                                	                    t                    rt          ||
           n"t	          d           t          ||||           |                                	                    d          rt          ||||           t          j        |
          }t          j                            |
|d                   }t          |          dk    r2t          j                            |          rd| vrt          |           t          j        |
          }|D ]S}t!          j        t          j                            |
|          t          j                            ||                     T	 d	d	d	           d	S # 1 swxY w Y   d	S )
zUncompress a downloaded source.zExtracting download)dirzNWarning: Unrecognized source format. Source file will be copied to the SRC_DIR)lockingz.whlr   r   no_hoistN)r\   r   r=   r@   printr   r>   r
   lowerendswithr   r   r   r_   lenre   rM   rN   )rQ   src_dirrO   rP   crootrR   timeoutri   src_pathrT   rc   unhashed_destrb   folderfs                  r,   unpackrv      sO    .k; Hk >> 
G %#$$$		&	&	& K&V[99>>$$%899 	I8V$$$$ `   hwHHHH>>$$V,, 	I hwHHHH
6""feAh// u::??rw}}V44?;9V9V)&111
6"" 	K 	KAKVQ//gq1I1IJJJJ	K-K K K K K K K K K K K K K K K K K Ks   F#HHHc                |    	 t          | dddg|          }|o|                                S # t          $ r Y dS w xY w)Nlfszls-files--allcwdF)r   rJ   r   )gitr{   lfs_list_outputs      r,   check_git_lfsr~      s\    *C
G+LRUVVV:?#8#8#:#::   uus   *- 
;;c                    t          | ddg|          }t                              |           t          | ddddg|||           d S )Nrx   versionrz   fetchoriginry   r{   stdoutstderr)r   r;   r<   r   )r|   r{   r   r   lfs_versions        r,   git_lfs_fetchr      sc    "C	#:DDDKHH[	eWh0c&QW     r.   c	                8
   |rd}	d}
nt          t          j        d          }|}	|}
|                    |t          j        z             st          j        d|d|           t          | |                              d          }t          | |                              d          }|pd}|                    d          }t          t          j
                            |                    s1t          j        t          j
                            |                     t          |          r	 |dk    r8t          | dg||	|
           t          | |          rt          | ||	|
           n.t          | dd	d
g||	|
           t          | dddg||	|
           n;# t           $ r: d                    |          }t%          |           t'          j        |            w xY w| ddg}|dk    r|dt+          |          gz  }	 t          |||gz   |	|
           t          | |          rt          | ||	|
           n# t           $ r| t
          j        dk    r$|                    d          rt/          |          }t          j
                            |          rt3          |          }t          |||gz   |	|
           Y nw xY wt          |          sJ t          | d||g|	|
           |rm|}|                    d          r*t5          | d|g|	|
          }|                    d          }|rt%          d|z             |rt          | d|g||	|
           	 t5          | dddddg|	|          }|                    d                                          }n# t           $ r g }Y nw xY w|D ]}t:                              |          }|r|                    d          d         dk    r|                    d           }|                    d          }tA          |dz   |          }t          j
                            t          j
        !                    ||                    }|r$t%          d!                    |||                     tE                      5 }tG          | ||||||d"|#	  	         ddd           n# 1 swxY w Y   |r1t          | gd$d%d&d'd(||	|
           tI          |d| |)           |s|%                                 dS dS )*aQ  Mirror (and checkout) a Git repository recursively.

    It's not possible to use `git submodule` on a bare
    repository, so the checkout must be done before we
    know which submodules there are.

    Worse, submodules can be identified by using either
    absolute URLs or relative paths.  If relative paths
    are used those need to be relocated upon mirroring,
    but you could end up with `../../../../blah` and in
    that case conda-build could be tricked into writing
    to the root of the drive and overwriting the system
    folders unless steps are taken to prevent that.
    NwbzError: Attempting to mirror to z which is outside of GIT_CACHE r9   HEADr   r   r   z+HEAD:_conda_cache_origin_headzsymbolic-refz#refs/heads/_conda_cache_origin_headzAFailed to update local git cache. Deleting local cached repo: {} clonez--mirrorr   z--depthr   r   win32.	rev-parseutf-8checkout: %rcheckoutconfigz--filez.gitmodulesz--get-regexpr0   )r   r{      r   z?Relative submodule {} found: url is {}, submod_mirror_dir is {}F	git_cachegit_ref	git_depthis_top_levelrR   )z-czprotocol.file.allow=always	submoduleupdatez--initz--recursive)r|   rR   )&openr=   devnullrF   sepsysexitr   rstripr   r>   r^   r@   r   r~   r   r   rE   rk   rM   rmtreerI   platformr#   r   r   r   decode
splitlinesgit_submod_rematchgroupr%   r
   r   git_mirror_checkout_recursivegit_infoclose)r|   
mirror_dircheckout_dirgit_urlr   r   r   r   rR   r   r   FNULLgit_mirror_dirgit_checkout_dirmsgargsr   output
submodulesr   matchessubmod_namesubmod_rel_path
submod_urlsubmod_mirror_dirtemp_checkout_dirs                             r,   r   r      s   4  RZ&&  RV!344 
zz99&	
 	
 	
 6c:FFMMcRRN7\JJQQRUVV G""3''J,,-- 1
BGOOJ//000Z A!)	&  'N
6&    !j11 C!#z66BBB '8-MN"!!	    &=	 #!!
 
 
 
 " 
	 
	 
	228&2D2D  #JJJ M*%%%
	 Wj)q==YI//D	00    S*-- ?c:vv>>>! 	 	 	 |w&&7+=+=c+B+B&27;;w~~g&& ,"7++00     	 Z      	g~'78PV     c"" 	.%k8,VF  F }}W--H 	-.8+,,, 	j(+ 	   %(Hm^UK
 
 


  &&w//::<<

   


  	%%i00 	w}}Q''*c11!--**K%mmA..O 3@@J " 0 0Z99! !  U\\#Z1B   
 $%% ):-%%'#'!&#
 
 
 
                ? 	 6 	
    	
 	
 	
 	
 	tg>>>>  sE   .A,F AG 9H= =BKK?N N,+N,SS		S	c                   t          |          st          j        |           t          j        d          }|st          j        d           t          |                     dd                    }|                     d          pd}| d         }|	                    d          rt          j
                            |          }|	                    d	          rlt          t          t          j
                            ||                              }t
          j        d
k    r|                    dd          }	n|dd         }	nx|                    d          d                             dt          j                  }	|		                    t          j                  r
|	dd         }	|	                    dd          }	t          ||	          }
t'          ||
|||||d|	  	         |S )z=Download a source from a Git repo (or submodule, recursively)r|   zOError: git is not installed in your root environment or as a build requirement.r   r   git_revr   r   r6   r   r   :_r   Nr5   r9   Tr   )r   r=   r@   r   find_executabler   r   intgetrF   r>   r   r   r   r
   r   rH   splitr   r   )rQ   r   ro   rP   rR   r|   r   r   r   git_dnr   s              r,   
git_sourcer     s    
I

"5
)
)C 
]	
 	
 	
 KOOK4455Iooi((2FG)$G# .'$$W--# *(27<<W#E#EFFGG<7""__S#..FFQRR[FFu%%b)11#rv>>RV$$ 	 ABBZFS))i((J!
 
 
 
 Jr.   c                &   t          |           sJ |st          j        d|          }|st                              d           dS |rd}nt          t          j        d          }|}t          j        	                                }t          | d          |d<   d |                                D             }|dd	fd
f|dddfdf|dfd
ffD ]D\  }}		 t          ||| |          }
n8# t          $ r+}|	rt          dt          |          z            Y d}~nd}~ww xY wt!          j                    }|st$          j        j        }|pd}t+          |
d          r|
                    |d          }
|rV|                    d                    d
                    |                               |r|                    |
dz              |rGt3          d                    d
                    |                               t5          |
dz              FdS )zPrint info about a Git repo.r|   zGgit not installed in root environment.  Skipping recording of git info.Nr   .gitGIT_DIRc                N    i | ]"\  }}t          |          t          |          #S  )rI   ).0keyvalues      r,   
<dictcomp>zgit_info.<locals>.<dictcomp>  s*    
>
>
>JC3s88SZZ
>
>
>r.   r;   z-n1Tdescribez--tagsz--dirtyFstatus)r   r{   envzgit error: %sr   r   ignorez==> {} <==
 
)r   r   r   r;   rD   r   r=   r   environcopyr
   itemsr   r   	ExceptionrI   localegetpreferredencodingr   r   encodinghasattrr   writerE   rk   r   )ro   build_prefixr|   rR   for   r   r   cmdcheck_errorr   rW   r   s                r,   r   r     sa   >> <&ul;; U	
 	
 	
 	 RZ&& *//

C'6**C	N
>
>#))++
>
>
>C
ue	d#
z8Y	/7
x$ 2 2[
	:%c&g3OOOFF! 	: 	: 	: :#a&& 8999: : : : :	: .00 	+z*H&w68$$ 	7]]8X66F 	2HH^**388C==99::: ($''' 2n++CHHSMM::;;;"6D=111/2 2s   C&&
D0!DDc                   |rd}d}nt          t          j        d          }|}|}| d         }t          |          st          j        |           |                    d          d                             dd          }t          ||          }	t          |	          rt          dd	g|	||
           n't          dd||	g||           t          |	          sJ | 	                    d          pd}
|rt          d|
z             t          dd|	|g||           t          ddd|
g|||
           |s|                                 |S )z&Download a source from Mercurial repo.Nr   hg_urlr   r   r9   r   hgpullr   r   r   hg_tagtipr   r   z-C)r   r=   r   r   r@   r   rH   r
   r   r   rk   r   )rQ   ro   hg_cacherR   r   r   r   r   hg_dn
cache_repor   s              r,   	hg_sourcer     s    RZ&&"F?? 
HLLb!))#s33Eh&&JZ !f~:fVTTTTT7FJ/v	
 	
 	
 	
 Z      __X&&/%F 'nv%&&&D':w7vVVVV	xv&GF6     Nr.   c           
        |rd}d}nt          t          j        d          }|}|}d }	| d         }
|                     d          pd} |	|                     d          pd          }t	          |          st          j        |           |
                    d	d
          d                             dd                              d	d          }t          ||          }g }|r|	                    d           d| v rEd| v rA|
                    ddd|                     d          d|                     d          g           t	          |          rt          ddd|g|z   |||           n/t          ddd|g|z   |
|gz   ||           t	          |          sJ t          |||d|           |s|                                 |S )z Download a source from SVN repo.Nr   c                l    t          |                                                                           dv S )N)yestrue1on)rI   rl   rJ   )ss    r,   
parse_boolzsvn_source.<locals>.parse_bool6  s(    1vv||~~##%%)CCCr.   svn_urlsvn_revheadsvn_ignore_externalsnor   r   r   r9   r   z--ignore-externalssvn_usernamesvn_passwordz--non-interactivez--no-auth-cachez
--usernamez
--passwordsvnupz-rr   cor   T)symlinksri   )r   r=   r   r   r   r@   r   rH   r
   appendextendr   r   r   )rQ   ro   	svn_cacherR   rq   ri   r   r   r   r   r   svn_revisionr   svn_dnr   
extra_argss                   r,   
svn_sourcer  *  s<     RZ&&D D D )$G??9--7L%:koo6L&M&M&UQUVV 
I]]3""2&..sC88@@cJJFi((JJ 0.///$$;)F)F#!////		
 		
 		
 Z !D$-
:		
 	
 	
 	
 	
 	D$-
:gz=RR	
 	
 	
 	

 Z      j'7T7KKKK Nr.   c                   	 t          t          | d                    r.t          g d|           }t          g d|           }d| d| S t          t          | d                    rFt          g d|           }t          d	d
g|                                           d         }d| d| S t          t          | d                    rt          ddg|           }|                    d          }t          j        d|t          j                  	                    d          }t          j        d|t          j                  	                    d          }| d| S d
                    | t          j        t          j                            t          | d                                        S # t           $ r t#          t$                                        d| z              d
                    | t          j        t          j                            t          | d                                        cY S w xY w)zThis tries to get information about where a recipe came from.  This is different
    from the source - you can have a recipe in svn that gets source via git.r   )r|   r   z--getzremote.origin.urlrz   )r|   r   r   zOrigin z	, commit z.hg)r   pathsdefaultr   idr   z.svnr   r<   r   zRepository Root: (.*)$)flagsr   zRevision: (.*)$z, Revision z{}, last modified {}z	meta.yamlzFailed to checkout source in )r   r
   r   r   r   r   researchMr   rE   timectimer=   r>   getmtimer   r   __name__debug)rP   r   revr<   serverrevisions         r,   get_repository_infor  f  sX   
${F++,, 	%???[  F ##?#?#?[QQQC3V33c3334U++,, 	%&@&@&@kRRRF"D$<[AAAGGII!LC3V33c3334V,,-- 	#UFOEEED;; D Y7RTJJJPPQRSSFy!2DEEEKKANNH33333)00
27++Dk,J,JKKLL    
 
 
8""#B[#PQQQ%,,BG$4$4T+{5S5S$T$TUU
 
 	
 	
 	

s(   A
F7 A"F7 0B3F7 $AF7 7BI Is	   (?<!\r)\ns   \r\nsrcos.PathLikedstos.PathLike | Nonereturnr   c                    t          |           } t          |p|           }|                    t                              d|                                                      |S )zFReplace windows line endings with Unix.  Return path to modified file.   
)r   write_bytes_RE_CRLFr)   
read_bytesr  r  s     r,   
_ensure_LFr#    sM    
s))C
szc

COOHLL(8(899:::Jr.   c                    t          |           } t          |p|           }|                    t                              d|                                                      |S )zBReplace unix line endings with win.  Return path to modified file.s   
)r   r  _RE_LFr)   r!  r"  s     r,   _ensure_CRLFr&    sM    
s))C
szc

COOFJJw(8(899:::Jr.   patchesIterable[str | os.PathLike]ro   str | os.PathLiketuple[int, bool]c           	       	 t          t          t          |                     } t          d | D                       }d}|dk    rd}nd t	          |dz             D             | D ]f}|j        }t	          |dz             D ]J}t          |g|t          |           |z   d         R                                  r|xx         dz  cc<   Kgt          j	        d          		d                  	d                  k    rt          d	           d}t          	fd
                                D                       }||fS )z.Determine the patch strip level automatically.c              3  H   K   | ]}t          |j        j                  V  d S N)rn   ra   parts)r   patchs     r,   	<genexpr>z+_guess_patch_strip_level.<locals>.<genexpr>  s/      @@u3u|)**@@@@@@r.   Fr   c                    i | ]}|d S )r   r   )r   is     r,   r   z,_guess_patch_strip_level.<locals>.<dictcomp>  s    333!A333r.   r   NT)r   reversez+Patch level ambiguous, selecting least deepc              3  F   K   | ]\  }}|d                   k    |V  dS )r   Nr   )r   r   r   histoorders      r,   r0  z+_guess_patch_strip_level.<locals>.<genexpr>  sB       
 
C5E%(O3K3KC3K3K3K3K
 
r.   )setmapr   minranger.  rn   r   sortedr   rk   r   )
r'  ro   maxlevelguessed
patchlevelr/  r.  levelr5  r6  s
           @@r,   _guess_patch_strip_levelr@    s    #dG$$%%G@@@@@@@HG1}}

33uX\22333 	& 	&EKEx!|,, & &?%Ue(;(=(=">???FFHH &%LLLA%LLL& u%)T:::q?eE!Ho--?@@@G 
 
 
 
 
"'++--
 
 
 
 

 wr.   c                   t          j        d          }g }t          | d          5 }g }d}d}|                                D ]}|rt          j        d|          sd}d}|                    |          }|rB|                    d          dk    r)|                    |                    d                     v|r,|                    d	          r|                    d
          sd}	 d d d            n# 1 swxY w Y   ||fS )Nz^(?:---|\+\+\+) ([^\n\t]+)r   errorsTzFrom [0-9a-f]{40}Fr   z	/dev/nullr|   z
git --diff)	r  compiler   	readlinesr   r  r   r   rF   )r>   re_filesfilesru   
first_lineis_git_formatlinems           r,   _get_patch_file_detailsrL    s`   z788HE	d8	$	$	$ &
KKMM 	& 	&D &"(+?"F"F & %J%%A &QWWQZZ;..QWWQZZ((((&OOE**& 55&
 !&	&	& & & & & & & & & & & & & & &" =!!s   C C55C9<C9c                P   d                     | d         rdnd| d         rdnd| d                             |          rdnd| d	         sd
nd| d         rdndt          | d                   | d         sdnd| d         sdnd| d         sdnd| d         sdnd|dd                    S )Nz)[[ {}{}{}{}{}{}{}{}{}{} ]] - [[ {:>71} ]]
reversibleR-
applicableA	patch_exeYamalgamatedr  dry_runnableDr?  level_ambiguousLoffsetsOfuzzyVr   Ei)rE   rF   rI   )parel_pathr   s      r,   _patch_attributes_debugra    s    6==,(S,(S+)),77@Sm$-#.!*sBwK'(1ci=)cg;'Ch<(S  r.   c                    t          |           rQt          d           t          d                    |                      t          d           t          d           d S d S )NzPatch analysis gives:r   z
Key:
a_  R :: Reversible                       A :: Applicable
Y :: Build-prefix patch in use        M :: Minimal, non-amalgamated
D :: Dry-runnable                     N :: Patch level (1 is preferred)
L :: Patch level not-ambiguous        O :: Patch applies without offsets
V :: Patch applies without fuzz       E :: Patch applies without emitting to stderr
)rn   rk   r
   )
attributess    r,   _patch_attributes_debug_printrd    ss    
: 

%&&&dii
##$$$jd	
 	
 	
 	
 	
	

 

r.   c                D  ' ddl m} t          |           \  }}	t          |          }
d}t	          |          t	          |
          k    rd}t          |
|          \  '}'r'fd|
D             }
| |
|r|	r|n||	rdndd d d |d d d '|g d}d}d}t          | d	
          5 }|                                }|                    d          D ]1}|	                    d          r|
                    d          rd}/d}2	 d d d            n# 1 swxY w Y   |r|rdn|rdnd|d<   |s;t                              d|             |st                              d           |S  G d d          } |dgg g           }|r|r ||          nt                      5 }i |d<   |                                D ]\  }}t           j                            |t           j                            |           d| z             }|dk    r3	 t)          j        | |           nI#  t)          j        | |           Y n0xY w|dk    rt/          | |           n|dk    rt1          | |           ||d         |<   t           j                            |d          }d } ||||
            |dgg dg          }|                                D ];\  }}|                                D ]\  }}d                     |d!                   d"|d         |         g|z   |z   }	 t           j                                        } d#| d$<   dd%lm}!m}"  |"|g|z   ||!|!d&          }#|#                                \  }$}%d'|$v |d(<   d)|$v |d*<   t?          |%          |d+<   |r|                     |$           |r|                     |%           |||<   |d,k    r|d-         s||d-<    n,# tB          $ r}&tE          |&           d||<   Y d }&~&d }&~&ww xY w=	 d d d            n# 1 swxY w Y   |sd|v r|d= |S ).Nr   )OrderedDictFTc                H    h | ]}|                     d           d         S )r9   r   )r   )r   ru   strip_levels     r,   	<setcomp>z(_get_patch_attributes.<locals>.<setcomp>  s,    >>>1k**2.>>>r.   r|   generic)r/  rG  rS  rE   rV  rQ  rN  rU  rZ  r\  r   r?  rX  r   r   rB  r   )r   +rP  mixedcrlflfline_endingsz>No patch program found, cannot determine patch attributes for zFNo git program found either. Please add a dependency for one of these.c                  $    e Zd ZdZd Zd Zd ZdS )+_get_patch_attributes.<locals>.noop_contextNc                    || _         d S r-  r   )selfr   s     r,   __init__z4_get_patch_attributes.<locals>.noop_context.__init__%  s    DJJJr.   c                    | j         S r-  rt  )ru  s    r,   	__enter__z5_get_patch_attributes.<locals>.noop_context.__enter__(  s
    :r.   c                    d S r-  r   )ru  excr   tbs       r,   __exit__z4_get_patch_attributes.<locals>.noop_context.__exit__+  s    Fr.   )r  
__module____qualname__r   rv  rx  r|  r   r.   r,   noop_contextrr  "  sF        	 	 		 	 		 	 	 	 	r.   r  z--binary)nativero  rn  r'  r   r  ro   c                "   	 t          j        |           n#  Y nxY w|D ]}t          j                            ||          }t          j                            |          }	 t          j        |           n'#  t          j                            |          s Y nxY wt          j                            t          j                            | |                    r3t          j        t          j                            | |          |           d S r-  )	rM   r   r=   r>   r
   r^   r@   r   copy2)ro   tmp_src_dirrG  filer  dst_dirs         r,   copy_to_be_patched_filesz7_get_patch_attributes.<locals>.copy_to_be_patched_filesE  s    M+....D! 
G 
GD',,{D99C gooc22G"G,,,,"!w~~g66 "!" " w~~bgll7D&A&ABB GRW\\'4%@%@#FFF
G 
Gs    "A77"B	--dry-runz-R)rV  rQ  rN  z-Np{}r?  z-iCLC_ALL)PIPEPopen)r{   r   r   shells   offsetrZ  s   fuzzr\  r   rQ  r   )#collectionsrf  rL  r7  rn   r@  r   readr   rF   rm   r;   warningerrorr   r   r=   r>   r
   r   rM   r  r   r#  r&  rE   r   
subprocessr  r  communicateboolr   r   rk   )(r>   rS  r|   ro   r   r   retained_tmpdirrf  
files_listrI  rG  rU  strip_level_guessedresultrn  ro  ru   _contentrJ  r  fmtsrc   fmtr   	new_patchr  r  checks
check_namer  fmt_args
patch_argsr   r  r  processr   r  rW   rh  s(                                          @r,   _get_patch_attributesr    s"    (''''' 7 = =J
OOEK
:#e**$$'?w'O'O$K$ ?>>>>>>>  B]BSS(7%%i". F$ D	B	d8	$	$	$ 6688NN4(( 	 	D// ==&& DDB	               *.S"SWWT;S66tF> STSS	
 	
 	
  	IIX   
 
 
 
 
 
 
 
 ;zlr;;;D O 7\\
 
 
"4"6"6M	:@ "F9**,, 3 3QGLL1A1A$1G1G)c))1STT	(??5T955555D)44444D[[tY////F]] y111)2y!#&&',,vy99KG G G" %$Wk5AAA [)]rtf  F +1,,.. $ $&
J%)ZZ\\ # #MC w88$y@QRU@VW$%"# 
 joo//(+H::::::::"'%&K*4 +#'#'"'# # # )0(;(;(=(=,5,?y)*1V*;w+/;;x(! 1"LL000! 0"LL/// .1z*%55fVn5-7F6N %   a-2z*7$SM	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	 M	^  yF229Msj    AD		DDA(PHPH20C"PB$O7P
O:	O5	/P5O:	:PPPc           
     R   t           j                            ||          }|j        rt	          d|            d }d }t          |          st          d|z            |j        rd }d }	nt          t           j        d          }
|
}|
}	d}t          j
        d          }|st          d          t                      5 }t          |||| ||	|          }|t          |||j                  z  }|rL|d         d	k    r@t           j        }d
|d<   d|d<   t#          |ddd|g| ||	|           |xj        dz  c_        nO|d         }|j        rt	          d| d|            	  |||| ||	           n# t&          $ r}|}Y d }~nd }~ww xY w|r|	 d d d            n# 1 swxY w Y   |S )NzApplying patch: c                   t           j                            t          j                    t          t          j                                        }ddg|z   }	 |d d          }|                    d           t          	                    d|  d|            t          | g|z   |||           t          | g|z   |||           n# t          $ r}|d }~ww xY w	 t           j                            |          rt          j        |           d S d S # t           j                            |          rt          j        |           w w xY w)Nz--no-backup-if-mismatchz--batchr  zdry-run applying with
r   r   )r=   r>   r
   tempfile
gettempdirnext_get_candidate_namesr   r;   r  r   r   r   unlink)	r/  r  r{   r   r   	temp_namebase_patch_argstry_patch_argsrW   s	            r,   try_apply_patchz(apply_one_patch.<locals>.try_apply_patch  s|   6 GLL!!4(E(G(G#H#H
 
	 5i@:M	%,QQQ/N!!+...IIHHHHHIII.(c&    /)s6&      	 	 	G	 w~~i(( %	)$$$$$% %rw~~i(( %	)$$$$%s+   AC .D 
CCCD 6EzError: no such patch: %sr   r4   r/  z.Failed to find conda-build dependency: 'patch'rE   r|   zconda-buildGIT_COMMITTER_NAMEzconda@conda-build.orgGIT_COMMITTER_EMAILamz-3z--committer-date-is-author-date)r{   r   r   r   r   r   z with args:
r   )r=   r>   r
   rR   rk   r	   rK   r   r   r   r   r"   r   r  ra  r   r   r   git_commits_since_tagr   )ro   
recipe_dirr`  r   r|   r>   r  	exceptionr   r   r   attributes_outputrS  rc   patch_attributesgit_envr  rW   s                     r,   apply_one_patchr    s   7<<
H--D~ )'''(((0% 0% 0%d I$<< >5<===~ RZ&& (11I R PQQQ			 %0)S'666
 
 	4h(;
 
 	
  	#H-66 jG,9G()-DG)*dD"CTJ    ((A-((()&1J~ JHHHJHHIIIzwvf        						 	O	I% % % % % % % % % % % % % % %L s=   ?B!F!E21F2
F<F>FFFF #F c                    t          | t          j                            |          t          j                            |          ||           d S r-  )r  r=   r>   r^   r   )ro   r/  r   r|   s       r,   apply_patchr    sG    '')9)9%)@)@&#    r.   c                   |                      d          }t          j                            | j        j                  st          j        | j        j                   d}t          |d          r|g}n|}	 |D ]                    d          }t          j        	                    | j        j
        |r|nd          }t          fddD                       rPt          || j        j        | j        | j        j        | j        j        | j        j        | j        j                   nd	v r/t%          | j        j        || j        | j        j        
          }ndv r)t)          || j        j        | j        j        
           ndv r?t-          || j        j        | j        j        | j        j        | j        j                   nodv rGt          j                            d                   }t3          t5          t          | j        |                              }dv }|r'|s%t7          d           d}t9          j        d           |ryt          j                            |          }	t          |	          st          j        |	           | j        j        rt7          d| d|            t          j        ||           nn| j        j        rt7          d| d|            tA          ||| j        j        d| j        j        d           n#t          |          st          j        |           tC                              dg                     }
g }|
D ]#}|tE          || j        || j        |          gz  }$tG          |           n;# tH          $ r. tK          j&        | j        j
        | j        j
        dz               w xY w| j        j
        S )zk
    given a recipe_dir:
      - download (if necessary)
      - unpack
      - apply patches (if any)
    sourceNkeysrt   r4   c              3      K   | ]}|v V  	d S r-  r   )r   krQ   s     r,   r0  zprovide.<locals>.<genexpr>  s(      ;;1#;;;;;;r.   )r*   r0   )rP   rp   rR   rq   ri   r   )rR   r   r   )rR   rq   ri   r>   path_via_symlinkaG  WARNING: `path_via_symlink` is too dangerous without specifying a folder,
  conda could end up changing - or deleting - your local source code!
  Going to make copies instead. When using `path_via_symlink` you should
  also take care to run the build outside of your local source code folder(s)
  unless that is your intention.Fr   z#Creating sybmolic link pointing to z at zCopying z to T)r   ri   clobberr'  _failed_provide)'get_sectionr=   r>   r   r   build_folderr@   r   r   r
   work_diranyrv   	src_cacherp   rR   rq   ri   r   r   r   r   r  r  r   r   r   rk   r   r   r^   symlinkr   r   r  rd  r   rM   rN   )metadatametar|   dictsrt   ro   source_pathr>   r  src_dir_symlinkr'  patch_attributes_outputr/  rQ   s                @r,   provider    s]    ))D7==566 2
HO0111
CtV \  U	C U	CK __X..Fgll8?#;v=UVVSUVVG;;;;];;;;; J)O- ("//$O3$O3$O3	 	 	 	 	 k)) O-M$O3   [((O,$O3	     k))O-$O3$O3$O3     ;&& g00V1DEEX]K(H(H I IJJ#5#D # 	 F 	 ;   (-$HQKKK# &(goog&>&>O 11 5O444. YWDWWgWWXXXJtW----. ><<<7<<===  /!% ( 7 $     W~~ )K(((!+//)R"@"@AAG&(#   '#GX]E8?TWXX, '' **ABBBBkU	Cn    O$ho&>AR&R	
 	
 	
 		 ?##s   7L!N 8O)F)Frf   T)Nr   TT)NT)NTN)Trf   Tr-  )r  r  r  r  r  r   )r'  r(  ro   r)  r  r*  )R
__future__r   r   r=   r  rM   r   r  r  os.pathr   r   r   r   r   r	   r
   r   pathlibr   r  r   typingr   conda_build.conda_interfacer   r   conda_build.os_utilsr   conda_build.utilsr   r   r   r   r   r   r   r   r   r   r   r   conda_interfacer   r    r!   
exceptionsr"   r  r;   r#   version_infourllib.parser%   urlparserD  r   r(   r-   r\   re   rv   r~   r   r   r   r   r   r  r  r%  r   r#  r&  r@  rL  ra  rd  r  r  r  r  r   r.   r,   <module>r     sE   # " " " " "  				 				  



   X X X X X X X X X X X X X X X X X X X X       ) ) ) ) ) )       @ @ @ @ @ @ @ @ ) ) ) ) ) )                            H G G G G G G G G G ) ) ) ) ) )j	 ;::::::A!$$$$$$$      
899	0	1	16 6 6W W W WtR R R* *K *K *K *KZ     F F F FR) ) ) )Z.2 .2 .2 .2b$ $ $P IM9 9 9 9x
 
 
D 
M	"	"2:h           4" " ".   
 
 
 DHX X X Xvp p p pf   o$ o$ o$ o$ o$r.   