Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 09-26-2020, 01:13 AM   #1
EbookMakers
Member
EbookMakers began at the beginning.
 
Posts: 24
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.
Attached Files
File Type: zip Typex 1.4.3.zip (1.64 MB, 101 views)
EbookMakers is offline   Reply With Quote
Old 09-28-2020, 10:15 AM   #2
DaltonST
Deviser
DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.DaltonST ought to be getting tired of karma fortunes by now.
 
DaltonST's Avatar
 
Posts: 1,880
Karma: 1804640
Join Date: Aug 2013
Location: Texas
Device: 10" Win10 Tablet w/Calibre64, CalibreSpy & Freda+
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
DaltonST is offline   Reply With Quote
Advert
Old 09-28-2020, 02:27 PM   #3
EbookMakers
Member
EbookMakers began at the beginning.
 
Posts: 24
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
Thanks a lot, DaltonST !
EbookMakers is offline   Reply With Quote
Old 09-29-2020, 01:33 AM   #4
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,420
Karma: 85000000
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:
must be
Code:
with open(os.path.join(config_dir, 'dictionaries', fn), 'wb') as f:
zipfile.ZipFile('something.zip').read('a_file.txt' ) returns bytes and must therefore be written to f.write() using bytes.

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
This will let you see the python errors, and post them for analysis. e.g. the original plugin:

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
This pointed to the first error needing to be fixed.
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'
Then
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
eschwartz is offline   Reply With Quote
Old 09-29-2020, 02:16 AM   #5
EbookMakers
Member
EbookMakers began at the beginning.
 
Posts: 24
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.
EbookMakers is offline   Reply With Quote
Advert
Old 09-29-2020, 02:36 PM   #6
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,257
Karma: 19618507
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.
Attached Files
File Type: zip Typex 1.4.4.zip (1.64 MB, 74 views)
Doitsu is offline   Reply With Quote
Old 09-29-2020, 07:25 PM   #7
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 64,019
Karma: 103820051
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Aura H2O, PRS-650, PRS-T1, nook STR, iPad 4, iPhone SE 2020, PW3
Is there any way to run Python-Modernize with Windows 10?
JSWolf is offline   Reply With Quote
Old 09-29-2020, 11:08 PM   #8
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 15,861
Karma: 76463049
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Forma, Clara HD, Nexus 7 HD, iPad Pro, Tolino epos
Quote:
Originally Posted by JSWolf View Post
Is there any way to run Python-Modernize with Windows 10?
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.
DNSB is offline   Reply With Quote
Old 09-30-2020, 12:36 AM   #9
EbookMakers
Member
EbookMakers began at the beginning.
 
Posts: 24
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!
EbookMakers is offline   Reply With Quote
Old 09-30-2020, 08:00 AM   #10
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 64,019
Karma: 103820051
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Aura H2O, PRS-650, PRS-T1, nook STR, iPad 4, iPhone SE 2020, PW3
Quote:
Originally Posted by DNSB View Post
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.
Thank you. I'll give it a go when I have the time. I'm really curious how it would deal with the DeDRM plugin.
JSWolf is offline   Reply With Quote
Old 09-30-2020, 12:18 PM   #11
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 15,861
Karma: 76463049
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Forma, Clara HD, Nexus 7 HD, iPad Pro, Tolino epos
Quote:
Originally Posted by JSWolf View Post
Thank you. I'll give it a go when I have the time. I'm really curious how it would deal with the DeDRM plugin.
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.
DNSB is offline   Reply With Quote
Old 09-30-2020, 01:23 PM   #12
jhowell
Wizard
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 4,735
Karma: 45518723
Join Date: Nov 2011
Location: Tampa Bay, Florida
Device: Oasis 2, Fire, iPad Air 2, Nexus 7
Quote:
Originally Posted by DNSB View Post
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.
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.
jhowell is offline   Reply With Quote
Old 09-30-2020, 01:46 PM   #13
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 64,019
Karma: 103820051
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Aura H2O, PRS-650, PRS-T1, nook STR, iPad 4, iPhone SE 2020, PW3
Quote:
Originally Posted by DNSB View Post
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.
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.
JSWolf is offline   Reply With Quote
Old 09-30-2020, 02:47 PM   #14
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 15,861
Karma: 76463049
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Forma, Clara HD, Nexus 7 HD, iPad Pro, Tolino epos
Quote:
Originally Posted by JSWolf View Post
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.
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.
DNSB is offline   Reply With Quote
Old 09-30-2020, 03:17 PM   #15
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 64,019
Karma: 103820051
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Aura H2O, PRS-650, PRS-T1, nook STR, iPad 4, iPhone SE 2020, PW3
Quote:
Originally Posted by DNSB View Post
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.
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.
JSWolf is offline   Reply With Quote
Reply

Tags
[editor plugin]

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 12:34 AM.


MobileRead.com is a privately owned, operated and funded community.