
    c9                    *   d dl m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	Z	d dl
m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 d dlmZ d d	lmZ erd d
lmZ ej        dk    rd dlZnd dlZddZej         dd            Z! G d d          Z"dS )    )annotationsN)Iterator)Path)TYPE_CHECKINGAnyTextIO)utils)Option)OptionParser)
OptionDict)OptionsProviderMixin)      selfoptparse.HelpFormatteroptionr
   returnstrc                   | j         | j        st          |j                  S |j        d         dd         }	 | j         j        j        |         }|                    |          }|                    ||          }t          |j
        ||          }t          j        ||          }n# t          $ r d}Y nw xY w|t          j        u s|s| j        }|j                            | j        t          |                    S )zPatch OptionParser.expand_default with custom behaviour.

    This will handle defaults to avoid overriding values in the
    configuration file.
    Nr      )parserdefault_tagr   help
_long_optsoptions_manager_all_optionsget_option_defoption_attrnamegetattrconfigr	   _format_option_valueKeyErroroptparse
NO_DEFAULTNO_DEFAULT_VALUEreplace)r   r   optnameprovideroptdictvalues         Blib/python3.11/site-packages/pylint/config/option_manager_mixin.py_expand_defaultr,   &   s    {  $"2  6;"122&G;;.;GD ))'22**7G<<'::*7E::     ## &5 &%;t/U<<<s   B' 'B65B6Iterator[None]c               #     K   t           j        } 	 t          t           j        _        d V  | t           j        _        d S # | t           j        _        w xY wN)r#   HelpFormatterr,   expand_default)orig_defaults    r+   _patch_optparser3   =   sQ       )L=0?-0<----<<<<s	   = Ac                      e Zd ZdZd?dZd@d?dZ	 dAdBdZdCdZdDdZdEdZ	dFdZ
dGd Z	 dHdId'ZdJd(Z	 dKdLd-ZdMd0ZdJd1ZdNd3ZdOd6Z	 dPdQd:ZdRdSd>Zd!S )TOptionsManagerMixInzMHandle configuration from both a configuration file and command line options.usager   r   Nonec                    t          j        dt          d           |                     |           g | _        t          j                    | _        i | _        i | _	        i | _
        d| _        d S )NzIOptionsManagerMixIn has been deprecated and will be removed in pylint 3.0r   )
stacklevelr   )warningswarnDeprecationWarningreset_parsersoptions_providerscollectionsOrderedDictr   _short_options_nocallback_options	_mygroups	_maxlevelr   r6   s     r+   __init__zOptionsManagerMixIn.__init__K   su    W	
 	
 	
 	

 	5!!!=??J?V?X?X.035 )+     c                    t          j        d          | _        t          t          |          | _        | | j        _        t          | j        j        j	                  | _
        d S )N)#;)inline_comment_prefixes)r6   )configparserConfigParsercfgfile_parserr   r
   cmdline_parserr   setoption_classATTRS_optik_option_attrsrE   s     r+   r=   z!OptionsManagerMixIn.reset_parsers]   s`    *7$.
 
 
 +6???.2+#&t':'G'M#N#N   rG   Tr(   r   	own_groupboolc                  	 | j                             |           d |j        D             }t          |dd          }|r7|r5|                     |j                                        |j        ||           n%|D ]"\  }}|                     || j	        ||           #|D ]D\  	}	                                		fd|j        D             }|                     	|||           EdS )zRegister an options provider.c                &    g | ]}d |d         v|S )group    ).0r   s     r+   
<listcomp>zAOptionsManagerMixIn.register_options_provider.<locals>.<listcomp>l   s6     "
 "
 "
WF1I5M"
"
 "
 "
rG   option_groupsr[   c                x    g | ]6}|d                               dd                                          k    4|7S )rZ   rY   rH   )getupper)r\   r   gnames     r+   r]   zAOptionsManagerMixIn.register_options_provider.<locals>.<listcomp>|   sR       !9=="--3355>  rG   N)
r>   appendoptionsr   add_option_groupnamera   __doc__add_optik_optionrP   )
r   r(   rU   non_group_spec_optionsgroupsoptr)   gdocgoptionsrb   s
            @r+   register_options_providerz-OptionsManagerMixIn.register_options_providerg   sL    	%%h///"
 "
!)!1"
 "
 "
 ?B77 		S/ 		S!!##%% &	    !7 S SW%%h0CS'RRRR! 	C 	CKE4KKMME   &.  H
 !!%xBBBB	C 	CrG   
group_name_r   rd   c                   || j         v r| j         |         }nt          j        | j        |                                          }| j                            |           || j         |<   |dk    r(|| j        j        vr| j                            |           |D ]K\  }}t          |
                    dd          t                    sd|d<   |                     ||||           Ld S )N)titleDEFAULTactionstorecallback)rC   r#   OptionGrouprP   
capitalizere   rO   	_sectionsadd_section
isinstancer`   r   rh   )r   ro   rp   rd   r(   rY   rk   r)   s           r+   re   z$OptionsManagerMixIn.add_option_group   s    ' 	<N:.EE(#:+@+@+B+B  E 00777).DN:& i'<d&9&CC< #//
;;;# 	A 	ALCgkk(G<<cBB /$.!!!(E3@@@@	A 	ArG   optikcontainerrk   r)   r   c                    |                      |||          \  }} |j        |i |}|| j        |<   t          | j        |j        pd          | _        d S )Nr   )optik_option
add_optionr   maxrD   level)r   r(   r|   rk   r)   argsr   s          r+   rh   z$OptionsManagerMixIn.add_optik_option   sa     ))(CAAg**D<G<<!)#T^V\->Q??rG   tuple[list[str], OptionDict]c                   t          j         |          }d|v r|| j        |<   nd|d<   | j        |d<   d|v r6d|v r/|                    d          |d         dvr|dxx         dz  cc<   |d= dt	          |          z   g}d	|v r1|| j        |d	         <   |                    d
|d	         z              |d	= t          |                                          D ] }|| j	        vr|
                    |           !||fS )zkGet our personal option definition and return a suitable form for
        use with optik/optparse.
        rt   rv   defaultr   N)
store_truestore_falsez [current: %default]--short-)copyrB   cb_set_provider_optionr`   r   rA   rc   listkeysrT   pop)r   r(   rk   r)   r   keys         r+   r~   z OptionsManagerMixIn.optik_option   sN    )G$$w 	>14D$X.. *GH"&"=GJ  	#'!:KK	**: H%-JJ:
 #99	"s3xx g 	!47D 01KKgg../// '' 	! 	!C$22 !C   W}rG   r   r
   r*   r   c                    |                     d          r|dd         }n| j        |dd                  }|d}|                     ||           dS )z"Optik callback for option setting.r   r   NrZ   )
startswithrA   global_set_option)r   r   rk   r*   r   s        r+   r   z*OptionsManagerMixIn.cb_set_provider_option   sg     >>$ 	/abb'CC %c!""g.C 	EsE*****rG   c                H    | j         |                             ||           dS )z*Set option on the correct option provider.N)r   
set_option)r   rk   r*   s      r+   r   z%OptionsManagerMixIn.global_set_option   s&    #))#u55555rG   Nr[   streamTextIO | Noneskipsectionstuple[str, ...]c           	        i }g }| j         D ]m}|                                D ]V\  }}||j        }||v rd |D             }|s"||vr|                    |           |                    |g           }||z  }Wn|pt
          j        }d}	|D ]R}|	rt          d|           t          j	        ||
                                t          ||                              d}	SdS )zsWrite a configuration file according to the current configuration
        into the given stream or stdout.
        Nc                t    g | ]5\  }}}|                     d           |                     d          0|||f6S )typeN
deprecated)r`   )r\   ndvs       r+   r]   z7OptionsManagerMixIn.generate_config.<locals>.<listcomp>   sZ       !AquuV}} :;|9L9L1I  rG   F
fileT)r>   options_by_sectionrf   rc   
setdefaultsysstdoutprintr	   format_sectionra   sorted)
r   r   r   r   sectionsr(   sectionrd   all_optionsprinteds
             r+   generate_configz#OptionsManagerMixIn.generate_config   sT    LN. 	' 	'H$,$?$?$A$A ' '  ,&mGl*  %,  
  (* -OOG,,,0;;GRHHw&'  %3: 	 	G )d(((( 0B70K)L)L   GG	 	rG   c                B    | j         D ]}|                                 dS )z.Initialize configuration using default values.N)r>   load_defaults)r   r(   s     r+   load_provider_defaultsz*OptionsManagerMixIn.load_provider_defaults   s3    . 	% 	%H""$$$$	% 	%rG   Fconfig_filePath | Noneverbosec                z   |ryt          t          j                            |                                                    }|                                s t          dt          |           d          | j        }|j	        dk    r-	 | 
                    ||           n# t          j        $ r Y nw xY wt          |d          5 }|                    |           ddd           n# 1 swxY w Y   t          |j                                                  D ]c\  }}|                    d          r|t'          d          d         }|                                s|r||j        |                                <   d|sdS |r|                                rd| d	}nd
}t-          |t.          j                   dS )ztRead the configuration file but do not load it (i.e. dispatching
        values to each option's provider).
        zThe config file z doesn't exist!z.toml	utf_8_sig)encodingNzpylint.zUsing config file ''z1No config file found, using default configurationr   )r   ospath
expandvars
expanduserexistsOSErrorr   rO   suffix_parse_tomltomllibTOMLDecodeErroropen	read_filer   ry   itemsr   lenisupperra   r   r   stderr)r   r   r   r   fpsectvaluesmsgs           r+   read_config_filez$OptionsManagerMixIn.read_config_file  s%     	@rw11+>>??JJLLK%%'' TR[1A1ARRRSSS(F!W, @$$[&9999.   D +<<< )$$R((() ) ) ) ) ) ) ) ) ) ) ) ) ) ) %))9)?)?)A)A$B$B @ @LD&y11 6#C	NN$4$45<<>> @f @9?(6 	F 	F;--// 	F6666CCECc
######s$   	B   B21B2C((C,/C,r   configparser.ConfigParserc                ^   t          |d          5 }t          j        |          }ddd           n# 1 swxY w Y   	 |d         d         }n# t          $ r Y dS w xY w|                                D ]8\  }}|                                }t          |t                    s|                     dd||f           J|                                D ]d\  }	}
t          |
t                    r
|
rd	nd
||	<   $t          |
t                    rd                    |
          ||	<   Rt          |
          ||	<   e|                                D ]`\  }	}
	 |                    ||	|
           # t          j        $ r0 |                    |           |                    ||	|
           Y ]w xY w:dS )z5Parse and handle errors of a toml configuration file.rb)modeNtoolpylintzbad-configuration-sectionr   )liner   yesno,)r*   )r   r   loadr"   r   ra   r{   dictadd_messagerV   r   joinr   rQ   rM   NoSectionErrorrz   )r   r   r   r   contentsections_valuesr   r   section_namer   r*   s              r+   r   zOptionsManagerMixIn._parse_toml'  s:   +D))) 	'Rl2&&G	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'	%foh7OO 	 	 	FF	.4466 	B 	BOGV"==??L fd++   /aw>O !    !' 0 0eT** 0.3%=UUF6NNt,, 0%(XXe__F6NN%(ZZF6NN!' B BBJJ|V5JAAAA#2 B B B&&|444JJ|V5JAAAAABB#	B 	Bs/   377A 
AAE))<F('F(c                    | j         }|                                D ]P}|                    |          D ]8\  }}	 |                     ||           # t          t
          j        f$ r Y 5w xY wQdS )zeDispatch values previously read from a configuration file to each
        option's provider.
        N)rO   r   r   r   r"   r#   OptionError)r   r   r   r   r*   s        r+   load_config_filez$OptionsManagerMixIn.load_config_fileG  s     $(( 	 	G!'g!6!6  **659999 ("67   H	 	s   AA)(A)kwargsc                ,    |                      |          S )z5Override configuration according to given parameters.)load_configuration_from_config)r   r   s     r+   load_configurationz&OptionsManagerMixIn.load_configurationS  s    226:::rG   r    dict[str, Any]c                    |                                 D ]>\  }}|                    dd          }| j        |         }|                    ||           ?d S )Nrp   r   )r   r&   r   r   )r   r    rk   	opt_valuer(   s        r+   r   z2OptionsManagerMixIn.load_configuration_from_configW  s`    $llnn 	0 	0NC++c3''C(-HY////	0 	0rG   r   list[str] | None	list[str]c                   t                      5  |t          j        dd         nt          |          }| j                            |          \  }}| j        D ]J}|j        }|j        	                                D ]'}t          ||d          }|t          |||           (K|cddd           S # 1 swxY w Y   dS )zjOverride configuration according to command line parameters.

        return additional arguments
        NrZ   )r   )r3   r   argvr   rP   
parse_argsrB   r    __dict__r   r   setattr)r   r   rd   r(   r    attrr*   s          r+   load_command_line_configurationz3OptionsManagerMixIn.load_command_line_configuration]  s      
	 
	#'?38ABB<<T$ZZD"1<<$<GGOWd 4 1 1!"O0022 1 1D#GT488E ! FD%0000	1
 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	s   BB33B7:B7r   r   intc                    || j         j        _        t                      5  t	          | j                                                   cddd           S # 1 swxY w Y   dS )z.Return the usage string for available options.N)rP   	formatteroutput_levelr3   r   format_help)r   r   s     r+   r   zOptionsManagerMixIn.helpp  s    5:%2 	: 	:t*668899	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   &AAA)r6   r   r   r7   )rH   )T)r(   r   rU   rV   r   r7   )
ro   r   rp   r   rd   r   r(   r   r   r7   )
r(   r   r|   r   rk   r   r)   r   r   r7   )r(   r   rk   r   r)   r   r   r   )
r   r
   rk   r   r*   r   r   r   r   r7   )rk   r   r*   r   r   r7   )Nr[   )r   r   r   r   r   r7   )r   r7   )NF)r   r   r   rV   r   r7   )r   r   r   r   r   r7   )r   r   r   r7   )r    r   r   r7   r/   )r   r   r   r   )r   )r   r   r   r   )__name__
__module____qualname__rg   rF   r=   rn   re   rh   r~   r   r   r   r   r   r   r   r   r   r   r   r[   rG   r+   r5   r5   H   s       WW   $O O O O O AEC C C C C8A A A A0
@ 
@ 
@ 
@   B+ + + +6 6 6 6
 MO! ! ! ! !F% % % % @E"$ "$ "$ "$ "$HB B B B@
 
 
 
; ; ; ;0 0 0 0 (,    &: : : : : : :rG   r5   )r   r   r   r
   r   r   )r   r-   )#
__future__r   r?   rM   
contextlibr   r#   r   r   r:   collections.abcr   pathlibr   typingr   r   r   r   r	   pylint.config.optionr
   pylint.config.option_parserr   pylint.typingr   $pylint.config.options_provider_mixinr   version_infor   tomlir,   contextmanagerr3   r5   r[   rG   r+   <module>r     s   # " " " " "               				 



  $ $ $ $ $ $       - - - - - - - - - -       ' ' ' ' ' ' 4 4 4 4 4 4 $ $ $ $ $ $       w NNNN= = = =. = = = =l: l: l: l: l: l: l: l: l: l:rG   