ó
á0]c           @   s'  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 y d d l m	 Z	 Wn d d l
 m	 Z	 n Xd 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 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sž  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.
iÿÿÿÿN(   t   TemporaryDirectory(   t   Errort   PackageError(   t   FIELDSt   LICENSE_FAMILIESt   CONDA_FORGE_COMMENTS(   t	   all_asciit   get_bad_seqt   get_object_typet   ensure_listt	   fullmatcht   rm_rfs:   ^(?:[><=]{0,2}(?:(?:[\d\*]+[!\._]?){1,})[+\w\*]*[|,]?){1,}i   c            ss   t  t | ƒ } | s- t d j | ƒ ƒ ‚ n	 | ƒ  } x0 t ‡  ‡ f d †  d ƒ D] } | j | ƒ qR W| j ƒ  S(   Ns   Unrecognized hash algorithm: {}c              s   ˆ j  ˆ  ƒ S(   N(   t   read(    (   t
   buffersizet   fd(    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   <lambda>-   t    R   (   t   getattrt   hashlibt
   ValueErrort   formatt   itert   updatet	   hexdigest(   R   t	   algorithmR   t	   hash_implt   block(    (   R   R   s2   lib/python2.7/site-packages/conda_verify/checks.pyt	   _checksum'   s    	"c         C   s   t  |  d ƒ S(   Nt   sha256(   R   (   R   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   sha256_checksum2   s    t   CondaPackageCheckc           B   sg  e  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 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) RS(&   s:   Create checks in order to validate conda package tarballs.c         C   së  t  t |  ƒ j ƒ  | |  _ |  j |  j ƒ |  _ t ƒ  |  _ |  j j |  _	 t
 j j |  j |  j	 ƒ |  j j d d ƒ \ |  _ |  _ |  _ g  t j |  j	 ƒ D]C \ } } } | D]- } t j j t j j | | ƒ |  j	 ƒ ^ q² qŸ |  _ |  _ t t j j |  j	 d d ƒ d ƒ  } | j ƒ  |  _ Wd QXt j |  j j d ƒ ƒ |  _ t t j j |  j	 d d ƒ d ƒ  } | j ƒ  |  _ Wd QXy@ t t j j |  j	 d d	 ƒ d ƒ  } | j ƒ  |  _ Wd QXWn t k
 räd |  _ n Xt! ƒ  |  _" yi t t j j |  j	 d d
 ƒ ƒ B } t j# | ƒ |  _$ x& |  j$ d D] } | |  j" | d <q8WWd QXWn2 t k
 rŽ|  j j% d k s‚t& ‚ i  |  _$ n Xt' |  j d d k ƒ |  _( t) j* d ƒ |  _+ t) j* d t) j, ƒ |  _- t) j* d ƒ |  _. d S(   sA   Initialize conda package information for use with package checks.t   -i   t   infos
   index.jsont   rbNs   utf-8t   filest
   has_prefixs
   paths.jsont   pathst   _patht   noarcht   platformt   wins   [a-z0-9_][a-z0-9_\-\.]*$s   [gh][0-9a-f]{5,}s   [\w\.]+$(/   t   superR   t   __init__t   patht   retrieve_package_namet   distR    t   _tmpdirt   namet   tmpdirt   conda_package_handlingt   apit   extractt   rsplitt   versiont   buildt   ost   walkt   relpatht   joinR$   t   archive_memberst   openR   t   indext   jsont   loadst   decodeR    t
   files_filet   prefix_filet   IOErrort   Nonet   dictt   paths_json_patht   loadt
   paths_jsont   subdirt   AssertionErrort   boolt   win_pkgt   ret   compilet   name_patt   It   hash_patt   version_pat(   t   selfR+   t   dpt   dnt	   filenamest   f(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR*   9   sB    	'D'''$c         C   s   t  |  j j ƒ d  S(   N(   R   R.   R/   (   RS   t   exct   valuet   tb(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   __exit__d   s    c         C   sª   t  j j |  ƒ }  t |  ƒ } | r< t d j | ƒ ƒ ‚ n  |  j d ƒ rS |  d  S|  j d ƒ rj |  d  S|  j d ƒ r |  d  St d j t  j j |  ƒ d	 ƒ ƒ ‚ d
 S(   s6   Retrieve the package name from the conda package path.u9   Found invalid sequence "{}" in package in info/index.jsons   .tar.bz2iøÿÿÿs   .tariüÿÿÿs   .condaiúÿÿÿs)   Found package with invalid extension "{}"i   N(   R7   R+   t   basenameR   R   R   t   endswitht   splitext(   R+   t   seq(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR,   g   s    c         C   s›   |  j  j d ƒ } | d k r1 t |  j d d ƒ S|  j j | ƒ sS | j d ƒ rf t |  j d d ƒ S| |  j k r— t |  j d	 d
 j	 | |  j ƒ ƒ Sd S(   s2   Check the package name located in info/index.json.R/   t   C1101s'   Missing package name in info/index.jsont   .R   t   _t   C1103s-   Found invalid package name in info/index.jsont   C1102uG   Found package name in info/index.json "{}" does not match filename "{}"N(   Ra   R   Rb   (
   R    t   getRD   R   R+   RO   t   matchR]   R/   R   (   RS   t   package_name(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_package_name~   s    	c         C   sÏ   t  |  j j d ƒ ƒ } | d k r7 t |  j d d ƒ S| j d ƒ sU | j d ƒ rh t |  j d d ƒ S|  j j | ƒ s‡ t	 | ƒ rš t |  j d	 d
 ƒ S| |  j
 k rË t |  j d d j | |  j
 ƒ ƒ Sd S(   s5   Check the package version located in info/index.json.R5   RD   t   C1104s*   Missing package version in info/index.jsonRb   Ra   t   C1107sF   Package version in info/index.json cannot start or end with '_' or '.'t   C1105s/   Found invalid version number in info/index.jsont   C1106uR   Found package version in info/index.json "{}" does not match filename version "{}"N(   Rb   Ra   (   Rb   Ra   (   t   strR    Re   R   R+   t
   startswithR]   RR   Rf   R   R5   R   (   RS   t   package_version(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_package_version”   s&    	c         C   sx   |  j  j d ƒ } | d k	 rt y/ t | ƒ } | d k  rL t |  j d d ƒ SWqt t k
 rp t |  j d d ƒ SXn  d S(   s2   Check the build number located in info/index.json.t   build_numberi    t   C1109s<   Build number in info/index.json cannot be a negative integert   C1108s2   Build number in info/index.json must be an integerN(   R    Re   RD   t   intR   R+   R   (   RS   Rq   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_build_number°   s    c         C   su   |  j  j d ƒ } |  j j | ƒ s@ t |  j d d j | ƒ ƒ S| |  j k rq t |  j d d j | |  j ƒ ƒ Sd S(   s*   Check the build string in info/index.json.R6   t   C1110s2   Found invalid build string "{}" in info/index.jsont   C1111sW   Found build number in info/index.json "{}" does not match build number "{}" in filenameN(   R    Re   RR   Rf   R   R+   R   R6   (   RS   t   build_string(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_build_stringÄ   s    
c         C   s5   |  j  j d ƒ } | d k r1 t |  j d d ƒ Sd S(   s@   Check that the dependencies field is present in info/index.json.t   dependst   C1112s*   Missing "depends" field in info/index.jsonN(   R    Re   RD   R   R+   (   RS   Rz   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_index_dependenciesØ   s    c         C   sÄ   t  |  j j d ƒ ƒ } | d
 g k rÀ x– | D]‹ } | j ƒ  } t | ƒ d k re t |  j d d ƒ St | ƒ d k r‹ t t	 | d ƒ s t | ƒ d k r. t |  j d d	 j
 | ƒ ƒ Sq. Wn  d
 S(   sF   Check that the dependencies in info/index.json are properly formatted.Rz   i    t   C1113s+   Found empty dependencies in info/index.jsoni   i   i   t   C1114s0   Found invalid dependency "{}" in info/index.jsonN(   R	   R    Re   RD   t   splitt   lenR   R+   R
   t   ver_spec_patR   (   RS   t   dependenciest
   dependencyt   dependency_parts(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_index_dependencies_specsà   s"    c         C   sM   |  j  j d |  j  j d ƒ ƒ } | t k rI t |  j d d j | ƒ ƒ Sd S(   s:   Check that the license family in info/index.json is valid.t   license_familyt   licenset   C1115s-   Found invalid license "{}" in info/index.jsonN(   R    Re   R   R   R+   R   (   RS   R‡   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_license_familyù   s    !c         C   s,   t  |  j |  j ƒ s( t |  j d d ƒ Sd S(   s@   Check that contents of info/index.json are all ascii characters.t   C1116s1   Found non-ascii characters inside info/index.jsonN(   R   R=   RL   R   R+   (   RS   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_index_encoding  s    c         C   sj   xc |  j  D]X } t j j d k r4 | j d ƒ } n | j d ƒ } t | ƒ s
 t |  j d d ƒ Sq
 Wd S(   s7   Check the tar archive members for non ascii characters.i   s   utf-8t   C1118s:   Found archive member names containing non-ascii charactersN(	   R;   t   syst   version_infot   majorR@   t   encodeR   R   R+   (   RS   t   membert   unicode_path(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_members
  s    c         C   s,   t  |  j |  j ƒ s( t |  j d d ƒ Sd S(   s3   Check the info/files file for non ascii characters.t   C1119s=   Found filenames in info/files containing non-ascii charactersN(   R   RA   RL   R   R+   (   RS   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_files_file_encoding  s
    c         C   sh   g  |  j  j d ƒ j ƒ  D] } | j ƒ  ^ q } x0 | D]( } | j d ƒ r8 t |  j d d ƒ Sq8 Wd S(   sZ   Check that the info/files file does not contain any files found within the info directory.s   utf-8R    t   C1120s4   Found filenames in info/files that start with "info"N(   RA   R@   t
   splitlinest   stripRn   R   R+   (   RS   R+   RV   t   filename(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_files_file_for_info"  s    1c         C   sf   g  |  j  j d ƒ j ƒ  D] } | j ƒ  ^ q } t | ƒ t t | ƒ ƒ k rb t |  j d d ƒ Sd S(   s)   Check the info/files file for duplicates.s   utf-8t   C1121s'   Found duplicate filenames in info/filesN(   RA   R@   R—   R˜   R€   t   setR   R+   (   RS   R+   RV   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_files_file_for_duplicates/  s    1c         C   s)  t  g  |  j D]A } t j j t j j |  j | ƒ ƒ r | j d ƒ r | ^ q ƒ } t  g  |  j j	 d ƒ j
 ƒ  D]3 } | j ƒ  j d ƒ ss t j j | j ƒ  ƒ ^ qs ƒ } t | j | ƒ ƒ } x^ | D]V } | | k rù t |  j d d j | ƒ ƒ S| | k rË t |  j d d j | ƒ ƒ SqË Wd S(   sR   Check that the files listed in info/files exist in the tar archive and vice versa.R    s   utf-8t   C1122u9   Found filename in info/files missing from tar archive: {}t   C1123u9   Found filename in tar archive missing from info/files: {}N(   Rœ   R;   R7   R+   t   isdirR:   R0   Rn   RA   R@   R—   R˜   t   normpatht   sortedt   unionR   R   (   RS   R‘   t   membersR+   RV   t   sorted_union_filenamesR™   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_files_file_for_validity7  s.    %6
c         C   sX   xQ |  j  D]F } t j j t j j |  j | ƒ ƒ r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   s$   Check the tar archive for hardlinks.t   C1124u    Found hardlink {} in tar archiveN(   R;   R7   R+   t   islinkR:   R0   R   R   (   RS   R‘   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_hardlinksX  s    $c         C   sd   d d d d d h } xH |  j  D]= } | | k s@ | j d ƒ r t |  j d d	 j | ƒ ƒ Sq Wd
 S(   s0   Check the tar archive for unallowed directories.s
   conda-metas	   conda-bldt   pkgst   pkgs32t   envss	   .DS_Storet   ~t   C1125u'   Found unallowed file in tar archive: {}N(   s	   .DS_StoreR­   (   R$   R]   R   R+   R   (   RS   t   unallowed_directoriest   filepath(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_unallowed_filesb  s    	c         C   s‰   x‚ |  j  D]w } | t j j d d ƒ t j j d d ƒ f k r
 |  j d d k r d |  j k r t |  j d d j | ƒ ƒ Sq
 q
 Wd	 S(
   sD   Check that noarch Python packages contain the proper metadata files.R    s   package_metadata.jsons	   link.jsonRI   R&   t   preferred_envt   C1126u0   Found {} however package is not a noarch packageN(   R$   R7   R+   R:   R    R   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_noarch_infop  s    "c         C   s¥   g  |  j  D] } | j d ƒ r
 | d  ^ q
 } g  |  j  D] } | j d ƒ r9 | d  ^ q9 } t | ƒ j | ƒ } t | ƒ d k r¡ t |  j d d j | ƒ ƒ Sd S(   sD   Check that both .bat and .exe files don't exist in the same package.s   .batiüÿÿÿs   .exei    t   C1127sD   Found both .bat and .exe files with same basename in same folder: {}N(   R$   R]   Rœ   t   intersectionR€   R   R+   R   (   RS   R°   t	   bat_filest	   exe_filest   isect(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_bat_and_exe€  s    //c         C   s>   |  j  d k	 r: t |  j  |  j ƒ s: t |  j d d ƒ Sn  d S(   s5   Check the info/has_prefix file for proper formatting.t   C1128s-   Found non-ascii characters in info/has_prefixN(   RB   RD   R   RL   R   R+   (   RS   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_prefix_file“  s    c         C   s®   |  j  d k	 rª x˜ |  j  j d ƒ j ƒ  D]{ } | j ƒ  } y7 | j ƒ  \ } } } | j d ƒ } | j d ƒ } Wn% t k
 r˜ d d | } } } n X| | | f SWn  d S(   s‡   Extract the contents of the has_prefix file and return them.

        If the has_prefix file does not exist, None is returned.
        s   utf-8s   '"s   /<dummy>/<placeholder>t   textN(   RB   RD   R@   R—   R˜   R   R   (   RS   t   linet   placeholdert   modeR™   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   prefix_file_contents›  s    c         C   s_   |  j  d k	 r[ |  j  \ } } } t j j | ƒ |  j k r[ t |  j d d j | ƒ ƒ Sn  d S(   s<   Check that the filenames in has_prefix exist in the archive.t   C1129u>   Found filename "{}" in info/has_prefix not included in archiveN(   RÁ   RD   R7   R+   R¡   R$   R   R   (   RS   Rb   R™   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_prefix_file_filename®  s    c         C   sP   |  j  d k	 rL |  j  \ } } } | d k rL t |  j d d j | ƒ ƒ Sn  d S(   s8   Check that the has_prefix mode is either binary or text.t   binaryR½   t   C1130u*   Found invalid mode "{}" in info/has_prefixN(   RÄ   R½   (   RÁ   RD   R   R+   R   (   RS   Rb   RÀ   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_prefix_file_mode¼  s    c         C   s£   |  j  d
 k	 rŸ |  j  \ } } } | d k rŸ |  j d k rO t |  j d d ƒ S|  j rk t |  j d d ƒ St | ƒ d k rœ t |  j d d	 j | ƒ ƒ SqŸ n  d
 S(   s6   Check that the has_prefix file binary mode is correct.RÄ   t   pythont   C1131sL   Binary placeholder found in info/has_prefix not allowed when building Pythont   C1132sJ   Binary placeholder found in info/has_prefix not allowed in Windows packageiÿ   t   C1133uT   Binary placeholder "{}" found in info/has_prefix does not have a length of 255 bytesN(   RÁ   RD   R/   R   R+   RL   R€   R   (   RS   R¿   RÀ   Rb   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_prefix_file_binary_modeÈ  s&    	c         C   sC   x< |  j  D]1 } | j d
 ƒ r
 t |  j d d j | ƒ ƒ Sq
 Wd	 S(   s2   Check the tar archive for pre and post link files.s   -post-link.shs   -pre-link.shs   -pre-unlink.shs   -post-link.bats   -pre-link.bats   -pre-unlink.batt   C1134u(   Found pre/post link file "{}" in archiveN(   s   -post-link.shs   -pre-link.shs   -pre-unlink.shs   -post-link.bats   -pre-link.bats   -pre-unlink.bat(   R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_post_linksã  s         	c         C   sC   x< |  j  D]1 } | j d ƒ r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   s$   Check the tar archive for egg files.s   .eggt   C1135u   Found egg file "{}" in archiveN(   R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_eggö  s    c         C   sg   x` |  j  D]U } | j t j j d d ƒ t j j d d ƒ f ƒ r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   s/   Check the tar archive for easy_install scripts.t   bint   easy_installt   Scriptst   C1136u)   Found easy_install script "{}" in archiveN(   R$   Rn   R7   R+   R:   R   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_easy_install_script   s    c         C   sO   xH |  j  D]= } | j d ƒ r
 t |  j d d j t j j | ƒ ƒ ƒ Sq
 Wd S(   s%   Check the tar archive for .pth files.s   .ptht   C1137u$   Found namespace file "{}" in archiveN(   R$   R]   R   R+   R   R7   R¡   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_pth_file  s    c         C   sR   xK |  j  D]@ } | j d ƒ r
 |  j d k r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   s$   Check the tar archive for .pyo filess   .pyoRÇ   t   C1138u   Found pyo file "{}" in archiveN(   R$   R]   R/   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_pyo_file  s    c         C   s[   xT |  j  D]I } | j d ƒ r
 d | k r
 d | k r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   sV   Check that .pyc files are only found within the site-packages or disutils directories.s   .pycs   site-packagest	   distutilst   C1139u(   Found pyc file "{}" in invalid directoryN(   R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_pyc_in_site_packages%  s    c         C   sO   xH |  j  D]= } d | k r
 | j d ƒ r
 t |  j d d j | ƒ ƒ Sq
 Wd S(   s(   Check the tar archive for .pickle files.t   lib2to3s   .picklet   C1140u   Found lib2to3 .pickle file "{}"N(   R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_2to3_pickle3  s    c         C   sw   d |  j  k rs xa |  j D]S } d | k r | j d ƒ rl | d |  j k rl t |  j d d j | ƒ ƒ Sq q Wn  d S(   sG   Check that a .pyc file exists for every .py file in a Python 2 package.t   py3s   site-packagess   .pyt   ct   C1141u7   Found python file "{}" without a corresponding pyc fileN(   R6   R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_pyc_files=  s    "c         C   sÌ   g  |  j  D]4 } | j d t j j ƒ r
 | j d ƒ r
 | ^ q
 } t | ƒ d k r£ | d } | t j j d j |  j	 ƒ ƒ k rÈ t
 |  j d d j | ƒ ƒ Sn% t | ƒ d k rÈ t
 |  j d d	 ƒ Sd
 S(   sK   Check that the Menu/package.json filename is identical to the package name.t   Menus   .jsoni   i    s   {}.jsont   C1142u!   Found invalid Menu json file "{}"t   C1143s"   Found more than one Menu json fileN(   R$   Rn   R7   R+   t   sepR]   R€   R¡   R   R/   R   (   RS   R°   t   menu_json_filesR™   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_menu_json_nameK  s    4
$c         C   s  |  j  rþ |  j d } | d k r> t |  j d d j | ƒ ƒ Sx½ |  j D]¯ } | j d ƒ rH t t j j	 |  j
 | ƒ d ƒ t } | j d	 ƒ } t | ƒ } | d k r´ | d
 k sÌ | d k rî | d k rî t |  j d d j | | | ƒ ƒ SWd QXqH qH Wn  d S(   sG   Check that Windows package .exes and .dlls contain the correct headers.t   archt   x86t   x86_64t   C1144u,   Found unrecognized Windows architecture "{}"s   .exes   .dllR!   i   s   DLL I386s	   DLL AMD64t   C1145u8   Found file "{}" with object type "{}" but with arch "{}"N(   Rê   Rë   (   s   .exes   .dll(   RL   R    R   R+   R   R;   R]   R<   R7   R:   R0   R   R   (   RS   Ré   R‘   t   file_objectt   file_headert   file_object_type(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_windows_arch^  s&    	$c         C   sò   xë |  j  D]à } t j j |  j | ƒ } | |  j k r
 t j j | ƒ rê |  j | } t j | ƒ j } | | d k r” t	 |  j d d j
 | ƒ ƒ St | d ƒ  } t | ƒ } Wd QX| | d k rç t	 |  j d d j
 | ƒ ƒ Sqê q
 q
 Wd S(	   sC   Check the sha256 checksum and filesize of each file in the package.t   size_in_bytest   C1147sA   Found file "{}" with filesize different than listed in paths.jsonR!   NR   t   C1146sD   Found file "{}" with sha256 hash different than listed in paths.json(   R;   R7   R+   R:   R0   RF   t   isfilet   statt   st_sizeR   R   R<   R   (   RS   R‘   t	   file_pathR+   t   sizeRî   t   sha256_digest(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_package_hashes_and_sizez  s(    
c         C   sY   |  j  d d k rU x? |  j D]1 } | j d
 ƒ r t |  j d d j | ƒ ƒ Sq Wn  d	 S(   sF   Check that noarch packages do not contain architecture specific files.RI   R&   s   .sos   .dylibs   .dllt   libt   C1148u1   Found architecture specific file "{}" in package.N(   s   .sos   .dylibs   .dllRü   (   R    R$   R]   R   R+   R   (   RS   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_noarch_files•  s    (*   t   __name__t
   __module__t   __doc__R*   R[   t   staticmethodR,   Rh   Rp   Ru   Ry   R|   R…   R‰   R‹   R“   R•   Rš   R   R¦   R©   R±   R´   Rº   R¼   t   propertyRÁ   RÃ   RÆ   RË   RÍ   RÏ   RÔ   RÖ   RØ   RÛ   RÞ   Râ   Rè   Rñ   Rû   Rþ   (    (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR   6   sL   	+								
							!	
									
			
		
				t   CondaRecipeCheckc           B   sz   e  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 RS(   s1   Create checks in order to validate conda recipes.c         C   s˜   t  t |  ƒ j ƒ  | |  _ | |  _ t j d ƒ |  _ t j d ƒ |  _ t j d ƒ |  _	 i t j d ƒ d 6t j d ƒ d 6t j d ƒ d	 6|  _
 d
 S(   s?   Initialize conda recipe information for use with recipe checks.s   [a-z0-9_][a-z0-9_\-\.]*$s   [\w\.]+$s   (ftp|http(s)?)://s   [a-f0-9]{32}$t   md5s   [a-f0-9]{40}$t   sha1s   [a-f0-9]{64}$R   N(   R)   R  R*   t   metat
   recipe_dirRM   RN   RO   RR   t   url_patRQ   (   RS   R  R  (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR*   ¦  s    		c         C   s°   |  j  j d i  ƒ j d d ƒ } | d k r@ t |  j d d ƒ S|  j j | ƒ sb | j d ƒ r~ t |  j d	 d
 j | ƒ ƒ St | ƒ } | r¬ t |  j d d j | ƒ ƒ Sd S(   s:   Check the package name in meta.yaml for proper formatting.t   packageR/   R   t   C2101s!   Missing package name in meta.yamlRa   R   Rb   t   C2102u,   Found invalid package name "{}" in meta.yamlt   C2103u+   Found invalid sequence "{}" in package nameN(   Ra   R   Rb   (	   R  Re   R   R  RO   Rf   R]   R   R   (   RS   Rg   R_   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyRh   ´  s    !	c         C   sÑ   |  j  j d i  ƒ j d d ƒ } | d k r@ t |  j d d ƒ St | t ƒ rÍ |  j j | ƒ s€ | j d ƒ s€ | j	 d ƒ rœ t |  j d d	 j
 | ƒ ƒ St | ƒ } | rÍ t |  j d
 d j
 | ƒ ƒ Sn  d S(   s=   Check the package version in meta.yaml for proper formatting.R
  R5   R   t   C2104s$   Missing package version in meta.yamlRb   Ra   t   C2105u/   Found invalid package version "{}" in meta.yamlt   C2106u.   Found invalid sequence "{}" in package versionN(   Rb   Ra   (   Rb   Ra   (   R  Re   R   R  t
   isinstanceRm   RR   Rf   Rn   R]   R   R   (   RS   Ro   R_   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyRp   Ì  s&    !
c         C   s„   |  j  j d i  ƒ j d ƒ } | d k	 r€ y/ t | ƒ } | d k  rX t |  j d d ƒ SWq€ t k
 r| t |  j d d ƒ SXn  d S(	   s:   Check the build number in meta.yaml for proper formatting.R6   t   numberi    t   C2108s<   Build number in info/index.json cannot be a negative integert   C2107s2   Build number in info/index.json must be an integerN(   R  Re   RD   Rt   R   R  R   (   RS   Rq   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyRu   ë  s    c      	   C   s  x	|  j  D]þ } | t k rD | d k rD t |  j d d j | ƒ ƒ S| d k r
 |  j  j | ƒ } t | d ƒ r´ x‘ | D]5 } | t | k rx t |  j d d j | | ƒ ƒ Sqx WqxQ | D]F } x= | D]5 } | t | k rÈ t |  j d d j | | ƒ ƒ SqÈ Wq» Wq
 q
 Wd S(   s4   Check that the fields listed in meta.yaml are valid.t   extrat   C2109u   Found invalid section "{}"t   keyst   C2110u(   Found invalid field "{}" in section "{}"N(   R  R   R   R  R   Re   t   hasattr(   RS   t   sectiont   subfieldt   keyt   entry(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_fields   s0    c         C   s±  |  j  j d i  ƒ j d g  ƒ } |  j  j d i  ƒ j d g  ƒ } xô | | D]è } | j ƒ  } | d } |  j j | ƒ sÎ | | k r£ t |  j d d j | ƒ ƒ S| | k rÎ t |  j d d j | ƒ ƒ Sn  t | ƒ d k ró t |  j d	 d
 ƒ St | ƒ d k rM t	 t
 | d ƒ rM t |  j d d j | ƒ ƒ SqM Wt | ƒ t t | ƒ ƒ k rst |  j d d j | ƒ ƒ St | ƒ t t | ƒ ƒ k r­t |  j d d j | ƒ ƒ Sd S(   s:   Check that the requirements listed in meta.yaml are valid.t   requirementsR6   t   runi    t   C2111u$   Found invalid build requirement "{}"t   C2112u"   Found invalid run requirement "{}"t   C2113s%   Found empty dependencies in meta.yamli   i   t   C2114u*   Found invalid dependency "{}" in meta.yamlt   C2115u&   Found duplicate build requirements: {}t   C2116u$   Found duplicate run requirements: {}N(   R  Re   R   RO   Rf   R   R  R   R€   R
   R   Rœ   (   RS   t   build_requirementst   run_requirementst   requirementt   requirement_partst   requirement_name(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_requirements$  sF    !!
c         C   s#  |  j  j d i  ƒ j d ƒ } | d k	 rO t | ƒ d k rO t |  j d d ƒ S|  j  j d i  ƒ j d ƒ } |  j  j d i  ƒ j d ƒ } |  j  j d i  ƒ j d ƒ } |  j  j d i  ƒ j d	 ƒ } xU | | | | g D]A } | d k	 rÚ |  j j | ƒ rÚ t |  j d
 d j | ƒ ƒ SqÚ Wd S(   s9   Check the about field in meta.yaml for proper formatting.t   aboutt   summaryiP   t   C2117s4   Found summary with length greater than 80 characterst   homet   dev_urlt   doc_urlt   license_urlt   C2118u#   Found invalid URL "{}" in meta.yamlN(	   R  Re   RD   R€   R   R  R	  Rf   R   (   RS   R.  R0  R1  R2  R3  t   url(    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_aboutW  s     c         C   s-  t  |  j j d i  ƒ ƒ } x| D]} | j d ƒ } | d k	 rß |  j j | ƒ rÀ x„ d d d g D]T } | j | ƒ } | d k	 re |  j | j | ƒ re t |  j d d j	 | ƒ ƒ Sqe Wqß t |  j d d	 j	 | ƒ ƒ Sn  | j d
 ƒ } | r" | j d ƒ r" | j d ƒ r" t |  j d d ƒ Sq" Wd S(   s:   Check the source field in meta.yaml for proper formatting.t   sourceR5  R  R  R   t   C2119u$   Found invalid hash "{}" in meta.yamlt   C2120u#   Found invalid URL "{}" in meta.yamlt   git_urlt   git_tagt
   git_brancht   C2121s;   Found both git_branch and git_tag in meta.yaml source fieldN(
   R	   R  Re   RD   R	  Rf   RQ   R   R  R   (   RS   t   sourcesR7  R5  t   hash_algorithmR   R:  (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_sourceo  s2    
$c         C   sq   |  j  j d i  ƒ j d |  j  j d i  ƒ j d ƒ ƒ } | d k	 rm | t k rm t |  j d d j | ƒ ƒ Sd S(   s;   Check that the license family listed in meta.yaml is valid.R-  R†   R‡   t   C2122u!   Found invalid license family "{}"N(   R  Re   RD   R   R   R  R   (   RS   R†   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR‰   “  s    $c         C   s  |  j  j d i  ƒ j d g  ƒ } |  j  j d i  ƒ j d g  ƒ } t |  j  j d i  ƒ ƒ } g  } x' | D] } | j | j d g  ƒ ƒ qj Wx‡ | | | D]w } t j j |  j | ƒ } | j d ƒ rå t	 |  j d d j
 | ƒ ƒ St j j | ƒ sœ t	 |  j d	 d
 j
 | ƒ ƒ Sqœ Wd S(   s/   Check that the files listed in meta.yaml exist.t   testR"   t   source_filesR7  t   patchess   ..t   C2123u/   Found file "{}" listed outside recipe directoryt   C2124u/   Found file "{}" in meta.yaml that doesn't existN(   R  Re   R	   t   extendR7   R+   R:   R  Rn   R   R   t   exists(   RS   t
   test_filest   test_source_filesR>  t   source_patchesR7  R™   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_for_valid_files   s&    !!c      
   C   s   d } xt t  j |  j ƒ D]` \ } } } xN | D]F } t  j j | | ƒ } | j | ƒ r/ t |  j d d j | ƒ ƒ Sq/ Wq Wd S(   s7   Check for disallowed files inside the recipe directory.s   .tars   .tar.gzs   .tar.bz2s   .tar.xzs   .sos   .dylibs   .las   .as   .dlls   .pydt   C2125u)   Found disallowed file with extension "{}"N(
   s   .tars   .tar.gzs   .tar.bz2s   .tar.xzs   .sos   .dylibs   .las   .as   .dlls   .pyd(   R7   R8   R  R+   R:   R]   R   R   (   RS   t   disallowed_extensionst   dirpathRb   RV   R™   R°   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_dir_content»  s$             "c         C   sˆ   t  j j |  j d ƒ } t | ƒ  } | j ƒ  j ƒ  } Wd QXxB | D]: } | j d ƒ rF | t j ƒ  k rF t	 |  j d d ƒ SqF Wd S(   s9   Check for default comments in conda-forge example recipe.s	   meta.yamlNt   #t   C2126s+   Found conda-forge comment in meta.yaml file(
   R7   R+   R:   R  R<   R   R—   Rn   R   R   (   RS   R  t	   meta_filet   recipeR¾   (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   check_recipes_commentsÔ  s    !(   Rÿ   R   R  R*   Rh   Rp   Ru   R  R,  R6  R@  R‰   RL  RP  RU  (    (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyR  £  s   					$	3		$			(   R  R   R>   R7   RM   R   t   conda_package_handling.apiR1   t   tempfileR    t   backports.tempfilet   conda_verify.errorsR   R   t   conda_verify.constantsR   R   R   t   conda_verify.utilitiesR   R   R   R	   R
   R   R   R   R   t   objectR   R  (    (    (    s2   lib/python2.7/site-packages/conda_verify/checks.pyt   <module>
   s(   .
	ÿ ÿ o