Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 17 additions & 7 deletions datalad_catalog/catalog/assets/app_component_dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const datasetView = () =>
}
// Show / hide binder button: if disp_dataset.url exists OR if dataset has a notebook specified in metadata
disp_dataset.show_binder_button = false
if ( disp_dataset.url || disp_dataset.hasOwnProperty("notebooks") && disp_dataset.notebooks.length > 0 ) {
if ( disp_dataset.url || dataset.hasOwnProperty("notebooks") && dataset.notebooks.length > 0 ) {
disp_dataset.show_binder_button = true
}

Expand Down Expand Up @@ -754,29 +754,39 @@ const datasetView = () =>
window.open(url);
},
openWithBinder(dataset_url, current_dataset) {
const environment_url =
var environment_url =
"https://mybinder.org/v2/gh/datalad/datalad-binder/main";
var content_url = "https://github.com/jsheunis/datalad-notebooks";
var content_repo_name = "datalad-notebooks";
var notebook_name = "download_data_with_datalad_python.ipynb";
var has_custom_notebook = false;
if (current_dataset.hasOwnProperty("notebooks") && current_dataset.notebooks.length > 0) {
// until including the functionality to select from multiple notebooks in a dropdown, just select the first one
has_custom_notebook = true
notebook = current_dataset.notebooks[0]
content_url = notebook.git_repo_url.replace(".git", "")
content_repo_name = content_url.substring(content_url.lastIndexOf('/') + 1)
notebook_name = notebook.notebook_path
notebook_name = escapeHTML(notebook.notebook_path)
if (notebook.hasOwnProperty("binder_env_url") && notebook["binder_env_url"]) {
environment_url = notebook["binder_env_url"]
}
}

binder_url =
environment_url +
"?urlpath=git-pull%3Frepo%3D" +
content_url +
"%26urlpath%3Dnotebooks%252F" +
content_repo_name +
"%252F" +
notebook_name +
"%3Frepourl%3D%22" +
dataset_url +
"%22";
notebook_name;
Comment on lines +770 to +782
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you are trying to do too much here, and end up being too restrictive.

AFAIK, the ?urlpath=git-pull and probably the following bits come from nbgitpuller, which pulls the notebook into the defined environment. This is in general considered good practice (because changing just the notebook does not necessitate binder container rebuild), but what if I have my binder link ready and do not want to use the nbgitpuller?

I do not fully parse the other components at the moment, but it looks like there may be further assumptions.

In my current example, I have a repo with environment and notebook. I generated the Binder URL (https://mybinder.org/v2/gh/sfb1451/rostami_etal_2024-demo/HEAD?labpath=Demo.ipynb) with the help of https://mybinder.org/. If I were more familiar with nbgitpuller and wanted to use it, I would probably be able to generate a matching URL too.

So... why not just have a metadata property for Binder URL?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree with your observations, and I'd add that I think both should be an option, i.e.:

  • have a metadata property on the dataset schema that allows to specify a fully self-contained binder url, which would open an environment that contains the relevant notebook(s)
  • have the property on a per-notebook level as proposed in this PR.


if (!has_custom_notebook) {
binder_url = binder_url +
"%3Frepourl%3D%22" +
dataset_url +
"%22"
}
window.open(binder_url);
},
sortByName() {
Expand Down
4 changes: 4 additions & 0 deletions datalad_catalog/catalog/assets/app_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,7 @@ function pruneObject(obj) {
return newObj;
}


function escapeHTML(str){
return new Option(str).innerHTML;
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,12 @@
}
}
}
],
"notebooks": [
{
"git_repo_url": "https://github.com/mcnakhaee/palmerpenguins",
"notebook_path": "notebooks/example.ipynb",
"binder_env_url": "https://mybinder.org/v2/gh/datalad/datalad-binder/enhs"
}
]
}
5 changes: 5 additions & 0 deletions datalad_catalog/catalog/schema/jsonschema_dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@
"description": "The path to the notebook, relative to the repository root, including the filename and extension",
"title": "Notebook path",
"type": "string"
},
"binder_env_url": {
"description": "The URL to a myBinder base environment that is built up by specifying a git repository URL and branch/tag name, see https://mybinder.org. The public repository should contain the Binder environment configuration as specified by https://mybinder.readthedocs.io/en/latest/using/config_files.html#. An example: https://mybinder.org/v2/gh/datalad/datalad-binder/main",
"title": "Binder repo URL",
"type": "string"
}
},
"required": ["git_repo_url", "notebook_path"]
Expand Down
1 change: 1 addition & 0 deletions datalad_catalog/tests/test_schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"top_display": [{"name": "", "value": ""}],
"notebooks": [
{
"binder_env_url": "",
"git_repo_url": "",
"notebook_path": "",
},
Expand Down