main.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. from jupyterlab_server import LabServerApp, LabConfig
  4. from jupyterlab_server.server import FileFindHandler
  5. from notebook.utils import url_path_join as ujoin
  6. import json
  7. import os
  8. from traitlets import Unicode
  9. HERE = os.path.dirname(__file__)
  10. # Turn off the Jupyter configuration system so configuration files on disk do
  11. # not affect this app. This helps this app to truly be standalone.
  12. os.environ["JUPYTER_NO_CONFIG"]="1"
  13. with open(os.path.join(HERE, 'package.json')) as fid:
  14. version = json.load(fid)['version']
  15. class ExampleApp(LabServerApp):
  16. base_url = '/foo'
  17. default_url = Unicode('/example',
  18. help='The default URL to redirect to from `/`')
  19. lab_config = LabConfig(
  20. app_name = 'JupyterLab Example Federated App',
  21. app_settings_dir = os.path.join(HERE, 'build', 'application_settings'),
  22. app_version = version,
  23. app_url = '/example',
  24. schemas_dir = os.path.join(HERE, 'core_package', 'build', 'schemas'),
  25. static_dir = os.path.join(HERE, 'core_package', 'build'),
  26. templates_dir = os.path.join(HERE, 'templates'),
  27. themes_dir = os.path.join(HERE, 'core_package', 'build', 'themes'),
  28. user_settings_dir = os.path.join(HERE, 'core_package', 'build', 'user_settings'),
  29. workspaces_dir = os.path.join(HERE, 'core_package', 'build', 'workspaces'),
  30. )
  31. def init_webapp(self):
  32. super().init_webapp()
  33. # Handle md ext assets
  34. web_app = self.web_app
  35. base_url = web_app.settings['base_url']
  36. static_path = ujoin(base_url, 'example', 'ext', 'mdext', '(.*)')
  37. static_dir = os.path.join(HERE, 'md_package', 'build')
  38. web_app.add_handlers('.*$', [(static_path, FileFindHandler, {
  39. 'path': static_dir,
  40. })])
  41. def start(self):
  42. settings = self.web_app.settings
  43. # By default, make terminals available.
  44. settings.setdefault('terminals_available', True)
  45. super().start()
  46. if __name__ == '__main__':
  47. ExampleApp.launch_instance()