-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace template string {resource_dir} in kernelspec #932
base: main
Are you sure you want to change the base?
Changes from all commits
1ee82ba
2d1dcdd
8890490
45afcc6
63446c5
d0f740d
8c798fc
b375cfe
67edba9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,19 @@ def is_kernelspec_model(spec_dict): | |
) | ||
|
||
|
||
def update_kernelspec_model(spec_dict): | ||
"""Returns the original kernelspec unless template substitutions are available.""" | ||
model = spec_dict | ||
if "resource_dir" in spec_dict: | ||
spec_str = json.dumps(spec_dict["spec"]) | ||
template_found = "{resource_dir}" in spec_str | ||
resource_dir_exists = os.path.exists(spec_dict["resource_dir"]) | ||
if template_found and resource_dir_exists: | ||
spec_str = spec_str.replace("{resource_dir}", spec_dict["resource_dir"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change will result in the substitution of (I don't see any issue with that but just wanted to make that comment in case others do.) |
||
model["spec"] = json.loads(spec_str) | ||
return model | ||
|
||
|
||
class KernelSpecsAPIHandler(APIHandler): | ||
auth_resource = AUTH_RESOURCE | ||
|
||
|
@@ -73,6 +86,7 @@ async def get(self): | |
kernel_info["spec"], | ||
kernel_info["resource_dir"], | ||
) | ||
d = update_kernelspec_model(d) | ||
except Exception: | ||
self.log.error("Failed to load kernel spec: '%s'", kernel_name, exc_info=True) | ||
continue | ||
|
@@ -95,6 +109,7 @@ async def get(self, kernel_name): | |
model = spec | ||
else: | ||
model = kernelspec_model(self, kernel_name, spec.to_dict(), spec.resource_dir) | ||
model = update_kernelspec_model(model) | ||
self.set_header("Content-Type", "application/json") | ||
self.finish(json.dumps(model)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure when this will be true since it's asking if the kernelspec model contains the key
"resource_dir"
yet, in the models,resource_dir
is used to identify the other resources of the kernel (icon, etc.) and not retained as a key/value. As a result, this logic is probably better suited inkernelspec_model()
directly.I don't think this resource_dir-substitution logic applies to
spec_dict
s that satisfy theis_kernelspec_model()
check because, for those, the water is under the bridge and the resource_dir is not available (nor is it local). The specs returned from a Gateway server are examples of those.