
    0]
                         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m	Z	 n#  ddl
m	Z	 Y nxY wddlmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZ dZdd	Zd
 Z G d de          Z G d de          ZdS )a  The checks module contains two classes that are used to verify
conda packages and recipes: CondaPackageCheck and CondaRecipeCheck.

Each class contains specific checks that relate to validating packages
and recipes. These checks start with the letter 'C', which is an
abbreviation for 'conda'.

Checks C1101 through C1148 are housed in CondaPackageCheck.
Checks C2101 through C2126 are housed in CondaRecipeCheck.
    N)TemporaryDirectory)ErrorPackageError)FIELDSLICENSE_FAMILIESCONDA_FORGE_COMMENTS)	all_asciiget_bad_seqget_object_typeensure_list	fullmatchrm_rfz:^(?:[><=]{0,2}(?:(?:[\d\*]+[!\._]?){1,})[+\w\*]*[|,]?){1,}   c                     t          t          |          }|s"t          d                    |                     |            }t	           fdd          D ]}|                    |           |                                S )NzUnrecognized hash algorithm: {}c                  .                                    S N)read)
buffersizefds   3lib/python3.11/site-packages/conda_verify/checks.py<lambda>z_checksum.<locals>.<lambda>-   s    bggj11     r   )getattrhashlib
ValueErrorformatiterupdate	hexdigest)r   	algorithmr   	hash_implblocks   ` `  r   	_checksumr#   '   s    ++I  :AA)LLMMMIKK	11111377       r   c                 "    t          | d          S )Nsha256)r#   )r   s    r   sha256_checksumr&   2   s    R"""r   c                       e Zd ZdZ fdZd Ze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e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* xZ+S )'CondaPackageCheckz:Create checks in order to validate conda package tarballs.c                 h    t          t                                                      | _                              j                   _        t                       _         j        j         _	        t          j                             j         j	                    j                            dd          \   _         _         _         fdt!          j         j	                  D             x _         _        t)          t           j                             j	        dd          d          5 }|                                 _        ddd           n# 1 swxY w Y   t1          j         j                            d                     _        t)          t           j                             j	        dd	          d          5 }|                                 _        ddd           n# 1 swxY w Y   	 t)          t           j                             j	        dd
          d          5 }|                                 _        ddd           n# 1 swxY w Y   n# t<          $ r
 d _        Y nw xY wt?                       _         	 t)          t           j                             j	        dd                    5 }t1          j!        |           _"         j"        d         D ]}| j         |d         <   	 ddd           n# 1 swxY w Y   n)# t<          $ r  j        j#        dk    sJ i  _"        Y nw xY wtI           j        d         dk               _%        tM          j'        d           _(        tM          j'        dtL          j)                   _*        tM          j'        d           _+        dS )zAInitialize conda package information for use with package checks.-   c           	          g | ]N\  }}}|D ]E}t           j                            t           j                            ||          j                  FOS  )ospathrelpathjointmpdir).0dpdn	filenamesfselfs        r   
<listcomp>z.CondaPackageCheck.__init__.<locals>.<listcomp>C   sh     -
 -
 -
!B	-
 -
  GOOBGLLQ//==-
 -
 -
 -
r   infoz
index.jsonrbNutf-8files
has_prefixz
paths.jsonpaths_pathnoarchplatformwin[a-z0-9_][a-z0-9_\-\.]*$z[gh][0-9a-f]{5,}[\w\.]+$),superr(   __init__r/   retrieve_package_namedistr   _tmpdirnamer2   conda_package_handlingapiextractrsplitversionbuildr.   walkr?   archive_membersopenr1   r   indexjsonloadsdecoder:   
files_fileprefix_fileIOErrordictpaths_json_pathload
paths_jsonsubdirboolwin_pkgrecompilename_patIhash_patversion_pat)r8   r/   r7   	__class__s   `  r   rG   zCondaPackageCheck.__init__9   s   &&//111	..ty99	)++l'"**49dkBBB.2i.>.>sA.F.F+	4<-
 -
 -
 -
%'WT[%9%9-
 -
 -
 	

T)
 "',,t{FLAA4HH 	"ADJ	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"Jtz0099::	"',,t{FG<<dCC 	'qffhhDO	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'	$bgll4;EEtLL ,PQ#$6688 , , , , , , , , , , , , , , , 	$ 	$ 	$#D	$  $vv	!bgll4;EEFF ?!"&)A,, OG4 ? ?D:>D(g77?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?  	! 	! 	!9#x//// DOOO	! DIj1U:;;
#>??
#6==:k22s   1EEEG--G14G194I -II II II I32I3
3L =:L8L LL LL #L65L6c                 8    t          | j        j                   d S r   )r   rJ   rK   )r8   excvaluetbs       r   __exit__zCondaPackageCheck.__exit__d   s    dl     r   c                    t           j                            |           } t          |           }|r"t	          d                    |                    |                     d          r
| dd         S |                     d          r
| dd         S |                     d          r
| dd         S t	          d	                    t           j                            |           d
                             )z6Retrieve the package name from the conda package path.z9Found invalid sequence "{}" in package in info/index.json.tar.bz2Ni.tarz.condaiz)Found package with invalid extension "{}"   )r.   r/   basenamer
   r   r   endswithsplitext)r/   seqs     r   rH   z'CondaPackageCheck.retrieve_package_nameg   s     w%%$ 	LSSTWXX   ==$$ 	9]]6"" 		9]]8$$ 	9;BBG$$T**1-   r   c                 h   | j                             d          }|t          | j        dd          S | j                            |          r|                    d          rt          | j        dd          S || j        k    r/t          | j        dd	                    || j                            S dS )
z2Check the package name located in info/index.json.rK   NC1101z'Missing package name in info/index.json.r*   _C1103z-Found invalid package name in info/index.jsonC1102zGFound package name in info/index.json "{}" does not match filename "{}")	r:   getr   r/   re   matchru   rK   r   )r8   package_names     r   check_package_namez$CondaPackageCheck.check_package_name~   s    y}}V,,G-VWWW}""<00 	L4I4I5
 5
 	 	7$S   49$$	Zaa $)    %$r   c                    t          | j                            d                    }|dk    rt          | j        dd          S |                    d          s|                    d          rt          | j        dd          S | j                            |          rt          |          rt          | j        dd	          S || j
        k    r/t          | j        d
d                    || j
                            S dS )z5Check the package version located in info/index.json.rP   NoneC1104z*Missing package version in info/index.jsonr|   r{   C1107zFPackage version in info/index.json cannot start or end with '_' or '.'C1105z/Found invalid version number in info/index.jsonC1106zRFound package version in info/index.json "{}" does not match filename version "{}"N)strr:   r   r   r/   
startswithru   rh   r   r
   rP   r   )r8   package_versions     r   check_package_versionz'CondaPackageCheck.check_package_version   s&   dimmI6677f$$	7$P   %%j11 	_5M5M6
 6
 	 	X  
 %%o66 	+o:V:V 		7$U   dl**	ell#T\    +*r   c                     | j                             d          }|T	 t          |          }|dk     rt          | j        dd          S dS # t
          $ r t          | j        dd          cY S w xY wdS )z2Check the build number located in info/index.json.build_numberNr   C1109<Build number in info/index.json cannot be a negative integerC11082Build number in info/index.json must be an integer)r:   r   intr   r/   r   r8   r   s     r   check_build_numberz$CondaPackageCheck.check_build_number   s    y}}^44#"<00!## 	V   $#    IH     $#s   *A  A.-A.c                 4   | j                             d          }| j                            |          s)t	          | j        dd                    |                    S || j        k    r/t	          | j        dd                    || j                            S dS )z*Check the build string in info/index.json.rQ   C1110z2Found invalid build string "{}" in info/index.jsonC1111zWFound build number in info/index.json "{}" does not match build number "{}" in filenameN)r:   r   rh   r   r   r/   r   rQ   )r8   build_strings     r   check_build_stringz$CondaPackageCheck.check_build_string   s    y}}W--%%l33 		DKK     4:%%	ipp $*    &%r   c                 j    | j                             d          }|t          | j        dd          S dS )z@Check that the dependencies field is present in info/index.json.dependsNC1112z*Missing "depends" field in info/index.json)r:   r   r   r/   )r8   r   s     r   check_index_dependenciesz*CondaPackageCheck.check_index_dependencies   s=    )--	**?	7$P   ?r   c                    t          | j                            d                    }|dgk    r|D ]}|                                }t	          |          dk    rt          | j        dd          c S t	          |          dk    rt          t          |d                   rt	          |          dk    r+t          | j        d	d
	                    |                    c S dS dS )zFCheck that the dependencies in info/index.json are properly formatted.r   Nr   C1113z+Found empty dependencies in info/index.jsonr+   rs      C1114z0Found invalid dependency "{}" in info/index.json)
r   r:   r   splitlenr   r/   r   ver_spec_patr   )r8   dependencies
dependencydependency_partss       r   check_index_dependencies_specsz0CondaPackageCheck.check_index_dependencies_specs   s   "49==#;#;<<D6!!*  
#-#3#3#5#5 '((A-- 	E     ())Q..%l4DQ4GHH /+,,q00 	JQQ&      1 "! r   c                     | j                             d| j                             d                    }|t          vr)t          | j        dd                    |                    S dS )z:Check that the license family in info/index.json is valid.license_familylicenseC1115z-Found invalid license "{}" in info/index.jsonN)r:   r   r   r   r/   r   )r8   r   s     r   check_license_familyz&CondaPackageCheck.check_license_family   se    )-- 0$)--	2J2JKK***	?FFwOO   +*r   c                 f    t          | j        | j                  st          | j        dd          S dS )z@Check that contents of info/index.json are all ascii characters.C1116z1Found non-ascii characters inside info/index.jsonN)r	   rU   rb   r   r/   r8   s    r   check_index_encodingz&CondaPackageCheck.check_index_encoding  s>    T\22 		7$W  	 	r   c                     | j         D ]i}t          j        j        dk    r|                    d          }n|                    d          }t          |          st          | j        dd          c S jdS )z7Check the tar archive members for non ascii characters.r+   r<   C1118z:Found archive member names containing non-ascii charactersN)	rS   sysversion_infomajorrX   encoder	   r   r/   )r8   memberunicode_paths      r   check_memberszCondaPackageCheck.check_members
  s    * 	 	F%**%}}W55%}}W55\** IP    	 	r   c                 f    t          | j        | j                  st          | j        dd          S dS )z3Check the info/files file for non ascii characters.C1119z=Found filenames in info/files containing non-ascii charactersN)r	   rY   rb   r   r/   r   s    r   check_files_file_encodingz+CondaPackageCheck.check_files_file_encoding  s?    $,77 		O  	 	r   c                     d | j                             d                                          D             }|D ]/}|                    d          rt	          | j        dd          c S 0dS )zZCheck that the info/files file does not contain any files found within the info directory.c                 6    g | ]}|                                 S r-   stripr3   r/   s     r   r9   z?CondaPackageCheck.check_files_file_for_info.<locals>.<listcomp>$  -     
 
 
!DJJLL
 
 
r   r<   r:   C1120z4Found filenames in info/files that start with "info"N)rY   rX   
splitlinesr   r   r/   )r8   r6   filenames      r   check_files_file_for_infoz+CondaPackageCheck.check_files_file_for_info"  s    
 
%)_%;%;G%D%D%O%O%Q%Q
 
 
	 " 	 	H""6** IJ    	 	r   c                     d | j                             d                                          D             }t          |          t          t	          |                    k    rt          | j        dd          S dS )z)Check the info/files file for duplicates.c                 6    g | ]}|                                 S r-   r   r   s     r   r9   zECondaPackageCheck.check_files_file_for_duplicates.<locals>.<listcomp>1  r   r   r<   C1121z'Found duplicate filenames in info/filesN)rY   rX   r   r   setr   r/   )r8   r6   s     r   check_files_file_for_duplicatesz1CondaPackageCheck.check_files_file_for_duplicates/  sz    
 
%)_%;%;G%D%D%O%O%Q%Q
 
 
	 y>>SY0000G-VWWW 10r   c                     t           fd j        D                       }t          d  j                            d                                          D                       }t          |                    |                    }|D ]`}||vr+t           j        dd	                    |                    c S ||vr+t           j        dd	                    |                    c S adS )	zRCheck that the files listed in info/files exist in the tar archive and vice versa.c                     g | ][}t           j                            t           j                            j        |                    D|                    d           Y|\S r:   )r.   r/   isdirr1   r2   r   )r3   r   r8   s     r   r9   zCCondaPackageCheck.check_files_file_for_validity.<locals>.<listcomp>9  sg     
 
 
7==dk6!B!BCC
 %%f--	

 
 
r   c                     g | ]Z}|                                                     d           )t          j                            |                                           [S r   )r   r   r.   r/   normpathr   s     r   r9   zCCondaPackageCheck.check_files_file_for_validity.<locals>.<listcomp>?  s\     
 
 
::<<**622
GTZZ\\**
 
 
r   r<   C1122z9Found filename in info/files missing from tar archive: {}C1123z9Found filename in tar archive missing from info/files: {}N)
r   rS   rY   rX   r   sortedunionr   r/   r   )r8   membersr6   sorted_union_filenamesr   s   `    r   check_files_file_for_validityz/CondaPackageCheck.check_files_file_for_validity7  sD    
 
 
 
.
 
 
    
 
..w77BBDD
 
 
  	 "(i(@(@!A!A. 	 	Hw&&IWfX&&     **IPWW       +	 	r   c                     | j         D ]o}t          j                            t          j                            | j        |                    r+t          | j        dd                    |                    c S pdS )z$Check the tar archive for hardlinks.C1124z Found hardlink {} in tar archiveN)rS   r.   r/   islinkr1   r2   r   r   )r8   r   s     r   check_for_hardlinksz%CondaPackageCheck.check_for_hardlinksX  s    * 	 	Fw~~bgll4;??@@ I7>>vFF    	 	r   c                     h d}| j         D ]F}||v s|                    d          r+t          | j        dd                    |                    c S GdS )z0Check the tar archive for unallowed directories.>   	conda-bld
conda-metaenvspkgspkgs32)z	.DS_Store~C1125z'Found unallowed file in tar archive: {}Nr?   ru   r   r/   r   )r8   unallowed_directoriesfilepaths      r   check_for_unallowed_filesz+CondaPackageCheck.check_for_unallowed_filesb  s     U U U
 	 	H000H4E4E"5 50 I>EEhOO     1	 	r   c                 (   | j         D ]}|t          j                            dd          t          j                            dd          fv rE| j        d         dk    r4d| j        vr+t          | j        dd                    |                    c S d	S )
zDCheck that noarch Python packages contain the proper metadata files.r:   zpackage_metadata.jsonz	link.jsonr`   rA   preferred_envC1126z0Found {} however package is not a noarch packageN)r?   r.   r/   r1   r:   r   r   r8   r   s     r   check_for_noarch_infoz'CondaPackageCheck.check_for_noarch_infop  s    
 	 	HV%<==V[11   9X&(22di7W7W 	KRR$     	 	r   c                    d | j         D             }d | j         D             }t          |                              |          }t          |          dk    r)t	          | j        dd                    |                    S dS )zDCheck that both .bat and .exe files don't exist in the same package.c                 L    g | ]!}|                     d           |dd         "S )z.batNrr   ru   r3   r   s     r   r9   z;CondaPackageCheck.check_for_bat_and_exe.<locals>.<listcomp>  C     
 
 
&8I8I&8Q8Q
SbSM
 
 
r   c                 L    g | ]!}|                     d           |dd         "S ).exeNrr   r   r   s     r   r9   z;CondaPackageCheck.check_for_bat_and_exe.<locals>.<listcomp>  r   r   r   C1127zDFound both .bat and .exe files with same basename in same folder: {}N)r?   r   intersectionr   r   r/   r   )r8   	bat_files	exe_filesisects       r   check_for_bat_and_exez'CondaPackageCheck.check_for_bat_and_exe  s    
 
*.*
 
 
	
 
*.*
 
 
	 I++I66u::>>	V]]    >r   c                 x    | j         0t          | j         | j                  st          | j        dd          S dS dS )z5Check the info/has_prefix file for proper formatting.NC1128z-Found non-ascii characters in info/has_prefix)rZ   r	   rb   r   r/   r   s    r   check_prefix_filez#CondaPackageCheck.check_prefix_file  sP    'T-t|<< Iw(W   (' r   c                 Z   | j         | j                             d                                          D ]v}|                                }	 |                                \  }}}|                    d          }|                    d          }n# t
          $ r	 dd|}}}Y nw xY w|||fc S dS )zExtract the contents of the has_prefix file and return them.

        If the has_prefix file does not exist, None is returned.
        Nr<   z'"z/<dummy>/<placeholder>text)rZ   rX   r   r   r   r   )r8   lineplaceholdermoder   s        r   prefix_file_contentsz&CondaPackageCheck.prefix_file_contents  s     '(//88CCEE 	5 	5zz||Y26**,,/Kx"-"3"3E":":K'~~e44HH! Y Y Y2JFTXxKKKY $T84444ts   ABB! B!c                     | j         Z| j         \  }}}t          j                            |          | j        vr+t          | j        dd                    |                    S dS dS )z<Check that the filenames in has_prefix exist in the archive.NC1129z>Found filename "{}" in info/has_prefix not included in archive)r  r.   r/   r   r?   r   r   )r8   r|   r   s      r   check_prefix_file_filenamez,CondaPackageCheck.check_prefix_file_filename  sv    $0!6NAq(w));;IU\\    	 10 <;r   c                     | j         8| j         \  }}}|dvr+t          | j        dd                    |                    S dS dS )z8Check that the has_prefix mode is either binary or text.N)binaryr  C1130z*Found invalid mode "{}" in info/has_prefix)r  r   r/   r   )r8   r|   r  s      r   check_prefix_file_modez(CondaPackageCheck.check_prefix_file_mode  s`    $02JAtQ---IAHHNN  	 10 .-r   c                 2   | j         | j         \  }}}|dk    r|| j        dk    rt          | j        dd          S | j        rt          | j        dd          S t          |          dk    r-t          | j        d	d
                    |                    S dS dS dS )z6Check that the has_prefix file binary mode is correct.Nr  pythonC1131zLBinary placeholder found in info/has_prefix not allowed when building PythonC1132zJBinary placeholder found in info/has_prefix not allowed in Windows package   C1133zTBinary placeholder "{}" found in info/has_prefix does not have a length of 255 bytes)r  rK   r   r/   rb   r   r   )r8   r  r  r|   s       r   check_prefix_file_binary_modez/CondaPackageCheck.check_prefix_file_binary_mode  s    $0#'#< Kqx9(( 	f  
 \  	d  
 %%,, 	ovv'   # 10   -,r   c                     | j         D ]B}|                    d          r+t          | j        dd                    |                    c S CdS )z2Check the tar archive for pre and post link files.)z-post-link.shz-pre-link.shz-pre-unlink.shz-post-link.batz-pre-link.batz-pre-unlink.batC1134z(Found pre/post link file "{}" in archiveNr   r   s     r   check_for_post_linksz&CondaPackageCheck.check_for_post_links  sv    
 	 	H  	 	  I?FFxPP    	 	r   c                     | j         D ]B}|                    d          r+t          | j        dd                    |                    c S CdS )z$Check the tar archive for egg files.z.eggC1135zFound egg file "{}" in archiveNr   r   s     r   check_for_eggzCondaPackageCheck.check_for_egg  sm    
 	 	H  (( I5<<XFF    	 	r   c                    | j         D ]}|                    t          j                            dd          t          j                            dd          f          r+t          | j        dd                    |                    c S dS )z/Check the tar archive for easy_install scripts.bineasy_installScriptsC1136z)Found easy_install script "{}" in archiveN)r?   r   r.   r/   r1   r   r   r   s     r   check_for_easy_install_scriptz/CondaPackageCheck.check_for_easy_install_script   s    
 	 	H""GLL77GLLN;;  
 I@GGQQ    
	 	r   c           
          | j         D ]_}|                    d          rHt          | j        dd                    t
          j                            |                              c S `dS )z%Check the tar archive for .pth files.z.pthC1137z$Found namespace file "{}" in archiveN)r?   ru   r   r/   r   r.   r   r   s     r   check_for_pth_filez$CondaPackageCheck.check_for_pth_file  s    
 	 	H  (( I;BB((22     	 	r   c                     | j         D ]M}|                    d          r6| j        dk    r+t          | j        dd                    |                    c S NdS )z$Check the tar archive for .pyo filesz.pyor  C1138zFound pyo file "{}" in archiveN)r?   ru   rK   r   r/   r   r   s     r   check_for_pyo_filez$CondaPackageCheck.check_for_pyo_file  su    
 	 	H  (( TY(-B-BI5<<XFF    	 	r   c                     | j         D ]J}|                    d          r3d|vr/d|vr+t          | j        dd                    |                    c S KdS )zVCheck that .pyc files are only found within the site-packages or disutils directories.z.pycsite-packages	distutilsC1139z(Found pyc file "{}" in invalid directoryNr   r   s     r   check_for_pyc_in_site_packagesz0CondaPackageCheck.check_for_pyc_in_site_packages%  s    
 
	 
	H!!&))	#833x//I?FFxPP    
	 
	r   c                     | j         D ]F}d|v r@|                    d          r+t          | j        dd                    |                    c S GdS )z(Check the tar archive for .pickle files.lib2to3z.pickleC1140zFound lib2to3 .pickle file "{}"Nr   r   s     r   check_for_2to3_picklez'CondaPackageCheck.check_for_2to3_pickle3  sq    
 	 	HH$$):):9)E)E$I6==hGG    	 	r   c                     d| j         vrZ| j        D ]T}d|v rL|                    d          r7|dz   | j        vr+t          | j        dd                    |                    c S SdS dS )zGCheck that a .pyc file exists for every .py file in a Python 2 package.py3r(  z.pycC1141z7Found python file "{}" without a corresponding pyc fileN)rQ   r?   ru   r   r/   r   r   s     r   check_pyc_filesz!CondaPackageCheck.check_pyc_files=  s    
"" J 	 	"h..((// X^DJ4V4V$ I#V]] (       	 #"	 	r   c                 |   d | j         D             }t          |          dk    rn|d         }|t          j                            d                    | j                            k    r)t          | j        dd                    |                    S d	S t          |          dk    rt          | j        dd          S d	S )
zKCheck that the Menu/package.json filename is identical to the package name.c                     g | ]@}|                     d t          j        j        z             )|                    d          >|AS )Menuz.json)r   r.   r/   sepru   r   s     r   r9   z:CondaPackageCheck.check_menu_json_name.<locals>.<listcomp>M  s^     
 
 
""6BGK#788
 >F=N=Nw=W=W

 
 
r   rs   r   z{}.jsonC1142z!Found invalid Menu json file "{}"C1143z"Found more than one Menu json fileN)r?   r   r.   r/   r   r   rK   r   )r8   menu_json_filesr   s      r   check_menu_json_namez&CondaPackageCheck.check_menu_json_nameK  s    
 
 J
 
 
 1$$&q)H27++I,<,<TY,G,GHHHHI8??II   IH !!A%%G-QRRR &%r   c                 L   | j         r| j        d         }|dvr)t          | j        dd                    |                    S | j        D ]}|                    d          rt          t          j        	                    | j
        |          d          5 }|                    d          }t          |          }|dk    r|d	k    s|d
k    r?|dk    r9t          | j        dd                    |||                    cddd           c S ddd           n# 1 swxY w Y   dS dS )zGCheck that Windows package .exes and .dlls contain the correct headers.arch)x86x86_64C1144z,Found unrecognized Windows architecture "{}")r   .dllr;   i   r?  zDLL I386r@  z	DLL AMD64C1145z8Found file "{}" with object type "{}" but with arch "{}"N)rb   r:   r   r/   r   rS   ru   rT   r.   r1   r2   r   r   )r8   r>  r   file_objectfile_headerfile_object_types         r   check_windows_archz$CondaPackageCheck.check_windows_arch^  s   < 	9V$D,,,ICJJ4PP   .  ??#344 bgll4;??FF +&1&6&6t&<&<+:;+G+G( EMM.>*.L.L H,,1A[1P1P $) $	 ' [ b b$*,<d!" !"$ $                        	 	 s   A'DD	D	c                 N   | j         D ]}t          j                            | j        |          }|| j        v rt          j                            |          r| j        |         }t          j        |          j        }||d         k    r+t          | j        dd
                    |                    c S t          |d          5 }t          |          }ddd           n# 1 swxY w Y   ||d         k    r+t          | j        dd
                    |                    c S dS )	zCCheck the sha256 checksum and filesize of each file in the package.size_in_bytesC1147zAFound file "{}" with filesize different than listed in paths.jsonr;   Nr%   C1146zDFound file "{}" with sha256 hash different than listed in paths.json)rS   r.   r/   r1   r2   r]   isfilestatst_sizer   r   rT   r&   )r8   r   	file_pathr/   sizerD  sha256_digests          r   check_package_hashes_and_sizez/CondaPackageCheck.check_package_hashes_and_sizez  s   * 	 	FT[&99I---7>>),, /7D79--5DtO444$ I#_ff &        i.. E+(7(D(DE E E E E E E E E E E E E E E$X66$ I#bii &       #	 	s   C!!C%	(C%	c                     | j         d         dk    rJ| j        D ]D}|                    d          r+t          | j        dd                    |                    c S CdS dS )zFCheck that noarch packages do not contain architecture specific files.r`   rA   ).so.dylibrB  libC1148z1Found architecture specific file "{}" in package.N)r:   r?   ru   r   r/   r   r   s     r   check_noarch_filesz$CondaPackageCheck.check_noarch_files  s    9X(** J  $$%EFF  	LSS$      +* r   ),__name__
__module____qualname____doc__rG   rn   staticmethodrH   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   propertyr  r	  r  r  r  r  r   r#  r&  r+  r/  r4  r<  rG  rR  rX  __classcell__ri   s   @r   r(   r(   6   sz       DD)3 )3 )3 )3 )3V! ! !   \,  ,  8  (  (    2          X X X  B         &     X$  
 
 
  6  &    
 
 
        S S S&  8  6      r   r(   c                   d     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Z xZS )CondaRecipeCheckz1Create checks in order to validate conda recipes.c                    t          t          |                                            || _        || _        t          j        d          | _        t          j        d          | _        t          j        d          | _	        t          j        d          t          j        d          t          j        d          d| _
        dS )	z?Initialize conda recipe information for use with recipe checks.rD   rE   z(ftp|http(s)?)://z[a-f0-9]{32}$z[a-f0-9]{40}$z[a-f0-9]{64}$md5sha1r%   N)rF   rb  rG   meta
recipe_dirrc   rd   re   rh   url_patrg   )r8   rg  rh  ri   s      r   rG   zCondaRecipeCheck.__init__  s    %%..000	$
#>??:k22z"677:.//J/00j!122
 
r   c                    | j                             di                               dd          }|dk    rt          | j        dd          S | j                            |          r|                    d          r)t          | j        dd                    |                    S t          |          }|r)t          | j        d	d
                    |                    S dS )z:Check the package name in meta.yaml for proper formatting.packagerK    C2101z!Missing package name in meta.yamlrz   C2102z,Found invalid package name "{}" in meta.yamlC2103z+Found invalid sequence "{}" in package nameN)	rg  r   r   rh  re   r   ru   r   r
   )r8   r   rw   s      r   r   z#CondaRecipeCheck.check_package_name  s    y}}Y3377CC2'3VWWW}""<00 	L4I4I5
 5
 	 ?FF|TT   ,'' 	>EEcJJ  	 	r   c                    | j                             di                               dd          }|dk    rt          | j        dd          S t	          |t
                    r| j                            |          r*|                    d          s|	                    d          r)t          | j        dd
                    |                    S t          |          }|r+t          | j        d	d

                    |                    S dS dS )z=Check the package version in meta.yaml for proper formatting.rk  rP   rl  C2104z$Missing package version in meta.yamlr   C2105z/Found invalid package version "{}" in meta.yamlC2106z.Found invalid sequence "{}" in package versionN)rg  r   r   rh  
isinstancer   rh   r   r   ru   r   r
   )r8   r   rw   s      r   r   z&CondaRecipeCheck.check_package_version  s1   )--	266::9bIIb  *P   os++ 	$**?;;"--j99 #++J77
 OFMM'    o..C OELLSQQ  !	 	 r   c                    | j                             di                               d          }|T	 t          |          }|dk     rt          | j        dd          S dS # t
          $ r t          | j        dd          cY S w xY wdS )	z:Check the build number in meta.yaml for proper formatting.rQ   numberNr   C2108r   C2107r   )rg  r   r   r   rh  r   r   s     r   r   z#CondaRecipeCheck.check_build_number  s    y}}Wb1155h??#"<00!## V   $#    OH     $#s   *A  BBc                    | j         D ]}|t          vr1|dk    r+t          | j        dd                    |                    c S |dk    r| j                             |          }t          |d          rC|D ]?}|t          |         vr.t          | j        dd                    ||                    c c S @|D ]F}|D ]A}|t          |         vr0t          | j        dd                    ||                    c c c S BGdS )z4Check that the fields listed in meta.yaml are valid.extraC2109zFound invalid section "{}"keysC2110z(Found invalid field "{}" in section "{}"N)rg  r   r   rh  r   r   hasattr)r8   sectionsubfieldkeyentrys        r   check_fieldszCondaRecipeCheck.check_fields   s    y 	" 	"Gf$$G););O188AA     '!!9==118V,, "'  fWo55#( $ ' K R R$'!" !"$ $      6 "* 	" 	"#( " "C"&/99',$(O$+$O$V$V(+W%& %&(" (" !" !" !" !" !" !" !"  :"/	" 	"r   c                 ^   | j                             di                               dg           }| j                             di                               dg           }||z   D ]}|                                }|d         }| j                            |          s^||v r+t          | j        dd                    |                    c S ||v r+t          | j        dd                    |                    c S t          |          dk    rt          | j        d	d
          c S t          |          dk    rFt          t          |d                   s+t          | j        dd                    |                    c S t          |          t          t          |                    k    r)t          | j        dd                    |                    S t          |          t          t          |                    k    r)t          | j        dd                    |                    S dS )z:Check that the requirements listed in meta.yaml are valid.requirementsrQ   runr   C2111z$Found invalid build requirement "{}"C2112z"Found invalid run requirement "{}"C2113z%Found empty dependencies in meta.yamlr+   rs   C2114z*Found invalid dependency "{}" in meta.yamlC2115z&Found duplicate build requirements: {}C2116z$Found duplicate run requirements: {}N)rg  r   r   re   r   r   rh  r   r   r   r   r   )r8   build_requirementsrun_requirementsrequirementrequirement_partsrequirement_names         r   check_requirementsz#CondaRecipeCheck.check_requirements$  so   !Y]]>2>>BB7BOO9==<<@@KK-0@@ 	 	K + 1 1 3 303=&&'788 "444 ?FF{SS    
 !$444 =DD[QQ     $%%**OW.U     &''1,,Y/26 6, OAHHUU     !""c#.@*A*A&B&BBB9@@ASTT     C,<(=(=$>$>>>7>>?OPP   ?>r   c                    | j                             di                               d          }|)t          |          dk    rt          | j        dd          S | j                             di                               d          }| j                             di                               d          }| j                             di                               d	          }| j                             di                               d
          }||||fD ]I}|E| j                            |          s+t          | j        dd                    |                    c S JdS )z9Check the about field in meta.yaml for proper formatting.aboutsummaryNP   C2117z4Found summary with length greater than 80 charactershomedev_urldoc_urllicense_urlC2118#Found invalid URL "{}" in meta.yaml)rg  r   r   r   rh  ri  r   r   )r8   r  r  r  r  r  urls          r   check_aboutzCondaRecipeCheck.check_aboutW  sW   )--,,00;;3w<<"#4#4F   y}}Wb))--f55)--,,00;;)--,,00;;immGR0044]CC'7K8 	 	Ct|'9'9#'>'>O:AA#FF    	 	r   c           	         t          | j                            di                     }|D ]"}|                    d          }|| j                            |          rjdD ]f}|                    |          }|M| j        |                             |          s-t          | j        dd                    |                    c c S gn+t          | j        dd                    |                    c S |                    d	          }|rB|                    d
          r-|                    d          rt          | j        dd          c S $dS )z:Check the source field in meta.yaml for proper formatting.sourcer  Nrd  C2119z$Found invalid hash "{}" in meta.yamlC2120r  git_urlgit_tag
git_branchC2121z;Found both git_branch and git_tag in meta.yaml source field)	r   rg  r   ri  r   rg   r   rh  r   )r8   sourcesr  r  hash_algorithmr   r  s          r   check_sourcezCondaRecipeCheck.check_sourceo  s   dimmHb99:: 	 	F**U##C<%%c** *C  $*JJ~$>$>	$0*:%	** 1 $) $ ' G N N$-!" !"$ $      !>EEcJJ     jj++G FJJy11 fjj6N6N OQ    7	 	r   c                 (   | j                             di                               d| j                             di                               d                    }|2|t          vr+t          | j        dd                    |                    S dS dS )z;Check that the license family listed in meta.yaml is valid.r  r   r   NC2122z!Found invalid license family "{}")rg  r   r   r   rh  r   )r8   r   s     r   r   z%CondaRecipeCheck.check_license_family  s    w3377dimmGR88<<YGG
 
 %.@P*P*P4;;NKK   &%*P*Pr   c                    | j                             di                               dg           }| j                             di                               dg           }t          | j                             di                     }g }|D ]+}|                    |                    dg                      ,||z   |z   D ]}t          j                            | j        |          }|                    d          r+t          | j        dd
                    |                    c S t          j                            |          s+t          | j        d	d

                    |                    c S dS )z/Check that the files listed in meta.yaml exist.testr=   source_filesr  patchesz..C2123z/Found file "{}" listed outside recipe directoryC2124z/Found file "{}" in meta.yaml that doesn't existN)rg  r   r   extendr.   r/   r1   rh  r   r   r   exists)r8   
test_filestest_source_filesr  source_patchesr  r   r   s           r   check_for_valid_filesz&CondaRecipeCheck.check_for_valid_files  s   Y]]62..227B??
 IMM&"5599."MMdimmHb99:: 	= 	=F!!&**Y";";<<<<"%66G 	 	Hw||DOX>>H""4(( OFMMhWW     7>>(++ OGNN      	 	r   c           	         d}t          j        | j                  D ]m\  }}}|D ]d}t           j                            ||          }|                    |          r-t          | j        dd                    |                    c c S endS )z7Check for disallowed files inside the recipe directory.)
rq   z.tar.gzrp   z.tar.xzrT  rU  z.laz.arB  z.pydC2125z)Found disallowed file with extension "{}"N)r.   rR   rh  r/   r1   ru   r   r   )r8   disallowed_extensionsdirpathr|   r6   r   r   s          r   check_dir_contentz"CondaRecipeCheck.check_dir_content  s    !
 &(WT_%=%= 	 	!GQ	%  7<<::$$%:;;  DKKHUU      	 	r   c                 x   t           j                            | j        d          }t	          |          5 }|                                                                }ddd           n# 1 swxY w Y   |D ]D}|                    d          r-|t          j                    v rt          | j        dd          c S EdS )z9Check for default comments in conda-forge example recipe.z	meta.yamlN#C2126z+Found conda-forge comment in meta.yaml file)
r.   r/   r1   rh  rT   r   r   r   r   r   )r8   rg  	meta_filereciper  s        r   check_recipes_commentsz'CondaRecipeCheck.check_recipes_comments  s    w||DO[99$ZZ 	39^^%%0022F	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3  	 	Ds## 0D0O0Q0Q(Q(QOA    	 	s   'A((A,/A,)rY  rZ  r[  r\  rG   r   r   r   r  r  r  r  r   r  r  r  r_  r`  s   @r   rb  rb    s        ;;
 
 
 
 
  0  >  *"" "" ""H1 1 1f  0" " "H    6  2      r   rb  )r   )r\  r   rV   r.   rc   r   conda_package_handling.apirL   tempfiler   backports.tempfileconda_verify.errorsr   r   conda_verify.constantsr   r   r   conda_verify.utilitiesr	   r
   r   r   r   r   r   r#   r&   objectr(   rb  r-   r   r   <module>r     s  	 	   				 				 



 ! ! ! !6+++++++655555555 3 3 3 3 3 3 3 3 Q Q Q Q Q Q Q Q Q Q                M! ! ! !# # #j	 j	 j	 j	 j	 j	 j	 j	Z} } } } }v } } } } }s   # -