← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Fix wrong directory building for python plugins

 

Hi Jean-Pierre,

old code:
if os.path.isdir(plugins_dir+module):
	__import__(module, locals(), globals())

plugins_dir+module dir name never exists.
In fact it is existing actually since user's home ".kicad_plugins" directory was build in a bad way (string contact with tailing "/" instead of os.path.join)
new code:
if os.path.isdir(os.path.join(plugins_dir,module)):
	__import__(module, locals(), globals())

Now, if a subdir exists in a plugins_dir (it was the case in my install),
__import__(module, locals(), globals()) is executed.
But, for me, this code makes no sense: I do not even understand the purpose of the code.
(however I am not a Python specialist, and to tell the Truth, my knowledge in Python is near zilch).

So I am inclined to remove this code (which was previously never executed) and commit your patch.
For me It can be useful to keep this feature. With this, we are able to maintain directory based python plugins.
An example there:
https://forum.kicad.info/t/howto-register-a-python-plugin-inside-pcbnew-tools-menu/5540/22
It follow some discussions like this:
https://forum.kicad.info/t/a-via-fence-generator-plugin-for-pcbnew/6638/15

If we have this feature we can maintain easily "really big python plugins" inside sub directories.

Anyway, I don't know in your case why it break your python. Perhaps you have a sub-directory with some bad things ? In my case (Linux) It work properly. I had made a quick test in windows (an old XP) by manualy "patch" pcbnew.py on a fresh install and I don't have this issue. If it's an error on a dirty sub directory, I propose to just move this code (if os.path.isdir...) under following try/except to avoid this kind of errors.


Thanks,


Follow ups

References