#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Provide Bokeh-specific warning subclasses.The primary use of these subclasses to to force them to be unconditionallydisplayed to users by default.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsimportinspectimportosimportwarnings# lgtm [py/import-and-import-from]#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('BokehDeprecationWarning','BokehUserWarning','find_stack_level','warn',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classBokehDeprecationWarning(DeprecationWarning):''' A Bokeh-specific ``DeprecationWarning`` subclass. Used to selectively filter Bokeh deprecations for unconditional display. '''
[docs]classBokehUserWarning(UserWarning):''' A Bokeh-specific ``UserWarning`` subclass. Used to selectively filter Bokeh warnings for unconditional display. '''
[docs]deffind_stack_level()->int:"""Find the first place in the stack that is not inside Bokeh. Inspired by: pandas.util._exceptions.find_stack_level """importbokehpkg_dir=os.path.dirname(bokeh.__file__)# https://stackoverflow.com/questions/17407119/python-inspect-stack-is-slowframe=inspect.currentframe()n=0whileframe:fname=inspect.getfile(frame)iffname.startswith(pkg_dir):frame=frame.f_backn+=1else:breakreturnn
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------