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

Add Lightning Studio Launch Button #851

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"binderhub_url": "https://mybinder.org",
"colab_url": "https://colab.research.google.com/",
"deepnote_url": "https://deepnote.com/",
"lightning_studio_url": "https://lightning.ai/",
"notebook_interface": "jupyterlab",
"thebe": True,
# "jupyterhub_url": "https://datahub.berkeley.edu", # For testing
Expand Down
16 changes: 16 additions & 0 deletions docs/content/launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ html_theme_options = {
This will create a new Deepnote project every time you click the launch button.
```

## Lightning Studio

To add [Ligthning Studio](https://lightning.ai) links to your page, add the following configuration:
agoose77 marked this conversation as resolved.
Show resolved Hide resolved


```python
html_theme_options = {
...
"launch_buttons": {
"lightning_studio_url": "https://lightning.ai"
},
...
}
```



## Live code cells with Thebe

Expand Down
17 changes: 17 additions & 0 deletions src/sphinx_book_theme/header_buttons/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def add_launch_buttons(
binderhub_url = launch_buttons.get("binderhub_url", "").strip("/")
colab_url = launch_buttons.get("colab_url", "").strip("/")
deepnote_url = launch_buttons.get("deepnote_url", "").strip("/")
lightning_studio_url = launch_buttons.get("lightning_studio_url", "").strip("/")

# Loop through each provider and add a button for it if needed
if binderhub_url:
Expand Down Expand Up @@ -189,6 +190,22 @@ def add_launch_buttons(
}
)

if lightning_studio_url:
if provider.lower() != "github":
SPHINX_LOGGER.warning(f"Provider {provider} not supported on Lightning.")
else:
github_path = f"%2F{org}%2F{repo}%2Fblob%2F{branch}%2F{path_rel_repo}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we probably need to URL escape these.

Copy link
Author

Choose a reason for hiding this comment

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

@agoose77 is the latest commit what you were looking for? At least the tests seem to pass again. Let me know if I need to change something else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @nilsleh not quite -- I'm worried about the case where org, repo, branch, or path_rel_repo aren't URL escaped properly.

Equally, it's something that the other launchers would need to worry about, so I'll just merge for now!

url = f"{lightning_studio_url}/new?repo_url=https://github.com{github_path}"
agoose77 marked this conversation as resolved.
Show resolved Hide resolved
launch_buttons_list.append(
{
"type": "link",
"text": "Lightning Studio",
"tooltip": translation("Launch on") + " Lightning Studio",
"icon": "_static/images/logo_lightning_studio.svg",
"url": url,
}
)

# Add thebe flag in context
if launch_buttons.get("thebe", False):
launch_buttons_list.append(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/sites/base/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jupyterhub_url": "https://datahub.berkeley.edu",
"colab_url": "https://colab.research.google.com",
"deepnote_url": "https://deepnote.com",
"lightning_studio_url": "https://lightning.ai/",
"notebook_interface": "jupyterlab",
"thebe": True,
},
Expand Down
10 changes: 10 additions & 0 deletions tests/test_build/build__header-article.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
</span>
</a>
</li>
<li>
<a class="btn btn-sm dropdown-item" data-bs-placement="left" data-bs-toggle="tooltip" href="https://lightning.ai/new?repo_url=https://github.com%2Fexecutablebooks%2Fsphinx-book-theme%2Fblob%2Fmaster%2FTESTPATH/section1/ntbk.ipynb" target="_blank" title="Launch on Lightning Studio">
agoose77 marked this conversation as resolved.
Show resolved Hide resolved
<span class="btn__icon-container">
<img alt="Lighting Studio logo" src="../_static/images/logo_lightning_studio.svg"/>
</span>
<span class="btn__text-container">
Lightning Studio
</span>
</a>
</li>
<li>
<button class="btn btn-sm btn-launch-thebe dropdown-item" data-bs-placement="left" data-bs-toggle="tooltip" onclick="initThebeSBT()" title="Launch Thebe">
<span class="btn__icon-container">
Expand Down
10 changes: 10 additions & 0 deletions tests/test_build/test_header_launchbtns.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
</span>
</a>
</li>
<li>
<a class="btn btn-sm dropdown-item" data-bs-placement="left" data-bs-toggle="tooltip" href="https://lightning.ai/new?repo_url=https://github.com%2Fexecutablebooks%2Fsphinx-book-theme%2Fblob%2Fmaster%2FTESTPATH/section1/ntbk.ipynb" target="_blank" title="Launch on Lightning Studio">
agoose77 marked this conversation as resolved.
Show resolved Hide resolved
<span class="btn__icon-container">
<img alt="Lightning Studio logo" src="../_static/images/logo_lightning_studio.svg"/>
</span>
<span class="btn__text-container">
Lightning Studio
</span>
</a>
</li>
<li>
<button class="btn btn-sm btn-launch-thebe dropdown-item" data-bs-placement="left" data-bs-toggle="tooltip" onclick="initThebeSBT()" title="Launch Thebe">
<span class="btn__icon-container">
Expand Down