
    c                     2   d dl mZmZ d dlZd dlZd dlZ	 d dlmZ n# e$ r	 d dl	mZ Y nw xY wd dl
Z
d dl	Z	d dlmZ d dlmZ d dlmZ d dlmZmZ ej                            d          Z ee           d	 Zd
 Zd ZddZddZddZddZd Zd Zd Z dS )    )print_functionabsolute_importN)TemporaryDirectory)makedirs_ok_if_exists)LocalStateFile)_load_string)possible_project_file_namesDEFAULT_PROJECT_FILENAMEz./build/tmpc           	         t          d          }t          j                            |j                  }	 |                                 D ]\  }}t          j                            ||          }|t          |           7t          t          j                            |                     t          j
        |dd          5 }|                    |           d d d            n# 1 swxY w Y    |t          j                            |                    }	 |                                 n# t          $ rJ}	t          d           t          d|z              t          dt          |	          z              Y d }	~	nyd }	~	ww xY w# 	 |                                 w # t          $ rJ}	t          d           t          d|z              t          dt          |	          z              Y d }	~	w d }	~	ww xY wxY w|S )Ntest-prefixwutf-8z.Unexpected error cleaning temporary directory:z  )r   ospathrealpathnameitemsjoinr   dirnamecodecsopenwritecleanup	Exceptionprintstr)
contentsfunctempdr   filenamefile_contentr   fresultexcs
             Llib/python3.11/site-packages/anaconda_project/internal/test/tmpfile_utils.pywith_directory_contentsr(      s'   g...Eguz**G&.nn&6&6 	* 	*"Hl7<<22D *%d++++%bgood&;&;<<<[sG44 *GGL)))* * * * * * * * * * * * * * *bg&&w//00	MMOOOO 	 	 	BCCC$.!!!$S/"""DDDD			MMOOOO 	 	 	BCCC$.!!!$S/"""DDDD		
 Mst   BF C%F %C)	)F ,C)	-,F D/ /
F9A E>>FG4FG4
G1'A G,'G4,G11G4c                 :   t          |           }|t          d| z            | }d|vr|dz   dz   dz   dz   dz   }d|vr|dz   dz   }d	|vr|dz   d
z   }|| urD	 t          |           |S # t          $ r%}t          d|z   t          j                   |d }~ww xY w| S )NzBroken yaml: %r	env_specs
zenv_specs:
z  default:
z    description: default
r   zname: some_name
	platformsz&platforms: [linux-64, osx-64, win-64]
zFailed to parse: )file)r   AssertionErrorr   r   sysstderr)contentyamlmodifiedes       r'   complete_project_file_contentr5   :   s     D :.8999H$ mtOn4~EHddgkkT ;tO&99$ QtO&OOw 		"""O 	 	 	%0szBBBBG	 s   A) )
B3 BBc                     i }|                                  D ]"\  }}|t          v rt          |          }|||<   #t          d |                                D                       dk    rt          d          |t
          <   t          ||          S )Nc                 $    g | ]}|t           v |S  )r	   ).0keys     r'   
<listcomp>zCwith_directory_contents_completing_project_file.<locals>.<listcomp>[   s#    UUUC#9T2TUCUUU    r    )r   r	   r5   lenkeysr
   r(   )r   r    new_contentsr"   r#   s        r'   /with_directory_contents_completing_project_filerA   U   s    L"*.."2"2 . .,22 	G8FFL!-X
UU<,,..UUUVVZ[[ S1Nr1R1R-."<666r<   c                    |t           }t          j        |d          }	  | |          |                                 t	          j        |j                   S # |                                 t	          j        |j                   w xY w)NFdirdelete)	local_tmptempfileNamedTemporaryFilecloser   remover   )r    rD   r$   s      r'   with_temporary_filerK   `   s    
 
 	#E:::AtAww				
	!& 	
			
	!&s   
A /Bc                 n   |t           }t          d          5 }t          j                            ||           }t          j        |dd          5 }|                    |           |                                 d d d            n# 1 swxY w Y    ||          cd d d            S # 1 swxY w Y   d S )Nr   r   r   r   )encoding)	rF   r   r   r   r   r   r   r   flush)r"   r   r    rD   r   fullr$   s          r'   with_named_file_contentsrP   o   s+   
 	7	+	+	+ ww||GX..[sW555 	GGHGGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 tDzz                 s5   8B**B<B*B	B*B	B**B.1B.c                 4      fd}t          ||          S )Nc                     |                                          d                     |                                  |                                   | j                  S )NzUTF-8)r   encoderN   rI   r   )r$   r   r    s    r'   with_file_objectz,with_file_contents.<locals>.with_file_object|   sM    	(()))				 	
			tAF||r<   rD   rK   )r   r    rD   rT   s   ``  r'   with_file_contentsrW   {   s8          /S9999r<   c                 2    fd}t          | ||          S )Nc                 X     dt           j                            |           g          S )Npython)r   r   abspath)r"   r    s    r'   script_wrapperz9with_temporary_script_commandline.<locals>.script_wrapper   s&    tXrwx889:::r<   rU   )rW   )r   r    rD   r\   s    `  r'   !with_temporary_script_commandliner]      s3    ; ; ; ; ; hC@@@@r<   c                     dd l } |j        t          ddd          }|                    |                     d                     |                                 dt          j                            |j	                  gS )Nr   Fz.pyscript_)rD   rE   suffixr   r   rZ   )
rG   rH   rF   r   rS   rI   r   r   r[   r   )r   rG   r$   s      r'   tmp_script_commandlinera      so    OOO 	$#	%V_```AGGHOOG$$%%%GGIIIbgooaf--..r<   c                      dd l }  | j        t          d          }t          |j                  }|                                 t          j        |j                   |S )Nr   FrC   )rG   rH   rF   r   r   rI   r   rJ   )rG   r$   local_states      r'   tmp_local_state_filerd      sV    OOO##	%@@@A ((KGGIIIIafr<   c                 0      fd}t          |          S )zFCall 'f' with a zip of 'contents' and an empty working directory name.c                 6    t          j         j        d          5 }                                D ].\  }}|                    ||                    d                     /	 d d d            n# 1 swxY w Y    fd}t          t                      |          S )Nr   r   c                 &     j         |           S N)r   )r   r$   handles    r'   using_directoryzGwith_tmp_zipfile.<locals>.using_temporary_file.<locals>.using_directory   s    1V['***r<   )zipfileZipFiler   r   writestrrS   r(   dict)ri   zfr:   valuerj   r   r$   s   `    r'   using_temporary_filez.with_tmp_zipfile.<locals>.using_temporary_file   s    _V[#.. 	8"&nn.. 8 8
UCg!6!677778	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8	+ 	+ 	+ 	+ 	+ 	+ 'tvv???s   AA..A25A2rV   )r   r$   rq   s   `` r'   with_tmp_zipfilerr      s9    @ @ @ @ @ @ 3444r<   rh   )!
__future__r   r   r   r   r/   backports.tempfiler   ImportErrorrG   rk   "anaconda_project.internal.makedirsr   !anaconda_project.local_state_filer   anaconda_project.yaml_filer   anaconda_project.project_filer	   r
   r   r[   rF   r(   r5   rA   rK   rP   rW   r]   ra   rd   rr   r8   r<   r'   <module>rz      s   7 6 6 6 6 6 6 6  				 



,5555555 , , ,++++++++,   D D D D D D < < < < < < 3 3 3 3 3 3 a a a a a a a aGOOM**	  i        :  67 7 7   	 	 	 		: 	: 	: 	:A A A A/ / /  5 5 5 5 5s    ++