class_docstr: Load an application directory which modifies a Document.
      
class_docstr_tok: ["Load","an","application","directory","which","modifies","a","Document","."]
docstr: Keywords:
      filename (str) : a path to an application directory with either "main.py" or "main.ipynb"
  
      argv (list[str], optional) : a list of string arguments to make available as sys.argv to main.py
docstr_tok: ["Keywords",":","filename","(","str",")",":","a","path","to","an","application","directory","with","either","``","main.py","''","or","``","main.ipynb","''","argv","(","list","[","str","]",",","optional",")",":","a","list","of","string","arguments","to","make","available","as","sys.argv","to","main.py"]
code: def __init__(
      self, *, filename: PathLike, argv: list[str] = []
  ) -> None:
      """
      Keywords:
          filename (str) : a path to an application directory with either "main.py" or "main.ipynb"
  
          argv (list[str], optional) : a list of string arguments to make available as sys.argv to main.py
      """
      super().__init__()
  
      src_path = filename
  
      init_py = join(src_path, "__init__.py")
      if exists(init_py):
          with open(init_py, encoding="utf8") as init_py_f:
              self._package_runner = CodeRunner(
                  init_py_f.read(), init_py, argv
              )
          self._package = self._package_runner.new_module()
          assert self._package is not None
          sys.modules[self._package.__name__] = self._package
      else:
          self._package_runner = None
          self._package = None
  
      main_py = join(src_path, "main.py")
      main_ipy = join(src_path, "main.ipynb")
      if exists(main_py) and exists(main_ipy):
          log.warning(
              f"Found both 'main.py' and 'main.ipynb' in {src_path}, using 'main.py'"
          )
          main = main_py
      elif exists(main_py):
          main = main_py
      elif exists(main_ipy):
          main = main_ipy
      else:
          raise ValueError(
              f"No 'main.py' or 'main.ipynb' in {src_path}"
          )
      self._path = src_path
      self._main = main
  
      handler = (
          NotebookHandler if main.endswith(".ipynb") else ScriptHandler
      )
      self._main_handler = handler(
          filename=self._main, argv=argv, package=self._package
      )
  
      hooks = None
      app_hooks = join(src_path, "app_hooks.py")
      lifecycle = join(src_path, "server_lifecycle.py")
      if exists(app_hooks) and exists(lifecycle):
          raise ValueError(
              "Directory style apps can provide either server_lifecycle.py or app_hooks.py, not both."
          )
      elif exists(lifecycle):
          hooks = lifecycle
      elif exists(app_hooks):
          hooks = app_hooks
  
      if hooks is not None:
          self._lifecycle_handler = ServerLifecycleHandler(
              filename=hooks, argv=argv, package=self._package
          )
      else:
          self._lifecycle_handler = Handler()  # no-op handler
  
      if exists(app_hooks):
          assert hooks is not None
          self._request_handler = ServerRequestHandler(
              filename=hooks, argv=argv, package=self._package
          )
      else:
          self._request_handler = Handler()  # no-op handler
  
      self._theme = None
      themeyaml = join(src_path, "theme.yaml")
      if exists(themeyaml):
          from bokeh.themes import Theme
  
          self._theme = Theme(filename=themeyaml)
  
      appstatic = join(src_path, "static")
      if exists(appstatic):
          self._static = appstatic
  
      self._template = None
      appindex = join(src_path, "templates", "index.html")
      if exists(appindex):
          env = Environment(loader=FileSystemLoader(dirname(appindex)))
          self._template = env.get_template("index.html")
  
imports: from __future__ import annotations
  import logging
  import sys
  from os.path import basename, dirname, exists, join
  from types import ModuleType
  from typing import TYPE_CHECKING, Any, Coroutine
  from jinja2 import Environment, FileSystemLoader, Template
  from ...core.types import PathLike
  from ...document import Document
  from ..application import ServerContext, SessionContext
  from .code_runner import CodeRunner
  from .handler import Handler
  from .notebook import NotebookHandler
  from .script import ScriptHandler
  from .server_lifecycle import ServerLifecycleHandler
  from .server_request_handler import ServerRequestHandler
label_desc: Use image node_id 1 to create a new DirectoryHandler object from inherited base classes: Handler with example: obj = DirectoryHandler()