Leseratte10 / acsm-calibre-plugin

Calibre plugin for ACSM->EPUB and ACSM->PDF conversion.
https://www.mobileread.com/forums/showthread.php?t=341975
GNU General Public License v3.0
600 stars 23 forks source link

Don't hide import errors #3

Closed fperrin closed 2 years ago

fperrin commented 2 years ago

Hi @Leseratte10 ,

I had the same errors as @Hellmark in issue #2 , that is, local variable 'update_account_path' referenced before assignment when trying to add the plugin. It turned out the problem was an import error inside libadobe. However, since import libadobe is inside a try/except block that prints something then throws away the exception, I was unable to see the actual error; even the "show details" button in Calibre would not print the error.

This PR replaces the inner try: import ... except: print(...) pattern with a simple import , so that the actual error is shown by calibre.

Beyond that, why are the imports not at the top of the file as is usual?

Leseratte10 commented 2 years ago

Interesting that you got an import error inside libadobe. That one should only use Python modules that come with Calibre. Which import error would that be? The PyCrypto one you tried to fix with #4?

If I remember correctly there was a reason why I used the deprecated PyCrypto instead of the new Cryptodome, but right now I don't remember what that was. I'll take a look again and test everything with that change and see if everything still works as intended.

fperrin commented 2 years ago

The import error I got was indeed when trying to import Crypto.

local variable 'update_account_path' referenced before assignment can only happen if from calibre_plugins.deacsm.libadobe import ..., update_account_path fails; and if that import fails, the software can't do anything useful, so, in my opinion, there is no point in catching the exception.

Leseratte10 commented 2 years ago

Beyond that, why are the imports not at the top of the file as is usual?

Forgot to answer that question - the imported files themselves (libadobe, libadobeAccount and libadobeFulfill) depend on some of the Python modules that are extracted from ZIP files (because they aren't included with Calibre) in the init function. If the imports were at the top of the file they would fail since the dependencies wouldn't be extracted yet.