#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------'''To generate the serialized JSON representation for a Bokeh applicationfrom a single Python script, pass the script name to ``bokeh json`` on thecommand line:.. code-block:: sh bokeh json app_script.pyThe generated JSON will be saved in the current working directory withthe name ``app_script.json``.Applications can also be created from directories. The directory shouldcontain a ``main.py`` (and any other helper modules that are required) aswell as any additional assets (e.g., theme files). Pass the directory nameto ``bokeh json`` to generate the JSON:.. code-block:: sh bokeh json app_dirBy default, the generated JSON is output as one line, with no indentation.To generate "pretty printed" JSON on multiple lines, you can specify anindentation level with the ``--indent`` argument:.. code-block:: sh bokeh json app_script.py --indent=2'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromargparseimportNamespace# Bokeh importsfrom...core.json_encoderimportserialize_jsonfrom...documentimportDocumentfrom..subcommandimportArgumentfrom.file_outputimportFileOutputSubcommand#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('JSON',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classJSON(FileOutputSubcommand):''' Subcommand to output applications as serialized JSON '''#: name for this subcommandname="json"#: file extension for output generated by this :class:`~bokeh.command.subcommands.file_output.FileOutputSubcommand`extension="json"help="Create JSON files for one or more applications"args=(FileOutputSubcommand.files_arg("JSON"),('--indent',Argument(metavar='LEVEL',type=int,help="indentation to use when printing",default=None,)),*FileOutputSubcommand.other_args(),)