Skip to content

Commit

Permalink
Merge pull request #8223 from meeseeksmachine/auto-backport-of-pr-821…
Browse files Browse the repository at this point in the history
…8-on-1.2.x

Backport PR #8218 on branch 1.2.x (Expose global app instance with command-line option)
  • Loading branch information
Steven Silvester committed Apr 15, 2020
2 parents 4004493 + 877b285 commit ac891bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dev_mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ function main() {
register.forEach(function(item) { lab.registerPluginModule(item); });
lab.start({ ignorePlugins: ignorePlugins });

// Expose global lab instance when in dev mode.
if ((PageConfig.getOption('devMode') || '').toLowerCase() === 'true') {
window.lab = lab;
// Expose global app instance when in dev mode or when toggled explicitly.
var exposeAppInBrowser = (PageConfig.getOption('exposeAppInBrowser') || '').toLowerCase() === 'true';
var devMode = (PageConfig.getOption('devMode') || '').toLowerCase() === 'true';

if (exposeAppInBrowser || devMode) {
window.jupyterlab = lab;
}

// Handle a browser test.
Expand Down
1 change: 1 addition & 0 deletions jupyterlab/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def load_jupyter_server_extension(nbapp):
# Client-side code assumes notebookVersion is a JSON-encoded string
# TODO: fix this when we can make such a change
page_config['notebookVersion'] = dumps(version_info)
page_config['exposeAppInBrowser'] = getattr(nbapp, 'expose_app_in_browser', False)

if nbapp.file_to_run and type(nbapp).__name__ == "LabApp":
relpath = os.path.relpath(nbapp.file_to_run, nbapp.notebook_dir)
Expand Down
7 changes: 7 additions & 0 deletions jupyterlab/labapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ def start(self):
{'LabApp': {'watch': True}},
"Start the app in watch mode."
)
lab_flags['expose-app-in-browser'] = (
{'LabApp': {'expose_app_in_browser': True}},
"Expose the global app instance to browser via window.jupyterlab"
)


class LabApp(NotebookApp):
Expand Down Expand Up @@ -400,6 +404,9 @@ class LabApp(NotebookApp):
watch = Bool(False, config=True,
help="Whether to serve the app in watch mode")

expose_app_in_browser = Bool(False, config=True,
help="Whether to expose the global app instance to browser via window.jupyterlab")

def init_webapp(self, *args, **kwargs):
super().init_webapp(*args, **kwargs)
settings = self.web_app.settings
Expand Down

0 comments on commit ac891bc

Please sign in to comment.