Python correctness (i.e., lint) analyzing for Notepad++
Asked Answered
F

5

14

Does anyone know of anything like pylint or pychecker for notepad++? Or perhaps how to use pylint in notepad++.

Fifth answered 14/2, 2011 at 0:32 Comment(0)
H
15

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...)

Heikeheil answered 8/6, 2011 at 1:3 Comment(3)
As getting from the above link to the actual download is somewhat torturous, here is a direct link: sourceforge.net/projects/npppythonscript/filesStaves
You have to install Pylint first though.Animated
isn't it in plugin manager? then just install it from notepad++: menu>plugins>plugin managerTempest
I
3

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

Idiolect answered 18/6, 2014 at 11:43 Comment(0)
R
1

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.

Rhnegative answered 18/3, 2011 at 9:39 Comment(2)
can you explain more detailly?Domini
For most recent software (Windows 10, N++, etc.), what you want is: cmd /c pylint "$(FULL_CURRENT_PATH)" & pause.Volitant
A
1

None of the other answers worked for me, but this does:

  1. Install PyLint using python -m pip install pylint

  2. 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.

Acceptable answered 25/4, 2016 at 17:4 Comment(0)
M
0

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()))
  1. Path to pylint.exe (i used a Shortname instead of Doublequotes)
  2. 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:

Manservant answered 22/5, 2016 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.