o
    g                     @   s  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Zd dl	m
Z
 d dlmZmZmZmZmZmZ d dlZd dlmZmZ d dlmZmZmZmZmZ d dlmZm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'm(Z(m)Z) d dl*m+Z+m,Z, d dl-mZ. d dl/m0Z0m1Z1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8m9Z9m:Z:m;Z; ej<Z<dd Z=de>de?fddZ@ddddddddddd d!d"d#gifd$d%d&d'd(ZAG d)d* d*ejBe,ejCejDZEdS )+    N)TextIOWrapper)IterableIteratorListOptionalSequenceUnion)AstroidErrornodes)checkersconfig
exceptions
interfaces	reporters)MAIN_CHECKER_NAME	MSG_TYPES)expand_modules)check_parallel)report_messages_by_module_statsreport_messages_statsreport_total_messages_stats)fix_import_pathget_fatal_error_messageprepare_crash_report)MessageDefinitionStoreMessagesHandlerMixIn)r
   )CheckerStatsFileItemModuleDescriptionDict)	ASTWalker	FileStateutils)	OPTION_POInvalidPragmaErrorUnRecognizedOptionErrorparse_pragmac                   C   s   t tj ddt_tj S )Nutf-8encoding)r   sysstdindetachread r-   r-   R/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/pylint/lint/pylinter.py_read_stdin/   s   
r/   reporter_classreturnc                 C   s4   | }t j|}t j|}|dd }t||S )N.)astroidmodutilsget_module_partload_module_from_namesplitgetattr)r0   qnamemodule_partmodule
class_namer-   r-   r.   _load_reporter_by_class5   s
   
r>   )%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.26	old_names)I0014zdeprecated-disable-all)r?   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;Plugin '%s' is impossible to load, is it installed ? ('%s')bad-plugin-valuez0Used when a bad value is used in 'load-plugins'.)F0001F0002F0010I0001I0010I0011I0013I0020I0021I0022E0001E0011E0012E0013c                       s"  e Zd ZU dZejfZeZdZ	dZ
eZdZeed< edd ZdZdb fd
d	Zdd Zdd Zdd ZdcddZdedejfddZdd Zddd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&d0d1 Z'd2d3 Z(d4d5 Z)eded7d8Z*d9d: Z+d;e,e-e ef dd	fd<d=Z.d>ed?ed@edd	fdAdBZ/dCe0dd	fdDdEZ1dFe2e0 dd	fdGdHZ3dCe0fdIdJZ4ed?ede0fdKdLZ5de6e0 fdMdNZ7de8e9 fdOdPZ:dfd?e;e fdQdRZ<e=j>dSdT Z?dfdUdVZ@dWdX ZAdYeBjCfdZd[ZDd\d] ZEd^d_ ZFd`da ZG  ZHS )gPyLintera  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.

    This class needs to support pickling for parallel linting to work. The exception
    is reporter member; see check_parallel function for more details.
    r   zpylint-crash-%Y-%m-%d-%H.txtcrash_file_pathc                   C   s  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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d0d1d2d3d4d5fd6d7dd8d9d5fd:d;d<d7d=d> t jD d?d@dAdBdC t jD  dDdEfdFdd8dGd?dHdIfdJdd8dKd?dLdIfdMddNd!dOdPfdQdRdSdTddUdVfdWddXd%ddYdZfd[dRd\d]d^d_fd`ddag dbd_fdcddag ddd_fdeddXddfd_fdgdhdidjfdkdhdldjfdmtjd dn dodpdqd5ffS )rNignorecsvz<file>[,<file>...]
black_list)CVSzIFiles or directories to be skipped. They should be base names, not paths.)typemetavardestdefaulthelpzignore-patterns
regexp_csvz<pattern>[,<pattern>...]black_list_rer-   znFiles or directories matching the regex patterns are skipped. The regex matches against base names, not paths.zignore-pathsignore_list_paths_reziAdd files or directories matching the regex patterns to the ignore-list. The regex matches against paths.
persistentTynz<y_or_n>   z,Pickle collected data for later comparisons.)rd   ra   rb   levelre   zload-pluginsz	<modules>ztList of plugins (as comma separated values of python module names) to load, usually to register additional checkers.)ra   rb   rd   rl   re   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.)rd   ra   rb   shortgroupre   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)aV  Python expression which should return a score less than or equal to 10. You have access to the variables 'error', 'warning', 'refactor', and 'convention' which contain the number of messages in each category, as well as 'statement' which is the total number of statements analyzed. This score is used by the global evaluation report (RP0004).)ra   rb   rs   rl   rd   re   scoreszActivate the evaluation score.z
fail-under
   floatz<score>zISpecify a score threshold to be exceeded before program exits with error.)rd   ra   rb   re   zfail-on z	<msg ids>zReturn non-zero exit code if any of these messages/categories are detected, even if score is above --fail-under value. Syntax same as enable. Messages specified are enabled, while categories only check already-enabled messages.
confidencemultiple_choicez<levels>c                 S   s   g | ]}|j qS r-   name.0cr-   r-   r.   
<listcomp>=  s    z)PyLinter.make_options.<locals>.<listcomp>Messages controlz]Only show warnings with the listed confidence levels. Leave empty to show all. Valid levels: z, c                 s   s    | ]}|j V  qd S Nr~   r   r-   r-   r.   	<genexpr>@  s    z(PyLinter.make_options.<locals>.<genexpr>r2   )ra   rb   rd   choicesrs   re   enable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.)ra   rb   rr   rs   re   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.)ra   rb   rs   re   jobsintz<n-processes>jzsUse multiple processes to speed up Pylint. Specifying 0 will auto-detect the number of processors available to use.)ra   rb   rr   rd   re   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.)ra   rb   rd   hidere   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. )ra   rb   rd   re   zextension-pkg-allow-listz<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extension-pkg-whitelista  A 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. (This is an alternative name to extension-pkg-allow-list for backward compatibility.)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.)actionre   z
from-stdinzlInterpret the stdin as a python script, whose filename needs to be passed as the module_or_package argument.z
py-version   
py_versionz<py_version>zgMin Python version to use for version dependend checks. Will default to the version used to run pylint.)r   CONFIDENCE_LEVELSjoinr)   version_infor-   r-   r-   r.   make_options   sx  
  zPyLinter.make_options))r   z%Options controlling analysis messages)rq   z2Options related to output formatting and reportingr-   Nc                    s2  t  | _d| _d| _i | _tt| _i | _	d| _
t | _d| _d| _i | _g | _|| _|t  | _|tj | _| j| j| jd| _| jd | jd d| _t|  tj|  t jt |pft!t"# dd t$j%|  dd	t&fd
dt'fddt(ff| _)| *|  t+ | _,d| _-| .  |r| /| dS dS )z{Some stuff has to be done before ancestors initialization...
        messages store / checkers / reporter / astroid managerNF)r   r   disable-nextr   r   )zdisable-msgz
enable-msg)usageconfig_fileRP0001zMessages by categoryRP0002z% errors / warnings by moduleRP0003Messages)0r   
msgs_storereporter_reporter_names
_reporterscollectionsdefaultdictlist	_checkers_pragma_lineno_ignore_filer    
file_statecurrent_namecurrent_filestatsfail_on_symbols_external_optsr[   r   optionsoption_groupsr   r   disable_next_options_methods_bw_options_methodsr   __init__r   ReportsHandlerMixInsuper__doc__nextr   find_default_config_filesr   BaseTokenCheckerr   r   r   rt   register_checkerset_dynamic_plugins_error_modeload_provider_defaultsset_reporter)selfr   r   r   pylintrc	__class__r-   r.   r     sV   

	zPyLinter.__init__c                 C   s*   t |  t|  | js|   d S d S r   )r   
initializer   r   _load_reportersr   r-   r-   r.   load_default_plugins"  s
   

zPyLinter.load_default_pluginsc              	   C   sR   |D ]$}|| j v r
q| j | ztj|}||  W q ty&   Y qw dS )z`take a list of module names which are pylint plugins and load
        and register them
        N)r   addr4   r5   r7   registerModuleNotFoundError)r   modnamesmodnamer<   r-   r-   r.   load_plugin_modules*  s   
zPyLinter.load_plugin_modulesc                 C   sl   | j D ]0}ztj|}t|dr||  W q ty3 } z| jd||fdd W Y d}~qd}~ww 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_configurationrL   r   argslineN)r   r4   r5   r7   hasattrr   r   add_message)r   r   r<   r   r-   r-   r.   load_plugin_configuration8  s   


 z"PyLinter.load_plugin_configurationr1   c           	   	   C   s   g }g }t  A}| jdD ]-}|dd^}}| |}|| |r<|\}|t|ddd}|| || q|	 j
}W d    n1 sLw   Y  t|dksY|rd| t|| d S | |d  d S )N,:rk   wr&   r'   r   )
contextlib	ExitStackr   r8   _load_reporter_by_nameappendenter_contextopen
set_outputpop_allcloselenr   r   MultiReporter)	r   sub_reportersoutput_filesstackreporter_namereporter_outputr   output_fileclose_output_filesr-   r-   r.   r   G  s2   




zPyLinter._load_reportersr   c              
   C   sX   |  }|| jv r| j|  S zt|}W | S  ttfy+ } zt||d }~ww r   )lowerr   r>   ImportErrorAttributeErrorr   InvalidReporterError)r   r   r   r0   r   r-   r-   r.   r   i  s   

zPyLinter._load_reporter_by_namec                 C   s   || _ | |_dS )z5set the reporter used to display messages and reportsN)r   linter)r   r   r-   r-   r.   r   u  s   
zPyLinter.set_reporterc              
   C   s  || j v s
|| jv rR|rQz| j | }W n ty1   | j| }t| d|dd  t Y nw t|}t	|t
tfrK|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| d	tjd
 Y dS w )z[overridden from config.OptionsProviderMixin to handle some
        special options
        z is deprecated, replace it by -r   T)ignore_unknownNrm   zoption z can't be read from config file)file)r   r   KeyErrorwarningswarnr8   DeprecationWarningr!   
_check_csv
isinstancer   tupler   r   r   r   r   
set_optionr   UnsupportedActionprintr)   stderr)r   optnamevaluer   optdictmeth_idr-   r-   r.   r   z  s8   

zPyLinter.set_optionc                 C   s   || j |j< d S r   )r   r   )r   r0   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{   )r9   )xr-   r-   r.   <lambda>  s    z'PyLinter.report_order.<locals>.<lambda>)key)sorted_reportspopindex
ValueErrorr   )r   rt   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 >= 0msgsenabledTN)priorityr   r   r   rt   register_reportregister_options_providerr   r   register_messages_from_checkerload_defaultsr9   r   )r   checkerr_idr_titler_cbr-   r-   r.   r     s   

zPyLinter.register_checkerc                 C   s   | j j}|sdS t }t }|D ]}|tv r|| q|| q| j D ]3}|D ].}|jD ](}|j|v s<|j	|v rJ| 
|j | j|j	 q0|jd |v rX| j|j	 q0q+q'dS )zenable 'fail on' msgs

        Convert values in config.fail_on (which might be msg category, msg id,
        or symbol) to specific msgs, then enable and flag them for later.
        Nr   )r   fail_onr   r   r   r   valuesmessagesmsgidsymbolr   r   r   )r   fail_on_valsfail_on_catsfail_on_msgsvalall_checkersr  msgr-   r-   r.   enable_fail_on_messages  s*   
z PyLinter.enable_fail_on_messagesc                    s2    j o j dd uot fdd j d D S )Nby_msgc                 3   s    | ]}| j v V  qd S r   )r   )r   r  r   r-   r.   r     s    z.PyLinter.any_fail_on_issues.<locals>.<genexpr>)r   getanyr   r-   r   r.   any_fail_on_issues  s
   zPyLinter.any_fail_on_issuesc                 C   sL   | j j D ]\}}|dv r|D ]}| | qq|D ]}| | qqd S )N)EF)r   _msgs_by_categoryitemsr   r   )r   msgcatmsgidsr  r-   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	  r  disable_report)r   r   	report_id_r-   r-   r.   disable_reporters  s
   zPyLinter.disable_reportersc                 C   s@   d| _ |   | d | dd | dd | dd dS )z9error mode: enable only errors; no reports, no persistentTmiscellaneousrt   Fri   rw   N)r   r/  r   r   r   r-   r-   r.   
error_mode  s   
zPyLinter.error_modec                 C   s   | j  \}}g }g }|D ]%}| |jr$|d|j d|j d q|d|j d|j d qtd |D ]}t| q9td |D ]}t| qFtd |D ]}td|j d|j d qStd d S )Nz  z ()zEnabled messages:z
Disabled messages:z1
Non-emittable messages with current interpreter:r{   )r   find_emittable_messagesis_message_enabledr  r   r  r   )r   	emittablenon_emittabler  disabledmessager#  r-   r-   r.   list_messages_enabled  s"   

zPyLinter.list_messages_enabledc                 C   sd  h d}d}d}d}|D ]"\}}}}	}	|r ||d kr |}d}|d }|t jt jfv r.d}|t jkr4qt|}
|
du r>qzt|
dD ]}|jdv rm|jdkr\| j	d	|d dd
 | j	d|d d d| _
 W  dS z| j|j }W n! ty   | j|j }| j	d	|d |j|jddfd
 Y nw |jD ]W}|j|v r|d | j|< |j|fdkr| j	d	|d dd
 | j	d|d d d| _
  W  dS |d }|s|d8 }z||d| W q tjy   | j	d||d d Y qw qFW q ty } z| j	d|j|d d W Y d}~qd}~w ty/ } z| j	d|j|d d W Y d}~qd}~ww dS )zXProcess tokens from the current module to search for module/block level
        options.>   r   r   r   NTr   Fr   )disable-all	skip-filer>  rF   r   r   rE   )r   z-msgr{   )r   all)zdisable=allr?  rk   r<   rK   r   rJ   rD   )tokenizeNLNEWLINECOMMENTr"   searchr%   rs   r   r   r   r   r   r   replacer  r   r   UnknownMessageErrorr$   tokenr#   )r   tokenscontrol_pragmas	prev_linesaw_newlineseen_newlinetok_typecontentstartr2  matchpragma_reprr  r  l_starterrr-   r-   r.   process_tokens  s   









1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-   )r   r   r   r   r-   r.   r   h  s    z)PyLinter.get_checkers.<locals>.<listcomp>)r   r  r   r-   r   r.   get_checkersf  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 tkr|j qS r-   )r   r   )r   r  r-   r-   r.   	<setcomp>s  s
    
z-PyLinter.get_checker_names.<locals>.<setcomp>)rW  r  )r   current_checkersr-   r-   r.   get_checker_nameso  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 reportsrk   Nc                    s   h | ]	}  |r|qS r-   )r8  )r   r#  r   r-   r.   rX    s    z,PyLinter.prepare_checkers.<locals>.<setcomp>c                 3   s    | ]
}  |d  V  qdS )r   N)report_is_enabled)r   ru   r   r-   r.   r     s    z,PyLinter.prepare_checkers.<locals>.<genexpr>r  T)r  reverse)
r   rt   r3  rW  r  r'  r   r  operator
attrgetter)r   needed_checkersr  r  r-   r   r.   prepare_checkersz  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: Whether 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   pathis_argumentr-   r-   r.   should_analyze_file  s   
zPyLinter.should_analyze_filec                 C   s&   | j jD ]}| sd| j|j< qdS )zaInitialize linter for linting

        This method is called before any linting is done.
        FN)r   r  may_be_emitted_msgs_stater  )r   r#  r-   r-   r.   r     s
   zPyLinter.initializefiles_or_modulesc                 C   s  |    t|ttfstdt |f}| jjrOt	|dkr#t
d|d }t| | tj| jt d| |g W d   dS 1 sHw   Y  dS | jjdkrvt| | | j| | W d   dS 1 sow   Y  dS t| | jj| || dS )zmain checking entry: check a list of files or modules from their name.

        files_or_modules is either a string or list of strings presenting modules to check.
        zNIn pylint 3.0, the checkers check function will only accept sequence of stringrk   z*Missing filename required for --from-stdinr   )dataN)r   r   r   r   r   r   r   r   
from_stdinr   r   InvalidArgsErrorr   _check_files	functoolspartialget_astr/   _get_file_descr_from_stdinr   _iterate_file_descrsr   )r   rg  filepathr-   r-   r.   check  s>   

"
"zPyLinter.checkr   rq  r   c                 C   s"   t dt | t||| d S )NzkIn pylint 3.0, the checkers check_single_file function will be removed. Use check_single_file_item instead.)r   r   r   check_single_file_itemr   )r   r   rq  r   r-   r-   r.   check_single_file  s
   zPyLinter.check_single_filer   c                 C   s>   |   }| | j|| W d   dS 1 sw   Y  dS )zCheck single file item

        The arguments are the same that are documented in _check_files

        The initialize() method should be called before calling this method
        N)_astroid_module_checker_check_filern  )r   r   check_astroid_moduler-   r-   r.   rs    s   
"zPyLinter.check_single_file_itemfile_descrsc           	      C   s   |   R}|D ]F}z	| ||| W q tyM } z/t||j| j}t|j|}t|tr:d}| j	||j|fd n	d}| j	||d W Y d}~qd}~ww W d   dS 1 sYw   Y  dS )z Check all files from file_descrsrA   r   r@   N)
ru  rv  	Exceptionr   rq  r\   r   r   r	   r   )	r   rn  rx  rw  r   extemplate_pathr#  r  r-   r-   r.   rk    s$   


"zPyLinter._check_filesc           	      C   s~   |  |j|j ||j|j}|du rdS d| _t|j| _|j| _|| | j	| j
}|D ]\}}}| ||d| q/dS )a  Check a file using the passed utility functions (get_ast and check_astroid_module)

        :param callable get_ast: callable returning AST from defined file taking the following arguments
        - filepath: path to the file to check
        - name: Python module name
        :param callable check_astroid_module: callable checking an AST taking the following arguments
        - ast: AST of the module
        :param FileItem file: data about the file
        NF)set_current_moduler   rq  r   r    modpathr   r   r   "iter_spurious_suppression_messagesr   r   )	r   rn  rw  r   ast_nodespurious_messagesr  r   r   r-   r-   r.   rv    s   
zPyLinter._check_filec                 C   sN   zd tj| }W n ty    tjtj| d }Y nw t	|| | S )zReturn file description (tuple of module name, file path, base name) from given file path

        This method is used for creating suitable file description for _check_files when the
        source is standard input.
        r2   r   )
r   r4   r5   modpath_from_filer   osrb  splitextbasenamer   )rq  r   r-   r-   r.   ro    s   z#PyLinter._get_file_descr_from_stdinc                 c   sT    |  |D ]!}|d |d |d }}}| j|||dr't|||d V  qdS )zReturn generator yielding file descriptions (tuples of module name, file path, base name)

        The returned generator yield one item for each Python module that should be linted.
        r   rb  isarg)rc  r  N)_expand_filesrd  r   )r   rg  descrr   rq  is_argr-   r-   r.   rp  ,  s   zPyLinter._iterate_file_descrsc                 C   s~   t || jj| jj| jj\}}|D ]+}|d  }}|d }| | |dkr5t|d t	 tj
 d}| j||d q|S )z?get modules and errors from a list of modules and handle errorsmodr  r@   r{  r{   ry  )r   r   r_   rg   rh   r}  strrG  r  getcwdsepr   )r   modulesresulterrorserrorr<  r   r  r-   r-   r.   r  6  s   
zPyLinter._expand_filesc                 C   sr   |s|du rdS | j || || _|p|| _i | jd |< d| jd | d< t D ]}d| jd | |< q+dS )zYset the name of the currently analyzed module and
        init statistics for it
        N	by_moduler   	statement)r   on_set_current_moduler   r   r   r   r  )r   r   rq  msg_catr-   r-   r.   r}  G  s   
zPyLinter.set_current_modulec                 #   s    t  }  } fdd|D }dd |D }|D ]}|  t|tjr-|| qtj j	|||dV  |j
 jd< t|D ]}|  qCdS )z|Context manager for checking ASTs

        The value in the context is callable accepting AST as its only argument.
        c                    s&   g | ]}t |t jr| ur|qS r-   )r   
implementsITokenCheckerr   r   r-   r.   r   ]  s    z4PyLinter._astroid_module_checker.<locals>.<listcomp>c                 S   s   g | ]}t |t jr|qS r-   )r   r  IRawCheckerr   r-   r-   r.   r   b  s
    )walkertokencheckersrawcheckersr  N)r   r`  r   r   r  IAstroidCheckeradd_checkerrl  rm  rw  nbstatementsr   reversedr   )r   r  r   r  r  r  r-   r   r.   ru  U  s0   


z PyLinter._astroid_module_checkerc              
   C   s   z|du rt j||ddW S tjt |||W S  tjyC } z| jdt|j	ddt|j	ddt
|j	d W Y d}~dS d}~w tjy] } z| jd	|d
 W Y d}~dS d}~w ty} } zt  | jd|j|fd
 W Y d}~dS d}~ww )a9  Return an ast(roid) representation of a module or a string.

        :param str filepath: path to checked file.
        :param str modname: The name of the module to be checked.
        :param str data: optional contents of the checked file.
        :returns: the AST
        :rtype: astroid.nodes.Module
        NT)sourcerI   linenor   offset)r   
col_offsetr   rB   ry  rA   )MANAGERast_from_filer4   builderAstroidBuilderstring_buildAstroidSyntaxErrorr   r9   r  r  AstroidBuildingExceptionrz  	traceback	print_excr   )r   rq  r   rh  r{  r-   r-   r.   rn  w  s2   	zPyLinter.get_astc                 C   s4   |j }| ||||}|j | | jd | j d< |S )zlCheck a module from its astroid representation.

        For return value see _check_astroid_module
        r  r  )r  _check_astroid_moduler   r   )r   r  r  r  r  before_check_statementsretvalr-   r-   r.   rw    s   zPyLinter.check_astroid_modulenodec              
   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 )
a  Check given AST node with given walker and checkers

        :param astroid.nodes.Module node: AST node of the module to check
        :param pylint.utils.ast_walker.ASTWalker walker: AST walker
        :param list rawcheckers: List of token checkers to use
        :param list tokencheckers: List of raw checkers to use

        :returns: True if the module was checked, False if ignored,
            None if the module contents could not be parsed
        :rtype: bool
        rI   rk   r   r@  NrC   ry  FT)r!   tokenize_modulerB  
TokenErrorr   r   pure_pythonr   rV  r   r   collect_block_linesr   process_modulewalk)r   r  r  r  r  rJ  r{  r  r-   r-   r.   r    s&    

zPyLinter._check_astroid_modulec                 C   sd   i i d| _ | jjt_| jjt_tj| jj	 | jj
r$tj| jj
 t D ]}d| j |< q(dS )zinitialize counters)r  r%  r   N)r   r   unsafe_load_any_extensionr  always_load_extensionslimit_inference_resultsmax_inferable_valuesextension_package_whitelistupdateextension_pkg_allow_listextension_pkg_whitelistr   r  )r   r  r-   r-   r.   r     s   

zPyLinter.openc                 C   s   | j t  | jjdurJt| jj}| j | j	| | jj
r)| | j	|}nt }| jj
r7| j | |  }| jjrHt| j	| jj |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)r   display_messagesreport_nodesSectionr   	base_namer   load_resultson_closer   rt   make_reportsdisplay_reports_report_evaluationri   save_results)r   previous_statssectscore_valuer-   r-   r.   generate_reports  s    zPyLinter.generate_reportsc              
   C   s   d}t | jj}| jd dkr|S | j j}z	t|i | j}W n ty6 } zd| }W Y d}~n)d}~ww || jd< d|dd}|d}|dur[|d	|dd
|| dd7 }| j j	rjt
|}| j| |S )z!make the global evaluation reportNr  r   z$An exception occurred while rating: global_notezYour code has been rated at z.2fz/10z (previous run: z/10, z+.2fr6  )r   r  r   r  r   rv   evalrz  r&  rw   r  EvaluationSectionr   r  )r   noter  rv   r{  r#  pnoter  r-   r-   r.   r    s(   


zPyLinter._report_evaluation)r-   Nr-   N)r1   N)NN)Fr   )I__name__
__module____qualname__r   r   r  __implements__r   r   r  rl   MSGSr  r\   r  __annotations__staticmethodr   r   r   r   r   r   r   r   BaseReporterr   r   r   r  r  r   r$  r(  r/  r3  r5  r=  rV  rW  rZ  r`  rd  r   r   r   rr  rt  r   rs  r   rk  rv  ro  r   rp  r   r   r  r   r}  r   contextmanagerru  rn  rw  r
   Moduler  r   r  r  __classcell__r-   r-   r   r.   r[      sz   
 
  75
"
!
	R	'




!
*r[   )Fr   r   rl  r]  r  r)   rB  r  r   ior   typingr   r   r   r   r   r   r4   r	   r
   pylintr   r   r   r   r   pylint.constantsr   r   pylint.lint.expand_modulesr   pylint.lint.parallelr   pylint.lint.report_functionsr   r   r   pylint.lint.utilsr   r   r   pylint.messager   r   pylint.reporters.ureportsr  pylint.typingr   r   r   pylint.utilsr   r    r!   pylint.utils.pragma_parserr"   r#   r$   r%   r  r/   r  ra   r>   r  OptionsManagerMixInr   r   r[   r-   r-   r-   r.   <module>   sh    
T