It is currently Fri Jun 28, 2024 7:33 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: VS Code - configure linting for PythonFu
PostPosted: Sun Jul 26, 2020 4:04 pm  (#1) 
Offline
GimpChat Member

Joined: Jul 02, 2018
Posts: 7
Had a bad day setting up Microsoft VS Code Python Extension to Lint PythonFu scripts properly :gaah.

So thought I would document the process for posterity.

Symptom...
pylint import-error: Unable to import 'gimpfu'
This meant there were loads of other warning about pdb, gimp, etc.

Software...
  • Windows: v10.0.18362
  • Python 2.7.18 (Optional - could also use version installed in Gimp folder)
  • Pylint v1.9.5
  • VS Code: v1.47.2
  • Python extension for Visual Studio Code: v2020.7.96456 (ms-python.python)

Solution...
  • Install pylint to Python2: C:\Python27\python.exe -m pip install pylint
  • Open your plug-ins folder with VS Code (...\AppData\Roaming\GIMP\2.10\plug-ins\)
  • Add the following to ${workspaceFolder}/.vscode/settings.json
    "python.pythonPath": "c:/Python27/python.exe",
    "python.envFile": "${workspaceFolder}/.vscode/.env"
  • Add the following to ${workspaceFolder}/.vscode/.env
    PYTHONPATH="C:/Program Files/GIMP 2/lib/gimp/2.0/python"
  • Exit VSCode

Some comments & tips...
  • I've chosen to implement this in the workspace folder so it doesn't affect my Python3 apps, but you could also do it in your VS Code user (global) settings.
  • Note the forward slashes even though I'm on Windows. Alternative is to use escaped back-slashes... \\
  • VS Code will automatically look for the .env file in ${workspaceFolder}... but this is NOT the .vscode folder (I wanted it out of the way, so I explicitly set path under .vscode).
  • python.pythonPath pointing to Python2 location is required so the Linter does it's stuff to Python2 standards.
  • PYTHONPATH tells the Linter where to look for modules for import - gimpfu in our case.
  • If you don't have stand-alone Python 2.x installed, you can change the Python27 paths above to the python.exe in C:\Program Files\GIMP 2\bin (Only quickly tested this though).
  • You can add # pylint: disable=unused-wildcard-import to the top of your plugin script to hide some warnings related to the from gimpfu import * line.
  • I was hoping the VS Code "python.autoComplete.extraPaths" pointing to gimpfu.py would allow auto-complete for pdb functions etc, but it only seemed to recognise the a few enums etc. Might look at adding Gimp support to "typeshed" on GitHub next!
  • I use WinPDB, so have not looked at how to attach VS Code debugger to Pythonfu plugin.

If anyone knows an easy way to get VS Code auto-complete working for gimp/pdb or how to debug plugins via VS Code - please document it here!

Cheers.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Inserting pdb.python_gegl command in my code

21

No new posts Attachment(s) Source Code for all my GEGL Filters

35

No new posts Attachment(s) Kaleidoscope Plugin Source Code

1

No new posts timer plug-in acts sort of like a stop watch w/wo TRACKING CODE

1



* Login  



Powered by phpBB3 © phpBB Group