View Single Post
Old 07-19-2024, 02:24 AM   #7
xdgc
Junior Member
xdgc began at the beginning.
 
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
Onward now to the next issue: RemarkablePlugin's packaging script uses your system Python, whose compiled output is very likely not to be loadable by Calibre's Python.
xdgc is offline   Reply With Quote