#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# Standard library importsfromargparseimportNamespace# Bokeh importsfrombokeh.settingsimportsettingsfrombokeh.util.logconfigimportbasicConfig# Bokeh importsfrom...applicationimportApplicationfrom..subcommandimportSubcommandfrom..utilimportreport_server_init_errorsfrom.serveimportbase_serve_args#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('Static',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------
[docs]classStatic(Subcommand):''' Subcommand to launch the Bokeh static server. '''#: name for this subcommandname="static"help="Serve bokehjs' static assets (JavaScript, CSS, images, fonts, etc.)"args=base_serve_args
[docs]definvoke(self,args:Namespace)->None:''' '''basicConfig(format=args.log_format,filename=args.log_file)# This is a bit of a fudge. We want the default log level for non-server# cases to be None, i.e. we don't set a log level. But for the server we# do want to set the log level to INFO if nothing else overrides that.log_level=settings.py_log_level(args.log_level)iflog_levelisNone:log_level=logging.INFOlogging.getLogger('bokeh').setLevel(log_level)ifargs.use_configisnotNone:log.info(f"Using override config file: {args.use_config}")settings.load_config(args.use_config)# protect this import inside a function so that "bokeh info" can work# even if Tornado is not installedfrombokeh.server.serverimportServerapplications:dict[str,Application]={}_allowed_keys=['port','address']server_kwargs={key:getattr(args,key)forkeyin_allowed_keysifgetattr(args,key,None)isnotNone}withreport_server_init_errors(**server_kwargs):server=Server(applications,**server_kwargs)address_string=''ifserver.addressisnotNoneandserver.address!='':address_string=' address '+server.addresslog.info(f"Starting Bokeh static server at {server.port}{address_string}")log.debug(f"Serving static files from: {settings.bokehjs_path()}")server.run_until_shutdown()
#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Private API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Code#-----------------------------------------------------------------------------