Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open ExtensionApps at extension's landing page #113

Merged
merged 2 commits into from
Oct 9, 2019

Conversation

Zsailer
Copy link
Member

@Zsailer Zsailer commented Oct 8, 2019

Three things have changed:

  1. ExtensionApp patches the server's browser-open file and open at the extension's default_url. This logic only applies when the extension is launched directly (not loaded using the ServerApp.load_server_extensions() method).

  2. ExtensionApp patches the server's display_url (what's shown in the terminal when you launch) by overwriting the custom_display_url trait of the server.

  3. URLS in the ServerApp are constructed using urllib. Provides a cleaner way to construct/deconstruct urls.

Copy link
Contributor

@rolweber rolweber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rolweber rolweber merged commit fd1ecc0 into jupyter-server:master Oct 9, 2019
Copy link
Member

@vidartf vidartf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think merging stuff in less than 24h is a bit of an anti-pattern. See some comments below :)

self.serverapp.open_browser = True
# Hijack the server's browser-open file to land on
# the extensions home page.
self.serverapp._write_browser_open_file = self._write_browser_open_file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the wrong way to accomplish this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe. Let me explain what my reason:

I found two ways for an extension to reroute the server landing page.

  1. Change the server's default_url and have it land on the extension. There were two challenges with this approach:
    • The server's default_url needs to be set to <extension>.default_url before the server.initialize() is called, otherwise we have to change a bunch of downstream trails of default_url in serverapp. The issue is that <extension>.default_url doesn't get set until after server is initialized.
    • The server's default_url truly is a different trait than the extension's default_url. In my mind, they could/should point to two different urls (though, I don't have an example of when someone might want to do this right now).
  2. Change the server's browser open file. I chose this approach because:
    • The server doesn't open a browser window by default, anyways. In fact, a browser window doesn't really make sense without an ExtensionApp.
    • This file is only created if the server was started by an extension. In that case, I think it makes sense that the server's browser file always opens to the extension's homepage.
    • The ServerApp.default_url and ExtensionApp.default_url can be pointing to different URLs (maybe a plus?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I wrote "wrong way', I meant to overwrite a protected method on the app. This is basically monkey-patching, and it means that there isn't really a clear API boundary between the two objects.

path = url_path_join(self.base_url, self.default_url)
# Build query string.
if self.token:
token = urllib.parse.urlencode({'token': token})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably raise an error if token is None or default to '...'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if token is actually None, though?

Before this PR, token=None returned a url without a token. This PR maintains that pattern. Do we always want to require a token and change previous behavior in the PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I missed your actual point... 🤦‍♂

Yes, this will return token=None in the url. Good catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional should be if token, not if self.token. That was a typo.

ie.

if token:
    token = urllib.parse.urlencode({'token': token})

There are cases where we don't want the token, for example in self.connection_url.

"""Build a url for the application.
"""
if not ip:
ip = self.ip
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably raise if not self.ip, or default to localhost.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"""URL to display to the user."""
# Get url from server.
url = url_path_join(self.serverapp.base_url, self.default_url)
return self.serverapp.get_url(self.serverapp.ip, url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this fail if self.token is truthy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #115, this returns a url without a token. That's what we want here. The display_url property adds a token to custom_display_url.

@rolweber
Copy link
Contributor

rolweber commented Oct 9, 2019

Fair enough... I'll give others more time to review before merging in the future :-)

@Zsailer Zsailer mentioned this pull request Oct 9, 2019
@Zsailer Zsailer deleted the frontends branch January 10, 2020 17:35
Zsailer added a commit to Zsailer/jupyter_server that referenced this pull request Nov 18, 2022
* move deployment pieces here

* ignore deployment in check manifest

* add deployment directory to ignored check-manifest list

* blend publishing step

* remove blend

* bad yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants