21
21
S_ISCHR, S_ISBLK, S_ISFIFO, S_ISSOCK)
25
26
from bzrlib.lazy_import import lazy_import
26
27
lazy_import(globals(), """
885
_extension_load_failures = []
888
def failed_to_load_extension(exception):
889
"""Handle failing to load a binary extension.
891
This should be called from the ImportError block guarding the attempt to
892
import the native extension. If this function returns, the pure-Python
893
implementation should be loaded instead::
896
>>> import bzrlib._fictional_extension_pyx
897
>>> except ImportError, e:
898
>>> bzrlib.osutils.failed_to_load_extension(e)
899
>>> import bzrlib._fictional_extension_py
901
# NB: This docstring is just an example, not a doctest, because doctest
902
# currently can't cope with the use of lazy imports in this namespace --
905
# This currently doesn't report the failure at the time it occurs, because
906
# they tend to happen very early in startup when we can't check config
907
# files etc, and also we want to report all failures but not spam the user
909
from bzrlib import trace
910
exception_str = str(exception)
911
if exception_str not in _extension_load_failures:
912
trace.mutter("failed to load compiled extension: %s" % exception_str)
913
_extension_load_failures.append(exception_str)
916
def report_extension_load_failures():
917
if not _extension_load_failures:
919
from bzrlib.config import GlobalConfig
920
if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
922
# the warnings framework should by default show this only once
924
"bzr: warning: Failed to load compiled extensions:\n"
926
" Bazaar can run, but performance may be reduced.\n"
927
" Check Bazaar is correctly installed or set ignore_missing_extensions"
928
% '\n '.join(_extension_load_failures,))
885
932
from bzrlib._chunks_to_lines_pyx import chunks_to_lines
933
except ImportError, e:
934
failed_to_load_extension(e)
887
935
from bzrlib._chunks_to_lines_py import chunks_to_lines
1779
1828
from bzrlib._readdir_pyx import UTF8DirReader
1780
1829
file_kind_from_stat_mode = UTF8DirReader().kind_from_mode
1830
except ImportError, e:
1831
failed_to_load_extension(e)
1782
1832
from bzrlib._readdir_py import (
1783
1833
_kind_from_mode as file_kind_from_stat_mode