
    *#hS1                        d dl mZ d dlZd dlmZ d dlmZmZm	Z	 d dl
Z
ddlmZ ddlmZ dZe de Z ej"                  e      Zd	ed
e	eef   fdZ ed      \  ZZg dZe	eee   ee   f   Z G d d      Z ed       G d de             Zedk(  rTd dlmZ  ed      ZejA                  d       ejC                         Z" ee"jF                        Z#ejI                  e#      Z%yy)    N)Path)AnyListTuple   )	resources)
deprecatedzDhttps://github.com/huggingface/datasets/tree/main/src/datasets/utils/resourcereturnc                 v    t        j                  t        |       }t        j                  |      t
         d|  fS )Nz/resources/)pkg_resources	read_textr   yaml	safe_loadBASE_REF_URL)r   contents     R/var/www/html/sandstorm/venv/lib/python3.12/site-packages/datasets/utils/readme.pyload_yaml_resourcer      s3    %%i:G>>'"|nKz$JJJ    zreadme_structure.yaml)z[Needs More Information]z[More Information Needed]zj(https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)c            	       V    e Zd Zddededee   defdZddefdZded	e	fd
Z
d	efdZy)SectionNnamelevellinessuppress_parsing_errorsc                     || _         || _        || _        d| _        d| _        i | _        g | _        g | _        | j                  | j                  |       y y )N Tr   )	r   r   r   textis_empty_textr   parsing_error_listparsing_warning_listparse)selfr   r   r   r   s        r   __init__zSection.__init__$   s[    	

	!"$$&!::!JJ/FJG "r   c                    d}g }d}| j                   D ],  }|j                  d      dk(  r|j                  d      d d dk(  r| }4|j                         d   | j                  dz   k(  r|s|dk7  r*t	        || j                  dz   |      | j
                  |<   g }na|g k7  r\| xj                  dj                  |      j                         z  c_        | j                  dk7  r| j                  t        vrd| _	        g }dj                  |j                         d	d        j                  d      }|j                  |       / |dk7  rU|| j
                  v r| j                  j                  d
| d       t	        || j                  dz   |      | j
                  |<   n_|g k7  rZ| xj                  dj                  |      j                         z  c_        | j                  dk7  r| j                  t        vrd| _	        | j                  dk(  rq|sn| j                  g k7  s| j                  g k7  rOdj                  d | j                  | j                  z   D              x}}d| j                   d|z   }t        |      y y y )Nr   F 
   z```r   # r   z)Multiple sections with the same heading `z:` have been found. Please keep only one of these sections.
c              3   &   K   | ]	  }d |z     yw)-	N ).0xs     r   	<genexpr>z Section.parse.<locals>.<genexpr>V   s     +s!EAI+ss   z=The following issues were found while parsing the README at ``:
)r   stripsplitr   r   r   r    joinFILLER_TEXTr!   appendr"   r#   r   
ValueError)r%   r   current_sub_levelcurrent_lines
code_startlineerrorserror_strings           r   r$   zSection.parse0   s`   
JJ 	3Dzz% B&E"2A&%/!+^
aDJJ$44Z$*6=>OQUQ[Q[^aQacp6qDLL!23$&M$*		RWW]%;%A%A%CC	99?tyy/K16D.(*$'HHTZZ\!"-=$>$D$DU$K!$$T*%	3( !B&$4++22CDUCV  WQ  R 3::KTZZZ]M]_l2m./ B&II!7!=!=!??IyyB499K+G-2*::$;&&",0I0IR0O"&))+st?V?VY]YrYr?r+s"ss!^_c_h_h^iimnqww .. 1P %<r   	structurer   c                    g }g }|d   du r:| j                   r.| j                  i k(  r|j                  d| j                   d       |d   du r+| j                   r|j                  d| j                   d       |d   C| j                  i k(  r[|d   D cg c]  }|d	   	 }}|j                  d
| j                   ddj	                  |D cg c]
  }d|z   dz    c}       d       n|d   D cg c]  }|d	   	 }}d}t        |      D ]z  \  }	}
|
| j                  vr%|j                  d
| j                   d|
 d       d}9| j                  dk(  rI| j                  |
   j                  |d   |	         \  }}}||z  }||z  }| |r8| j                  D ])  }
|
|vs|j                  d| j                   d|
 d       + |ri ||fS | j                         ||fS c c}w c c}w c c}w )aC  Validates a Section class object recursively using the structure provided as a dictionary.

        Args:
            structute (:obj: `dict`): The dictionary representing expected structure.

        Returns:
            :obj: `ReadmeValidatorOutput`: The dictionary representation of the section, and the errors.
        allow_emptyFz"Expected some content in section `z` but it is empty.allow_empty_textzExpected some text in section `z4` but it is empty (text in subsections are ignored).subsectionsr   z	Section `z&` expected the following subsections: , `z. Found 'None'.z` is missing subsection: `z`.Tz###z` has an extra subsection: `z[`. Skipping further validation checks for this subsection as expected structure is unknown.)	r!   r   r8   r   r6   	enumerater   validateto_dict)r%   r@   
error_listwarning_list
subsectionvaluesr1   structure_nameshas_missing_subsectionsidxr   _subsec_error_listsubsec_warning_lists                 r   rH   zSection.validateZ   sc    
]#u,!!dllb&8!!$FtyykQc"de'(E1!!!!5dii[@tu ]#/||r!?H?WX*V,XX!!		{*PQUQZQZou[vjk\_`a\abe\e[vQwPx  yH  I
 IRR_H`"a*:f#5"a"a*/'!*?!; <IC4<</"))Idii[@Z[_Z``b*cd26/  ::.$HLUYHZHcHc )- 8 =IEA02E #&77
$(;;#<& + $ 6(//"#DII;.J4&  Ql  !m z<//<<>:|;;O Y \w #bs   G
G /G%c                     | j                   | j                  | j                  | j                  j	                         D cg c]  }|j                          c}dS c c}w )z3Returns the dictionary representation of a section.)r   r    r!   rD   )r   r    r!   r   rM   rI   )r%   values     r   rI   zSection.to_dict   sL     IIII!//9=9L9L9NOEMMOO	
 	
 Ps   A
NFF)__name__
__module____qualname__strr   boolr&   r$   dictReadmeValidatorOutputrH   rI   r/   r   r   r   r   #   s^    
HS 
H 
HT#Y 
H`d 
H(/T (/TE<$ E<+@ E<N
 
r   r   z*Use `huggingface_hub.DatasetCard` instead.c            
            e Zd Zddedee   dedef fdZd Ze	dde
dedefd       Ze		 dd	eded
edefd       Zddef fdZd Zd Z xZS )ReadMer   r   r@   r   c                     t         |   |d       || _        d| _        d| _        || _        | j
                  | j                  |       y y )Nr   )r   r   r   r   )superr&   r@   yaml_tags_line_count	tag_countr   r$   )r%   r   r   r@   r   	__class__s        r   r&   zReadMe.__init__   sP    d"-"$&!
::!JJ/FJG "r   c                 2   | j                   | j                  t              \  }}}n| j                  | j                         \  }}}|g k7  s|g k7  rCdj                  ||z   D cg c]  }d|z   	 c}      }d| j                   d|z   }t        |      y c c}w )Nr,   r.   z3The following issues were found for the README at `r3   )r@   	_validatereadme_structurer6   r   r9   )r%   r   rJ   rK   r1   r>   r?   s          r   rH   zReadMe.validate   s    >>!04?O0P-GZ04t~~0N-GZ|r1YY:3LMa	MNFPQUQZQZP[[_`ciiL\**  2Ms   "Bpathc                 ~    t        |d      5 }|j                         }d d d         | |||      S # 1 sw Y   xY w)Nzutf-8)encodingr   )open	readlines)clsrj   r@   r   fr   s         r   from_readmezReadMe.from_readme   s@    $) 	"QKKME	"4	CZ[[	" 	"s   3<string	root_namec                 <    |j                  d      } | ||||      S )Nr,   r   )r5   )ro   rr   r@   rs   r   r   s         r   from_stringzReadMe.from_string   s$     T"9eYH_``r   c                 ~   d}| j                   D ]V  }| xj                  dz  c_        |j                  d      dk(  r&| xj                  dz  c_        | j                  dk(  r n|dz  }X | j                  dk(  r| j                   |dz   d  | _         n| j                   | j                  d  | _         t        |   |       y )Nr   r   r(   z---   r   )r   rd   r4   re   rc   r$   )r%   r   
line_countr=   rf   s       r   r$   zReadMe.parse   s    
JJ 	D%%*%zz% E)!#>>Q&!OJ	 >>QJN$45DJDNN$45DJ.EFr   c                 4    t        | j                               S )z>Returns the string of dictionary representation of the ReadMe.)r[   rI   )r%   s    r   __str__zReadMe.__str__   s    4<<>""r   c           
      4   g }g }| j                   dk(  r|j                  d       nA| j                  dk(  r|j                  d       n | j                  dk(  r|j                  d       t        | j                  j                               }|dkD  rZ|j                  ddj                  t        | j                  j                               D cg c]
  }d|z   dz    c}       d	       n|dk  r|j                  d
       n{t        | j                  j                               d   }|j                  d      r3| j                  |   j                  |d   d         \  }}}	||z  }||	z  }n|j                  d       |ri ||fS | j                         ||fS c c}w )Nr   z-Empty YAML markers are present in the README.z*No YAML markers are present in the README.r   z2Only the start of YAML tags present in the README.z-The README has several first-level headings: rE   rF   zL. Only one heading is expected. Skipping further validation for this README.zmThe README has no first-level headings. One heading is expected. Skipping further validation for this README.zDataset Card forrD   zuNo first-level heading starting with `Dataset Card for` found in README. Skipping further validation for this README.)rd   r8   re   lenr   keysr6   list
startswithrH   rI   )
r%   ri   rJ   rK   num_first_level_keysr1   	start_keyrQ   sec_error_listsec_warning_lists
             r   rh   zReadMe._validate   s   
$$) OP^^q  LM^^q  TU"4<<#4#4#67!#?		^bcgcococtctcv^wJxYZ3q5QT9Jx@y?z  {G  H "A% T\\..01!4I##$676:ll96M6V6V$]3A673>#3 n,
 00 !! L z<//<<>:|;;7 Kys   FrV   )NrootFrW   )rX   rY   rZ   r[   r   r]   r\   r&   rH   classmethodr   rq   ru   r$   rz   rh   __classcell__)rf   s   @r   r`   r`      s    HS Hc Ht Hei H+ \t \ \VZ \ \
 kpaa%)a=@adha aGT G"#)<r   r`   __main__)ArgumentParserz?Validate the content (excluding YAML tags) of a README.md file.)usagereadme_filepath)&importlib.resourcesr   r   loggingpathlibr   typingr   r   r   r   r   deprecation_utilsr	   r   __file__this_url	getLoggerrX   loggerr[   r   ri   known_readme_structure_urlr7   r]   r^   r   r`   argparser   apadd_argument
parse_argsargsr   rq   readmer/   r   r   <module>r      s$   +   # #   ) V^1XJ'			8	$K KsCx K
 0BBY/Z , , dDItCy89 E
 E
P 89_<W _< :_<D z'	_	`BOO%&==?D4//0O0F r   