Display error while modifying a plug in

Hi,
When I modify one plug that I’m using. I change the python code of the plug in.
Then I do refresh plugin in the kicad menu.
And if I’ve made a mistake, the plugin does not show in the plugin list.

Is there a way to see the “compilation” error. Well it’s more a parsing error than compilation. But kicad is reading my python code, and it does not like it for some reason, but I want to know where the error is to fix it.

(Note, I’m on Windows 10, with Kicad 7.0.8)

You should be able to run the python code from a normal python interpreter. You may need some additional code to load the board. But that gives you the ability to use all the features you have with python.

Go to preferences → Action plugins, there will be a button with warning sign if you have plugin compilation errors, click it.

That would be nice, but that is not the behavior I see.

If I’ve got a compilation error, my plug in just disapear from the list in the preference windows.
When I fix the error, my plugin is showing up in this list

In the Python console:

import pcbnew
print(pcbnew.GetWizardsBackTrace())

That does not display anything.
I’ve started the pcbeditor. ONe of my plugin is not compiling (I’ve added an extra ‘)’ to a line).
Then I open the kicad scripting console and do :
import pcbnew
print(pcbnew.GetWizardsBackTrace())

And it just display a blank line

Works for me on Win11 for plugins in
%USERPROFILE%\Documents\KiCad\7.0\scripting\plugins or
%USERPROFILE%\Documents\KiCad\7.0\3rdparty\plugins

Also the warning button appears below the action plugins list:
image

Maybe some plugin intercepts the output?

I don’t see how that’s possible given how the plugins are loaded, it really would have to be maliciously designed to do that.

@bertrand_meneroud you likely didn’t put your plugin in the right place. Do you have a single .py file or a module? If it’s a folder module, does it have correct init file?

Hi,
my plugin is working (unless if I add a typo in the .py file).
I’ve modified the plugin Fabrication Toolkit, to suit me need.
it’s in the directory : C:\Users\mener\Documents\KiCad\7.0\scripting\plugins\JLC-Plugin-bert
it does have a init.py, a config.py.
And currently the plug in is listed in plugin menu and it is working.
So yes it’s a folder module.

But If I add and extra parenthesis in the code to create a compilation error, then the plugin does not show in the list of plugin, and I don’t see the compilation error.

I’ve been able to load the file manualy in python, and I get the line with the error. That’s usefull. However, when there is no error the compilation is not working, I’ve got some errors about importing module, I’m guessing it’s an environement issue.
But I’m a real noob in python, so I don’t know where to look for it.

See this post about setting up settings and environment variables for VS Code:

Python is extremely picky about Indentation.

It does prefer using Spaces and not using Tabs (though tabs can work… but…)

Don’t mix Spaces and Tabs!.. You should google it and learn about this to get a warm feeling about it…

That IS your “compilation” error. As you mentioned in first post, python doesn’t really compile stuff, it is an interpreted language, failure to import a module is the closest thing to a compilation error.

Yes I agree failure to import the module is what I would call a compilation error.

But What I’m saying, is that : I’ve try to manually load my module to see any loading error. But it’s not working because I will not correctly import some of the stuff. But kicad is able to load my module correctly.
So it’s my “procedure” to manually load it the is not working.

Well nevermind, I was hoping for a simple option to show any error when Kicad is failing to load a plugin. But I manage to work without it.

Thanks for your help

If you found a workaround it’s good but for the future, it would help if you described exactly what you did and what errors you got, not in your own words but with screenshots/copy-paste of error text and exact description of steps you took to get them.

Take a look at the __init__.py file for my plugins. I wrap the import in try…except block and on an exception I write the .log file

1 Like

Hi, thanks for that.
I’ve realized that the plugin I’ve started with had the same idea, but the logging of the error is not shown.
Once I’ve remove the Try catch from the init, I can see the error with the print(pcbnew.GetWizardsBackTrace())

I’ll try to do some like your plugin init.
Thanks again

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.