Python correctness (i.e., lint) analyzing for Notepad++
Does anyone know of anything like p开发者_Go百科ylint or pychecker for notepad++? Or perhaps how to use pylint in notepad++.
If you install the Python Script plugin, then you can add a new script with the following lines to get pretty good results:
console.show()
console.clear()
console.run('cmd.exe /c '
+ 'C:\\Python26\\Scripts\\pylint.bat --reports=n -f parseable '
+ '"%s"' % notepad.getCurrentFilename())
The output will include hyperlinks to the lines with the errors/warnings (if the filenames don't have spaces in them...)
The option "-f parseable" is deprecated in the current version of Pylint.
The current equivalent alternative is:
console.run('cmd.exe /c '
+ 'C:\\Python26\\Scripts\\pylint.bat --reports=n '
+ '--msg-template="%s" %s'
% ( '{path}:{line}: {msg_id}({symbol}), {obj} {msg}', notepad.getCurrentFilename()))
Note: python path can be different e.g. C:\\Python27.
Note2: double quotes in --msg-template="..."
are important
You could install PyLint using python -m pip install pylint
and use it via Notepad++'s Run...
command (F5):
cmd /c python -m pylint "$(FULL_CURRENT_PATH)" & pause
To get the output in Notepad++ and link to the code, use NppExec.
None of the other answers worked for me, but this does:
Install PyLint using
python -m pip install pylint
Install NppExec via the Plugin Manager, press F6, and save this script as "PyLint":
NPP_SAVE cd "$(FULL_CURRENT_PATH)" env_set PYTHONIOENCODING=utf-8 python -u -m pylint "$(FULL_CURRENT_PATH)"
Sample output:
NPP_SAVE: C:\Users\Cees\Documents\http_ear.py
CD: C:\Users\Cees\Documents\http_ear.py
Current directory: C:\Users\Cees\Documents
ENV_SET: PYTHONIOENCODING=utf-8
$(SYS.PYTHONIOENCODING) = utf-8
python -u -m pylint "C:\Users\Cees\Documents\http_ear.py"
Process started (PID=25136) >>>
************* Module http_ear
http_ear.py:16:0: C0301: Line too long (1780/100) (line-too-long)
http_ear.py:17:0: C0301: Line too long (226/100) (line-too-long)
http_ear.py:26:0: C0304: Final newline missing (missing-final-newline)
------------------------------------------------------------------
Your code has been rated at 8.00/10 (previous run: 8.00/10, +0.00)
<<< Process finished (PID=25136). (Exit code 16)
================ READY ================
You can link the bug locations using NppExec's Console Output Filters. Press Shift+F6 and enable this filter with Red set to FF
:
%FILE%:%LINE%:%CHAR%
Then double clicking a red line focuses the specified location in the editor.
You should use the Executable instead of the Batch if you want to use Pylint within NotePad++.
Go to the Configuration from Python Script and create a new .py File to run Pylint from that. (i called my file npphelper.py)
(Add that npphelper.py to Menu-items and Toolbar-icons, then you can execute it by pressing a Button.)
This will run Pylint into Notepad++, i splitted the Command into 2 Parts:
pyLint = 'C:\\PROGRA~1\\Python35\\Scripts\\pylint.exe --reports=n'
console.show()
console.clear()
console.run('%s "%s"' % (pyLint, notepad.getCurrentFilename()))
- Path to pylint.exe (i used a Shortname instead of Doublequotes)
- The File you want to check with Pylint (actualy returns the Path from active Tab)
(You have to change the Paths so that it fits to your Installation...)
All you have to do now is saving this npphelper.py, open the Tab with your Project-File and run the npphelper.py you created for pylint. (e.g. via button)
If you don't want to use the default Configuration then generate a pylintrc Template (save them where you want). I've done it via CMD with the following Command:
pylint.exe --generate-rcfile>>myfilename.pylintrc
Then you need to change some lines into the npphelper.py:
rcfile = 'C:\\PROGRA~1\\Python35\\Scripts\\myrcfile.pylintrc'
pyLint = 'C:\\PROGRA~1\\Python35\\Scripts\\pylint.exe --reports=n --rcfile="%s"' % rcfile
console.show()
console.clear()
console.run('%s "%s"' % (pyLint, notepad.getCurrentFilename()))
I've installed Python Script 1.0.8.0 with all the Extras using the .msi File here.
(Using the PluginManager in Notepad++ gives you version 1.0.6.0 instead of 1.0.8.0)
I use Windows 7 with Notepad++ 6.9.1, Python 3.5.1 and Pylint 1.5.5.
(i installed pylint via CMD -> "pip install pylint" and updated it.)
Some more usefull Links:
- How do I create a pylintrc file
- PyLint “Unable to import” error - how to set PYTHONPATH?
精彩评论