Fix #998 (py3: Load plugins from the same (correct) path)

This commit is contained in:
Kovid Goyal 2019-05-26 07:36:00 +05:30
parent 7114083e09
commit d8af514a92
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 14 additions and 11 deletions

View File

@ -147,6 +147,12 @@ def cache_dir():
ans = cache_dir.ans = _get_cache_dir() ans = cache_dir.ans = _get_cache_dir()
return ans return ans
plugins_loc = sys.extensions_location
if ispy3:
plugins_loc = os.path.join(plugins_loc, '3')
# plugins {{{ # plugins {{{
@ -195,9 +201,6 @@ class Plugins(collections.Mapping):
def load_plugin(self, name): def load_plugin(self, name):
if name in self._plugins: if name in self._plugins:
return return
plugins_loc = sys.extensions_location
if ispy3:
plugins_loc = os.path.join(plugins_loc, '3')
sys.path.insert(0, plugins_loc) sys.path.insert(0, plugins_loc)
try: try:
del sys.modules[name] del sys.modules[name]

View File

@ -22,7 +22,7 @@ from calibre import as_unicode, prints
from calibre.constants import ( from calibre.constants import (
DEBUG, __appname__ as APP_UID, __version__, config_dir, filesystem_encoding, DEBUG, __appname__ as APP_UID, __version__, config_dir, filesystem_encoding,
is_running_from_develop, isbsd, isfrozen, islinux, isosx, iswindows, isxp, is_running_from_develop, isbsd, isfrozen, islinux, isosx, iswindows, isxp,
plugins plugins, plugins_loc
) )
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
from calibre.gui2.linux_file_dialogs import ( from calibre.gui2.linux_file_dialogs import (
@ -821,7 +821,7 @@ class Application(QApplication):
if headless: if headless:
if not args: if not args:
args = sys.argv[:1] args = sys.argv[:1]
args.extend(['-platformpluginpath', sys.extensions_location, '-platform', 'headless']) args.extend(['-platformpluginpath', plugins_loc, '-platform', 'headless'])
self.headless = headless self.headless = headless
qargs = [i.encode('utf-8') if isinstance(i, unicode_type) else i for i in args] qargs = [i.encode('utf-8') if isinstance(i, unicode_type) else i for i in args]
self.pi, pi_err = plugins['progress_indicator'] self.pi, pi_err = plugins['progress_indicator']
@ -1167,7 +1167,7 @@ def ensure_app(headless=True):
args = sys.argv[:1] args = sys.argv[:1]
has_headless = isosx or islinux or isbsd has_headless = isosx or islinux or isbsd
if headless and has_headless: if headless and has_headless:
args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless'] args += ['-platformpluginpath', plugins_loc, '-platform', 'headless']
_store_app = QApplication(args) _store_app = QApplication(args)
if headless and has_headless: if headless and has_headless:
_store_app.headless = True _store_app.headless = True

View File

@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
Wrapper for multi-threaded access to a single sqlite database connection. Serializes Wrapper for multi-threaded access to a single sqlite database connection. Serializes
all calls. all calls.
''' '''
import sqlite3 as sqlite, traceback, time, uuid, sys, os import sqlite3 as sqlite, traceback, time, uuid, os
from sqlite3 import IntegrityError, OperationalError from sqlite3 import IntegrityError, OperationalError
from threading import Thread from threading import Thread
from threading import RLock from threading import RLock
@ -17,7 +17,7 @@ from functools import partial
from calibre.ebooks.metadata import title_sort, author_to_author_sort from calibre.ebooks.metadata import title_sort, author_to_author_sort
from calibre.utils.date import parse_date, isoformat, local_tz, UNDEFINED_DATE from calibre.utils.date import parse_date, isoformat, local_tz, UNDEFINED_DATE
from calibre import isbytestring, force_unicode from calibre import isbytestring, force_unicode
from calibre.constants import iswindows, DEBUG, plugins from calibre.constants import iswindows, DEBUG, plugins, plugins_loc
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
from calibre import prints from calibre import prints
from polyglot.builtins import unicode_type, cmp from polyglot.builtins import unicode_type, cmp
@ -238,7 +238,7 @@ def icu_collator(s1, s2):
def load_c_extensions(conn, debug=DEBUG): def load_c_extensions(conn, debug=DEBUG):
try: try:
conn.enable_load_extension(True) conn.enable_load_extension(True)
ext_path = os.path.join(sys.extensions_location, 'sqlite_custom.'+ ext_path = os.path.join(plugins_loc, 'sqlite_custom.'+
('pyd' if iswindows else 'so')) ('pyd' if iswindows else 'so'))
conn.load_extension(ext_path) conn.load_extension(ext_path)
conn.enable_load_extension(False) conn.enable_load_extension(False)

View File

@ -13,7 +13,7 @@ Test a binary calibre build to ensure that all needed binary images/libraries ha
import os, ctypes, sys, unittest, time import os, ctypes, sys, unittest, time
from calibre.constants import plugins, iswindows, islinux, isosx, ispy3 from calibre.constants import plugins, iswindows, islinux, isosx, ispy3, plugins_loc
from polyglot.builtins import iteritems, map, unicode_type, getenv, native_string_type from polyglot.builtins import iteritems, map, unicode_type, getenv, native_string_type
is_ci = os.environ.get('CI', '').lower() == 'true' is_ci = os.environ.get('CI', '').lower() == 'true'
@ -103,7 +103,7 @@ class BuildTest(unittest.TestCase):
if name in exclusions: if name in exclusions:
if name in ('libusb', 'libmtp'): if name in ('libusb', 'libmtp'):
# Just check that the DLL can be loaded # Just check that the DLL can be loaded
ctypes.CDLL(os.path.join(sys.extensions_location, name + ('.dylib' if isosx else '.so'))) ctypes.CDLL(os.path.join(plugins_loc, name + ('.dylib' if isosx else '.so')))
continue continue
mod, err = plugins[name] mod, err = plugins[name]
self.assertFalse(err or not mod, 'Failed to load plugin: ' + name + ' with error:\n' + err) self.assertFalse(err or not mod, 'Failed to load plugin: ' + name + ' with error:\n' + err)