04-08-2020, 12:51 AM | #466 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
|
08-22-2020, 03:32 PM | #467 |
Enthusiast
Posts: 38
Karma: 467802
Join Date: Apr 2016
Device: none
|
I'm writing here just in case some plugin developers would be interested in implementing an automated test suite for a Sigil plugin (also, suggestions for improvement are always welcome).
I understand that for most plugins an automated test suite would be an overkill, but for a plugin of medium or high complexity I think that would be a plus. Until two weeks ago, I had no idea if such an implementation would be feasible without too much headache. Turned out it's not too complex, at least for my needs. All the source code of the implementation for my last plugin is on github (is it ok to link it here?). What I did in summary: - I created a python3.8 virtual environment and installed via pip all the necessary dependencies (you can find which they are in the various Building_Sigil_on_* docs in the Sigil documentation on github. Probably a global installation or the bundled python interpreter shipped with Sigil installers would work the same, I didn't try it). - I tweaked with a shell script the PYTHONPATH environment variable to include the /path/to/sigil/plugin_launchers/python and the path to my plugin files (which are obviously platform and installation dependent). That's not exactly the same as in the real Sigil environment, since the paths added to PYTHONPATH are appended to sys.path, so there is the risk of name clashes (but for small projects that's very unlikely). - In the same script I set the environment variable SigilGumboLibPath to make it point to the shared library of sigilgumbo (this is platform dependent too, and I think it's needed only if the plugin uses the sigil's gumbo adapter for sigil_bs4). - After that, in the tests, I just needed to create a mock to use instead of the BookContainer object. And that's it. I don't know if there are simpler or better ways to simulate enough of Sigil environment to test the plugins, that's just what I put together in the last few days. If you have any questions or advice, I'm all ears... |
Advert | |
|
08-23-2020, 11:43 AM | #468 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
Sounds interesting! For larger projects, I typically unzip an epub into a "root" folder inside a new project folder, then copy all the plugin code itself and add the very minimum python code to invoke the launcher.py script properly.
For small projects, I just change the plugin.py final "return 0" with "return -1" so that a full debug log is always created and nothing will ever get changed in Sigil by my plugin, then add a bunch of print statements, fire up Sigil and can launch my plugin again and again tweaking the plugin code as needed inside where it gets unpacked to in the Sigil Prefs folder. There is no need to delete or reinstall the plugin itself, and no need to even relaunch Sigil. Just a quick edit, run cycle. I can easily see that a more rigorous test set-up outside Sigil itself might be valuable. The entire plugin interface is meant to be launched in a subprocess from within Sigil via the command line so it can be isolated away from Sigil. Just passing in the correct inputs and config file, setting paths, etc should be enough given an appropriate python3 setup is available. . Thanks! |
08-23-2020, 03:10 PM | #469 | ||
Enthusiast
Posts: 38
Karma: 467802
Join Date: Apr 2016
Device: none
|
Quote:
Obviously, while the project grows, it becomes less and less rigorous. Quote:
The main rigidity with this approach is that you need to launch the whole plugin every time (unless you launch a different wrapper module every time, I guess...). It sounds like if you put yours and my approach side by side, with some minor tweaks you could have both unit and functional testing capabilities at your disposal. |
||
08-23-2020, 10:05 PM | #470 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
GUI stuff always drives me bonkers when trying to debug inside of Sigil. So I usually create a method for launching the GUIs outside of Sigil -- dummying up any objects necessary from the launcher code to get things going. But yeah, sometimes a full-blown, separate plugin launcher environment is the only way to get any really good debug output.
|
Advert | |
|
11-09-2020, 10:52 PM | #471 |
Junior Member
Posts: 2
Karma: 10
Join Date: Nov 2020
Device: kindle
|
Hi all,i am a python beginner,when i attach my python code to sigil,breakpoint will not hit,what's wrong is it?How to debug during developing a sigil plugin?Any help please.I use vs2019 as IDE.
|
11-09-2020, 11:17 PM | #472 |
Grand Sorcerer
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
I don't use an IDE for debugging Python, so I probably won't be much help. In fact, I'm not even sure you CAN attach a debugger to the Sigil-launched python process that starts a Sigil plugin. Not without more work than it would probably be worth anyway.
|
11-10-2020, 06:59 AM | #473 | |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
def run(bk): # your code print(your_variable) return -1 |
|
11-10-2020, 09:30 AM | #474 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
I think I will add a plugin SDK to my to-do items for the future. Given the design of the plugin interface is all file and path based and returns xml, a standalone system is doable. That way a separate debugger could easily be used.
I will look into it more after this next release. |
09-02-2021, 05:18 PM | #475 |
Junior Member
Posts: 2
Karma: 10
Join Date: Sep 2021
Device: none
|
Documentation for plugin developers
Hi,
I'm potentially interested in developing a new plugin. Where should I look for documentation describing how to do so? Thanks, Lane |
09-02-2021, 05:32 PM | #476 |
Grand Sorcerer
Posts: 5,640
Karma: 23191067
Join Date: Dec 2010
Device: Kindle PW2
|
Here's the Framework Guide Github link.
Last edited by KevinH; 02-10-2022 at 05:02 PM. |
02-10-2022, 06:02 AM | #477 |
Member
Posts: 22
Karma: 624
Join Date: May 2013
Location: Moscow
Device: Kobo Aura H2o, Kobo Aura One, Kobo Forma
|
Hi,
Can I read/write selected text block from plugin? Thanks, Alexey. |
02-10-2022, 04:57 PM | #478 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
The plugin interface is file based. It does get a list of the files selected in BookBrowser when the plugin is launched.
So preselecting a specific text block requires you to insert a marker of some sort or add a span with an known id to your xhtml before launching the the plugin, then tweak your plugin to look for it and process it. If you want to you can copy text to clipboard and have the plugin work with that. Last edited by KevinH; 02-10-2022 at 05:01 PM. |
02-10-2022, 05:37 PM | #479 |
Member
Posts: 22
Karma: 624
Join Date: May 2013
Location: Moscow
Device: Kobo Aura H2o, Kobo Aura One, Kobo Forma
|
KevinH, Thank for possible solution. Very difficult to use.
|
02-10-2022, 07:11 PM | #480 |
Sigil Developer
Posts: 8,160
Karma: 5450818
Join Date: Nov 2009
Device: many
|
In my own plugins I use Sigil's Clips tool to specify a clip I made, then select the text I want and apply the clip. That makes it a single click to mark text the way my plugin needs. Simple and works well.
To be more specific, my clip inserts xhtml comments both immediately before and after the selected text with a unique comment identifier. The plugin itself finds and removes them when running. Setting id attributes or setting a specific class attribute for the text also works. Clips make these tasks quite easy. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 07:57 PM |
Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-05-2012 12:33 AM |
DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 10:46 AM |
Device plugin development | reader42 | Plugins | 10 | 03-29-2010 01:39 PM |
Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 01:44 PM |