/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

Update to bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    """Generate a message that something was deprecated in a release.
89
89
 
90
90
    >>> deprecated_in((1, 4, 0))
91
 
    '%s was deprecated in version 1.4'
 
91
    '%s was deprecated in version 1.4.'
92
92
    """
93
 
    return ("%s was deprecated in version "
94
 
            + bzrlib._format_version_tuple(version_tuple))
 
93
    return ("%%s was deprecated in version %s."
 
94
            % bzrlib._format_version_tuple(version_tuple))
95
95
 
96
96
 
97
97
def set_warning_method(method):
331
331
                return self._warn_deprecated(list.pop)
332
332
 
333
333
    return _DeprecatedList(initial_value)
 
334
 
 
335
 
 
336
def _check_for_filter(error_only):
 
337
    """Check if there is already a filter for deprecation warnings.
 
338
    
 
339
    :param error_only: Only match an 'error' filter
 
340
    :return: True if a filter is found, False otherwise
 
341
    """
 
342
    import warnings
 
343
    for filter in warnings.filters:
 
344
        if issubclass(DeprecationWarning, filter[2]):
 
345
            # This filter will effect DeprecationWarning
 
346
            if not error_only or filter[0] == 'error':
 
347
                return True
 
348
    return False
 
349
 
 
350
 
 
351
def suppress_deprecation_warnings(override=True):
 
352
    """Call this function to suppress all deprecation warnings.
 
353
 
 
354
    When this is a final release version, we don't want to annoy users with
 
355
    lots of deprecation warnings. We only want the deprecation warnings when
 
356
    running a dev or release candidate.
 
357
 
 
358
    :param override: If True, always set the ignore, if False, only set the
 
359
        ignore if there isn't already a filter.
 
360
    """
 
361
    import warnings
 
362
    if not override and _check_for_filter(error_only=False):
 
363
        # If there is already a filter effecting suppress_deprecation_warnings,
 
364
        # then skip it.
 
365
        return
 
366
    warnings.filterwarnings('ignore', category=DeprecationWarning)
 
367
 
 
368
 
 
369
def activate_deprecation_warnings(override=True):
 
370
    """Call this function to activate deprecation warnings.
 
371
 
 
372
    When running in a 'final' release we suppress deprecation warnings.
 
373
    However, the test suite wants to see them. So when running selftest, we
 
374
    re-enable the deprecation warnings.
 
375
 
 
376
    Note: warnings that have already been issued under 'ignore' will not be
 
377
    reported after this point. The 'warnings' module has already marked them as
 
378
    handled, so they don't get issued again.
 
379
 
 
380
    :param override: If False, only add a filter if there isn't an error filter
 
381
        already. (This slightly differs from suppress_deprecation_warnings, in
 
382
        because it always overrides everything but -Werror).
 
383
    """
 
384
    import warnings
 
385
    if not override and _check_for_filter(error_only=True):
 
386
        # DeprecationWarnings are already turned into errors, don't downgrade
 
387
        # them to 'default'.
 
388
        return
 
389
    warnings.filterwarnings('default', category=DeprecationWarning)