Change to allow working with pyinstaller
This commit is contained in:
parent
42f546c283
commit
19132f7a07
|
@ -5,3 +5,4 @@ pyexcel*-info
|
||||||
build
|
build
|
||||||
dist
|
dist
|
||||||
tmp.db
|
tmp.db
|
||||||
|
.idea/*
|
||||||
|
|
|
@ -19,21 +19,43 @@ from . import fileformat, database
|
||||||
|
|
||||||
exports = fileformat.exports + database.exports
|
exports = fileformat.exports + database.exports
|
||||||
|
|
||||||
from pkgutil import iter_modules
|
import pkgutil
|
||||||
|
|
||||||
black_list = [__name__, 'pyexcel_webio', 'pyexcel_text']
|
black_list = [__name__, 'pyexcel_webio', 'pyexcel_text']
|
||||||
|
|
||||||
for _, module_name, ispkg in iter_modules():
|
# load modules to work based with and without pyinstaller
|
||||||
|
# from: https://github.com/webcomics/dosage/blob/master/dosagelib/loader.py
|
||||||
|
# see: https://github.com/pyinstaller/pyinstaller/issues/1905
|
||||||
|
# load modules using iter_modules()
|
||||||
|
# (should find all plug ins in normal build, but not pyinstaller)
|
||||||
|
|
||||||
|
prefix = 'pyexcel_'
|
||||||
|
|
||||||
|
module_names = [m[1] for m in pkgutil.iter_modules()
|
||||||
|
if m[2] and m[1].startswith(prefix)]
|
||||||
|
|
||||||
|
# special handling for PyInstaller
|
||||||
|
toc = set()
|
||||||
|
for t in (i.toc for i in map(pkgutil.get_importer, __path__)
|
||||||
|
if hasattr(i, 'toc')):
|
||||||
|
toc |= t
|
||||||
|
|
||||||
|
for elm in toc:
|
||||||
|
if elm.startswith(prefix) and '.' not in elm:
|
||||||
|
module_names.append(elm)
|
||||||
|
|
||||||
|
# loop through modules and find our plug ins
|
||||||
|
for module_name in module_names:
|
||||||
|
|
||||||
if module_name in black_list:
|
if module_name in black_list:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if ispkg and module_name.startswith('pyexcel_'):
|
try:
|
||||||
try:
|
plugin = __import__(module_name)
|
||||||
plugin = __import__(module_name)
|
if hasattr(plugin, '__pyexcel_io_plugins__'):
|
||||||
if hasattr(plugin, '__pyexcel_io_plugins__'):
|
for p in plugin.__pyexcel_io_plugins__:
|
||||||
for p in plugin.__pyexcel_io_plugins__:
|
pre_register(p, module_name)
|
||||||
pre_register(p, module_name)
|
except ImportError:
|
||||||
except ImportError:
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
register_readers_and_writers(exports)
|
register_readers_and_writers(exports)
|
||||||
|
|
Loading…
Reference in New Issue