Skip to content

Commit c08d5db

Browse files
authored
Merge pull request #1383 from minrk/detect-lab-default
lab default only if available, change `filepath` definition
2 parents a5aca2c + 242bf46 commit c08d5db

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

binderhub/main.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@ async def get(self, provider_prefix, _unescaped_spec):
7070
nbviewer_url = 'https://nbviewer.jupyter.org/github'
7171
org, repo_name, ref = spec.split('/', 2)
7272
# NOTE: tornado unquotes query arguments too -> notebooks%2Findex.ipynb becomes notebooks/index.ipynb
73-
filepath = self.get_argument('filepath', '').lstrip('/')
73+
filepath = self.get_argument("labpath", "").lstrip("/")
74+
if not filepath:
75+
filepath = self.get_argument('filepath', '').lstrip('/')
7476

75-
# Check if we have a JupyterLab + file path, if so then use it for the filepath
77+
78+
# Check the urlpath parameter for a file path, if so use it for the filepath
7679
urlpath = self.get_argument('urlpath', '').lstrip('/')
77-
if urlpath.startswith("lab") and "/tree/" in urlpath:
80+
if urlpath and "/tree/" in urlpath:
7881
filepath = urlpath.split('tree/', 1)[-1]
7982

8083
blob_or_tree = 'blob' if filepath else 'tree'

binderhub/static/js/index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,14 @@ function loadingMain(providerSpec) {
346346
if (path) {
347347
pathType = 'url';
348348
} else {
349-
path = params.get('filepath');
349+
path = params.get('labpath');
350350
if (path) {
351-
pathType = 'file';
351+
pathType = 'lab';
352+
} else {
353+
path = params.get('filepath');
354+
if (path) {
355+
pathType = 'file';
356+
}
352357
}
353358
}
354359
build(providerSpec, log, fitAddon, path, pathType);

binderhub/static/js/src/image.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ export default class BinderImage {
4949
url = url.replace(/\/$/, "");
5050
// trim leading '/'
5151
path = path.replace(/(^\/)/g, "");
52-
if (pathType === "file") {
52+
if (pathType === "lab") {
5353
// trim trailing / on file paths
5454
path = path.replace(/(\/$)/g, "");
5555
// /doc/tree is safe because it allows redirect to files
5656
url = url + "/doc/tree/" + encodeURI(path);
57+
} else if (pathType === "file") {
58+
// trim trailing / on file paths
59+
path = path.replace(/(\/$)/g, "");
60+
// /tree is safe because it allows redirect to files
61+
url = url + "/tree/" + encodeURI(path);
5762
} else {
5863
// pathType === 'url'
5964
url = url + "/" + path;

binderhub/static/js/src/path.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
export function getPathType() {
22
// return path type. 'file' or 'url'
33
const element = document.getElementById("url-or-file-selected");
4-
return element.innerText.trim().toLowerCase();
4+
let pathType = element.innerText.trim().toLowerCase();
5+
if (pathType === "file") {
6+
// selecting a 'file' in the form opens with jupyterlab
7+
// avoids backward-incompatibility with old `filepath` urls,
8+
// which still open old UI
9+
pathType = "lab";
10+
}
11+
return pathType;
512
}
613

714
export function updatePathText() {

helm-chart/binderhub/values.yaml

+23-5
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,29 @@ jupyterhub:
188188
admin: true
189189
apiToken:
190190
singleuser:
191-
# start jupyter notebook for the server
192-
cmd: jupyter-notebook
193-
# use jupyterlab for the default UI
194-
defaultUrl: /lab
191+
# start notebook server with lab ui as default
192+
# *if available*
193+
cmd:
194+
- python3
195+
- "-c"
196+
- |
197+
import os
198+
import sys
199+
200+
try:
201+
import jupyterlab
202+
major = int(jupyterlab.__version__.split(".", 1)[0])
203+
except Exception:
204+
have_lab = False
205+
else:
206+
have_lab = major >= 3
207+
208+
if have_lab and "NotebookApp.default_url" not in " ".join(sys.argv):
209+
# if recent-enough lab is available, make it the default UI
210+
sys.argv.insert(1, "--NotebookApp.default_url=/lab/")
211+
212+
# launch the notebook server
213+
os.execvp("jupyter-notebook", sys.argv)
195214
events: false
196215
storage:
197216
type: none
@@ -282,4 +301,3 @@ podAnnotations: {}
282301

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

0 commit comments

Comments
 (0)