bg4dZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z ddlmZmZmZejdkrdd lmZndd lmZd*d Zd+d,dZe d-d.dZe d/d0dZ d1d2d$Zd3d4d(Zed)kr edSdS)5alEmacs and Flymake compatible Pylint. This script is for integration with Emacs and is compatible with Flymake mode. epylint walks out of python packages before invoking pylint. This avoids reporting import errors that occur when a module within a package uses the absolute import path to get another module within this package. For example: - Suppose a package is structured as a/__init__.py a/b/x.py a/c/y.py - Then if y.py imports x as "from a.b import x" the following produces pylint errors cd a/c; pylint y.py - The following obviously doesn't pylint a/c/y.py - As this script will be invoked by Emacs within the directory of the file we are checking we need to go out of it to avoid these false positives. You may also use py_run to run pylint with desired options and get back (or not) its output. ) annotationsN)Sequence)StringIO)PIPEPopen)NoReturnTextIOoverload))Literalreturndict[str, str]cttj}tjt j|d<|S)zVExtracts the environment PYTHONPATH and appends the current 'sys.path' to it. PYTHONPATH)dictosenvironpathsepjoinsyspath)envs _/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/pylint/epylint.py_get_envr8s2 rz  C 11C  Jfilenamestroptions Sequence[str]intcptj|}tj|}tj|}|dkrtjtj|drtjtj||}tj|}|dkr=tjtj|dd}tjd|gdddd|gzt|z}t|t|td 5}|j D]m}|d r|d } | r-| d |kr!d |g| ddz}t!|dn||jcdddS#1swxYwYdS)aPylint the given file. When run from Emacs we will be in the directory of a file, and passed its filename. If this file is part of a package and is trying to import other modules from within its own package or another package rooted in a directory below it, pylint will classify it as a failed import. To get around this, we traverse down the directory tree to find the root of the package this module is in. We then invoke pylint from this directory. Finally, we must correct the filenames in the output generated by pylint so Emacs doesn't become confused (it will expect just the original filename, while pylint may extend it with extra directories if we've traversed down the tree) /z __init__.pyz:import sys; from pylint.lint import Run; Run(sys.argv[1:])-cz--msg-templatez;{path}:{line}: {category} ({msg_id}, {symbol}, {obj}) {msg}z-rnT)stdoutcwdruniversal_newlineszNo config file found:rN )end)rrabspathdirnamebasenameexistsrr executablelistrrrr' startswithsplitprintwait returncode) rr full_path parent_path child_pathrun_cmdcmdprocesslinepartss rlintrAAsD"))I'//),,K!!),,J     [-00"" W\\"'"2"2;"?"?LL gook22     [-00"" KG w'  I       w--   Dkxzzd   " N ! !D566 JJsOOE 8qZ//xx U122Y 677 $C  !""""""""""""""""""sBH++H/2H/.command_options return_stdLiteral[False]r'TextIO | int | NonestderrNonecdSNrrBrCr'rFs rpy_runrK} Cr Literal[True]tuple[StringIO, StringIO]cdSrIrrJs rrKrKrLrFbool tuple[StringIO, StringIO] | NonecJtjdtddtjvr tjnd}|ddg}t j|tjd }||z}||rtn tj }||rtn tj }t|d ||td 5}|\} } |r*t| t| fcd d d S d d d d S#1swxYwYd S) asRun pylint from python. ``command_options`` is a string containing ``pylint`` command line options; ``return_std`` (boolean) indicates return of created standard output and error (see below); ``stdout`` and ``stderr`` are 'file-like' objects in which standard output could be written. Calling agent is responsible for stdout/err management (creation, close). Default standard output and error are those from sys, or standalone ones (``subprocess.PIPE``) are used if they are not set and ``return_std``. If ``return_std`` is set to ``True``, this function returns a 2-uple containing standard output and error related to created process, as follows: ``(stdout, stderr)``. To silently run Pylint on a module, and get its standard output and error: >>> (pylint_stdout, pylint_stderr) = py_run( 'module_name.py', True) ^'epylint' will be removed in pylint 3.0, use https://github.com/emacsorphanage/pylint instead. stacklevelpythonr%z(from pylint import epylint;epylint.Run()win)posixNFT)shellr'rFrr))warningswarnDeprecationWarningrr2shlexr5platformr4rr'rFrr communicater) rBrCr'rFr2 epylint_partr clir> proc_stdout proc_stderrs rrKrKs4 Mh $,s~#=#=8J&PQLk/S\5L5LU5S5S1STTTG  C~#3 ~#3   JJ      #*#6#6#8#8 [  @K(((;*?*??                          s7D DDDargvSequence[str] | Nonerctjdtd|sTttjdkr7t dtjddt jd|ptjdd}tj |ds.t |ddt jddSt jt|d|dddS) NrTrUrVr+zUsage: rz [options]z does not exist) r\r]r^lenrrfr6exitrrr1rA)rfs rRunrks Mh CMMQ&& : :::;;;   38ABB>$q' " "* a)))***   d1gtABBx(()))))r__main__)rr)r)rrr r!rr")....) rBrrCrDr'rErFrErrG)..) rBrrCrMr'rErFrErrN)rPFNN) rBrrCrQr'rErFrErrRrI)rfrgrr)__doc__ __future__rrr_rr\collections.abcrior subprocessrrtypingrr r version_infor typing_extensionsrrArKrk__name__rrrrvs>#""""" $$$$$$""""""""----------v))))))9"9"9"9"9"x !$"%"%   #&"%  "&"& 99999x*****$ zCEEEEEr