-
Notifications
You must be signed in to change notification settings - Fork 62
Does the following indicate a MacOS problem? #111
Comments
Did you save the schematics before running the plugin? |
Yes, all changes were saved previously. Or, let's put it this way. If I open the design, and make no changes, I will see exactly what I have shown above. In other words, there are no unsaved changes at the time that I run the plugin. I'm a competent Python programmer, though not familiar with the KiCAD API. So if you want me to investigate a specific issue to figure out what might be happening here, there is a good chance I can do that. |
Just covering bases. Which KiCad version are you running? The plugin only supports 5.1.x If you go to the project folder, delete and .log file and rerun the plugin and then hit cancel. There should be a |
It turns out there was already the appropriate log file in the project folder, and it should give some clues as to what going on
Notice the empty filename and sheet_id |
Whoa, this is certainly a new bug. Can you share the project? If you can, that would speed up the debugging, but if you can't then I'll need your help. I'll add instrumentation to the plugin, and you'll have to run the plugin again and send me back the .log file. Usually it takes 5 to 6 such cycles |
Sure, I can share the project, it is attached. I can also help. I'm assuming it is not possible to debug the script in Pycharm or Spyder? That is how I usually develop Python code and it would certain make things easy. |
Well as they say, teach a man how to catch fish, ... So if you are not in a hurry and you'd like to solve this on your own I would be glad to help how to setup up youre environment, how to start and how to fix. As I don't really know what is the KiCad python environment on macOs, you should first find the path of the KiCad interpreter. Run pcbnew, open python console and run I try to split GUI and backend (business logic) in my plugins so you should be able to reproduce this without KiCad and completely within pycharm. Put your project in a subdirectory within replicate_layout folder and then you modify If it is too much for you, just say so and I'll start working on it. BTW, any comments that you add to the code which would improve readability are greatly welcome (there is certainly one missing in |
Perfect, it all makes sense, I'll get to it later today. |
OK, there are couple problems trying to follow the instructions. First, print(sys.executable) doesn't return the python interpreter:
Apparently this doesn't work "embedded interpreters": So I tried looking off os.__file__, and found what looked like an interpreter:
|
I'm wondering whether just for now, it would be easier to just debug with print statements, so to run this script from the KiCAD scripting console on my project, what would I do? It looks like I modify main() but how and where do I need to put my project files. |
I've heard that the macOs does some randomization of executable paths, so the path that was reported by From what I've heard the KiCad on macOs bundles python interpreter the same as Windows release. So can you look into the folder where you have KiCad binary installed and look for python interpreter. On Windows I can find it under Why you need to do this? If KiCad is using its own bundled python interpreter then So if you bear with me and we find this out I am pretty certain it will help me (and others) in the future |
I'll keep working on trying to be able to actually debug with Pycharm, but if you could tell me how to run the script from the scripting console (it's probably simple), I could modify the code and debug with print statements. It probably wouldn't take too long, especially since you already have a hunch about where the problem might be. |
Update: I tried a few things to get a debug environment set up in pycharm, with no luck. I cannot find a sensible place where a python environment is set up by kicad. It looks like kicad is doing weird things with that on MacOS, and although I'm a decent python programmer, I'm not really a sysadmin so I don't have the patience or knowledge to deal with it. I also posted on the forum about how to get set up for script debug on MacOS - no answers. So I tried to set up a new environment using conda then installing this:
I was hopeful, but when I try to debug replicate-layout.py there are weird errors from within the code that imports kicad-python. It looks like once again they are doing weird stuff. Also, I looked at main(), and it appears to be hardwired to test a project you've created, it even seems to reference specific parts in the design. In summary, if I'm going to go after this with debug by print statements (which I'm willing to do). I need two things
|
Yeah, the main is hardwired to my test project. What you could do is to "rewire" it to your test project and then run the script. But it is the second part (run the script) that we have a problem with. You could just run pcbnew, open scripting console and run the plugin https://thecodingbot.com/how-to-run-scripts-from-the-python-shell/. And I prefer to use logger instead of printf, but that is just a personal preference |
I know how to run python scripts from a console. What I don't know is how to arrange arguments to the script so that my project is processed, and/or how to "rewire" the script to process my project. I didn't see any KiCAD scripting console examples in GoogleLand. But I'll see if I can figure it out. Logging is fine. What I really like are Python 3 Fast Strings. |
Ok, so my def main():
os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "subfolder_with_your_project"))
board = pcbnew.LoadBoard('name_of_your_pcb_file.kicad_pcb')
# get board information
replicator = Replicator(board)
# get source module info
src_anchor_module = replicator.get_mod_by_ref(C3)
# have the user select replication level
levels = src_anchor_module.filename
# get the level index from user
index = levels.index(levels[0])
# get list of sheets
sheet_list = replicator.get_sheets_to_replicate(src_anchor_module, src_anchor_module.sheet_id[index]) |
@michalelektryk I suspect that yours is a different issue. What is you linux distro and desktop environment? The more verbose you are the better. |
OK, the holidays are over so I'm getting back to this. I tried running the following in the scripting console, but I've still got basic issues:
|
My distro is arch and desktop enviroemnt is SDDM. if it matters I scaled default font size, I may check with defaults |
To be clear plugin is fully functional, only GUI renders wrong |
Just a question on my comment a couple days ago. I would have expected that the environment used by the scripting console would include kicad.pcbnew. Is this an issue with kiCAD Mac, and if so, do you know where I report kiCAD issues? |
@michalelektryk can you open a new issue for this, as this is clearly different issue than jandyman's. If you can also paste full Kicad info it would help. Also can you test any plugins from other authors? |
@jandyman yeah, it seems that the python interpreter that is running the script can not find the pcbnew module. Can you run import sys
print(sys.version) so that we can be sure which python are you runing and import sys
print(sys.executable) to find out where the interpreter is located. Only then we might consider reporting this upstream. But I suspect that MacOS executable relocation is the cause of this. While Kicad should be able to work with this. So I assume MacOS KiCad packagers should have the most knowledge on this. |
When I try to run the script, the heirarchy shows up as empty:
But in the schematic editor I see this:
Does this indicate a problem with the MacOS version of the plugin?
The text was updated successfully, but these errors were encountered: