885
def _failed_to_load_extension(exception):
885
_extension_load_failures = []
888
def failed_to_load_extension(exception):
886
889
"""Handle failing to load a binary extension.
888
891
This should be called from the ImportError block guarding the attempt to
893
896
>>> import bzrlib._fictional_extension_pyx
894
897
>>> except ImportError, e:
895
>>> bzrlib.osutils._failed_to_load_extension(e)
898
>>> bzrlib.osutils.failed_to_load_extension(e)
896
899
>>> import bzrlib._fictional_extension_py
898
901
# NB: This docstring is just an example, not a doctest, because doctest
899
902
# currently can't cope with the use of lazy imports in this namespace --
902
# We use Python warnings so you can turn this into an error etc if you
903
# want. Although there is a mechanism to disable particular extensions
904
# it's not very easy to use or to set persistently so we have a special
906
if os.environ.get('BZR_IGNORE_MISSING_EXTENSIONS') == '1':
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
909
"bzr: warning: Failed to load compiled extension: "
924
"bzr: warning: Failed to load compiled extensions: "
911
926
" Bazaar can run, but performance may be reduced.\n"
912
" Check Bazaar is correctly installed "
913
"(or set BZR_IGNORE_MISSING_EXTENSIONS=1)."
927
" Check Bazaar is correctly installed or set ignore_missing_extensions"
928
% '\n'.join(_extension_load_failures,))
919
932
from bzrlib._chunks_to_lines_pyx import chunks_to_lines
920
933
except ImportError, e:
921
_failed_to_load_extension(e)
934
failed_to_load_extension(e)
922
935
from bzrlib._chunks_to_lines_py import chunks_to_lines
1502
1515
from bzrlib._readdir_pyx import UTF8DirReader
1503
1516
_selected_dir_reader = UTF8DirReader()
1504
1517
except ImportError, e:
1505
_failed_to_load_extension(e)
1518
failed_to_load_extension(e)
1508
1521
if _selected_dir_reader is None:
1815
1828
from bzrlib._readdir_pyx import UTF8DirReader
1816
1829
file_kind_from_stat_mode = UTF8DirReader().kind_from_mode
1817
1830
except ImportError, e:
1818
_failed_to_load_extension(e)
1831
failed_to_load_extension(e)
1819
1832
from bzrlib._readdir_py import (
1820
1833
_kind_from_mode as file_kind_from_stat_mode