
    8xd                         d 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Zddl	Z	ddl
mZ ddlmZmZ d!dZd Zd Zd	 Zd
 Zd Zd"dZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'	 	 	 	 	 	 	 	 d#d Z(dS )$z%
Tools for converting conda packages
    N)Path)filter_info_fileswalkFc                    t          j        d          }g }t          j        |           5 }|                                D ]}}|                    d          rf|                    |          }d                    |                    d          	                    dd                    }|
                    |           ~	 ddd           n# 1 swxY w Y   |S )a  Check tarfile for compiled C files with '.pyd' or '.so' suffixes.

    If a file ends in either .pyd or .so, it is a compiled C file.
    Because compiled C code varies between platforms, it is not possible
    to convert packages containing C extensions to other platforms.

    Positional arguments:
    file_path (str) -- the file path to the source package tar file

    Keyword arguments:
    show_imports (bool) -- output the C extensions included in the package
    zC(Lib\/|lib\/python\d\.\d\/|lib\/)(site-packages\/|lib-dynload)?(.*))z.pydz.soz	import {}   /.N)recompiletarfileopengetnamesendswithmatchformatgroupreplaceappend)	file_pathshow_importsc_extension_patternimportstarfilenamefilename_matchimport_names           3lib/python3.11/site-packages/conda_build/convert.pyretrieve_c_extensionsr      s    *N  G	i	 	  ,C 	, 	,H  11 ,!4!:!:8!D!D)00"((++33C==  {+++	,, , , , , , , , , , , , , , , Ns   BCCCc                 X   t          j        |           5 }t          j        |                    d                                                              d                    }ddd           n# 1 swxY w Y   |d         }|                    d          dk    rd}n1|                    d          dk    rd	}n|                    d          }|                    d
          s|                    d          rd||fS |d                             d          rd||fS t          d          )zRetrieve the platform and architecture of the source package.

    Positional arguments:
    file_path (str) -- the file path to the source package tar file
    info/index.jsonutf-8Nplatformarchx86_6464x8632linuxosxunixwinz Package platform not recognized.)
r   r   jsonloadsextractfilereaddecodeget
startswithRuntimeError)r   r   indexr"   architectures        r   retrieve_package_platformr6   2   st    
i	 	  VC
3??+<==BBDDKKGTTUUV V V V V V V V V V V V V V V Z HyyH$$	6		e	#	#yy((7## ?x':':5'A'A ?,//	z		%	%e	,	, ?x..=>>>s   AA..A25A2c                 :   d| v rBt          j        d          }|                    |           }|r|                    d          S dS |                     d          ryt          j        |           5 }t          j        |	                    d          
                                                    d                    }ddd           n# 1 swxY w Y   n[t          j                            | d          }t          |          5 }t          j        |          }ddd           n# 1 swxY w Y   t          j        d|d	                                       d
          }t          j        dd|d	                   }d                    ||d         |d                   S )a  Retrieve the python version from a path.

    This function is overloaded to handle three separate cases:
    when a path is a tar archive member path such as 'lib/python3.6/site-packages',
    when a path is the file path to the source package tar file, and when a path
    is the path to the temporary directory that contains the extracted contents
    of the source package tar file. This allows one function to handle the three
    most common cases of retrieving the python version from the source package.

    Positional arguments:
    file_path (str) -- the file path to a tar archive member, the file path
        to the source tar file itself, or the file path to the
        temporary directory containing the extracted source package contents
    pythonzpython\d\.\d+r   )z.tar.bz2z.tarr    r!   Nz(.*)?(py)(\d\d)(.*)?buildr   z\A.*py\d\d.*\Zz{}{}.{}   )r
   r   searchr   r   r   r   r,   r-   r.   r/   r0   ospathjoinloadsubr   )	r   patternmatchedr   r4   	path_file
index_filebuild_version_numberbuild_versions	            r   retrieve_python_versionrG   L   s    9*-....++ 	$==###	$ 	$ 233 
	.i(( C
OO$566;;==DDWMM                Y0ABBIi .J	*--. . . . . . . . . . . . . . .  "y)@%.QQWW 
  
 0(E'NKK/24H4K
 
 	
s%   0AC		CCD%%D),D)c                     t          j                    }t          j        |           }|                    |           |                                 |S )zExtract the source tar archive contents to a temporary directory.

    Positional arguments:
    file_path (str) -- the file path to the source package tar file
    )tempfilemkdtempr   r   
extractallclose)r   temporary_directorysources      r   extract_temporary_directoryrO   y   sJ     #*,,\)$$F
)***
LLNNN    c                    d | D             }d |D             }|                     |          }t          |          dk    r4|D ]1}|D ],}|                    |          r|                    |           -2|                    |            |S )a0  Update the source package's existing dependencies.

    When a user passes additional dependencies from the command line,
    these dependencies will be added to the source package's existing dependencies.
    If the dependencies passed from the command line are existing dependencies,
    these existing dependencies are overwritten.

    Positional arguments:
    new_dependencies (List[str]) -- the dependencies passed from the command line
    existing_dependencies (List[str]) -- the dependencies found in the source
        package's index.json file
    c                 B    h | ]}|                                 d          S r   split).0
dependencys     r   	<setcomp>z&update_dependencies.<locals>.<setcomp>   s)    QQQ*
((**1-QQQrP   c                 B    h | ]}|                                 d          S rS   rT   )rV   r4   s     r   rX   z&update_dependencies.<locals>.<setcomp>   s%    RRR5ekkmmA.RRRrP   r   )intersectionlenr2   removeextend)new_dependenciesexisting_dependenciesdependency_namesindex_dependency_namesrepeated_packagesindex_dependencyrW   s          r   update_dependenciesrd      s     RQ@PQQQRR<QRRR.;;<LMM
!! 5 	C 	C/ C C
#..z:: C)001ABBBC   !1222  rP   c                 .   t           j                            | d          }t          |          5 }t	          j        |          }ddd           n# 1 swxY w Y   |                    d          \  }}g d}	||	v r|}
n|                    d          dk    rd}
nd}
|rut          d		                    |d
         |                     t          d	                    |d         |                     t          d	                    |
|                     ||d
<   ||d<   |dk    rd|d<   n|dk    rd|d<   n||d<   |rt          ||d                   |d<   t          |d          5 }t	          j        ||d           ddd           n# 1 swxY w Y   |S )a  Update the source package's index file with the target platform's information.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory that contains
        the source package's extracted contents
    target_platform (str) -- the target platform and architecture in
        the form of platform-architecture such as linux-64
    dependencies (List[str]) -- the dependencies passed from the command line
    verbose (bool) -- show output of items that are updated
    r    N-)linux-ppc64linux-ppc64lelinux-s390xlinux-armv6llinux-armv7llinux-aarch64r#   r$   r%   r'   zUpdating platform from {} to {}r"   zUpdating subdir from {} to {}subdirz#Updating architecture from {} to {}r&   dependsw   indent)r<   r=   r>   r   r,   r?   rU   r1   printr   rd   dump)temp_dirtarget_platformdependenciesverboserD   filer4   r"   r5   other_platformssource_architectures              r   update_index_filer|      sT    h(9::J	j		  T	$                              -22377Hl  O /))*	6		h	&	&"" 
/66uZ7H(SSTTT-44U8_oVVWWW188#\ 	
 	
 	
 !E*%E(Ot f			f$f O.|U9=MNNi	j#		 )$	%a(((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) s#   AAA&F

FFc                    |dk    r:t          |           }t          j        dd|                               |d          }ns|dk    rmt          |          }t          j                            d|                              dd          }t          j        d	||                     dd                    }t          j                            |          S )
a	  Update the lib path found in the source package's paths.json file.

    For conversions from unix to windows, the 'lib/pythonx.y/' paths are
    renamed to 'Lib/' and vice versa for conversions from windows to unix.

    Positional arguments:
    path (str) -- path to rename in the paths.json file
    target_platform (str) -- the platform to target: 'unix' or 'win'

    Keyword arguments:
    temp_dir (str) -- the file path to the temporary directory that
        contains the source package's extracted contents
    r+   z\AlibLib r*   lib\\\z\ALib)rG   r
   r@   r   r<   r=   r>   normpath)r=   rv   ru   python_versionrenamed_lib_pathlib_python_versions         r   update_lib_pathr      s     %0666(E488@@QSTT	F	"	"0::W\\%@@HHvVV6($,,tV*D*D
 
 7,---rP   c                    |dk    r_	 t          j        |  d          D ]}d|v rTt          j                            |t          j                            dd                    }t          j        ||           Zt          |          8t          |          }t          j        ||                    |d                     n# t          $ r Y nw xY w	 t          j
        t          j         |  d          d                    n# t          $ r Y nw xY wt          j        t          j                            |d          t          j                            |d	                     dS |d
k    rt          |          }|d	z  }|dz  }|                    |           t          |                     d                    }	t          |          }||z  }
|
                    dd           |	D ]!}|                    |
|j        z              dS dS )a  Update the source package's 'lib' directory.

    When converting from unix to windows, the 'lib' directory is renamed to
    'Lib' and the contents inside the 'pythonx.y' directory are renamed to
    exclude the 'pythonx.y' prefix. When converting from windows to unix,
    the 'Lib' is renamed to 'lib' and the pythonx.y' prefix is added.

    Positional arguments:
    lib_directory (str) -- the file path to the 'lib' directory located in the
        temporary directory that stores the package contents
    temp_dir (str) -- the file path to the temporary directory that contains
        the source package's extracted contents
    target_platform (str) -- the platform to target: 'unix' or win'
    file_path (str) -- the file path to the source package tar file
    r+   z/python*/**zsite-packagesr   Nr   z/python*r   r~   r*   *T)parentsexist_ok)globiglobr<   r=   r>   renamesrG   r   OSErrorshutilrmtree
IndexErrormover   renametuplemkdirname)lib_directoryru   rv   r   lib_filenew_site_packages_pathr   src_dirdst_dircontents	py_folders              r   update_lib_contentsr      s=     %	 J-'D'D'DEE 	S 	S"h..-/W\\ "',,uo"F"F. .* Jx)?@@@@.x88D)@)J)J
8X-=-=nb-Q-QRRR	S  	 	 	D		M$)}$>$>$>??BCCCC 	 	 	D	 	BGLL51127<<%3P3PQQQQQ	F	"	">>U"U" 	w c**++ 1;;n,	t444 ! 	7 	7HOOI56666% 
#	""	7 	7s$   B9C 
CC/D 
DDc                    |dk    rt           j                            |                              d          st	          | |          rt          j        dd|          }nqt           j                            t          j        dd|                    d         }| d}n2|dk    r,t          j        dd	|          }|                    dd
          }|S )a  Update the name of the executable files found in the paths.json file.

    When converting from unix to windows, executables are renamed with a '-script.py'
    suffix. When converting from windows to unix, this suffix is removed. The
    paths in paths.json need to be updated accordingly.

    Positional arguments:
    file_path (str) -- the file path to the executable to rename in paths.json
    target_platform (str) -- the platform to target: 'unix' or 'win'
    r+   r	   z\AbinScriptsr   
-script.pyr*   z	\AScriptsbinr   )	r<   r=   basenamer2   is_binary_filer
   r@   splitextr   )ru   r   rv   renamed_executable_pathrenamed_paths        r   update_executable_pathr   ;  s     %7I&&11#66 	B.i;
 ;
 	B ')fXy)&L&L##7++BF8Y	,R,RSSTUVL)5&A&A&A##	F	"	"vlE9=="."6"6|R"H"H""rP   c                    t          t          j                            | |          d          5 }|                                }t          j        |                                          cddd           S # 1 swxY w Y   dS )zUpdate the sha of executable scripts.

    When moving from windows to linux, a shebang line is removed/added from
    script files which requires to update the sha.

    rbN)r   r<   r=   r>   r/   hashlibsha256	hexdigest)package_directoryexecutable_pathscript_filescript_file_contentss       r   update_executable_shar   V  s     
bgll,o>>	E	E @*//11~233==??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @s   :A66A:=A:c                 |    t           j                            t           j                            | |                    S )a^  Update the size of the converted executable files.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    executable (str) -- the executable whose size to update including its file extension

    Returns:
    byte size (int) of the executable file
    )r<   r=   getsizer>   )ru   
executables     r   update_executable_sizer   b  s(     7??27<<*==>>>rP   c           
         t          t          j                            | |          d          5 }|                                }d| dt          j        |                                          t          j                            t          j                            | |                    d}ddd           n# 1 swxY w Y   |S )a  Add a new path to the paths.json file.

    When an executable is renamed during a unix to windows conversion, a
    an exe is also created. The paths.json file is updated with the
    exe file's information.

    Positional arguments:
    executable_directory (str) -- the file path to temporary directory's 'Scripts' directory
    executable (str) -- the filename of the script to add to paths.json
    r   zScripts/hardlink)_path	path_typer   size_in_bytesN)	r   r<   r=   r>   r/   r   r   r   r   )executable_directoryr   r   r   new_paths        r   add_new_windows_pathr   p  s     
bgll/<<d	C	C 	
{*//11,
,,#n%9::DDFFW__1:>> 	
 
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 Os   A>B99B= B=c                    t           j                            | d          }t           j                            |          rt	          |          5 }t          j        |          }ddd           n# 1 swxY w Y   |dk    rp|d         D ]}|d                             d          rt          |d         d          |d<   ng|d                             d          rLt          | |d         d          |d<   t          | |d                   |d<   t          | |d                   |d	<   |d                             d
d                              dd          |d<   t           j                            | d          }t           j                            |          rUt          j        |          D ]@}|                    d          r)|d                             t#          ||                     An|dk    r|d         D ]	}|d                             d          rt          |d         d|           |d<   ng|d                             d          rLt          | |d         d          |d<   t          | |d                   |d<   t          | |d                   |d	<   |d                             d
d                              dd          |d<   |d                             d          r|d                             |           t	          |d          5 }t          j        ||d           ddd           dS # 1 swxY w Y   dS dS )a  Update the paths.json file when converting between platforms.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    target_platform (str) -- the platform to target: 'unix' or 'win'
    zinfo/paths.jsonNr+   pathsr   r   r   r   r   r   r   r   r   .exer*   r~   ).batr   ro   rp   rq   )r<   r=   r>   isfiler   r,   r?   r2   r   r   r   r   r   isdirlistdirr   r   r   r\   rt   )ru   rv   
paths_filery   r   r=   script_directoryscripts           r   update_paths_filer     s    h(9::J	w~~j!! 0-* 	$IdOOE	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ e##g V V=++E22 
$3DM5$I$IDMM']--e44 $: $w-% %DM &;8T']%S%SDN,B $w-- -D) !%W 5 5dC @ @ H HQT U UW!w||Hi@@w}}-..  j)9::  Fv.. g--01A6JJ   &&g 0 0=++E22 
$3DM68$T$TDMM']--i88 $: $w-% %DM &;8T']%S%SDN,B $w-- -D) !%W 5 5dC @ @ H HQT U UW=))*:;; 0'N))$///*c"" 	-dIeT!,,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-_0- 0-s$   A11A58A5MM	Mc                     t           j                            t           j                            |                     d         S )a%  Retrieve the name of the executable to rename.

    When converting between unix and windows, we need to be careful
    that the executables are renamed without their file extensions.

    Positional arguments:
    executable (str) -- the executable to rename including its file extension
    r   )r<   r=   r   r   )r   s    r   retrieve_executable_namer     s/     7BG,,Z8899!<<rP   c           
         t           j                            | |          }t           j                            |          rt	          |d          5 }|                    d          }ddd           n# 1 swxY w Y   t          h d                    t          t          dd                    dhz
                      }t          |                    d|                    S dS )	aq  Read a file's contents to check whether it is a binary file.

    When converting files, we need to check that binary files are not
    converted.

    Source: https://stackoverflow.com/questions/898669/

    Positional arguments:
    directory (str) -- the file path to the 'bin' or 'Scripts' directory
    executable (str) -- the name of the executable to rename
    r   i   N>         	   
                      F)r<   r=   r>   r   r   r/   	bytearrayunionsetrangebool	translate)	directoryr   r   buffered_filefile_contentstext_characterss         r   r   r     s    Y
33I	w~~i   D)T"" 	5m)..t44M	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 $%%%++CdE0B0B,C,Ctf,LMM
 
 M++D/BBCCC5s   A22A69A6c                    t           j                            | |          }|dk    rt           j                            | t          |           d          }t	          |          5 }|                                                                }ddd           n# 1 swxY w Y   t	          |d          5 }|dd         D ]}|                    |dz              	 ddd           n# 1 swxY w Y   t          j        ||           dS |	                    d          r|
                    dd          }t	          |          5 }|                                                                }ddd           n# 1 swxY w Y   t	          |d          5 }|                    d	           |D ]}|                    |dz              	 ddd           n# 1 swxY w Y   t          j        ||           dS dS )
a-  Rename an executable file when converting between platforms.

    When converting from unix to windows, each file inside the 'bin' directory
    is renamed to include '-script.py' as a suffix. When converting from windows
    to unix, each executable inside the 'Scripts' directory has its '-script.py'
    suffix removed.

    Positional arguments:
    directory (str) -- the file path to the 'bin' or 'Scripts' directory
    executable (str) -- the name of the executable to rename
    target_platform (str) -- the platform to target: 'unix' or 'win'
    r+   r   Nro   r:   
z.pyr   z.#!/opt/anaconda1anaconda2anaconda3/bin/python
)r<   r=   r>   r   r   r/   
splitlineswriter   r   r   )	r   r   rv   old_executable_pathnew_executable_pathscript_file_inlinesscript_file_outlines	            r   rename_executabler     s    ',,y*==% gll2:>>JJJ
 
 %&& 	7."''))4466E	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 %s++ 	3abb	 3 3%%dTk22223	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	
&(;<<<<< ''.. 	A"5"="=lB"O"O)** ;n&++--88::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; )3// 7?%%J   " 7 7D#))$+66667	7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 J*,?@@@@@	A 	AsH   &'BB B4&C''C+.C+'E66E:=E:3GGGc                     |                     d          r6t          j                            | |          }t          j        |           dS dS )aS  Remove an executable from the 'Scripts' directory.

    When converting from windows to unix, the .exe or .bat files
    need to be removed as they do not exist in unix packages.

    Positional arguments:
    directory (str) -- the file path to the 'Scripts' directory
    executable (str) -- the filename of the executable to remove
    )r   r   N)r   r<   r=   r>   r\   )r   r   r   s      r   remove_executabler     sP     +,, i44
	& rP   c                 j   t           j                            t                    }|                    d          r!t           j                            |d          }n t           j                            |d          }t           j                            | | d          }t          j        ||           dS )a@  Create an exe file for each executable during a unix to windows conversion.

    Positional arguments:
    directory (str) -- the file path to the 'Scripts' directory
    executable (str) -- the filename of the executable to create an exe file for
    target_platform -- the platform to target: 'win-64' or 'win-32'
    r'   z
cli-32.exez
cli-64.exer   N)r<   r=   dirname__file__r   r>   r   copyfile)r   r   rv   exe_directoryexecutable_filerenamed_executable_files         r   create_exe_filer   )  s     GOOH--M%% D',,}lCC ',,}lCC gll96I6I6IJJ
OO%<=====rP   c                     t           j                            | d          }t          |d          5 }|D ]}|                    |           	 ddd           dS # 1 swxY w Y   dS )a  Update the source package's 'has_prefix' file.

    Each file in the 'bin' or 'Scripts' folder will be written
    to the 'has_prefix' file located in the package's 'info' directory.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    prefixes (List[str])-- the prefixes to write to 'has_prefix'
    zinfo/has_prefixzw+N)r<   r=   r>   r   r   )ru   prefixeshas_prefix_fileprefix_fileprefixs        r   update_prefix_filer   >  s     gll8->??O	ot	$	$ & 	& 	&Ff%%%%	&& & & & & & & & & & & & & & & & & &s   AA!Ac           	      D  
 t           j                            | d          }t          |d          5 }g }t	          |           D ]\  }}}t           j                            ||           

fd|D             }t          |d          D ]S}|                    |                    dd                              dd                     |rt          d|            Tt          |          D ]}	|                    |	d	z              	 d
d
d
           d
S # 1 swxY w Y   d
S )af  Update the source package's 'files' file.

    The file path to each file that will be in the target archive is
    written to the 'files' file.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    verbose (bool) -- show output of items that are updated
    z
info/filesro   c                 P    g | ]"}t           j                            |          #S  r<   r=   r>   rV   frelative_dirs     r   
<listcomp>z%update_files_file.<locals>.<listcomp>a  )    JJJ1lA66JJJrP   r   r   r   r   z	Updating r   N)r<   r=   r>   r   r   relpathr   r   r   rs   sortedr   )ru   rx   
files_filefiles
file_pathsdirpathdirnames	filenamesr   r   r  s             @r   update_files_filer  P  s    h55J	j#		 *%
,0NN 	2 	2(GXy7??7H==LJJJJ	JJJI-i<< 2 2!!("2"24"="="E"Efc"R"RSSS 20h001112
  
++ 	* 	*IKK	D())))	** * * * * * * * * * * * * * * * * *s   CDDDc           	         t           j                            ||          }t           j                            |          st          j        |           t           j                            |t           j                            |                     }t          j        |d          5 }t          |          D ]n\  }}}	t           j        	                    ||          fd|	D             }	|	D ]7}
|
                    t           j                            ||
          |
           8o	 ddd           dS # 1 swxY w Y   dS )az  Create the converted package's tar file.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    platform (str) -- the platform to convert to: 'win-64', 'win-32', 'linux-64',
        'linux-32', or 'osx-64'
    zw:bz2c                 P    g | ]"}t           j                            |          #S r   r   r  s     r   r  z)create_target_archive.<locals>.<listcomp>  r  rP   )arcnameN)r<   r=   r>   r   makedirsr   r   r   r   r  add)r   ru   r"   
output_diroutput_directorydestinationtargetr  r  r  r   r  s              @r   create_target_archiver  k  s    w||J997==)** &
$%%%',,/1A1A)1L1LMMK	k7	+	+ Ov,0NN 	O 	O(GXy7??7H==LJJJJ	JJJI% O O

27<<(;;X
NNNNO	OO O O O O O O O O O O O O O O O O Os   'A?D44D8;D8c                     t          |           }t          ||||           t          | |||           t          j        |           dS )a  Convert package between unix platforms.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    output_dir (str) -- the file path to where to output the converted tar file
    platform (str) -- the platform to convert to: 'linux-64', 'linux-32', or 'osx-64'
    dependencies (List[str]) -- the dependencies passed from the command line
    verbose (bool) -- show output of items that are updated
    NrO   r|   r  r   r   r   r  r"   rw   rx   ru   s         r   convert_between_unix_platformsr    Q     +955Hh,@@@)XxDDD M(rP   c                     t          |           }t          ||||           t          | |||           t          j        |           dS )a  Convert package between windows architectures.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    output_dir (str) -- the file path to where to output the converted tar file
    platform (str) -- the platform to convert to: 'win-64' or 'win-32'
    dependencies (List[str]) -- the dependencies passed from the command line
    verbose (bool) -- show output of items that are updated
    Nr  r  s         r   &convert_between_windows_architechturesr    r  rP   c           	         t          |           }t                      }t          j        |          D ]}t          j                            ||          }t          j                            |          r5|                    t          j                  dk    rt          ||d|            t          j                            |          r6|                    t          j                  dk    rt          j        |          D ]}	t          j        
                    t          j                            ||	                    rt          ||	          sy|	                    d          sdt          ||	d           t          |t          |	          |           |                    d                    t          |	                               t          j                            |d          }
t          j        ||
           t'          ||||           t)          ||           t+          |d           t-          ||           t/          | |||           t1          j        |           dS )	a  Convert a package from a unix platform to windows.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    output_dir (str) -- the file path to where to output the converted tar file
    platform (str) -- the platform to convert to: 'win-64' or 'win-32'
    dependencies (List[str]) -- the dependencies passed from the command line
    verbose (bool) -- show output of items that are updated
    r   r+   r   r	   z;/opt/anaconda1anaconda2anaconda3 text Scripts/{}-script.py
r   rv   N)rO   r   r<   r   r=   r>   r   stripsepr   r   r   r2   r   r   r   r  r   r   r|   r   r   r  r  r   r   r   r  r"   rw   rx   ru   r   entryr   r   new_bin_paths              r   convert_from_unix_to_windowsr'    s*    +955HuuHH%% 0 0GLL511	7==## 	GBF(;(;u(D(D	8UIFFF7==## 	0BF(;(;u(D(D*Y//  GNN27<<	6#B#BCC*9f== #--c22
 &i???#!#;F#C#CX   LLV]]4V<<    7<<)<<LJy,///h,@@@x***h6666h((()XxDDD
M(rP   c           	         t          |            t          |           }t                      }t          j        |          D ]B}t          j                            ||          }t          j                            |          rd|v rt          ||d|            t          j                            |          rd|v rt          j        |          D ]}}	t          ||	          sk|	
                    d          sVt          ||	d           t          ||	           |                    d                    t          |	                               ~t          j                            |d          }
t          j        ||
           Dt#          ||||           t%          ||           t'          |d           t)          ||           t+          | |||           t-          j        |           dS )	a  Convert a package from windows to a unix platform.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    output_dir (str) -- the file path to where to output the converted tar file
    platform (str) -- the platform to convert to: 'linux-64', 'linux-32', or 'osx-64'
    dependencies (List[str]) -- the dependencies passed from the command line
    verbose (bool) -- show output of items that are updated
    r~   r*   r   r	   z-/opt/anaconda1anaconda2anaconda3 text bin/{}
r   r!  N)rG   rO   r   r<   r   r=   r>   r   r   r   r2   r   r   r  r   r   r   r|   r   r   r  r  r   r   r$  s              r   convert_from_windows_to_unixr)    s    I&&&*955HuuHH%% 0 0GLL511	7==## 	H(:(:	8VYGGG7==## 	0	Y(>(>*Y// 	 	%i88 ARARSVAWAW %i@@@%i888LLHOO4V<<    7<<%88LJy,///h,@@@x***h7777h((()XxDDD
M(rP   r	   c	                 |   |rYt          |           }	t          |	          dk    rt          d           n|	D ]}
t          |
           t          j                     |s't          |          dk    rt          j        d           t          t          |                     dk    rF|sDt          j        d                    t          j                            |                                t          |           \  }}}| d| }d|v rg d}|D ]+}||k    r$t          d                    ||                     -|sAt          d	                    t          j                            |           ||                     |
                    d
          r|dk    rt          | ||||           |
                    d          r|dk    rt          | ||||           |
                    d
          r|dk    rt          | ||||           |
                    d          r|dk    rt          | ||||           -dS )a9  Convert a conda package between different platforms and architectures.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    output_dir (str) -- the file path to where to output the converted tar file
    show_imports (bool) -- show all C extensions found in the source package
    platforms (str) -- the platforms to convert to: 'win-64', 'win-32', 'linux-64',
        'linux-32', 'osx-64', or 'all'
    force (bool) -- force conversion of packages that contain C extensions
    dependencies (List[str]) -- the new dependencies to add to the source package's
        existing dependencies
    verbose (bool) -- show output of items that are updated
    quiet (bool) -- hide all output except warnings and errors
    dry_run (bool) -- show which conversions will take place
    r   zNo imports found.z?Error: --platform option required for conda package conversion.z[WARNING: Package {} contains C extensions; skipping conversion. Use -f to force conversion.rf   all)zosx-64z	osx-arm64zlinux-32zlinux-64rg   rh   ri   rj   rk   rl   zwin-32zwin-64z	win-arm64zQSource platform '{}' and target platform '{}' are identical. Skipping conversion.zConverting {} from {} to {})r)   r(   r*   r+   N)r   r[   rs   sysexitr   r<   r=   r   r6   r2   r  r'  r)  r  )r   r  r   	platformsforcerw   rx   quietdry_runr   c_extensionconversion_platformsource_platformr5   source_platform_architecturer"   s                   r   conda_convertr6    s   4  '	22w<<1%&&&&& # #k""""


 TC	NNa//RSSS
 ++,,q000**0&1A1A)1L1L*M*M	
 	
 	

 :S: :6, '6#F#F#F#F 	
 
 
	   ! !333''-v.JH'U'U    	-44G$$Y//1Mx    /00 	5HF5R5R*:xw      '' 	,?6,I,I(:xw      !122 	7Je7S7S(:xw      '' 	,?5,H,H2:xw  ?! !rP   )F)N)r	   FNFNFFF))__doc__r   r   r,   r<   r
   r   r,  r   rI   pathlibr   conda_build.utilsr   r   r   r6   rG   rO   rd   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r'  r)  r6  r   rP   r   <module>r:     s[       				 				  



         5 5 5 5 5 5 5 5   <? ? ?4*
 *
 *
Z  ! ! !>: : :z. . . .887 87 87v# # #6	@ 	@ 	@? ? ?  0:- :- :-z	= 	= 	=  6+A +A +A\  > > >*& & &$* * *6O O O2  ,  ,1 1 1h, , ,b 

c c c c c crP   