mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Port DeVendor
This commit is contained in:
parent
38686dd905
commit
02ff98d8dc
@ -17,15 +17,16 @@ builtins.__dict__['_'] = lambda s: s
|
||||
# immediately translated to the environment language
|
||||
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
|
||||
winutil = winutilerror = None
|
||||
|
||||
if not _run_once:
|
||||
_run_once = True
|
||||
from importlib import import_module
|
||||
|
||||
if not isfrozen:
|
||||
if not isfrozen and not ispy3:
|
||||
# Prevent PyQt4 from being loaded
|
||||
class PyQt4Ban(object):
|
||||
|
||||
@ -40,15 +41,28 @@ if not _run_once:
|
||||
|
||||
class DeVendor(object):
|
||||
|
||||
def find_module(self, fullname, path=None):
|
||||
if fullname == 'calibre.web.feeds.feedparser' or fullname.startswith('calibre.ebooks.markdown'):
|
||||
return self
|
||||
if ispy3:
|
||||
|
||||
def load_module(self, fullname):
|
||||
from importlib import import_module
|
||||
if fullname == 'calibre.web.feeds.feedparser':
|
||||
return import_module('feedparser')
|
||||
return import_module(fullname[len('calibre.ebooks.'):])
|
||||
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):
|
||||
if fullname == 'calibre.web.feeds.feedparser' or fullname.startswith('calibre.ebooks.markdown'):
|
||||
return self
|
||||
|
||||
def load_module(self, fullname):
|
||||
if fullname == 'calibre.web.feeds.feedparser':
|
||||
return import_module('feedparser')
|
||||
return import_module(fullname[len('calibre.ebooks.'):])
|
||||
|
||||
sys.meta_path.insert(0, DeVendor())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user