08-24-2022, 08:05 AM | #1 |
Member
Posts: 18
Karma: 10
Join Date: Aug 2022
Location: Australia
Device: reMarkable 2
|
Dealing with non-Python Dependencies
Hello!
I'm currently attempting to troubleshoot someone else's plugin for Calibre. The plugin in question is here: https://github.com/naclander/Calibre...-Driver-Plugin At the moment, it looks like certain Rust binaries in the Cryptography module aren't importing correctly due to an 'unknown location'. Code:
ImportError: cannot import name 'asn1' from 'cryptography.hazmat.bindings._rust' (unknown location) Would it be possible to get some help on including non-Python dependencies in a Calibre plugin? |
08-24-2022, 08:16 AM | #2 |
creator of calibre
Posts: 44,483
Karma: 24495778
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The appropriate folders need to be on sys.path before attempting the import.
|
Advert | |
|
08-24-2022, 08:33 AM | #3 |
Member
Posts: 18
Karma: 10
Join Date: Aug 2022
Location: Australia
Device: reMarkable 2
|
|
08-24-2022, 09:28 AM | #4 |
creator of calibre
Posts: 44,483
Karma: 24495778
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The folder that contains the python package you are importing has to be on sys.path if it is and the abi version of the compiled module is a match it will import.
|
08-31-2022, 12:22 AM | #5 |
Junior Member
Posts: 1
Karma: 10
Join Date: Aug 2022
Device: Remarkable2
|
I've posted a workaround on GitHub here. You were right, the path added to sys.path was the path to the zip file.
Having the library somewhere else is not the most elegant solution, is there a better way to do this? Maybe the plugin could decompress the zip file temporarily? Last edited by Kenivia; 08-31-2022 at 12:26 AM. |
Advert | |
|
08-31-2022, 02:12 AM | #6 |
creator of calibre
Posts: 44,483
Karma: 24495778
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
with self: import whatever |
07-19-2024, 02:24 AM | #7 |
Junior Member
Posts: 7
Karma: 10
Join Date: Aug 2019
Device: Kindle DX, Kindle PW, Nook Tab, Nook Glow, reMarkable 2, Kobo Clara BW
|
I just found this plugin and am having the same trouble, two years later. (It's abandonware so not taking updates.)
The plugin is a zip plugin. All the dependencies are in the zip, and Python can import python text or bytecode from a zip, but it can't import native code from a zip. (Presumably this is because python text/bytecode can be compiled or executed from memory, but the OS loader has to memory-map native DSOs.) Kovid pointed to the Plugin base class's __enter__ method, which in principle knows how to handle this situation. It scans the zipfile for unimportable files and unpacks if needed. But this is a device plugin and device plugins are not loaded as context managers, so that's inapplicable on the surface. After some ponderment, what I think Kovid is cryptically suggesting is that the library code's startup method, prior to importing modules that include DSOs, should use itself as a context manager. Indeed this patch allows the pycrypto code to load: Code:
diff --git a/__init__.py b/__init__.py index e548b30..71c41bb 100644 --- a/__init__.py +++ b/__init__.py @@ -20,12 +20,17 @@ class RemarkablePlugin(DevicePlugin): supported_platforms = ["linux", "windows", "osx"] version = (1, 2, 3) # The version number of this plugin minimum_calibre_version = (0, 7, 53) + seen_device = False FORMATS = ["epub", "pdf"] MANAGES_DEVICE_PRESENCE = True def startup(self): + with self: + return self._startup() + + def _startup(self): # Use the plugins directory that's included with the plugin sys.path.append(self.plugin_path) global remarkable_fs |
07-19-2024, 08:23 PM | #8 |
Junior Member
Posts: 7
Karma: 10
Join Date: Aug 2019
Device: Kindle DX, Kindle PW, Nook Tab, Nook Glow, reMarkable 2, Kobo Clara BW
|
|
07-19-2024, 08:24 PM | #9 |
Junior Member
Posts: 7
Karma: 10
Join Date: Aug 2019
Device: Kindle DX, Kindle PW, Nook Tab, Nook Glow, reMarkable 2, Kobo Clara BW
|
|
07-19-2024, 08:28 PM | #10 |
Junior Member
Posts: 7
Karma: 10
Join Date: Aug 2019
Device: Kindle DX, Kindle PW, Nook Tab, Nook Glow, reMarkable 2, Kobo Clara BW
|
Fixed reMarkable plugin
This plugin works for me now, without any module hacks. On MacOS there is a code-signing issue, but the plugin detects if it's a problem and gives a remediation on the debug log.
I forked and patched it here [github]. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plugin dependencies | jpwhiting | Development | 9 | 09-10-2021 09:39 AM |
Python 2 to Python 3, Polyglot & Plugins | DaltonST | Calibre | 18 | 04-24-2019 12:10 AM |
Calibre Plugin with External Dependencies | ClashTheBunny | Development | 1 | 06-22-2015 10:41 AM |
Dependencies | Bada Bing | Calibre | 3 | 03-11-2011 07:17 AM |
[Rant] New dependencies for 0.6.11? | Jellby | Calibre | 15 | 10-16-2009 10:17 AM |