o
    bz                    @   s  d Z ddlmZ ddlZddlZddlZddlZzddlZW n ey)   dZY nw 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 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ejZdd Zdd Zdd Zdddddddddddddd gifd!d"d#d$Z d%e!fd&d'Z"edurG d(d) d)ej#Z$G d*d+ d+ej%ej&ej'ej(Z)d,d- Z*d.d/ Z+d0d1 Z,G d2d3 d3e-Z.d4d5 Z/ej0d6d7 Z1G d8d9 d9Z2d:d; Z3d<d= Z4e5d>kre2e	j6d?d  dS dS )@a   %prog [options] modules_or_packages

  Check that module(s) satisfy a coding standard (and more !).

    %prog --help

  Display this help message and exit.

    %prog --help-msg <msg-id>[,<msg-id>]

  Display help messages about given message identifiers and exit.
    )print_functionN)version)modutils)checkers)
interfaces)	reporters)
exceptions)utils)config)nodesc                 C   s2   | j | j| j| j| j| jf}| j| j|| j| j	fS N)
abspathpathmoduleobjlinecolumnmsg_idsymbolmsg
confidence)messagelocation r   J/var/www/secure340b-portal/env/lib/python3.10/site-packages/pylint/lint.py_get_new_args\   s   r   c                 C   sj   t jt j| }t j|st j|}	 t jt j|ds$|S |}t j|}||kr4t  S q)NTz__init__.py)	osr   realpath
expanduserisdirdirnameexistsjoingetcwd)filepathr    Zold_dirnamer   r   r   _get_python_pathh   s   r%   c                 C   s   i }t  }| D ]4}|di }|| | D ]"\}}||vr&|||< qt|tr3|| | q|| | ||< qq||d< |S )Nby_msg)collectionsCounterpopupdateitems
isinstancedict)statsmergedr&   statZmessage_statskeyitemr   r   r   _merge_statsv   s   


	r3   )%sfatalzoUsed when an error occurred preventing the analysis of a               module (unable to find it for instance).)z%s: %sastroid-errorzUsed when an unexpected error occurred while building the Astroid  representation. This is usually accompanied by a traceback. Please report such errors !)zerror while code parsing: %sparse-errorzlUsed when an exception occurred while building the Astroid representation which could be handled by astroid.)z0Unable to run raw checkers on built-in module %sraw-checker-failedzRUsed to inform that a built-in module has not been checked using the raw checkers.)z#Unable to consider inline option %rbad-inline-optionzUUsed when an inline option is either badly formatted or can't be used inside modules.)zLocally disabling %s (%s)zlocally-disabledzEUsed when an inline option disables a message or a messages category.)zIgnoring entire filefile-ignoredz0Used to inform that the file will not be checked)zSuppressed %s (from line %d)zsuppressed-messagezA message was triggered on a line, but suppressed explicitly by a disable= comment in the file. This message is not generated for messages that are ignored due to configuration settings.)zUseless suppression of %szuseless-suppressionzbReported when a message is explicitly disabled for a line or a block of code, but never triggered.z+Pragma "%s" is deprecated, use "%s" insteaddeprecated-pragmazSome inline pylint options have been renamed or reworked, only the most recent form should be used. NOTE:skip-all is only available with pylint >= 0.26Z	old_names)ZI0014zdeprecated-disable-all)r4   syntax-errorz0Used when a syntax error is raised for a module.)zUnrecognized file option %runrecognized-inline-optionz2Used when an unknown inline option is encountered.)zBad option value %rbad-option-valuez:Used when a bad value for an inline option is encountered.)ZF0001ZF0002ZF0010ZI0001ZI0010ZI0011ZI0013ZI0020ZI0021ZI0022ZE0001ZE0011ZE0012returnc                  C   s,   t tdd} | rt| dS trt S dS )zNUse sched_affinity if available for virtualized or containerized environments.sched_getaffinityNr      )getattrr   lenmultiprocessing	cpu_count)r@   r   r   r   
_cpu_count   s   rF   c                   @   s   e Zd Zdd Zdd ZdS )ChildLinterc                 C   s   | j \}}| _d| jd< | jdd | _| jdd | _t|jdD ]7}z| |d }|| W q" t	yY } zt
d| tjd t
|tjd |i  W Y d }~q"d }~ww d S )	NrA   jobspython3_porting_modepluginsSTOPr   z0internal error with sending report for module %sfile)_args_configr)   _python3_porting_mode_pluginsiterget_run_linterput	Exceptionprintsysstderr)selftasks_queueresults_queuefile_or_moduleresultexr   r   r   run   s(   
zChildLinter.runc                 C   s   t  }|  | jr|| j || j |  |t	  | j
r(|  || dd |jjD }||jj|j||j|jfS )Nc                 S   s   g | ]}t |qS r   )r   ).0mr   r   r   
<listcomp>  s    z+ChildLinter._run_linter.<locals>.<listcomp>)PyLinterload_default_pluginsrQ   load_plugin_modulesZload_configuration_from_configrO   load_plugin_configurationset_reporterr   ZCollectingReporterrP   rI   checkreportermessages
file_state	base_namecurrent_namer.   
msg_status)rZ   r]   lintermsgsr   r   r   rT      s$   
zChildLinter._run_linterN)__name__
__module____qualname__r`   rT   r   r   r   r   rG      s    rG   c                       sL  e Zd ZdZejfZdZdZdZ	e
Zedd ZdZdJ fd	d
	Zdd Zdd Zdd Zdd Zdd Zdd ZdKddZdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Z d-d. Z!edLd0d1Z"d2d3 Z#d4d5 Z$d6d7 Z%d8d9 Z&d:d; Z'd<d= Z(dMd>d?Z)d@dA Z*dBdC Z+dDdE Z,dFdG Z-dHdI Z.  Z/S )Nrd   a  lint Python modules using external checkers.

    This is the main checker controlling the other ones and the reports
    generation. It is itself both a raw checker and an astroid checker in order
    to:
    * handle message activation / deactivation at the module level
    * handle some basic but necessary stats'data (number of classes, methods...)

    IDE plugin developers: you may have to call
    `astroid.builder.MANAGER.astroid_cache.clear()` across runs if you want
    to ensure the latest code version is actually checked.
    masterr   c                   C   sh  dddddddfdd	d
ddddfdddddddfdddddddfdddddddd fd!d"ddd#dd$d fd%dd&ddd'd(d)fd*dddd+dd,d fd-d.d/d0d1d2 t jD d3d4d5d6d7 t jD f d8fd9dd:d;d3d<d=fd>dd:d?d3d@d=fdAddBddCdDfdEdFdGdHddIdJfdKddLd"ddMdNfdOdFdPdQdRdSfdTddUg dVdSfdWddLddXdSfdYdZd[d\ffS )]Nignorecsvz<file>[,<file>...]
black_list)CVSzPAdd files or directories to the blacklist. They should be base names, not paths.)typemetavardestdefaulthelpzignore-patternsZ
regexp_csvz<pattern>[,<pattern>...]black_list_rer   zwAdd files or directories matching the regex patterns to the blacklist. The regex matches against base names, not paths.
persistentTZynz<y_or_n>rA   z,Pickle collected data for later comparisons.)r}   rz   r{   levelr~   load-pluginsz	<modules>zuList of plugins (as comma separated values of python modules names) to load, usually to register additional checkers.)rz   r{   r}   r   r~   output-formattextstringz<format>fReportszSet the output format. Available formats are text, parseable, colorized, json and msvs (visual studio). You can also give a reporter class, e.g. mypackage.mymodule.MyReporterClass.)r}   rz   r{   shortgroupr~   reportsFrz<Tells whether to display a full report or only the messages.
evaluationz<python_expression>zN10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)a6  Python expression which should return a note less than 10 (10 is the highest note). You have access to the variables errors warning, statement which respectively contain the number of errors / warnings messages and the total number of statements analyzed. This is used by the global evaluation report (RP0004).)rz   r{   r   r   r}   r~   scoreszActivate the evaluation score.r   Zmultiple_choicez<levels> c                 S   s   g | ]}|j qS r   namera   cr   r   r   rc     s    z)PyLinter.make_options.<locals>.<listcomp>Messages controlz`Only show warnings with the listed confidence levels. Leave empty to show all. Valid levels: %s.z, c                 s   s    | ]}|j V  qd S r   r   r   r   r   r   	<genexpr>  s    z(PyLinter.make_options.<locals>.<genexpr>)rz   r{   r}   choicesr   r~   enablez	<msg ids>ea/  Enable the message, report, category or checker with the given id(s). You can either give multiple identifier separated by comma (,) or put this option multiple time (only on the command line, not in the configuration file where it should appear only once). See also the "--disable" option for examples.)rz   r{   r   r   r~   disabledac  Disable the message, report, category or checker with the given id(s). You can either give multiple identifiers separated by comma (,) or put this option multiple times (only on the command line, not in the configuration file where it should appear only once). You can also use "--disable=all" to disable everything first and then reenable specific checks. For example, if you want to run only the similarities checker, you can use "--disable=all --enable=similarities". If you want to run only the classes checker, but have no Warning level messages displayed, use "--disable=all --enable=classes --disable=W".zmsg-templatez
<template>zTemplate used to display messages. This is a python new-style format string used to format the message information. See doc for all details.)rz   r{   r   r~   rH   intz<n-processes>jzsUse multiple processes to speed up Pylint. Specifying 0 will auto-detect the number of processors available to use.)rz   r{   r   r}   r~   zunsafe-load-any-extensionz<yn>zAllow loading of arbitrary C extensions. Extensions are imported into the active Python interpreter and may run arbitrary code.)rz   r{   r}   hider~   zlimit-inference-resultsz<number-of-results>d   zControl the amount of potential inferred values when inferring a single object. This can help the performance when dealing with large functions or complex, nested conditions. )rz   r{   r}   r~   zextension-pkg-whitelistz<pkg[,pkg]>zA comma-separated list of package or module names from where C extensions may be loaded. Extensions are loading into the active Python interpreter and may run arbitrary code.zsuggestion-modezWhen enabled, pylint would attempt to guess common misconfiguration and emit user-friendly hints instead of false-positive error messages.z	exit-zero
store_truezAlways return a 0 (non-error) status code, even if lint errors are found. This is primarily useful in continuous integration scripts.)actionr~   )r   CONFIDENCE_LEVELSr"   r   r   r   r   make_options>  s$   zPyLinter.make_options))r   z%Options controlling analysis messages)r   z2Options related to output formatting and reportingr   Nc                    s:  t  | _d | _d | _i | _tt| _	i | _
d| _t  | _d | _d | _d | _|| _|t  | _|tj | _| j| jd| _| j| jd| _dtttjf }t j|  t j|  t t| jt!||pgt"j#d t$j%|  ddt&fdd	t'fd
dt(ff| _)| *|  t+ | _,d| _-d| _.| /  |r| 0| d S d S )NF)r   r   )zdisable-msgz
enable-msgz%%prog %s
astroid %s
Python %s)usager   config_fileZRP0001zMessages by categoryZRP0002z% errors / warnings by moduleZRP0003ZMessages)1r	   ZMessagesStore
msgs_storerj   _reporter_name
_reportersr'   defaultdictlist	_checkers_pragma_lineno_ignore_file	FileStaterl   rn   current_filer.   _external_optsrd   r   optionsoption_groupsr   r   _options_methods_bw_options_methodsr   astroid_versionrX   MessagesHandlerMixIn__init__ReportsHandlerMixInsuper__doc__r
   ZPYLINTRCr   BaseTokenCheckerreport_total_messages_statsreport_messages_by_module_statsreport_messages_statsr   register_checkerset_dynamic_pluginsrP   _error_modeZload_provider_defaultsrh   )rZ   r   rj   r   pylintrcZfull_version	__class__r   r   r   6  sX   



	zPyLinter.__init__c                 C   s*   t |  t|  | js|   d S d S r   )r   Z
initializer   rj   _load_reporterrZ   r   r   r   re   l  s
   

zPyLinter.load_default_pluginsc                 C   s:   |D ]}|| j v r
q| j | t|}||  qdS )z`take a list of module names which are pylint plugins and load
        and register them
        N)r   addr   load_module_from_nameregister)rZ   modnamesmodnamer   r   r   r   rf   t  s   

zPyLinter.load_plugin_modulesc                 C   s.   | j D ]}t|}t|dr||  qdS )zCall the configuration hook for plugins

        This walks through the list of plugins, grabs the "load_configuration"
        hook, if exposed, and calls it to allow plugins to configure specific
        settings.
        load_configurationN)r   r   r   hasattrr   )rZ   r   r   r   r   r   rg     s   



z"PyLinter.load_plugin_configurationc              	   C   sd   | j  }|| jv r| | j|   d S z|  }W n ttfy)   t|w | |  d S r   )	r   lowerr   rh   _load_reporter_classImportErrorAttributeErrorr   ZInvalidReporterError)rZ   r   reporter_classr   r   r   r     s   


zPyLinter._load_reporterc                 C   s2   | j }tt|}|dd }t||}|S )N.)r   r   r   Zget_module_partsplitrB   )rZ   qnamer   
class_namer   r   r   r   r     s
   
zPyLinter._load_reporter_classc                 C   s   || _ | |_dS )z5set the reporter used to display messages and reportsN)rj   rp   )rZ   rj   r   r   r   rh     s   
zPyLinter.set_reporterc              
   C   s  || j v s
|| jv rQ|rPz| j | }W n ty0   | j| }td||dd f t Y nw t|}t	|t
tfrJ|D ]}||dd q?dS || dS n|dkr_|| _| jr_|   ztj| |||| W dS  tjy   td| tjd	 Y dS w )
z[overridden from config.OptionsProviderMixin to handle some
        special options
        z"%s is deprecated, replace it by %s-r   T)Zignore_unknownNr   z(option %s can't be read from config filerL   )r   r   KeyErrorwarningswarnr   DeprecationWarningr	   Z
_check_csvr,   r   tupler   r   r   r   r   
set_optionr
   ZUnsupportedActionrW   rX   rY   )rZ   optnamevaluer   optdictmethZ_idr   r   r   r     s<   

zPyLinter.set_optionc                 C   s   || j |j< d S r   )r   r   )rZ   r   r   r   r   register_reporter  s   zPyLinter.register_reporterc                 C   sJ   t | jdd d}z
|||  W n
 ty   Y |S w ||  |S )Nc                 S   s   t | ddS )Nr   r   )rB   )xr   r   r   <lambda>  s    z'PyLinter.report_order.<locals>.<lambda>)r1   )sorted_reportsr)   index
ValueErrorappend)rZ   r   r   r   r   report_order  s   
zPyLinter.report_orderc                 C   s   |j dks	J d| j|j | |jD ]\}}}| |||| q| | t|dr3| j	| |
  t|ddsE| |j dS dS )zoregister a new checker

        checker is an object implementing IRawChecker or / and IAstroidChecker
        r   zchecker priority can't be >= 0rq   enabledTN)priorityr   r   r   r   Zregister_reportZregister_options_providerr   r   Zregister_messages_from_checkerZload_defaultsrB   r   )rZ   checkerZr_idZr_titleZr_cbr   r   r   r     s   

zPyLinter.register_checkerc                 C   sL   | j j D ]\}}|dv r|D ]}| | qq|D ]}| | qqd S )N)EF)r   Z_msgs_by_categoryr+   r   r   )rZ   ZmsgcatZmsgidsmsgidr   r   r   disable_noerror_messages  s   z!PyLinter.disable_noerror_messagesc                 C   s.   | j  D ]}|D ]
\}}}| | q	qdS )zdisable all reportersN)r   valuesZdisable_report)rZ   r   Z	report_id_r   r   r   disable_reporters  s
   zPyLinter.disable_reportersc                 C   s   d| _ |   | d | jr<| d | dD ]}|dr%| | q| j}|ddr;|	dd}| 
d| n| d | dd	 | d
d	 | dd	 dS )z9error mode: enable only errors; no reports, no persistentTZmiscellaneousallpython3r   MESSAGES CONTROLr   r   Fr   r   N)r   r   r   rP   _checker_messages
startswithr   cfgfile_parser
has_optionrS   global_set_optionr   rZ   r   config_parserr   r   r   r   
error_mode  s$   




zPyLinter.error_modec                 C   s~   |  d | d | jr%| dD ]}|dr| | q|  | q| j}|ddr:|dd}| d| d| _	dS )z8Disable all other checkers and enable Python 3 warnings.r   r   r   r   r   TN)
r   r   r   r   r   r   r   rS   r   rP   r   r   r   r   rI     s   



zPyLinter.python3_porting_modec                 C   s  ddh}|D ]\}}}}}|t jkrqtj|}|du rq|d}| dks/| dkrN| dkr?| jd|d d	d
 | jd|d d d| _ dS z
|	dd\}	}
W n t
ym   | jd| |d d Y qw |	 }	|	| jv s||	| jv rz| j|	 }W n ty   | j|	 }| jd|d |	|	ddfd
 Y nw t|
D ]L}|	|v r|d | j|< z+|	|fdkr| jd|d dd
 | jd|d d d| _W   dS ||d|d  W q tjy   | jd||d d Y qw q| jd|	|d d qdS )z`process tokens from the current module to search for module/block
        level options
        r   r   NrA   disable-all	skip-filer;   r   )r  r  r   argsr:   )r   T=r9   )r  r   z-msgr   )r   r   )zdisable=allr  r   r>   r=   )tokenizeCOMMENTr	   Z
OPTION_RGXsearchr   stripadd_messager   r   r   r   r   r   replace_splitstripr   r   ZUnknownMessageError)rZ   tokensZcontrol_pragmastok_typecontentstartr   matchZfirst_groupoptr   r   r   r   r   r   process_tokens$  sz   






zPyLinter.process_tokensc                    s    g fdd j  D  S )z'return all available checkers as a listc                    s"   g | ]}|D ]}| ur|qqS r   r   )ra   r   r   r   r   r   rc   j  s    z)PyLinter.get_checkers.<locals>.<listcomp>)r   r   r   r   r   r   get_checkersh  s   zPyLinter.get_checkersc                 C   s   |   }tdd |D S )z7Get all the checker names that this linter knows about.c                 S   s   h | ]
}|j d kr|j qS )ru   r   )ra   ri   r   r   r   	<setcomp>u  s    z-PyLinter.get_checker_names.<locals>.<setcomp>)r  r   )rZ   Zcurrent_checkersr   r   r   get_checker_namesq  s   zPyLinter.get_checker_namesc                    s~    j js    g}  dd D ]} fdd|jD }|s-t fdd|jD r2|| qt|t	ddd	}|S )
z9return checkers needed for activated messages and reportsrA   Nc                    s   h | ]	}  |r|qS r   )Zis_message_enabled)ra   r   r   r   r   r    s    z,PyLinter.prepare_checkers.<locals>.<setcomp>c                 3   s    | ]
}  |d  V  qdS r   N)Zreport_is_enabled)ra   r   r   r   r   r     s    z,PyLinter.prepare_checkers.<locals>.<genexpr>r   T)r1   reverse)
r
   r   r   r  rq   anyr   r   operator
attrgetter)rZ   Zneededcheckersr   rk   r   r   r   prepare_checkersx  s   
zPyLinter.prepare_checkersFc                 C   s   |rdS | dS )a  Returns whether or not a module should be checked.

        This implementation returns True for all python source file, indicating
        that all files should be linted.

        Subclasses may override this method to indicate that modules satisfying
        certain conditions should not be linted.

        :param str modname: The name of the module to be checked.
        :param str path: The full path to the source code of the module.
        :param bool is_argument: Whetter the file is an argument to pylint or not.
                                 Files which respect this property are always
                                 checked, since the user requested it explicitly.
        :returns: True if the module should be checked.
        :rtype: bool
        Tz.py)endswith)r   r   is_argumentr   r   r   should_analyze_file  s   
zPyLinter.should_analyze_filec                 C   s^   | j jD ]}| sd| j|j< qt|ttfs|f}| jj	dkr(| 
| dS | | dS )zWmain checking entry: check a list of files or modules from their
        name.
        FrA   N)r   rk   Zmay_be_emittedZ_msgs_stater   r,   r   r   r
   rH   	_do_check_parallel_check)rZ   files_or_modulesr   r   r   r   ri     s   zPyLinter.checkc                 C   s   t  }dh}|dd | jD  | j D ]}| D ]\}}}|dr(q||vr4t	||||< qq| j
|d< | j|d< |S )Nz	long-helpc                 s   s    | ]\}}|V  qd S r   r   )ra   opt_namer   r   r   r   r         z,PyLinter._get_jobs_config.<locals>.<genexpr>
deprecatedrI   rJ   )r'   OrderedDictr*   r   Z_all_optionsr   Zoptions_and_valuesrS   r	   Z_format_option_valuerP   r   )rZ   child_configZfilter_optionsZopt_providersr   r   valr   r   r   _get_jobs_config  s   


zPyLinter._get_jobs_configc                 c   s   |   }g }t }| }| }g }| |D ]}|d |d |d }	}
}| j|	|
|dr7|| qtt| j	j
t|D ]}t|||fd}|  || qC|D ]}|d }||g qYd}|D ]/}z| }W n# ty } ztdtjd t|tjd d	}W Y d }~ n	d }~ww |V  qjt| j	j
D ]}|d
 q|D ]}|  q|rtdtjd td d S d S )Nr   r   isargr  r  Fz8internal error while receiving results from child linterrL   TrK   z$Error occurred, stopping the linter.    )r)  rD   ManagerQueueexpand_filesr  r   rangeminr
   rH   rC   rG   r  rU   rS   rV   rW   rX   rY   r"   exit)rZ   r"  r'  childrenmanagerr[   r\   Zexpanded_filesdescrr   r$   is_argr   Zchild_linterZfiles_or_moduler   failedr^   r_   childr   r   r   _parallel_task  sT   

zPyLinter._parallel_taskc                 C   s   |    g }d }| |D ]0}|sq|\}| j_}}}}|D ]}	tj|	 }	| | | j|	 q|	| |  j
|O  _
qt|| _|| _|  D ]
}
|
| urT| j|
_qJd S r   )openr:  rl   rm   r	   Messageset_current_modulerj   Zhandle_messager   ro   r3   r.   rn   r  )rZ   r"  Z	all_statsr   r^   r   rk   r.   ro   r   r   r   r   r   r!    s(   



zPyLinter._parallel_checkc                    s>  t  }  } fdd|D }dd |D }|D ]}|  t|tjr-|| q |D ]X}|d |d |d }}	}
 j	||	|
dsLq3 
||	  |	|}|d u r]q3t |d  _d	 _|j _ ||||  j j}|D ]\}}} ||d | q}q3|j jd
< t|D ]}|  qd S )Nc                    s&   g | ]}t |t jr| ur|qS r   )r   
implementsITokenCheckerr   r   r   r   rc     s    z&PyLinter._do_check.<locals>.<listcomp>c                 S   s   g | ]}t |t jr|qS r   )r   r>  ZIRawCheckerr   r   r   r   rc     s
    r   r   r*  r+  basenameF	statement)r	   ZPyLintASTWalkerr  r;  r   r>  ZIAstroidCheckerZadd_checkerr0  r  r=  get_astr   rl   r   rM   r   check_astroid_moduleZ"iter_spurious_suppression_messagesr   r
  Znbstatementsr.   reversedclose)rZ   r"  walkerr   tokencheckersrawcheckersr   r6  r   r$   r7  ast_nodeZspurious_messagesr   r   r  r   r   r   r     sF   



zPyLinter._do_checkc                 C   sz   t || jj| jj\}}|D ]+}|d  }}|d }| | |dkr3t|d t	 tj
 d}| j||d q|S )zHget modules and errors from a list of modules and handle errors
        modr1   r5   r_   r   r,  )r	   Zexpand_modulesr
   rx   r   r=  strr  r   r#   sepr
  )rZ   modulesr^   errorserrorr   r   r1   r   r   r   r0  ?  s   
zPyLinter.expand_filesc                 C   st   |s|du rdS | j || || _|p|| _i | jd |< d| jd | d< tj D ]}d| jd | |< q,dS )zYset the name of the currently analyzed module and
        init statistics for it
        N	by_moduler   rA  )rj   Zon_set_current_modulern   r   r.   r	   	MSG_TYPESr   )rZ   r   r$   msg_catr   r   r   r=  N  s   
zPyLinter.set_current_modulec              
   C   s   z	t j||ddW S  tjy- } z| jdt|jddt|jd W Y d}~dS d}~w tjyG } z| jd|d	 W Y d}~dS d}~w t	yk } zddl
}|  | jd
|j|fd	 W Y d}~dS d}~ww )z/return an ast(roid) representation for a moduleT)sourcer<   linenor   r  Nr7   r,  r6   )MANAGERZast_from_fileastroidZAstroidSyntaxErrorr
  rB   rO  rK  ZAstroidBuildingExceptionrV   	traceback	print_excr   )rZ   r$   r   r_   rW  r   r   r   rB  \  s    "zPyLinter.get_astc              
   C   s   zt |}W n$ tjy+ } z| jd|jd d |jd d W Y d}~dS d}~ww |js8| jd|jd n&| | | j	rBdS | j
| j| |D ]}|| qL|D ]}|| qV|| d	S )
z/Check a module from its astroid representation.r<   rA   r   r  Nr8   r,  FT)r	   Ztokenize_moduler  
TokenErrorr
  r  Zpure_pythonr   r  r   rl   Zcollect_block_linesr   Zprocess_modulewalk)rZ   rI  rF  rH  rG  r  r_   r   r   r   r   rC  m  s&    

zPyLinter.check_astroid_modulec                 C   sN   i i d| _ | jjt_| jjt_tj| jj	 t
j D ]}d| j |< qdS )zinitialize counters)rP  r&   r   N)r.   r
   Zunsafe_load_any_extensionrU  Zalways_load_extensionsZlimit_inference_resultsZmax_inferable_valuesZextension_package_whitelistr*   Zextension_pkg_whitelistr	   rQ  r   )rZ   rR  r   r   r   r;    s   

zPyLinter.openc                 C   s   | j t  | jjdurLt| jj}| j | j	| | jj
r)| | j	|}nt }| jj
r7| j | |   | jjrJt| j	| jj dS dS | j | j	i  dS )zclose the whole package /module, it's time to make reports !

        if persistent run, pickle results for later comparison
        N)rj   Zdisplay_messagesreport_nodesZSectionrl   rm   r
   load_resultsZon_closer.   r   Zmake_reportsdisplay_reports_report_evaluationr   Zsave_results)rZ   previous_statssectr   r   r   generate_reports  s   zPyLinter.generate_reportsc              
   C   s   t | jj}| jd dkrdS | j j}z	t|i | j}W n ty3 } z
d| }W Y d}~n!d}~ww || jd< d| }|d}|durP|d||| f 7 }| j j	rat
|}| j| dS dS )z!make the global evaluation reportrA  r   Nz&An exception occurred while rating: %sZglobal_notez#Your code has been rated at %.2f/10z (previous run: %.2f/10, %+.2f))r
   r\  rl   rm   r.   r   evalrV   rS   r   r[  ZEvaluationSectionrj   r]  )rZ   r_  r   Znoter_   r   Zpnoter`  r   r   r   r^    s&   


zPyLinter._report_evaluation)r   Nr   N)NN)Fr   )0rr   rs   rt   r   r   r?  Z__implements__r   r   r   MSGSrq   staticmethodr   r   r   re   rf   rg   r   r   rh   r   r   r   r   r   r   r   rI   r  r  r  r  r  ri   r)  r:  r!  r   r0  r=  rB  rC  r;  ra  r^  __classcell__r   r   r   r   rd   $  sX    
 s6
"
D	3/
	rd   c                 C   s4   g d}|t ||d7 }| tj|ddd dS )z#make total errors / warnings report)rz   numberprevious
difference)
conventionrefactorwarningrO     rA   r4  colsZrheadersN)r   Ztable_lines_from_statsr   r[  Table)r`  r.   r_  linesr   r   r   r     s
   r   c                 C   sn   |d st  tdd |d  D }|  d}|D ]\}}||t|f7 }q| tj|ddd dS )	zmake messages type reportr&   c                 S   s"   g | ]\}}| d s||fqS )I)r   )ra   r   r   r   r   r   rc     s    z)report_messages_stats.<locals>.<listcomp>)z
message idoccurrences   rA   rm  N)	r   EmptyReportErrorr   r+   r  rK  r   r[  ro  )r`  r.   r   Zin_orderrp  r   r   r   r   r   r     s   
r   c                 C   sT  t |d dkrt tt}dD ],}|| }|d  D ]}|d | | }|dkr0d}nt|d | }||| |< qqg }	| D ]\}}
|		|
d |
d |
d |
d	 |f qF|	
  |	  g d
}|	D ]'}tdd |dd D r{qk|	|d  |dd D ]	}|	d|  qqkt |dkrt | 	tj|ddd dS )z(make errors / warnings by modules reportrP  rA   )r5   rO  rk  rj  ri  r   r   rO  rk  rj  ri  )r   rO  rk  rj  ri  c                 s   s    | ]}|d kV  qdS r  r   )ra   entryr   r   r   r     r$  z2report_messages_by_module_stats.<locals>.<genexpr>Nr   z%.2f   rm  )rC   r   rt  r'   r   r-   keysfloatr+   r   sortr  r   r[  ro  )r`  r.   r   Zby_modZm_typetotalr   Z	mod_totalpercentZsorted_resultZmod_inforp  r   r(  r   r   r   r     sF   
	r   c                   @   s   e Zd ZdZdS )ArgumentPreprocessingErrorz8Raised if an error occurs during argument preprocessing.N)rr   rs   rt   r   r   r   r   r   r|    s    r|  c           	      C   s   d}|t | k r| | }|drz|dd dd\}}W n ty1   |dd d}}Y nw z|| \}}W n tyG   |d7 }Y n?w | |= |rn|du rn|t | ks^| | drfd| }t|| | }| |= n|s||dur|d	| }t|||| n|d7 }|t | k sdS dS )
zlook for some options (keys of <search_for>) which have to be processed
    before others

    values of <search_for> are callback functions to call when the option is
    found
    r   z--rs  Nr  rA   r   zOption %s expects a valuez!Option %s doesn't expects a value)rC   r   r   r   r   r|  )	r  Z
search_foriargoptionr(  cbZtakeargr   r   r   r   preprocess_options  s6   
r  c              
   c   s|    t tj}g }| D ]}t|}||v rq
|| q
|dg tj tjdd< zdV  W |tjdd< dS |tjdd< w )aB  Prepare sys.path for running the linter checks.

    Within this context, each of the given arguments is importable.
    Paths are added to sys.path in corresponding order to the arguments.
    We avoid adding duplicate directories to sys.path.
    `sys.path` is reset to its original value upon exiting this context.
    r   N)r   rX   r   r%   r   )r  origchangesr~  r   r   r   r   fix_import_path;  s   
	"r  c                   @   sz   e Zd ZdZeZdZdddZdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )RunzEhelper class to use as main for pylint :

    run(*sys.argv[1:])
    ))CommandszROptions which are actually commands. Options in this group are mutually exclusive.NTc           	      C   s  d | _ g | _d | _zt|tdf| jdf| jdf| jdfd W n ty> } zt	|t
jd t
d W Y d }~nd }~ww | jdddd	 d
dddfdddd	 d
ddddfddd
d| jdddfddd| jddddfddd| jddddfddtdddd fd!dd| jddd"dfd#d| jdd$d%fd&d| jdd'dd(fd)d| jd*d+d,fd-d| jd.d/fd0d| jd1d2d,ff| j| j d3 | _}|  || j |jd4tjdd5 |jd6d7dd5 |jd8d9dd5 |d: |d; |j | jd< |j!}|"d=drtdt#$|%d=d |"d=d>r$t#&|%d=d>}|| |'  |r0|(| z|)|}W n t*yN } z
|j+d?krId|_+ d }~ww |s]t	|,  t
d |jj-d@k rtt	dA|jj- t
jd t
d |jj-dks|jj-d@krt.d u rt	dBt
jd |/dCd n|jj-d@krt0 |j_-|1  t2| |3| |4  W d    n	1 sw   Y  |r|jj5rt
d@ d S t
| jj6 d S d S )DNTF)	init-hookrcfiler   verboserL   r-  r  callbackc                  W      dS NrA   r   r,  r   r   r   r   {      zRun.__init__.<locals>.<lambda>r   z<file>zSpecify a configuration file.)r   r  rz   r{   r~   r  c                  W   r  r  r   r,  r   r   r   r     r  z<code>rA   zRPython code to execute, usually for sys.path manipulation such as pygtk.require().)r   r  rz   r{   r   r~   zhelp-msgz<msg-id>r  zqDisplay a help message for the given message id and exit. The value may be a comma separated list of message ids.)r   rz   r{   r  r   r~   z	list-msgszGenerate pylint's messages.)r   r{   r  r   r   r~   zlist-groupszList pylint's message groups.zlist-conf-levelsz$Generate pylint's confidence levels.)r   r  r   r   r~   zfull-documentationz%Generate pylint's full documentation.zgenerate-rcfilezGenerate a sample configuration file according to the current configuration. You can put other options before this one to get them in the generated configuration.)r   r  r   r~   zgenerate-manzGenerate pylint's man page.)r   r  r   r~   r   zerrors-onlyr   zIn error mode, checkers without error messages are disabled and for others, only the ERROR messages are displayed, and no reports are done by default.)r   r  r   r~   Zpy3kz{In Python 3 porting mode, all checkers will be disabled and only messages emitted by the porting checker will be displayed.)r   r  r~   r  vzBIn verbose mode, extra non-checker-related info will be displayed.)r   r   zEnvironment variables)r   Outputa5  Using the default text output, the message format is :                          
                                                                                
        MESSAGE_TYPE: LINE_NUM:[OBJECT:] MESSAGE                                
                                                                                
There are 5 kind of message types :                                             
    * (C) convention, for programming standard violation                        
    * (R) refactor, for bad code smell                                          
    * (W) warning, for python specific problems                                 
    * (E) error, for probable bugs in the code                                  
    * (F) fatal, if an error occurred which prevented pylint from doing further
processing.
zOutput status codea[  Pylint should leave with following status code:                                 
    * 0 if everything went fine                                                 
    * 1 if a fatal message was issued                                           
    * 2 if an error message was issued                                          
    * 4 if a warning message was issued                                         
    * 8 if a refactor message was issued                                        
    * 16 if a convention message was issued                                     
    * 32 on usage error                                                         
                                                                                
status 1 to 16 will be bit-ORed so you can know which different categories has
been issued by analysing pylint output status code
rq  zc-extension-no-memberr  ZMASTERr   rs  r   z5Jobs number (%d) should be greater than or equal to 0z>Multiprocessing library is missing, fallback to single processrH   )7_rcfilerQ   r  r  cb_init_hookcb_set_rcfilecb_add_pluginscb_verbose_moder|  rW   rX   rY   r3  LinterClasscb_help_messagecb_list_messagescb_list_groupscb_list_confidence_levelscb_full_documentationcb_generate_configcb_generate_manpagecb_error_modecb_python3_porting_moder   rp   re   rf   Zadd_help_sectionr
   ZENV_HELPr   r   Zread_config_filer   r   r	   _unquoterS   r  Zload_config_filerh   Zload_command_line_configuration
SystemExitcoder~   rH   rD   r   rF   rg   r  ri   ra  Z	exit_zeroro   )	rZ   r  rj   Zdo_exitr_   rp   r   rJ   excr   r   r   r   b  st  
   












zRun.__init__c                 C   s
   || _ dS z>callback for option preprocessing (i.e. before option parsing)N)r  rZ   r   r   r   r   r   r  d  s   
zRun.cb_set_rcfilec                 C   s   | j t| dS r  )rQ   extendr	   r  r  r   r   r   r  h  s   zRun.cb_add_pluginsc                 O      | j   dS )zerror mode:
        * disable all but error messages
        * disable the 'miscellaneous' checker which can be safely deactivated in
          debug
        * disable reports
        * do not save execution information
        N)rp   r   rZ   r  kwargsr   r   r   r  l  s   zRun.cb_error_modec                 O   s   | j jdd td dS )0optik callback for sample config file generation)ZCOMMANDS)Zskipsectionsr   N)rp   Zgenerate_configrX   r3  r  r   r   r   r  v  s   zRun.cb_generate_configc                 O   s&   ddl m} | j| td dS )r  r   )__pkginfo__N)pylintr  rp   Zgenerate_manpagerX   r3  )rZ   r  r  r  r   r   r   r  {  s   zRun.cb_generate_manpagec                 C   s"   | j jt| td dS )z@optik callback for printing some help about a particular messager   N)rp   r   Zhelp_messager	   r  rX   r3  rZ   r  r   r   parserr   r   r   r    s   zRun.cb_help_messagec                 C   s   | j   td dS )z.optik callback for printing full documentationr   N)rp   Zprint_full_documentationrX   r3  r  r   r   r   r    s   
zRun.cb_full_documentationc                 C   s   | j j  td dS )z.optik callback for printing available messagesr   N)rp   r   Zlist_messagesrX   r3  r  r   r   r   r    s   zRun.cb_list_messagesc                 O   s&   | j  D ]}t| qtd dS )zList all the check groups that pylint knows about

        These should be useful to know what check groups someone can disable
        or enable.
        r   N)rp   r  rW   rX   r3  )rZ   r  r  ri   r   r   r   r    s   
zRun.cb_list_groupsc                 O   r  )z*Activate only the python3 porting checker.N)rp   rI   r  r   r   r   r    s   zRun.cb_python3_porting_modec                 O   s
   d| _ d S NTr  r  r   r   r   r    s   
zRun.cb_verbose_moder  )rr   rs   rt   r   rd   r  r   r   r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  S  s$    
  

r  c                 C   s&   t jD ]}td|  qtd d S )Nz	%-18s: %sr   )r   r   rW   rX   r3  )r  r   r   r  r   r   r   r   r    s   
r  c                 C   s   t | dS )z0exec arbitrary code to set sys.path for instanceN)exec)r   r   r   r   r   r    s   r  __main__rA   )7r   
__future__r   r'   
contextlibr  r   rD   r   rX   r  r   rV  Zastroid.__pkginfo__r   r   r   r  r   r   r   r   r	   r
   Zpylint.__pkginfo__Zpylint.reporters.ureportsr   r[  rU  r   r%   r3   rc  r   rF   ProcessrG   ZOptionsManagerMixInr   r   r   rd   r   r   r   rV   r|  r  contextmanagerr  r  r  r  rr   argvr   r   r   r   <module>   s   0N
=       /	,#
  R