
    -Ph-              	          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n# e$ r ddlZY nw xY wddl	m
Z
 ddlmZmZ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j                  Zddej        defdZdej        deddfdZddddee         deeeef         df         deee         df         de fdZ!dS )z.Run numpydoc validation on contents of a file.    N)Path)AnyDictList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dS )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          pd| _        t          j        | j         d          | _        t          j        | j                  | _        t          |          	                                | _
        || _        t          |t          j                  | _        t          |t          j                  | _        d S )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       b/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numpydoc/hooks/validate_docstrings.py__init__zAstValidator.__init__%   s     &	-diuEEEK!/	FFF-6-Edl-S-S)-h)?)?)A)A"
(3<@@)(CJ??    c                      t          d          )Nz*AstValidator does not support this method.)NotImplementedError)names    r(   	_load_objzAstValidator._load_obj3   s    !"NOOOr*   c                     | j         S N)r!   r'   s    r(   r-   zAstValidator.name7   s
    zr*   c                 X    t          | j        t          j        t          j        f          S r0   )r"   r   r   FunctionDefAsyncFunctionDefr1   s    r(   is_function_or_methodz"AstValidator.is_function_or_method;   s    $)cos7K%LMMMr*   c                     | j         sdS t          j        | j                  D ]>}t	          |t          j                  r"t	          |j        t          j                  r dS ?dS )NFT)r5   r   iter_child_nodesr   r"   ExprvalueYield)r'   childs     r(   is_generator_functionz"AstValidator.is_generator_function?   sd    ) 	5)$)44 	 	E%** z%+sy/Q/Q ttur*   c                 V    | j         rdS | j        rdS | j        rdS t          d          )NfunctiontypemodulezUnknown type.)r5   r$   r&   
ValueErrorr1   s    r(   r?   zAstValidator.typeH   s>    % 	:= 	6> 	8)))r*   c                     | j         S r0   )r    r1   s    r(   source_file_namezAstValidator.source_file_nameR   s      r*   c                 ,    | j         s| j        j        ndS )Nr   )r&   r   linenor1   s    r(   source_file_def_linez!AstValidator.source_file_def_lineV   s    '+~<ty1<r*   c                     d }t                      }| j        r || j                  }nF| j        r?| j        j        D ]2}t          |t          j                  r|j        dk    r ||          }3|S )Nc                 h   | j         }g }dD ]}t          ||          }|dv rK|r#|dk    r|                    d|j                    |r#|dk    r|                    d|j                    a|                    d |D                        t          |          }|r|d         d	v r
|d
d          S |S )N)posonlyargsargsvararg
kwonlyargskwarg)rK   rM   rK   *rM   z**c                     g | ]	}|j         
S  )arg).0rQ   s     r(   
<listcomp>zPAstValidator.signature_parameters.<locals>.extract_signature.<locals>.<listcomp>g   s    ">">">s37">">">r*   r   >   clsr'   r   )rJ   getattrappendrQ   extendtuple)r   	args_nodeparamsarg_typeentriess        r(   extract_signaturez<AstValidator.signature_parameters.<locals>.extract_signature\   s    	IFT @ @!)X66222 98x#7#7&7'+&7&7888 :8w#6#6&87;&8&8999MM">">g">">">????6]]F "&)66abbz!Mr*   r)   )	rX   r5   r   r$   bodyr"   r   r3   r-   )r'   r]   rZ   r;   s       r(   signature_parametersz!AstValidator.signature_parametersZ   s    	 	 	" % 	6&&ty11FF] 	6 6 6eS_55 6%*
:R:R..u55Fr*   c                     t          | j                  5 }t          j        |                                | j                  }d d d            n# 1 swxY w Y   |S r0   )openrC   r   get_source_segmentreadr   )r'   filesources      r(   method_sourcezAstValidator.method_sourcev   s    $'(( 	DD+DIIKKCCF	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	Ds   -AAA)__name__
__module____qualname____doc__r   ASTosPathLikestrr)   staticmethodr.   propertyr-   boolr5   r<   r?   rC   intrF   r   r_   rf   rP   r*   r(   r   r      s        @7@.0k@EH@	@ @ @ @ P P \P c    X Nt N N N XN t    X *c * * * X* !# ! ! ! X! =c = = = X= eCj    X6 s    X  r*   r   c                   x    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dS )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                 z    || _         || _        t          | j                  j        | _        g | _        g | _        d S r0   )rv   ru   r   stemmodule_namestackfindings)r'   ru   rv   s      r(   r)   zDocstringVisitor.__init__   s9    
 #% $T] 3 3 8 "
 r*   r   checkc                     || j         d         vrdS | j         d         rN	 | j         d         |         }t          j        |t          j        |                    dS n# t
          $ r Y nw xY wdS )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	overridesNF)rv   researchr   r   KeyError)r'   r   r|   patterns       r(   _ignore_issuezDocstringVisitor._ignore_issue   s      H---4;{# 	+k2599Wc&7&=&=>>J4 K    us   :A 
A*)A*c                      d                      j                  t          j        t           j                   j                             fdd         D                        dS )z
        Get numpydoc validation issues.

        Parameters
        ----------
        node : ast.AST
            The node under inspection.
        .)r   r   c                 n    g | ]1\  }}                     |          j         d d          ||g2S ):	file_line)r   ru   )rR   r|   descriptionr-   r   reportr'   s      r(   rS   z9DocstringVisitor._get_numpydoc_issues.<locals>.<listcomp>   sa       &E;))$66M99F;$7994T  r*   errorsN)joinrz   r   r   ru   r{   rW   )r'   r   r-   r   s   ``@@r(   _get_numpydoc_issuesz%DocstringVisitor._get_numpydoc_issues   s     xx
##",
 
 
 	      *0*:  	
 	
 	
 	
 	
r*   c                    t          |t          j        t          j        t          j        t          j        f          r| j                            t          |t          j                  r| j        n|j	                   | j
        d         r8t          j        | j
        d         d                    | j                            s|                     |           |                     |           | j                                        }dS dS )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#   r3   r4   rz   rV   ry   r-   rv   r   r   r   r   generic_visitpop)r'   r   _s      r(   visitzDocstringVisitor.visit   s     3:s|S_c>RS
 
 	! J$.tSZ$@$@O  di  
 I&0Idk)4chhtz6J6JKK0 ))$///t$$$
  AAA	! 	!r*   )rg   rh   ri   rj   rn   dictr)   r   rk   rq   r   r   r   rP   r*   r(   rt   rt   }   s        	 		!	! 	! 
		! 	! 	! 	!#' # $    :
 
T 
 
 
 
*!#' !d ! ! ! ! ! !r*   rt   dir_pathr   c                   
 dht                      i d}t          |                                                                           } | dz  }| dz  }d 

fd}|                                rt          |d          5 }t          j        |          }|                    di                               d	i           }t          |                    d
|d
                             |d
<   |                    d|d                   }t          t          |t                    s|n|g          |d<    |||                                           ddd           n# 1 swxY w Y   nK|                                r6t          j                    }|                    |           d}		 	 t          |                    |	d
                              d                              d          p|d
                   |d
<   n# t          j        $ r Y nw xY w	 t          |                    |	d                              d                              d          p|d                   |d<   n# t          j        $ r Y nw xY w |||                    |	                     n# t          j        $ r Y nw xY wt'          j        |d
                   |d
<    
|d                   |d<   |S )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)r~   r   r   zpyproject.tomlz	setup.cfgc                 l    | r1t          j        d                    d | D                                 nd S )N|c              3      K   | ]}||V  	d S r0   rP   )rR   exps     r(   	<genexpr>z6parse_config.<locals>.compile_regex.<locals>.<genexpr>   s'       C Cs C C C C C C Cr*   )r   compiler   )expressionss    r(   compile_regexz#parse_config.<locals>.compile_regex   s>     BJtyy C C C C CCCDDD	
r*   c                     |D ]Z\  }}|                     d          r@|                    d          \  }}|r& |          | d         |                                <   [d S )N	override_r   r   )
startswithsplitupper)optionsconfig_itemsoptionr9   r   r|   r   s         r(   extract_check_overridesz-parse_config.<locals>.extract_check_overrides  s{    ) 	O 	OMFE  -- O!<<,,5 O:G-:N:NGK(7		O 	Or*   rbtoolnumpydoc_validationr~   r   Nztool:numpydoc_validation,)setr   
expanduserr   is_filera   tomllibloadgetr"   rn   itemsconfigparserConfigParserrc   rstripr   NoOptionErrorNoSectionErrorr   get_validation_checks)r   r   	toml_pathcfg_pathr   	toml_filepyproject_tomlrv   global_exclusions"numpydoc_validation_config_sectionr   s             @r(   parse_configr      sy   .  SUUDDGH~~((**2244H++I+%H
 
 
O O O O O  ,)T"" 	=i$\)44N#''33778MrRRF #FJJx9J$K$K L LGH &

9gi6H I I!$!"3S99)!!'(" "GI $#GV\\^^<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 
				 *,,H-G*	$'JJA8LLVC[[U3ZZ) x(	% %!!  -   %(JJA9MMVC[[U3ZZ* y)	& &	""  -    $#&HII    * 	 	 	D	 !6wx7HIIGH&wy'9::GINsi   >CEE E'AG< ;J <HJ HJ AI' &J 'I96J 8I99"J J.-J.ru   rv   zlist[list[str]]c                    t          |           5 }t          j        |                                |           }ddd           n# 1 swxY w Y   t	          t          |           |          }|                    |           |j        S )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)ru   rv   )ra   r   parserc   rt   rn   r   r{   )ru   rv   rd   module_nodedocstring_visitors        r(   process_filer   >  s      
h 74i		X667 7 7 7 7 7 7 7 7 7 7 7 7 7 7 )#h--OOOK(((%%s   (AAA)rv   ignorefilesr   c                B   t          |           \  }}t          |p|          }|dxx         t          |pg           z  cc<   g }| D ]%}|                    t	          ||                     &|r0t          t          |g ddd          t          j                   dS dS )	a  
    Run the numpydoc validation hook.

    Parameters
    ----------
    files : list[str]
        The absolute or relative paths to the files to inspect.
    config : Union[dict[str, Any], None], optional
        Configuration options for reviewing flagged issues.
    ignore : Union[list[str], None], optional
        Checks to ignore in the results.

    Returns
    -------
    int
        The return status: 1 if issues were found, 0 otherwise.
    r~   )rd   itemr|   r   grid2   )headerstablefmtmaxcolwidths)rd   r   r   )	r   r   r   rW   r   printr	   sysstderr)r   rv   r   project_rootr   config_optionsr{   rd   s           r(   run_hookr   W  s    . (..OL!!&"8L99N8FLb 1 11H < <T>::;;;; 
@@@	   	
 	
 	
 	
 q1r*   r0   )"rj   r   r   rl   r   r   r   ImportErrortomlipathlibr   typingr   r   r   r   r   r	   r   r   r   utilsr   	Validatorr   NodeVisitorrt   rm   r   r   r   rn   rr   r   rP   r*   r(   <module>r      s3   4 4 



     				 				 



NNNN          0 0 0 0 0 0 0 0 0 0 0 0 0 0       " " " " " " " " $ $ $ $ $ $c c c c c8% c c cL`! `! `! `! `!s `! `! `!F[ [2; [$ [ [ [ [|&2; & &9J & & & &8 +/%)	* * *9* $sCx.$&'* $s)T/"	*
 	* * * * * *s    	))