![]() |
#1 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
Need help diagnosing a plugin in Python 2
An active group of calibre users are using an editor plugin to polish public domain epubs from OCR according to French typography rules.
The add-in attached is a software package in Python that allows you to choose and launch saved searches from a pack of over a hundred regex-functions. The regex pack is updated regularly based on feedback from users. Flags allow communication between the saved searches package and the software envelope. The plugin could possibly be used in other languages, but with new, adapted saved searches. Whoever wrote the software suddenly disappeared a few months ago. We have reason to assume, without being sure, that he considered the need for compatibility with Python 3 because he had the skills to do so. We can't even install the add-in in calibre 5.1. We don't have the Python proficiency. We are looking for a goodwill who would like to make a diagnosis with the tools, in order to have an idea of the extent of the conversion work to be done. |
![]() |
![]() |
![]() |
#2 |
Deviser
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 2,265
Karma: 2090983
Join Date: Aug 2013
Location: Texas
Device: none
|
I did not install this plugin, but simply doing a basic syntax check in Python 3.8 independently installed on my PC revealed a trivial error occurring at least twice:
Python 2: reg = ur'{}'.format(kfind) The "ur'" in Python 2 means "unicode raw string". Python 3 is natively unicode. Search on ur' and change it to r'. Python 3: reg = r'{}'.format(kfind) DaltonST |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
Thanks a lot, DaltonST !
|
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
In addition to the two ur'string' instances previously mentioned...
You also need to change "from Queue import Queue" to "from queue import Queue" on line 15 of main.py (the module was renamed to lowercase). In the same file on line 108, Code:
with open(os.path.join(config_dir, 'dictionaries', fn), 'w') as f: Code:
with open(os.path.join(config_dir, 'dictionaries', fn), 'wb') as f: I could not find anything else obviously erroring out, the plugin now loads and provides a menu of options that seem to work. On the other hand, I don't read French so I have no idea what it says, and couldn't test anything other than randomly clicking every button and checking for python runtime errors. If there are any other errors, post them here and you're sure to find people willing to guide you in debugging it. But here's a tip when you do so: start the ebook editor from the command line, using the command: Code:
calibre-debug -t Code:
File "/home/eschwartz/git/calibre/src/calibre/gui2/tweak_book/plugin.py", line 115, in load_plugin_tools main = importlib.import_module(plugin.__class__.__module__+'.main') File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap>", line 618, in _load_backward_compatible File "/home/eschwartz/git/calibre/src/calibre/customize/zipplugin.py", line 179, in load_module compiled = compile(code, 'calibre_plugins.%s.%s'%(plugin_name, File "calibre_plugins.typex.main", line 328 reg = ur'{}'.format(kfind) ^ SyntaxError: invalid syntax Followed by Code:
File "/home/eschwartz/git/calibre/src/calibre/customize/zipplugin.py", line 184, in load_module exec(compiled, mod.__dict__) File "calibre_plugins.typex.main", line 15, in <module> ModuleNotFoundError: No module named 'Queue' Code:
File "/home/eschwartz/git/calibre/src/calibre/customize/zipplugin.py", line 179, in load_module compiled = compile(code, 'calibre_plugins.%s.%s'%(plugin_name, File "calibre_plugins.typex.jobutils", line 82 reg = ur'{}'.format(kfind) ^ SyntaxError: invalid syntax |
![]() |
![]() |
![]() |
#5 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
Many, many thanks, eschwartz, for this comprehensive answer. We will do so, and test, test. We are a little reassured about the extent of migration.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
@EbookMakers
I converted the plugin with the 2to3 utility and attached it as a starting point for further updates. It can be installed and some of the features appear to work, but others unfortunately don't. It's definitely not ready for production use!!! Someone else who's knows more than me about the Calibre plugin API should definitely double-check my changes, in particular all code that reads and writes container files. |
![]() |
![]() |
![]() |
#7 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,757
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Is there any way to run Python-Modernize with Windows 10?
|
![]() |
![]() |
![]() |
#8 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,210
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Install Python 3.8.whatever then use pip install modernize. If you have installed Python other than in the default AppData location (I like it to be in Program Files), I'd recommend running that command from a administrative command prompt. Assuming the executables are on your path, you can either run:
python -m modernize -w file_to_be_updated.py python-modernize file_to_be_updated.py For help, run python -m modernize --help or python-modernize --help. Just note that this will not give you a guaranteed to run Python 3 file, just that a lot of the gruntwork will have been done. |
![]() |
![]() |
![]() |
#9 |
Enthusiast
![]() Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
|
Thank you Doitsu, and all of you. You bring us the material to start working. We're getting started! All our gratitude!
|
![]() |
![]() |
![]() |
#10 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,757
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#11 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,210
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Not very well and the output is intended for Python 3. Adding back in Python 2 compatibility and fixing any leftover errors is not fun. Much like what @chaley went through with the ModifyEpub plugin.
|
![]() |
![]() |
![]() |
#12 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 7,072
Karma: 91577715
Join Date: Nov 2011
Location: Charlottesville, VA
Device: Kindles
|
From what I can see no attempt is being made to make the next version of DeDRM backward compatible with Python 2. It will only be usable in calibre 5 or later.
|
![]() |
![]() |
![]() |
#13 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,757
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Given that DeDRM is not distributed with the Calibre plugin system, I see no reason to to have 6.8.0 for 4.23 or earlier and 7.0.1 for 5.x. So if it was to work for some reason, then we'd have two versions.
|
![]() |
![]() |
![]() |
#14 |
Bibliophagist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 46,210
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
|
Much like the discussion in the Modify Epub plugin forum, if you fork the code so the new version does not require Python 2 compatibility, it does make life a lot easier for the person maintaining the code.
|
![]() |
![]() |
![]() |
#15 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,757
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
But the problem is that there is no way to show only Python 3 versions on 5+ and Python 2 versions on 4.23-. If that worked, then forking would be no problem.
|
![]() |
![]() |
![]() |
Tags |
[editor plugin] |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Attn plugin devs: porting to python 3 | kovidgoyal | Plugins | 129 | 06-16-2020 01:31 AM |
Python Libraries included in Plugin? | JimmXinu | Development | 5 | 06-15-2014 06:48 AM |
Can I develop a plugin in a launguage other than Python? | jamawg | Development | 2 | 06-13-2014 12:38 AM |
Do I need to download python before I plugin mobi dedrm | anarcHy | Plugins | 2 | 09-25-2010 09:33 AM |
How do I Create a Python Plugin? | Sydney's Mom | Plugins | 25 | 01-27-2010 06:26 AM |