Skip to content

Commit

Permalink
Merge pull request #1383 from minrk/detect-lab-default
Browse files Browse the repository at this point in the history
lab default only if available, change `filepath` definition
  • Loading branch information
consideRatio authored Sep 24, 2021
2 parents a5aca2c + 242bf46 commit c08d5db
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
9 changes: 6 additions & 3 deletions binderhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ async def get(self, provider_prefix, _unescaped_spec):
nbviewer_url = 'https://nbviewer.jupyter.org/github'
org, repo_name, ref = spec.split('/', 2)
# NOTE: tornado unquotes query arguments too -> notebooks%2Findex.ipynb becomes notebooks/index.ipynb
filepath = self.get_argument('filepath', '').lstrip('/')
filepath = self.get_argument("labpath", "").lstrip("/")
if not filepath:
filepath = self.get_argument('filepath', '').lstrip('/')

# Check if we have a JupyterLab + file path, if so then use it for the filepath

# Check the urlpath parameter for a file path, if so use it for the filepath
urlpath = self.get_argument('urlpath', '').lstrip('/')
if urlpath.startswith("lab") and "/tree/" in urlpath:
if urlpath and "/tree/" in urlpath:
filepath = urlpath.split('tree/', 1)[-1]

blob_or_tree = 'blob' if filepath else 'tree'
Expand Down
9 changes: 7 additions & 2 deletions binderhub/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,14 @@ function loadingMain(providerSpec) {
if (path) {
pathType = 'url';
} else {
path = params.get('filepath');
path = params.get('labpath');
if (path) {
pathType = 'file';
pathType = 'lab';
} else {
path = params.get('filepath');
if (path) {
pathType = 'file';
}
}
}
build(providerSpec, log, fitAddon, path, pathType);
Expand Down
7 changes: 6 additions & 1 deletion binderhub/static/js/src/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ export default class BinderImage {
url = url.replace(/\/$/, "");
// trim leading '/'
path = path.replace(/(^\/)/g, "");
if (pathType === "file") {
if (pathType === "lab") {
// trim trailing / on file paths
path = path.replace(/(\/$)/g, "");
// /doc/tree is safe because it allows redirect to files
url = url + "/doc/tree/" + encodeURI(path);
} else if (pathType === "file") {
// trim trailing / on file paths
path = path.replace(/(\/$)/g, "");
// /tree is safe because it allows redirect to files
url = url + "/tree/" + encodeURI(path);
} else {
// pathType === 'url'
url = url + "/" + path;
Expand Down
9 changes: 8 additions & 1 deletion binderhub/static/js/src/path.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
export function getPathType() {
// return path type. 'file' or 'url'
const element = document.getElementById("url-or-file-selected");
return element.innerText.trim().toLowerCase();
let pathType = element.innerText.trim().toLowerCase();
if (pathType === "file") {
// selecting a 'file' in the form opens with jupyterlab
// avoids backward-incompatibility with old `filepath` urls,
// which still open old UI
pathType = "lab";
}
return pathType;
}

export function updatePathText() {
Expand Down
28 changes: 23 additions & 5 deletions helm-chart/binderhub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,29 @@ jupyterhub:
admin: true
apiToken:
singleuser:
# start jupyter notebook for the server
cmd: jupyter-notebook
# use jupyterlab for the default UI
defaultUrl: /lab
# start notebook server with lab ui as default
# *if available*
cmd:
- python3
- "-c"
- |
import os
import sys
try:
import jupyterlab
major = int(jupyterlab.__version__.split(".", 1)[0])
except Exception:
have_lab = False
else:
have_lab = major >= 3
if have_lab and "NotebookApp.default_url" not in " ".join(sys.argv):
# if recent-enough lab is available, make it the default UI
sys.argv.insert(1, "--NotebookApp.default_url=/lab/")
# launch the notebook server
os.execvp("jupyter-notebook", sys.argv)
events: false
storage:
type: none
Expand Down Expand Up @@ -282,4 +301,3 @@ podAnnotations: {}

# Deprecated values, kept here so we can provide useful error messages
cors: {}

0 comments on commit c08d5db

Please sign in to comment.