def autoload_server(model=None, app_path=None, session_id=None, url="default", relative_urls=False, arguments=None): from bokeh.util.deprecation import deprecated deprecated((0, 12, 7), 'bokeh.embed.autoload_server', 'bokeh.embed.server_document or bokeh.embed.server_session') if session_id is None: return server_document(url, relative_urls, "default", arguments) else: return server_session(model, session_id, url, relative_urls, "default", arguments)
def test_since(mock_warn: MagicMock) -> None: dep.deprecated((1, 2, 3), old="foo", new="bar") assert mock_warn.called assert mock_warn.call_args[0] == ( "foo was deprecated in Bokeh 1.2.3 and will be removed, use bar instead.", dep.BokehDeprecationWarning) assert mock_warn.call_args[1] == {'stacklevel': 2}
def sort_legend(self, value): deprecated((0, 12, 0), 'Chart.sort_legend', 'Chart.legend_sort_field') self.legend_sort_field, direction = value[0] if direction: self.legend_sort_direction = "ascending" else: self.legend_sort_direction = "descending"
def from_networkx(graph, layout_function, **kwargs): from bokeh.util.deprecation import deprecated from bokeh.plotting import from_networkx as real_from_networkx deprecated( "Importing from_networkx from bokeh.models.graphs is deprecated and will be removed in Bokeh 3.0. Import from bokeh.plotting instead" ) return real_from_networkx(graph, layout_function, **kwargs)
def from_py_func(cls, func): """ Create a ``CustomJS`` instance from a Python function. The function is translated to JavaScript using PScript. """ from bokeh.util.deprecation import deprecated deprecated( "'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use CustomJS directly instead.") if not isinstance(func, FunctionType): raise ValueError('CustomJS.from_py_func needs function object.') pscript = import_required( 'pscript', 'To use Python functions for CustomJS, you need PScript ' + '("conda install -c conda-forge pscript" or "pip install pscript")' ) # Collect default values default_values = func.__defaults__ # Python 2.6+ default_names = func.__code__.co_varnames[:len(default_values)] args = dict(zip(default_names, default_values)) args.pop('window', None) # Clear window, so we use the global window object # Get JS code, we could rip out the function def, or just # call the function. We do the latter. code = pscript.py2js(func, 'cb') + 'cb(%s);\n' % ', '.join(default_names) return cls(code=code, args=args)
def test_since_with_extra(mock_warn): dep.deprecated((1, 2, 3), old="foo", new="bar", extra="baz") assert mock_warn.called assert mock_warn.call_args[0] == ( "foo was deprecated in Bokeh 1.2.3 and will be removed, use bar instead. baz", dep.BokehDeprecationWarning) assert mock_warn.call_args[1] == {'stacklevel': 2}
def set(self, **kwargs): ''' Updates the object's properties from the given keyword arguments. THIS FUNCTION IS DEPRECATED. Use the .update method instead. Returns: None Examples: The following are equivalent: .. code-block:: python from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20) ''' from bokeh.util.deprecation import deprecated deprecated((0, 12, 4), 'set method', 'update method') for kw in kwargs: setattr(self, kw, kwargs[kw])
def test_since_with_extra(mock_warn): dep.deprecated((1, 2, 3), old="foo", new="bar", extra="baz") assert mock_warn.called assert mock_warn.call_args[0] == ( "foo was deprecated in Bokeh 1.2.3 and will be removed, use bar instead. baz", dep.BokehDeprecationWarning, ) assert mock_warn.call_args[1] == {"stacklevel": 2}
def deprecated_property_tile(self): from bokeh.util.deprecation import deprecated deprecated( since_or_msg=(1, 1, 0), old=name, new="get_provider(Vendors.%s)" % name, ) return self.get_provider(provider_name=name)
def _deprecated_remove_session_callback(self, callback, originator): deprecation.deprecated((0, 12, 15), 'The ability to remove a callback function using its value', 'a value returned from the function that adds a callback') cb_objs = self._callback_objs_by_callable[originator].pop(callback) for cb_obj in cb_objs: self._session_callbacks.remove(cb_obj) return cb_objs
def CARTODBPOSITRON(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='CARTODBPOSITRON', new='get_provider(Provider.CARTODBPOSITRON)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='https://tiles.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', attribution=self._CARTO_ATTRIBUTION)
def STAMEN_TONER_LABELS(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='STAMEN_TONER_LABELS', new='get_provider(Provider.STAMEN_TONER_LABELS)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/toner-labels/{Z}/{X}/{Y}.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://www.openstreetmap.org/copyright">ODbL</a>')
def _deprecated_remove_session_callback(self, callback, originator): deprecation.deprecated( (0, 12, 15), 'The ability to remove a callback function using its value', 'a value returned from the function that adds a callback') cb_objs = self._callback_objs_by_callable[originator].pop(callback) for cb_obj in cb_objs: self._session_callbacks.remove(cb_obj) return cb_objs
def STAMEN_TERRAIN_RETINA(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(2, 0, 0), old='STAMEN_TERRAIN_RETINA', new='get_provider(provider.STAMEN_TERRAIN_RETINA)') from bokeh.models.tiles import WMTSTileSource return WMTSTileSource( url='http://tile.stamen.com/terrain/{Z}/{X}/{Y}@2x.png', attribution=self._STAMEN_ATTRIBUTION % '<a href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>' )
def test_since_bad_tuple(): with pytest.raises(ValueError): dep.deprecated((1, ), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, 3, 4), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, -4), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, "3"), old="foo", new="bar")
def test_since_bad_tuple(): with pytest.raises(ValueError): dep.deprecated((1,), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, 3, 4), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, -4), old="foo", new="bar") with pytest.raises(ValueError): dep.deprecated((1, 2, "3"), old="foo", new="bar")
def from_py_func(cls, func): ''' Create a ``FuncTickFormatter`` instance from a Python function. The function is translated to JavaScript using PScript. The variable ``tick`` will contain the unformatted tick value and can be expected to be present in the function namespace at render time. Example: .. code-block:: python code = """ def ticker(): return "{:.0f} + {:.2f}".format(tick, tick % 1) """ The python function must have no positional arguments. It's possible to pass Bokeh models (e.g. a ``ColumnDataSource``) as keyword arguments to the function. ''' from bokeh.util.deprecation import deprecated deprecated( "'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use FuncTickFormatter directly instead.") if not isinstance(func, FunctionType): raise ValueError('CustomJS.from_py_func needs function object.') pscript = import_required( 'pscript', 'To use Python functions for CustomJS, you need PScript ' + '("conda install -c conda-forge pscript" or "pip install pscript")' ) sig = signature(func) all_names, default_values = get_param_info(sig) if len(all_names) - len(default_values) != 0: raise ValueError( "Function `func` may only contain keyword arguments.") if default_values and not any( isinstance(value, Model) for value in default_values): raise ValueError("Default value must be a Bokeh Model.") func_kwargs = dict(zip(all_names, default_values)) # Wrap the code attr in a function named `formatter` and call it # with arguments that match the `args` attr code = pscript.py2js( func, 'formatter') + 'return formatter(%s);\n' % ', '.join(all_names) return cls(code=code, args=func_kwargs)
def test_message_no_extra_args(): with pytest.raises(ValueError): dep.deprecated("test", "foo") with pytest.raises(ValueError): dep.deprecated("test", old="foo") with pytest.raises(ValueError): dep.deprecated("test", new="foo") with pytest.raises(ValueError): dep.deprecated("test", extra="foo")
def test_message_no_extra_args(): with pytest.raises(ValueError): dep.deprecated('test', 'foo') with pytest.raises(ValueError): dep.deprecated('test', old='foo') with pytest.raises(ValueError): dep.deprecated('test', new='foo') with pytest.raises(ValueError): dep.deprecated('test', extra='foo')
def from_py_func(cls, func): ''' Create a ``FuncTickFormatter`` instance from a Python function. The function is translated to JavaScript using PScript. The variable ``tick`` will contain the unformatted tick value and can be expected to be present in the function namespace at render time. Example: .. code-block:: python code = """ def ticker(): return "{:.0f} + {:.2f}".format(tick, tick % 1) """ The python function must have no positional arguments. It's possible to pass Bokeh models (e.g. a ``ColumnDataSource``) as keyword arguments to the function. ''' from bokeh.util.deprecation import deprecated deprecated("'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use FuncTickFormatter directly instead.") if not isinstance(func, FunctionType): raise ValueError('CustomJS.from_py_func needs function object.') pscript = import_required('pscript', 'To use Python functions for CustomJS, you need PScript ' + '("conda install -c conda-forge pscript" or "pip install pscript")') sig = signature(func) all_names, default_values = get_param_info(sig) if len(all_names) - len(default_values) != 0: raise ValueError("Function `func` may only contain keyword arguments.") if default_values and not any(isinstance(value, Model) for value in default_values): raise ValueError("Default value must be a Bokeh Model.") func_kwargs = dict(zip(all_names, default_values)) # Wrap the code attr in a function named `formatter` and call it # with arguments that match the `args` attr code = pscript.py2js(func, 'formatter') + 'return formatter(%s);\n' % ', '.join(all_names) return cls(code=code, args=func_kwargs)
def nodejs_compile(code, lang="javascript", file=None): if lang == "coffeescript": from bokeh.util.deprecation import deprecated deprecated("CoffeeScript support is deprecated and will be removed in an eventual 2.0 release. " "Use JavaScript or TypeScript directly instead.") compilejs_script = join(bokehjs_dir, "js", "compiler.js") output = _run_nodejs([compilejs_script], dict(code=code, lang=lang, file=file, bokehjs_dir=bokehjs_dir)) lines = output.split("\n") for i, line in enumerate(lines): if not line.startswith("LOG"): break else: print(line) obj = json.loads("\n".join(lines[i:])) if isinstance(obj, dict): return AttrDict(obj) else: return dict(error=obj)
def loop_until_closed(self, suppress_warning=False): ''' Execute a blocking loop that runs and executes event callbacks until the connection is closed (e.g. by hitting Ctrl-C). While this method can be used to run Bokeh application code "outside" the Bokeh server, this practice is HIGHLY DISCOURAGED for any real use case. This function is intented to facilitate testing ONLY. ''' suppress_warning # shut up flake from bokeh.util.deprecation import deprecated deprecated("ClientSession.loop_until_closed is deprecated, and will be removed in an eventual 2.0 release. " "Run Bokeh applications directly on a Bokeh server instead. See:\n\n" " https//docs.bokeh.org/en/latest/docs/user_guide/server.html\n") self._connection.loop_until_closed()
def loop_until_closed(self, suppress_warning=False): ''' Execute a blocking loop that runs and executes event callbacks until the connection is closed (e.g. by hitting Ctrl-C). While this method can be used to run Bokeh application code "outside" the Bokeh server, this practice is HIGHLY DISCOURAGED for any real use case. This function is intented to facilitate testing ONLY. ''' suppress_warning # shut up flake from bokeh.util.deprecation import deprecated deprecated( "ClientSession.loop_until_closed is deprecated, and will be removed in an eventual 2.0 release. " "Run Bokeh applications directly on a Bokeh server instead. See:\n\n" " https//docs.bokeh.org/en/latest/docs/user_guide/server.html\n" ) self._connection.loop_until_closed()
def test_since_missing_extra_args(): with pytest.raises(ValueError): dep.deprecated((1, 2, 3)) with pytest.raises(ValueError): dep.deprecated((1, 2, 3), old="foo") with pytest.raises(ValueError): dep.deprecated((1, 2, 3), new="foo")
def from_py_func(cls, func): """ Create a ``CustomJS`` instance from a Python function. The function is translated to JavaScript using PScript. """ from bokeh.util.deprecation import deprecated deprecated("'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use CustomJS directly instead.") if not isinstance(func, FunctionType): raise ValueError('CustomJS.from_py_func needs function object.') pscript = import_required('pscript', 'To use Python functions for CustomJS, you need PScript ' + '("conda install -c conda-forge pscript" or "pip install pscript")') # Collect default values default_values = func.__defaults__ # Python 2.6+ default_names = func.__code__.co_varnames[:len(default_values)] args = dict(zip(default_names, default_values)) args.pop('window', None) # Clear window, so we use the global window object # Get JS code, we could rip out the function def, or just # call the function. We do the latter. code = pscript.py2js(func, 'cb') + 'cb(%s);\n' % ', '.join(default_names) return cls(code=code, args=args)
def from_py_func(cls, func): ''' Create a ``CustomJSFilter`` instance from a Python function. The function is translated to JavaScript using PScript. The ``func`` function namespace will contain the variable ``source`` at render time. This will be the data source associated with the ``CDSView`` that this filter is added to. ''' from bokeh.util.deprecation import deprecated deprecated("'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use CustomJSFilter directly instead.") if not isinstance(func, FunctionType): raise ValueError('CustomJSFilter.from_py_func only accepts function objects.') pscript = import_required( 'pscript', dedent("""\ To use Python functions for CustomJSFilter, you need PScript '("conda install -c conda-forge pscript" or "pip install pscript")""") ) argspec = inspect.getargspec(func) default_names = argspec.args default_values = argspec.defaults or [] if len(default_names) - len(default_values) != 0: raise ValueError("Function may only contain keyword arguments.") # should the following be all of the values need to be Models? if default_values and not any(isinstance(value, Model) for value in default_values): raise ValueError("Default value must be a plot object.") func_kwargs = dict(zip(default_names, default_values)) code = pscript.py2js(func, 'filter') + 'return filter(%s);\n' % ', '.join(default_names) return cls(code=code, args=func_kwargs)
def test_since(mock_warn): dep.deprecated((1,2,3), old="foo", new="bar") assert mock_warn.called assert mock_warn.call_args[0] == ("foo was deprecated in Bokeh 1.2.3 and will be removed, use bar instead.", dep.BokehDeprecationWarning) assert mock_warn.call_args[1] == {'stacklevel': 2}
def deprecated_property_tile(self): from bokeh.util.deprecation import deprecated deprecated(since_or_msg=(1, 1, 0), old=name, new='get_provider(Vendors.%s)' % name) return self.get_provider(provider_name=name)
def test_message(mock_warn): dep.deprecated('test') assert mock_warn.called assert mock_warn.call_args[0] == ("test", dep.BokehDeprecationWarning) assert mock_warn.call_args[1] == {'stacklevel': 2}
def test_bad_arg_type(): for x in [10, True, foo, [], (), {}]: with pytest.raises(ValueError): dep.deprecated(x)
### Deprecation note: ### bokeh.models.widgets.layouts has been deprecated in 0.11.1 in favor of ### bokeh.models.layouts and is awaiting removal. The following imports will ### allow layouts to be imported from bokeh.models.widgets during the ### deprecation cycle, but doing so will raise a warning. from bokeh.util.deprecation import deprecated deprecated((0, 11, 1), 'bokeh.models.widgets.layouts', 'bokeh.models.layouts') del deprecated from ..layouts import * # NOQA
from bokeh.util.deprecation import deprecated deprecated((0, 11, 0), 'bokeh.properties', 'bokeh.core.properties') del deprecated from .core.properties import * # NOQA
def __init__(self, *args, **kw): from bokeh.util.deprecation import deprecated deprecated( "CoffeeScript support is deprecated and will be removed in an eventual 2.0 release. " "Use JavaScript or TypeScript directly instead.") super(CoffeeScript, self).__init__(*args, **kw)
def test_message(mock_warn): dep.deprecated("test") assert mock_warn.called assert mock_warn.call_args[0] == ("test", dep.BokehDeprecationWarning) assert mock_warn.call_args[1] == {"stacklevel": 2}
from bokeh.util.deprecation import deprecated deprecated((0, 11, 0), 'bokeh.browserlib', 'bokeh.util.browser') del deprecated from .util.browser import * # NOQA
from bokeh.util.deprecation import deprecated deprecated((0, 11, 0), 'bokeh.mixins', 'bokeh.core.property_mixins') del deprecated from .core.property_mixins import * # NOQA
from bokeh.util.deprecation import deprecated deprecated((0, 11, 0), 'bokeh.plotting_helpers', 'bokeh.plotting.helpers') del deprecated from .plotting.helpers import * # NOQA
def sort_legend(self): deprecated((0, 12, 0), 'Chart.sort_legend', 'Chart.legend_sort_field') return [(self.legend_sort_field, self.legend_sort_direction)]
def from_py_func(cls, func, v_func): ''' Create a ``CustomJSTransform`` instance from a pair of Python functions. The function is translated to JavaScript using PScript. The python functions must have no positional arguments. It's possible to pass Bokeh models (e.g. a ``ColumnDataSource``) as keyword arguments to the functions. The ``func`` function namespace will contain the variable ``x`` (the untransformed value) at render time. The ``v_func`` function namespace will contain the variable ``xs`` (the untransformed vector) at render time. .. warning:: The vectorized function, ``v_func``, must return an array of the same length as the input ``xs`` array. Example: .. code-block:: python def transform(): from pscript.stubs import Math return Math.cos(x) def v_transform(): from pscript.stubs import Math return [Math.cos(x) for x in xs] customjs_transform = CustomJSTransform.from_py_func(transform, v_transform) Args: func (function) : a scalar function to transform a single ``x`` value v_func (function) : a vectorized function to transform a vector ``xs`` Returns: CustomJSTransform ''' from bokeh.util.deprecation import deprecated deprecated("'from_py_func' is deprecated and will be removed in an eventual 2.0 release. " "Use CustomJSTransform directly instead.") if not isinstance(func, FunctionType) or not isinstance(v_func, FunctionType): raise ValueError('CustomJSTransform.from_py_func only accepts function objects.') pscript = import_required( 'pscript', dedent("""\ To use Python functions for CustomJSTransform, you need PScript '("conda install -c conda-forge pscript" or "pip install pscript")""") ) def pscript_compile(func): sig = signature(func) all_names, default_values = get_param_info(sig) if len(all_names) - len(default_values) != 0: raise ValueError("Function may only contain keyword arguments.") if default_values and not any(isinstance(value, Model) for value in default_values): raise ValueError("Default value must be a Bokeh Model.") func_kwargs = dict(zip(all_names, default_values)) # Wrap the code attr in a function named `formatter` and call it # with arguments that match the `args` attr code = pscript.py2js(func, 'transformer') + 'return transformer(%s);\n' % ', '.join(all_names) return code, func_kwargs jsfunc, func_kwargs = pscript_compile(func) v_jsfunc, v_func_kwargs = pscript_compile(v_func) # Have to merge the function arguments func_kwargs.update(v_func_kwargs) return cls(func=jsfunc, v_func=v_jsfunc, args=func_kwargs)
from bokeh.util.deprecation import deprecated deprecated((0, 11, 0), 'bokeh.templates', 'bokeh.core.templates') del deprecated from .core.templates import * # NOQA