main.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. import os
  4. HERE = os.path.dirname(__file__)
  5. os.environ["JUPYTERLAB_SETTINGS_DIR"] = str(os.path.join(HERE, "settings"))
  6. import json
  7. from jupyterlab_server import LabConfig, LabServerApp
  8. from notebook.base.handlers import FileFindHandler, IPythonHandler
  9. from notebook.utils import url_path_join as ujoin
  10. from traitlets import Unicode
  11. from jupyterlab.labapp import LabApp
  12. with open(os.path.join(HERE, "package.json")) as fid:
  13. version = json.load(fid)["version"]
  14. class ListingsApp(LabApp):
  15. base_url = "/"
  16. default_url = Unicode("/lab", help="The default URL to redirect to from `/`")
  17. def init_webapp(self):
  18. """initialize tornado webapp and httpserver."""
  19. super().init_webapp()
  20. default_handlers = [
  21. (
  22. ujoin(self.base_url, r"/listings/(.*)"),
  23. FileFindHandler,
  24. {"path": os.path.join(HERE, "list")},
  25. )
  26. ]
  27. self.web_app.add_handlers(".*$", default_handlers)
  28. def start(self):
  29. settings = self.web_app.settings
  30. # By default, make terminals available.
  31. settings.setdefault("terminals_available", True)
  32. super().start()
  33. if __name__ == "__main__":
  34. ListingsApp.launch_instance()