
    ue.                     $   d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	 ddl
mZmZ 	 ddlZ ej                   e      Zdej&                  d<   h dZh dZ G d	 d
      Zd Zed        Zed        Zd Zd Zd Zd Zy# e$ r ddlZY ^w xY w)zLinter plugin for pylint.    N)PIPEPopen)hookimpllsphidePYGAME_HIDE_SUPPORT_PROMPT>   W0402W1505W1511W1512W1513>   W0611W0612W0613W0614W1304c                   B    e Zd Z ej                  e      Zedd       Zy)PylintLinterc                    |s| j                   |j                     S t        j                  dddd|j                  g|rt	        j
                  t        |            ng z   }t        j                  ddj                  |             |j                  j                  }|s#t        j                  j                  t              }t        |t         t         |d      5 }|j#                         \  }}d	d	d	       d
k7  rt        j%                  d|       j'                         sg | j                   |j                  <   g S g }	t)        j*                  |      D ]  }
|
d   dz
  }||
d   d||j,                  rt/        |j,                  |         nddd}|
d   dk(  rt0        j2                  j4                  }n|
d   dk(  rt0        j2                  j4                  }n|
d   dk(  rt0        j2                  j6                  }nh|
d   dk(  rt0        j2                  j6                  }nE|
d   dk(  rt0        j2                  j8                  }n"|
d   dk(  rt0        j2                  j:                  }|
d   }d|dj=                  |
d   |
d         |d}|t>        v rt0        j@                  jB                  g|d<   |tD        v rt0        j@                  jF                  g|d<   |	jI                  |        |	| j                   |j                  <   |	S # 1 sw Y   xY w) a  Plugin interface to pylsp linter.

        Args:
            document: The document to be linted.
            is_saved: Whether or not the file has been saved to disk.
            flags: Additional flags to pass to pylint. Not exposed to
                pylsp_lint, but used for testing.

        Returns:
            A list of dicts with the following format:

                {
                    'source': 'pylint',
                    'range': {
                        'start': {
                            'line': start_line,
                            'character': start_column,
                        },
                        'end': {
                            'line': end_line,
                            'character': end_column,
                        },
                    }
                    'message': msg,
                    'severity': lsp.DiagnosticSeverity.*,
                }
        z-cz:import sys; from pylint.lint import Run; Run(sys.argv[1:])z-fjsonzCalling pylint with '%s' T)stdoutstderrcwduniversal_newlinesN zError calling pylint: '%s'line   columnr   	characterr   startendtype
conventioninformationerrorfatalrefactorwarningz
message-idpylintz[{}] {}symbolmessage)sourceranger.   severitycodetags)%
last_diagspathsys
executableshlexsplitstrlogdebugjoin
_workspace	root_pathosdirname__file__r   r   communicater(   stripr   loadslineslenr   DiagnosticSeverityInformationErrorHintWarningformatUNNECESSITY_CODESDiagnosticTagUnnecessaryDEPRECATION_CODES
Deprecatedappend)clsdocumentis_savedflagscmdr   processjson_outerrdiagnosticsdiagr   	err_ranger1   r2   
diagnostics                   ;/usr/lib/python3/dist-packages/pylsp/plugins/pylint_lint.pylintzPylintLinter.lint2   s   :  >>(--00 NNHMM
 ).U[[U$27 			,chhsm<!!++''//(+CTst
 	2#//1MHc	2
 "9II2C8 ~~,.CNN8==)I0 JJx( .	+D<!#D !!%h ! ?GnnX^^D%9!:RS	I F||+11==f.11==f(1177f(1177f+1166f*1199%D #"$++DNDOL$J ((&)&7&7&C&C%D
6"((&)&7&7&B&B%C
6"z*].	+^ )4x}}%k	2 	2s   K==LN)r   )	__name__
__module____qualname__collectionsdefaultdictlistr4   classmethodra        r`   r   r   /   s(    (((.JH Hrj   r   c                 L    | j                  d      }|ydj                  |      S )z#Build arguments for calling pylint.argsr   r   )getr=   settingspylint_argss     r`   _build_pylint_flagsrq      s(    ,,v&K88K  rj   c                      dddg d diiS )Npluginsr,   F)enabledrl   r7   ri   ri   rj   r`   pylsp_settingsru      s'    
 	 "	
	 	rj   c                    |j                  d      5  | j                  d      }t        j                  d|       |j	                  d      rIt
        j                  d   dk\  r3t        |      }|j	                  dd      }t        |||      cddd       S t        |      }t        j                  |||      cddd       S # 1 sw Y   yxY w)	zRun pylint linter.zlint: pylintr,   zGot pylint settings: %sr7   r      N)rW   )report_progressplugin_settingsr;   r<   rm   r6   version_infobuild_args_stdiopylint_lint_stdinrq   r   ra   )config	workspacerU   rV   ro   rW   pylint_executables          r`   
pylsp_lintr      s     
	"	">	2 
B))(3		+X6 <<%#*:*:1*=*B$X.E (\8 D$%6%H
B 
B $H-  85 A
B 
B 
Bs   A8C "C  C	c                 0    | j                  d      }|g S |S )zBuild arguments for calling pylint.

    :param settings: client settings
    :type settings: dict

    :return: arguments to path to pylint
    :rtype: list
    rl   )rm   rn   s     r`   r{   r{      s#     ,,v&K	rj   c                 4    t        | ||      }t        ||      S )a  Run pylint linter from stdin.

    This runs pylint in a subprocess with popen.
    This allows passing the file from stdin and as a result
    run pylint on unsaved files. Can slowdown the workflow.

    :param pylint_executable: path to pylint executable
    :type pylint_executable: string
    :param document: document to run pylint on
    :type document: pylsp.workspace.Document
    :param flags: arguments to path to pylint
    :type flags: list

    :return: linting diagnostics
    :rtype: list
    )_run_pylint_stdio_parse_pylint_stdio_result)r   rU   rW   pylint_results       r`   r|   r|      s     " &&75IM%h>>rj   c                    t         j                  d| |       	 | g}|j                  |       |j                  d|j                  g       t	        |t
        t
        t
              }|j                  |j                  j                               \  }}|r$t         j                  d|j                                |j                         S # t        $ ru t         j                  d|        t        j                  ddg}|j                  |       |j                  d|j                  g       t	        |t
        t
        t
              }Y w xY w)aP  Run pylint in popen.

    :param pylint_executable: path to pylint executable
    :type pylint_executable: string
    :param document: document to run pylint on
    :type document: pylsp.workspace.Document
    :param flags: arguments to path to pylint
    :type flags: list

    :return: result of calling pylint
    :rtype: string
    zCalling %s with args: '%s'z--from-stdin)stdinr   r   z0Can't execute %s. Trying with 'python -m pylint'z-mr,   zError while running pylint '%s')r;   r<   extendr5   r   r   IOErrorr6   r7   rC   r/   encoder(   decode)r   rU   rW   rX   pr   r   s          r`   r   r   
  s     II*,=uE
= !

5

NHMM23#T$t< }}X__%;%;%=>VV		3V]]_E==?  =		DFWX~~tX.

5

NHMM23#T$t<=s   AC A;EEc           	         g }|j                         }|D ]  }t        j                  d|      }|st        j	                  d|       3|j                         }t        |      dk7  rt        j	                  d|       h|\  }}}}	}
t        |      dz
  }t        |      }t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  d}||	d      }d|	||d|t        | j                  |         dz
  dd	|
|d
}|	t        v rt        j                   j"                  g|d<   |	t$        v rt        j                   j&                  g|d<   |j)                  |        |S )zParse pylint results.

    :param document: document to run pylint on
    :type document: pylsp.workspace.Document
    :param stdout: pylint results to parse
    :type stdout: string

    :return: linting diagnostics
    :rtype: list
    z(.*):(\d*):(\d*): (\w*): (.*)z*Pylint output parser can't parse line '%s'   r   )CEFIRWr   r,   r    r"   )r/   r2   r0   r.   r1   r3   )
splitlinesrematchr;   r<   groupsrG   intr   rH   rI   rJ   rK   rL   rF   rN   rO   rP   rQ   rR   rS   )rU   r   r\   rF   raw_lineparsed_line_r   r!   r2   msgseverity_mapr1   r_   s                 r`   r   r   )  s    KE )'hh?JIIBHM!((*{q IIBHM(3%4D#4y1}	N	''33''--''--''33'',,''//
  Q("&Y? !$X^^D%9!:Q!>  

 $$"%"3"3"?"?!@Jv$$"%"3"3">">!?Jv:&S)'V rj   )__doc__re   loggingr@   r   r8   r6   
subprocessr   r   pylspr   r   ujsonr   	Exception	getLoggerrb   r;   environrQ   rN   r   rq   ru   r   r{   r|   r   r   ri   rj   r`   <module>r      s   
     	 	  
 "  g! ,2

' (  L L^! 
 
 
B 
B?*>8o  s   B 	BB