Closed vasi closed 1 month ago
Fixes #72
Thanks for that MR, but I haven't quite understood how / why this bugfix works. The init.py which you modified to include that line that modifies sys.path already exists in __calibre_compat_code.py and should already automatically be executed whenever the plugin is running inside of Calibre:
if "calibre" in sys.modules:
# Explicitly allow importing everything ...
if os.path.dirname(os.path.abspath(__file__)) not in sys.path:
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
Shouldn't that piece of code be enough and have the exact same functionality as your code change?
Are you trying to run the calibre plugin without running the bundle_calibre_plugin.sh script first? The missing sys import you added is also not strictly necessary (but probably a good idea to have clean code) since sys is already included from the file mentioned above.
If you say the issue only happens on FreeBSD, can you check / make sure that the statement if "calibre" in sys.module
is true within Calibre's python environment?
Ahh I see what's happening! The bundle_calibre_plugin.sh script uses sed -i
, which is only a GNU-sed thing. On platforms with non-GNU sed, it interprets -i
as a filename, and doesn't edit in place. That's why this affects both macOS and BSDs—it probably affects distros like Chimera that have a non-GNU userland, too.
There's a few potential solutions, I'm not sure what I like most:
sed
to call, eg: by using a SED variablesed -i
, use a wrapper function that does read/write-to-tmpfile/replaceWhile we're at it, we should probably fix the shebang in these files too. Not all systems have a /bin/bash, which can make bundle_calibre_plugin.sh
's attempt to call package_modules.sh
fail.
Closing in favor of #88
On recent versions of Calibre on BSD-based OSes, it appears that the plugin root directory (or ZIP file) is not always automatically added to the import path.
While we could change the plugin to always import using Calibre's plugin import system (eg:
import calibre_plugins.deacsm.libadobe
), that would be an invasive change. Instead, just force the directory/ZIP containing__init__.py
to always be in the import path. A bit of a hack, but it works.Also fix a missing
sys
import.Tested on Calibre 7.8. Working: