
    xhe                    Z   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 dd	l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%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1  e-e2          Z3 ej4        d          Z5 ej4        d          Z6d Z7d6dZ8d Z9	 	 	 d7dZ:d Z;d Z<	 	 	 	 d8dZ=d9dZ>d:dZ?d Z@	 d;dZAd ZB ej4        d          ZC ej4        d           ZDd<d=d'ZEd<d=d(ZFd>d.ZGd/ ZHd0 ZId1 ZJ	 d<d2ZKd<d3ZLd<d4ZMd5 ZNdS )?    )annotationsN)abspathbasenameexists
expanduserisdirisfilejoinnormpath)Path)CalledProcessError)Iterable)urljoin   )CondaHTTPErrorTemporaryDirectorydownloadhashsum_fileurl_path)MissingDependency)external)LoggingContextcheck_call_envcheck_output_env convert_path_for_cygwin_or_msys2convert_unix_path_to_win	copy_intodecompressible_extsensure_list
get_loggeron_winrm_rfsafe_print_unicodetar_xfz(?:.+)\.(.+)\.(?:.+)\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,   1   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| 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# t.          $ rV}t                               dt1          |                                          z             t5          |	           Y d}~d}~wt6          $ rV}t                               dt1          |                                          z             t5          |	           Y d}~d}~ww xY wt5          |	           t7          d|
z            d}dD ]_}||v rY||         }t9          |	|          }||k    r9t5          |	           t7          |                                 d| d| d           n`|sX|st9          |	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 Tz)No hash (md5, sha1, sha256) provided for zC.  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: 'z' != ''r2   ) loginfor   ospathislinkmakedirs
isinstancelistr   
ValueErrorr,   warnr
   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>   r/   ehashedtpexpected_hash	dest_paths                   r+   download_to_cacher[   5   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 $ 	6 6 6 6	
 	
 	
 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"xxzzMMvMM]MMM   E    	2!$11F%dF33	w~~i(( 	)Ki(((sJ   -J60JJ6J	J6J	J66
M4 ALM4AM//M4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   rL   rM   r
   r"   )nested_folderparentflisttmpdirentrys        r+   hoist_single_extracted_folderrd      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^   lenrd   rL   rM   )rP   src_dirrN   rO   crootrQ   timeoutrh   src_pathrS   rb   unhashed_destra   folderfs                  r+   unpackru      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   rI   r   )gitrz   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 )Nrw   versionry   fetchoriginrx   rz   stdoutstderr)r   r;   r<   r   )r{   rz   r   r   lfs_versions        r+   git_lfs_fetchr      sc    "C	#:DDDKHH[	eWh0c&QW     r-   c	                
   |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| 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           $ rs t*          r$|                    d          rt-          |          }t          j
                            |          rt1          |          }t          |||gz   |	|
           Y nw xY wt          |          sJ t          | d||g|	|
           |rm|}|                    d          r*t3          | d|g|	|
          }|                    d          }|rt#          d|z             |rt          | d|g||	|
           	 t3          | dddddg|	|          }|                    d                                          }n# t           $ r g }Y nw xY w|D ]}t8                              |          }|r|                    d          d         dk    r|                    d           }|                    d          }t?          |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 r8   HEADr   r   r   z+HEAD:_conda_cache_origin_headzsymbolic-refz#refs/heads/_conda_cache_origin_headz>Failed to update local git cache. Deleting local cached repo:  clonez--mirrorr   z--depthr   r   .	rev-parseutf-8checkout: %rcheckoutconfigz--filez.gitmodulesz--get-regexpr/   )r   rz      r   z?Relative submodule {} found: url is {}, submod_mirror_dir is {}F	git_cachegit_ref	git_depthis_top_levelrQ   )z-czprotocol.file.allow=always	submoduleupdatez--initz--recursive)r{   rQ   )&openr=   devnullrE   sepsysexitr   rstripr   r>   r]   r@   r   r}   r   r   rj   rL   rmtreerH   r!   r   r   r   r   decode
splitlinesgit_submod_rematchgroupr   r
   formatr   git_mirror_checkout_recursivegit_infoclose)r{   
mirror_dircheckout_dirgit_urlr   r   r   r   rQ   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 
djddYbdd	
 	
 	

 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"!!	    &=	 #!!
 
 
 
 " 
	 
	 
	=/9= = =  #JJJ M*%%%
	 Wj)q==YI//D	00    S*-- ?c:vv>>>! 	 	 	  <',,S11 <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>>>>  sD   .A,F 5G49H. .A:J+*J+?N NNR**R.	1R.	c                   t          |          st          j        |           t          j        d          }|st          j        d           t          |                     dd                    }|                     d          pd}| d         }|	                    d          rt          j
                            |          }|	                    d	          rct          t          t          j
                            ||                              }t          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   r5   r   :_r   Nr4   r8   Tr   )r   r=   r@   r   find_executabler   r   intgetrE   r>   r   r   r   r
   r!   rG   splitr   r   )rP   r   rn   rO   rQ   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 	!__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  )rH   ).0keyvalues      r+   
<dictcomp>zgit_info.<locals>.<dictcomp>  s*    
>
>
>JC3s88SZZ
>
>
>r-   r;   z-n1Tdescribez--tagsz--dirtyFstatus)r   rz   envzgit error: %sr   r   ignorez==> {} <==
r   
)r   r   r   r;   rD   r   r=   r   environcopyr
   itemsr   r   	ExceptionrH   localegetpreferredencodingr   r   encodinghasattrr   writer   rj   r#   )rn   build_prefixr{   rQ   for   r   r   cmdcheck_errorr   rV   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   r8   r   hgpullr   r   r   hg_tagtipr   r   z-C)r   r=   r   r   r@   r   rG   r
   r   r   rj   r   )rP   rn   hg_cacherQ   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)rH   rk   rI   )ss    r+   
parse_boolzsvn_source.<locals>.parse_bool2  s(    1vv||~~##%%)CCCr-   svn_urlsvn_revheadsvn_ignore_externalsnor   r   r   r8   r   z--ignore-externalssvn_usernamesvn_passwordz--non-interactivez--no-auth-cachez
--usernamez
--passwordsvnupz-rr   cor   T)symlinksrh   )r   r=   r   r   r   r@   r   rG   r
   appendextendr   r   r   )rP   rn   	svn_cacherQ   rp   rh   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.urlry   )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   r   timectimer=   r>   getmtimer   r    __name__debug)rO   r   revr<   serverrevisions         r+   get_repository_infor  b  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]rn   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)rm   r`   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+   r.  z+_guess_patch_strip_level.<locals>.<genexpr>  sB       
 
C5E%(O3K3KC3K3K3K3K
 
r-   )setmapr   minranger,  rm   r   sortedr   rj   r   )
r%  rn   maxlevelguessed
patchlevelr-  r,  levelr3  r4  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   rE   )r>   re_filesfilesrt   
first_lineis_git_formatlinems           r+   _get_patch_file_detailsrJ    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)r   rE   rH   )parel_pathr   s      r+   _patch_attributes_debugr_    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
)rm   rj   r
   )
attributess    r+   _patch_attributes_debug_printrb    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 )r8   r   )r   )r   rt   strip_levels     r+   	<setcomp>z(_get_patch_attributes.<locals>.<setcomp>  s,    >>>1k**2.>>>r-   r{   generic)r-  rE  rQ  r   rT  rO  rL  rS  rX  rZ  r   r=  rV  r   r   r@  r   )r   +rN  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+  rr  )rs  s    r+   	__enter__z5_get_patch_attributes.<locals>.noop_context.__enter__$  s
    :r-   c                    d S r+  r   )rs  excr   tbs       r+   __exit__z4_get_patch_attributes.<locals>.noop_context.__exit__'  s    Fr-   )r  
__module____qualname__r   rt  rv  rz  r   r-   r+   noop_contextrp    sF        	 	 		 	 		 	 	 	 	r-   r}  z--binary)nativerm  rl  r%  r   r~  rn   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+  )	rL   r   r=   r>   r
   r]   r@   r   copy2)rn   tmp_src_dirrE  filer  dst_dirs         r+   copy_to_be_patched_filesz7_get_patch_attributes.<locals>.copy_to_be_patched_filesA  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)rT  rO  rL  z-Np{}r=  z-iCLC_ALL)PIPEPopen)rz   r   r   shells   offsetrX  s   fuzzrZ  r   rO  r   )#collectionsrd  rJ  r5  rm   r>  r   readr   rE   rl   r;   warningerrorr   r   r=   r>   r
   r   rL   r  r   r!  r$  r   r   
subprocessr  r  communicateboolr   r   rj   )(r>   rQ  r{   rn   r   r   retained_tmpdirrd  
files_listrG  rE  rS  strip_level_guessedresultrl  rm  rt   _contentrH  r}  fmtsrb   fmtr   	new_patchr  r  checks
check_namer  fmt_args
patch_argsr   r  r  processr   r  rV   rf  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  rz   r   r   	temp_namebase_patch_argstry_patch_argsrV   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   r3   r-  z.Failed to find conda-build dependency: 'patch'r   r{   zconda-buildGIT_COMMITTER_NAMEzconda@conda-build.orgGIT_COMMITTER_EMAILamz-3z--committer-date-is-author-date)rz   r   r   r   r   r   z with args:
r   )r=   r>   r
   rQ   rj   r	   rJ   r   r   r   r   r   r   r  r_  r   r   r   git_commits_since_tagr   )rn   
recipe_dirr^  r   r{   r>   r  	exceptionr   r   r   attributes_outputrQ  rb   patch_attributesgit_envr  rV   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   )rn   r-  r   r{   s       r+   apply_patchr    sG    '')9)9%)@)@&#    r-   c                B   t          j        | j        j        d           d}	 |                     d          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                   }t/          t1          t          | j        |                              }dv }|r'|s%t3          d           d}t5          j        d           |ryt           j                            |          }t;          |          st          j        |           | j        j        rt3          d| d|            t          j        ||           nn| j        j        rt3          d| d|            t?          ||| j        j        d| j        j        d           n#t;          |          st          j        |           tA                              dg                     }g }	|D ]#}
|	tC          || j        |
| j        |          gz  }	$tE          |	           n;# tF          $ r. tI          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)
    T)exist_okNsourcers   r3   c              3      K   | ]}|v V  	d S r+  r   )r   krP   s     r+   r.  zprovide.<locals>.<genexpr>	  s(      ;;1#;;;;;;r-   )r)   r/   )rO   ro   rQ   rp   rh   r   )rQ   r   r   )rQ   rp   rh   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 )r   rh   clobberr%  _failed_provide)&r=   r@   r   build_folderget_sectionr   r>   r
   work_diranyru   	src_cachero   rQ   rp   rh   r   r   r   r   r  r   r   r   r   rj   r   r   r]   r   symlinkr   r   r  rb  r   rL   rM   )metadatar{   rs   rn   source_pathr>   r  src_dir_symlinkr%  patch_attributes_outputr-  rP   s              @r+   provider    s"    K,t<<<<
C\#//99 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   L4M 8N)F)Fre   T)Nr   TT)NT)NTN)Tre   Tr+  )r  r  r  r  r  r   )r%  r&  rn   r'  r  r(  )O
__future__r   r   r=   r
  rL   r   r  r  os.pathr   r   r   r   r   r	   r
   r   pathlibr   r  r   typingr   urllib.parser   conda_interfacer   r   r   r   r   
exceptionsr   os_utilsr   utilsr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r  r;   rB  r   r'   r,   r[   rd   ru   r}   r   r   r   r   r   r  r  r#  r  r!  r$  r>  rJ  r_  rb  r  r  r  r  r   r-   r+   <module>r     s   # " " " " "  				 				  



   X X X X X X X X X X X X X X X X X X X X       ) ) ) ) ) )                                * ) ) ) ) )                                     j
899	0	1	16 6 6U U U UpR R R* *K *K *K *KZ     E E E EP) ) ) )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   h$ h$ h$ h$ h$r-   