← Back to team overview

kicad-developers team mailing list archive

Re: Better organizing of Python plugins using subdirectories

 

Small followup. The 2nd solution currently does not work with KiCad,
because the module path (sys.path) is not setup correctly it seems.
As said here:
https://docs.python.org/2/library/sys.html
"As initialized upon program startup, the first item of this list,
path[0], is the directory containing the script that was used to invoke
the Python interpreter. If the script directory is not available (e.g.
if the interpreter is invoked interactively or if the script is read
from standard input), path[0] is the empty string, which directs Python
to search modules in the current directory first. Notice that the script
directory is inserted before the entries inserted as a result of
PYTHONPATH."
I.e. path[0] contains the path to the python executable that is run
(ideally)

Considering the following simple action_test_path.py file:
----
import sys
print(sys.path[0])
----

Executing the following gives
$ python action_test_path.py
/path/to/test_path.py

However, when starting pcbnew from command line (and it scans all the
.py files) it prints
/usr/lib/python2.7/dist-packages/wx-3.0-gtk2

This is not correct and not according to the documentation. Either it
should be empty or contain the path to the .py file containing the
print(sys.path[0]) command (preferred).
This actually breaks any sane python relative import mechanisms within
the python plugin.

Can someone confirm?

Best Regards
Simon
Am 09.06.2017 um 13:09 schrieb Simon Küppers:
> Hey guys,
> With my current work on python plugins for pcbnew, I noticed that you
> quickly want to go ahead and divide up your plugin into multiple
> subfiles (e.g. test_plugin.py, test_plugin_main_dialog.py, etc..)
> 
> Right now, KiCad loads the python files from the hardcoded folders (one
> of them being ~/.kicad_plugins however it does not do it recursively.
> Thus it is not possible to organize the files in a subdirectory (e.g.
> test_plugin/).
> 
> Another thing that I noticed (but did not confirm yet) is, that action
> plugins need actually have "action_" prepended to the .py file in order
> for them to load properly so that they are shown in the pcbnew menu.
> This is also on purpose right?
> 
> I guess my proposal for a _consistent_ handling of python plugins in the
> future might be either
> 1) Make test_plugin/ subfolder and place all files into this
> subdirectory. KiCad recursively loads all plugins in the hardcoded
> directories
> 
> 2) Make test_plugin/ subfolder and place all files into this
> subdirectory. When the user wants to use a plugin, he needs to create a
> relative link in the hardcoded directory to the corresponding entry-file
> in the test_plugin/ sub-directory.
> 
> I am currently leaning towards the 2nd solution. But in order for it to
> be user friendly (also to those who arent computer savvy), each plugin
> needs some kind of installer to perform the copying and linking. I guess
> this solution is also more "linuxy" since I have seen this technique in
> a lot of different applications (e.g. munin plugins).
> 
> What are your thoughts on that?
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
> 


References