
    Rtf3                        d Z ddlZddlZddlZddlZddlZddlZ	 ddlZddl
mZ ddlmZmZmZ ddlmZ ddlmZmZ dd	lmZ  G d
 dej,                        Z G d dej0                        Zddej4                  defdZdej4                  deddfdZddeee   df   defdZ e!dk(  r e" e              y# e$ r ddl	ZY w xY w)z.Run numpydoc validation on contents of a file.    N)Path)SequenceTupleUnion)tabulate   )	docscrapevalidate   )find_project_rootc                      e Zd ZdZdej
                  dej                  deddfdZ	e
d        Zedefd	       Zedefd
       Zedefd       Zedefd       Zedefd       Zedefd       Zedee   fd       Zedefd       Zy)AstValidatoraQ  
    Overrides the :class:`Validator` to work entirely with the AST.

    Parameters
    ----------
    ast_node : ast.AST
        The node under inspection.
    filename : os.PathLike
        The file where the node is defined.
    obj_name : str
        A name for the node to use in the listing of issues for the file as a whole.
    ast_nodefilenameobj_namereturnNc                   || _         t        j                  | j                   d      xs d| _        t        j                  | j                   d      | _        t        j                  | j                        | _        t        |      j                         | _
        || _        t        |t        j                        | _        t        |t        j                        | _        y )NF)clean T)nodeastget_docstringraw_doc	clean_docr	   NumpyDocStringdocr   resolve_source_file_name
isinstanceClassDefis_classModule	is_module)selfr   r   r   s       D/usr/lib/python3/dist-packages/numpydoc/hooks/validate_docstrings.py__init__zAstValidator.__init__&   s     &	--diiuEK!//		F-6-E-Edll-S)-h)?)?)A"
(3<<@)(CJJ?    c                     t        d      )Nz*AstValidator does not support this method.)NotImplementedError)names    r&   	_load_objzAstValidator._load_obj4   s    !"NOOr(   c                     | j                   S N)r   r%   s    r&   r+   zAstValidator.name8   s    zzr(   c                 j    t        | j                  t        j                  t        j                  f      S r.   )r    r   r   FunctionDefAsyncFunctionDefr/   s    r&   is_function_or_methodz"AstValidator.is_function_or_method<   s"    $))coos7K7K%LMMr(   c                     | j                   syt        j                  | j                        D ]C  }t	        |t        j
                        st	        |j                  t        j                        sC y y)NFT)r3   r   iter_child_nodesr   r    ExprvalueYield)r%   childs     r&   is_generator_functionz"AstValidator.is_generator_function@   sS    ))))$))4 	E%*z%++syy/Q	 r(   c                 f    | j                   ry| j                  ry| j                  ryt        d      )NfunctiontypemodulezUnknown type.)r3   r"   r$   
ValueErrorr/   s    r&   r=   zAstValidator.typeI   s-    %%==>>))r(   c                     | j                   S r.   )r   r/   s    r&   source_file_namezAstValidator.source_file_nameS   s       r(   c                 J    | j                   s| j                  j                  S dS )Nr   )r$   r   linenor/   s    r&   source_file_def_linez!AstValidator.source_file_def_lineW   s    '+~~tyy<1<r(   c                    d }t               }| j                  r || j                        }|S | j                  rN| j                  j                  D ]5  }t        |t        j                        s|j                  dk(  s. ||      }7 |S )Nc                 x   | j                   }g }dD ]  }t        ||      }|dv rM|r#|dk(  r|j                  d|j                          |s;|dk(  sA|j                  d|j                          `|j	                  |D cg c]  }|j                   c}        t        |      }|r|d   dv r|d	d  S |S c c}w )
N)posonlyargsargsvararg
kwonlyargskwarg)rI   rK   rI   *rK   z**r   >   clsr%   r   )rH   getattrappendargextendtuple)r   	args_nodeparamsarg_typeentriesrP   s         r&   extract_signaturez<AstValidator.signature_parameters.<locals>.extract_signature]   s    		IFT @!)X6228x#7'++&788w#67;;-&89MMg">s377">?@ 6]F&)6abz!M	 #?s    B7
r'   )	rR   r3   r   r"   bodyr    r   r1   r+   )r%   rW   rT   r9   s       r&   signature_parametersz!AstValidator.signature_parameters[   sx    	" %%&tyy1F
 	 ]] 6eS__5%**
:R.u5F6 r(   c                     t        | j                        5 }t        j                  |j	                         | j
                        }d d d        |S # 1 sw Y   S xY wr.   )openrA   r   get_source_segmentreadr   )r%   filesources      r&   method_sourcezAstValidator.method_sourcew   sK    $''( 	DD++DIIKCF	D	Ds   /AA)__name__
__module____qualname____doc__r   ASTosPathLikestrr'   staticmethodr,   propertyr+   boolr3   r:   r=   rA   intrD   r   rY   r`    r(   r&   r   r      s.   @77@.0kk@EH@	@ P P c   Nt N N t   *c * * !# ! ! =c = = eCj  6 s  r(   r   c                       e Zd ZdZdededdfdZdej                  dede	fd	Z
dej                  ddfd
Zdej                  ddfdZy)DocstringVisitora  
    Visits nodes in the AST from a given module and reporting numpydoc issues.

    Parameters
    ----------
    filepath : str
        The absolute or relative path to the file to inspect.
    config : dict
        Configuration options for reviewing flagged issues.
    filepathconfigr   Nc                     || _         || _        t        | j                        j                  | _        g | _        g | _        y r.   )rq   rp   r   stemmodule_namestackfindings)r%   rp   rq   s      r&   r'   zDocstringVisitor.__init__   s7    
 #% $T]] 3 8 8 "
 r(   r   checkc                     || j                   d   vry| j                   d   r?	 | j                   d   |   }t        j                  |t        j                  |            y	 yy# t
        $ r Y yw xY w)aW  
        Check whether the issue should be ignored.

        Parameters
        ----------
        node : ast.AST
            The node under inspection.
        check : str
            The code for the check being evaluated.

        Return
        ------
        bool
            Whether the issue should be excluded from the report.
        checksT	overridesF)rq   researchr   r   KeyError)r%   r   rw   patterns       r&   _ignore_issuezDocstringVisitor._ignore_issue   s}      H--;;{#++k25999Wc&7&7&=>J K
   s   ;A" "	A.-A.c           
      F   dj                  | j                        }t        j                  |t        || j                        }| j
                  j                  |d   D cg c]/  \  }}| j                  ||      s| j                   d|d    |||g1 c}}       yc c}}w )z
        Get numpydoc validation issues.

        Parameters
        ----------
        node : ast.AST
            The node under inspection.
        .)r   r   errors:	file_lineN)joinru   r
   r   rp   rv   rQ   r   )r%   r   r+   reportrw   descriptions         r&   _get_numpydoc_issuesz%DocstringVisitor._get_numpydoc_issues   s     xx

#"",
 	 +1*:&E;))$6 MM?!F;$7#894T	
s    4B
c                 :   t        |t        j                  t        j                  t        j                  t        j
                  f      r| j                  j                  t        |t        j                        r| j                  n|j                         | j                  d   r<t        j                  | j                  d   dj                  | j                              s| j                  |       | j                  |       | j                  j!                         }yy)z
        Visit a node in the AST and report on numpydoc validation issues.

        Parameters
        ----------
        node : ast.AST
            The node to visit.
        excluder   N)r    r   r#   r!   r1   r2   ru   rO   rt   r+   rq   r{   r|   r   r   generic_visitpop)r%   r   _s      r&   visitzDocstringVisitor.visit   s     3::s||S__c>R>RS
 JJ$.tSZZ$@  dii
 I&IIdkk)4chhtzz6JK))$/t$

 A
r(   )ra   rb   rc   rd   rh   dictr'   r   re   rk   r   r   r   rm   r(   r&   ro   ro   ~   st    		!	! 	! 
		!#'' # $ :
 
T 
*!#'' !d !r(   ro   dir_pathr   c                   
 dht               i d}t        |       j                         j                         } | dz  }| dz  }d 

fd}|j	                         rt        |d      5 }t        j                  |      }|j                  di       j                  d	i       }t        |j                  d
|d
               |d
<   |j                  d|d         }t        t        |t              s|n|g      |d<    |||j                                ddd       n|j	                         rt        j                         }|j                  |       d}		 	 t        |j                  |	d
      j                  d      j!                  d      xs |d
         |d
<   	 t        |j                  |	d      j                  d      j!                  d      xs |d         |d<    |||j                  |	             t'        j(                  |d
         |d
<    
|d         |d<   |S # 1 sw Y   4xY w# t        j"                  $ r Y w xY w# t        j"                  $ r Y }w xY w# t        j$                  $ r Y ~w xY w)a  
    Parse config information from a pyproject.toml or setup.cfg file.

    This function looks in the provided directory path first for a
    pyproject.toml file. If it finds that, it won't look for a setup.cfg
    file.

    Parameters
    ----------
    dir_path : os.PathLike
        An absolute or relative path to a directory containing
        either a pyproject.toml file specifying a
        [tool.numpydoc_validation] section or a setup.cfg file
        specifying a [tool:numpydoc_validation] section.
        For example, ``~/my_project``. If not provided, the hook
        will try to find the project root directory.

    Returns
    -------
    dict
        Config options for the numpydoc validation hook.
    all)ry   r   rz   zpyproject.tomlz	setup.cfgc                 `    | r+t        j                  dj                  d | D                    S d S )N|c              3   &   K   | ]	  }|s|  y wr.   rm   ).0exps     r&   	<genexpr>z6parse_config.<locals>.compile_regex.<locals>.<genexpr>   s      Cs Cs   )r{   compiler   )expressionss    r&   compile_regexz#parse_config.<locals>.compile_regex   s3      JJtyy C CCD	
 	
r(   c                     |D ]J  \  }}|j                  d      s|j                  d      \  }}|s/ |      | d   |j                         <   L y )N	override_r   rz   )
startswithsplitupper)optionsconfig_itemsoptionr7   r   rw   r   s         r&   extract_check_overridesz-parse_config.<locals>.extract_check_overrides  sU    ) 	OMFE  -!<<,5:G:NGK(7		Or(   rbtoolnumpydoc_validationry   r   Nztool:numpydoc_validation,)setr   
expanduserr   is_filer[   tomllibloadgetr    rh   itemsconfigparserConfigParserr]   rstripr   NoOptionErrorNoSectionErrorr
   get_validation_checks)r   r   	toml_pathcfg_pathr   	toml_filepyproject_tomlrq   global_exclusions"numpydoc_validation_config_sectionr   s             @r&   parse_configr      ss   .  SUDGH~((*224H++I+%H
O )T" 	=i$\\)4N#''3778MrRF #FJJx9J$K LGH &

9gi6H I!$!"3S9 "'("GI $GV\\^<	= 	= 
			**,H-G*	$'JJA8LVC[U3Z) x(	%!%(JJA9MVC[U3Z* y)	&	" $&HI !66wx7HIGH&wy'9:GIN_	= 	=4  --   --  ** 		s]   &B&HAH$ AH= I H!$H:7I 9H::I =II II I,+I,rp   rq   zlist[list[str]]c                     t        |       5 }t        j                  |j                         |       }ddd       t	        t        |       |      }|j                         |j                  S # 1 sw Y   <xY w)ad  
    Run numpydoc validation on a file.

    Parameters
    ----------
    filepath : path-like
        The absolute or relative path to the file to inspect.
    config : dict
        Configuration options for reviewing flagged issues.

    Returns
    -------
    list[list[str]]
        A list of [name, check, description] lists for flagged issues.
    N)rp   rq   )r[   r   parser]   ro   rh   r   rv   )rp   rq   r^   module_nodedocstring_visitors        r&   process_filer   ?  se      
h 74ii		X67 )#h-OK(%%%7 7s   %A,,A5argvc                    t        dg      \  }}t        |      }ddj                  t        t        j
                  j                               |d   z
  D cg c]  }d| dt        j
                  |     c}      z   dz   }t        j                  dt        j                        }|j                  d	t        d
d       |j                  dt        d       |j                  dt        dd|d   rdt        |      |z   d| dnd        |j                  |       }t        |j                        \  }}	t        |j                  xs |      }|dxx   t        |j                   xs g       z  cc<   g }
|j                  D ]  }|
j#                  t%        ||              |
r+t'        t)        |
g ddd      t*        j,                         yyc c}w )z!Run the numpydoc validation hook.r   z
  ry   z- z: 
zIRun numpydoc validation on files with option to ignore individual checks.)r   formatter_classfiles+z&File(s) to run numpydoc validation on.)r=   nargshelpz--configaC  Path to a directory containing a pyproject.toml or setup.cfg file.
The hook will look for it in the root project directory.
If both are present, only pyproject.toml will be used.
Options must be placed under
    - [tool:numpydoc_validation] for setup.cfg files and
    - [tool.numpydoc_validation] for pyproject.toml files.)r=   r   z--ignorerL   zCheck codes to ignore.z' Currently ignoring the following from z^Values provided here will be in addition to the above, unless an alternate config is provided.r   )r^   itemrw   r   grid2   )headerstablefmtmaxcolwidths)r^   r   r   )r   r   r   r   r
   
ERROR_MSGSkeysargparseArgumentParserRawTextHelpFormatteradd_argumentrh   r   
parse_argsr   rq   ignorerQ   r   printr   sysstderr)r   project_root_from_cwdconfig_fileconfig_optionsrw   ignored_checksparserrH   project_rootr   rv   r^   s               r&   mainr   X  s	    *;C5)A&;!"78N
++ !!4!4!9!9!;<~h?WW UG2h11%89:
	
 	  $$_ 55F c+S   I	   & "(+ :-.<=R?Opq 24	'    T"D'

3OL!!$++"=>N8DKK$52 66H

 <T>:;< @	 	
 {s    G
__main__r.   )#rd   r   r   r   rf   r{   r   r   ImportErrortomlipathlibr   typingr   r   r   r   r   r	   r
   utilsr   	Validatorr   NodeVisitorro   rg   r   r   r   rh   rl   r   ra   
SystemExitrm   r(   r&   <module>r      s    4  
  	 	 
  ) )  " $c8%% cL`!s `!F[2;; [$ [|&2;; & &9J &2EuXc]D() ES EP z
TV
 i  s   B9 9	CC