Skip to content

Commit

Permalink
Don't assume that resources entries are relative (#1182)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ojarjur and pre-commit-ci[bot] authored Jan 19, 2023
1 parent 3d96cf8 commit bc735a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 9 additions & 6 deletions jupyter_server/gateway/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ def _replace_path_kernelspec_resources(self, kernel_specs):
for resource_name in resources:
original_path = resources[resource_name]
split_eg_base_url = str.rsplit(original_path, sep="/kernelspecs/", maxsplit=1)
new_path = url_path_join(self.parent.base_url, "kernelspecs", split_eg_base_url[1])
kernel_specs["kernelspecs"][kernel_name]["resources"][resource_name] = new_path
if original_path != new_path:
self.log.debug(
f"Replaced original kernel resource path {original_path} with new "
f"path {kernel_specs['kernelspecs'][kernel_name]['resources'][resource_name]}"
if len(split_eg_base_url) > 1:
new_path = url_path_join(
self.parent.base_url, "kernelspecs", split_eg_base_url[1]
)
kernel_specs["kernelspecs"][kernel_name]["resources"][resource_name] = new_path
if original_path != new_path:
self.log.debug(
f"Replaced original kernel resource path {original_path} with new "
f"path {kernel_specs['kernelspecs'][kernel_name]['resources'][resource_name]}"
)
return kernel_specs

def _get_kernelspecs_endpoint_url(self, kernel_name=None):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def generate_kernelspec(name):
kernelspec_stanza = {
"name": name,
"spec": spec_stanza,
"resources": {"logo-64x64": f"f/kernelspecs/{name}/logo-64x64.png"},
"resources": {
"logo-64x64": f"f/kernelspecs/{name}/logo-64x64.png",
"url": "https://example.com/example-url",
},
}
return kernelspec_stanza

Expand Down

0 comments on commit bc735a1

Please sign in to comment.