py3: Port DeVendor

This commit is contained in:
Kovid Goyal 2019-04-01 14:58:41 +05:30
parent 38686dd905
commit 02ff98d8dc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -17,15 +17,16 @@ builtins.__dict__['_'] = lambda s: s
# immediately translated to the environment language # immediately translated to the environment language
builtins.__dict__['__'] = lambda s: s builtins.__dict__['__'] = lambda s: s
from calibre.constants import iswindows, preferred_encoding, plugins, isosx, islinux, isfrozen, DEBUG, isfreebsd from calibre.constants import iswindows, preferred_encoding, plugins, isosx, islinux, isfrozen, DEBUG, isfreebsd, ispy3
_run_once = False _run_once = False
winutil = winutilerror = None winutil = winutilerror = None
if not _run_once: if not _run_once:
_run_once = True _run_once = True
from importlib import import_module
if not isfrozen: if not isfrozen and not ispy3:
# Prevent PyQt4 from being loaded # Prevent PyQt4 from being loaded
class PyQt4Ban(object): class PyQt4Ban(object):
@ -40,12 +41,25 @@ if not _run_once:
class DeVendor(object): class DeVendor(object):
if ispy3:
def find_spec(self, fullname, path, target=None):
spec = None
if fullname == 'calibre.web.feeds.feedparser':
m = import_module('feedparser')
spec = m.__spec__
elif fullname.startswith('calibre.ebooks.markdown'):
m = import_module(fullname[len('calibre.ebooks.'):])
spec = m.__spec__
return spec
else:
def find_module(self, fullname, path=None): def find_module(self, fullname, path=None):
if fullname == 'calibre.web.feeds.feedparser' or fullname.startswith('calibre.ebooks.markdown'): if fullname == 'calibre.web.feeds.feedparser' or fullname.startswith('calibre.ebooks.markdown'):
return self return self
def load_module(self, fullname): def load_module(self, fullname):
from importlib import import_module
if fullname == 'calibre.web.feeds.feedparser': if fullname == 'calibre.web.feeds.feedparser':
return import_module('feedparser') return import_module('feedparser')
return import_module(fullname[len('calibre.ebooks.'):]) return import_module(fullname[len('calibre.ebooks.'):])