jupyter-book
jupyter-book copied to clipboard
Launching Binder from jupyterbook via gitlab repo causes error, URL not read correctly
Describe the bug
context I am trying to start binder from a jupyterbook, having provided the url in the config.yml, but binder doesn’t recognize the repo this way - it displays the colon (and only the colon) encoded so I suspect there might be some issue with that? Curiously, if I manually start a binder from repo directly via mybinder.org everything works just fine.
The repo url is: https://gitlab.gwdg.de/jmschmitz/abm-compendium-jupyterbook
Maybe the problem lies with the gitlab instance the repo is hosted on. When I pass a github repo in the config.yml, the binder integration also works fine. So only the gitlab url is read/passed on incorrectly.
See error log below.
expectation Start binder from jupyterbook with url given in config.yml, binder reads the url exactly as given in config, finds repo, launches binder
bug Start binder from jupyterbook with exact url given in config.yml, binder reads the url but with "%3A" instead of ":", fails to find repo, throws error
Error log from mybinder.org reads as follows:
Error resolving ref for git:https%3A//gitlab.gwdg.de/jmschmitz/abm-compendium-jupyterbook/main: Unable to run git ls-remote to get the resolved_ref: ssh: Could not resolve hostname https: Name or service not known fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
problem
This is a problem for people using gitlab (if that is the source of the problem) wanting to host built jupyterbooks on their website which users can directly interact with, without needing to download/build the book themselves.
This is how it looks like for the users of our website: https://modelsen.mpiwg-berlin.mpg.de/jupyterbooks/book/abmintro/
Reproduce the bug
- Use this repo and build the jupyterbook
- Go to chapter "Mesatutorial", subchapter "Introduction to mesa"
- Click rocket symbol/"binder" to launch binder instance of the repo
- See error
List your environment
OS: MacOS
Version(s): 11.6.1
Thanks for opening your first issue here! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.
If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).
Welcome to the EBP community! :tada:
Same for me. The / in the repo url aren't encoded correctly. The Binder link generated by jb is https://mybinder.org/v2/git/https%3A//gitlab.mydomain.de/username/reponame/main?urlpath=lab/tree/something.ipynb, but should be https://mybinder.org/v2/git/https%3A%2F%2Fgitlab.mydomain.de%2Fusername%2Freponame/main?urlpath=lab/tree/something.ipynb. The latter works as expected.
GitLab repos get special treatment in sphinx_book_theme (use %2F instead of /): https://github.com/executablebooks/sphinx-book-theme/blob/b0f7a35534e82a820720faf0a4738aa1a16d2ee1/src/sphinx_book_theme/header_buttons/launch.py#L128
But custom GitLab instances are handled as generic git repos without this special treatment: https://github.com/executablebooks/sphinx-book-theme/blob/b0f7a35534e82a820720faf0a4738aa1a16d2ee1/src/sphinx_book_theme/header_buttons/launch.py#L123
The quote function there does not quote / by default. Passing extra safe="" quotes /, too. This solves the problem.
The dirty way to implement this workaround:
- Open
your_python_env_path/lib/python3.12/site-packages/sphinx_book_theme/header_buttons/launch.py. - In line 125 replace
quote(repo_url)byquote(repo_url, safe=""). - Rebuild your books's HTML.
Each update to your packages will remove this workaround.