~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Martin Pool
  • Date: 2009-09-11 06:36:50 UTC
  • mto: This revision was merged to the branch mainline in revision 4688.
  • Revision ID: mbp@sourcefrog.net-20090911063650-yvb522sbe6k0i62r
Only mutter extension load errors when they occur, and record for later

Show diffs side-by-side

added added

removed removed

Lines of Context:
882
882
    return parents
883
883
 
884
884
 
885
 
def _failed_to_load_extension(exception):
 
885
_extension_load_failures = []
 
886
 
 
887
 
 
888
def failed_to_load_extension(exception):
886
889
    """Handle failing to load a binary extension.
887
890
 
888
891
    This should be called from the ImportError block guarding the attempt to
892
895
    >>> try:
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
897
900
    """
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 --
900
903
    # mbp 20090729
901
 
   
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
905
 
    # mechanism.
906
 
    if os.environ.get('BZR_IGNORE_MISSING_EXTENSIONS') == '1':
907
 
        return
 
904
    
 
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
 
908
    # with 10 warnings.
 
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)
 
914
 
 
915
 
 
916
def report_extension_load_failures():
 
917
    if not _extension_load_failures:
 
918
        return
 
919
    from bzrlib.config import GlobalConfig
 
920
    if GlobalConfig().get_user_option_as_bool('ignore_missing_extensions'):
 
921
        return
 
922
    # the warnings framework should by default show this only once
908
923
    warnings.warn(
909
 
        "bzr: warning: Failed to load compiled extension: "
 
924
        "bzr: warning: Failed to load compiled extensions: "
910
925
        "%s\n" 
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)."
914
 
        % (exception,),
915
 
        stacklevel=2)
 
927
        "    Check Bazaar is correctly installed or set ignore_missing_extensions"
 
928
        % '\n'.join(_extension_load_failures,))
916
929
 
917
930
 
918
931
try:
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
923
936
 
924
937
 
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)
1506
1519
                pass
1507
1520
 
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
1821
1834
                )