-
Notifications
You must be signed in to change notification settings - Fork 408
updates for Microsoft.DotNet.Interactive.Documents API stabilization #3169
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
Changes from all commits
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 |
---|---|---|
|
@@ -65,7 +65,7 @@ public async IAsyncEnumerable<InteractiveDocument> GetImportsAsync(bool recursiv | |
{ | ||
EnsureImportFieldParserIsInitialized(); | ||
|
||
if (!TryGetKernelInfoFromMetadata(Metadata, out var kernelInfos)) | ||
if (!TryGetKernelInfosFromMetadata(out var kernelInfos)) | ||
{ | ||
kernelInfos = new(); | ||
} | ||
|
@@ -198,7 +198,7 @@ public static async Task<InteractiveDocument> LoadAsync( | |
|
||
public string? GetDefaultKernelName() | ||
{ | ||
if (TryGetKernelInfoFromMetadata(Metadata, out var kernelInfo)) | ||
if (TryGetKernelInfosFromMetadata(Metadata, out var kernelInfo)) | ||
{ | ||
return kernelInfo.DefaultKernelName; | ||
} | ||
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. Why is the public API missing the remaining heuristics (like checking for |
||
|
@@ -208,16 +208,11 @@ public static async Task<InteractiveDocument> LoadAsync( | |
|
||
internal string? GetDefaultKernelName(KernelInfoCollection kernelInfos) | ||
{ | ||
if (TryGetKernelInfoFromMetadata(Metadata, out var kernelInfoCollection)) | ||
if (TryGetKernelInfosFromMetadata(Metadata, out var kernelInfoCollection)) | ||
{ | ||
return kernelInfoCollection.DefaultKernelName; | ||
} | ||
|
||
if (Metadata is null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (Metadata.TryGetValue("kernelspec", out var kernelspecObj)) | ||
{ | ||
if (kernelspecObj is IDictionary<string, object> kernelspecDict) | ||
|
@@ -243,7 +238,7 @@ public static async Task<InteractiveDocument> LoadAsync( | |
|
||
internal static void MergeKernelInfos(InteractiveDocument document, KernelInfoCollection kernelInfos) | ||
{ | ||
if (TryGetKernelInfoFromMetadata(document.Metadata, out var kernelInfoCollection)) | ||
if (TryGetKernelInfosFromMetadata(document.Metadata, out var kernelInfoCollection)) | ||
{ | ||
MergeKernelInfos(kernelInfoCollection, kernelInfos); | ||
} | ||
|
@@ -264,19 +259,23 @@ internal static void MergeKernelInfos(KernelInfoCollection destination, KernelIn | |
destination.AddRange(source.Where(ki => added.Add(ki.Name))); | ||
} | ||
|
||
internal static bool TryGetKernelInfoFromMetadata( | ||
public bool TryGetKernelInfosFromMetadata( | ||
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 seems like a new public API. I don't remember adding this during the sync - was this exposed intentionally? 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. We discussed this during the sync, that there's currently no way to get the kernel info using the public API, and that it's very useful to have. |
||
[NotNullWhen(true)] out KernelInfoCollection? kernelInfos) => | ||
TryGetKernelInfosFromMetadata(Metadata, out kernelInfos); | ||
|
||
internal static bool TryGetKernelInfosFromMetadata( | ||
IDictionary<string, object>? metadata, | ||
[NotNullWhen(true)] out KernelInfoCollection? kernelInfo) | ||
[NotNullWhen(true)] out KernelInfoCollection? kernelInfos) | ||
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. Can this be inlined into the above non-static overload (with all callers switched to calling the non-static overload)? Or can this be made private? Please ignore the above if we have more callers for the static overload outside the current class. 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. The static method has internal callers. |
||
{ | ||
if (metadata is not null) | ||
{ | ||
if (metadata.TryGetValue("kernelInfo", out var kernelInfoObj)) | ||
{ | ||
if (kernelInfoObj is JsonElement kernelInfoJson && | ||
JsonSerializer.Deserialize<KernelInfoCollection>(kernelInfoJson, JsonSerializerOptions) is | ||
kernelInfoJson.Deserialize<KernelInfoCollection>(JsonSerializerOptions) is | ||
{ } kernelInfoDeserialized) | ||
{ | ||
kernelInfo = kernelInfoDeserialized; | ||
kernelInfos = kernelInfoDeserialized; | ||
return true; | ||
} | ||
|
||
|
@@ -319,15 +318,15 @@ internal static bool TryGetKernelInfoFromMetadata( | |
deserializedKernelInfo.Add(new KernelInfo(name, language, aliases)); | ||
} | ||
} | ||
kernelInfo = deserializedKernelInfo; | ||
kernelInfos = deserializedKernelInfo; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
if (kernelInfoObj is KernelInfoCollection kernelInfoCollection) | ||
{ | ||
kernelInfo = kernelInfoCollection; | ||
kernelInfos = kernelInfoCollection; | ||
return true; | ||
} | ||
} | ||
|
@@ -338,17 +337,17 @@ internal static bool TryGetKernelInfoFromMetadata( | |
{ | ||
case KernelInfoCollection kernelInfoCollection: | ||
|
||
kernelInfo = kernelInfoCollection; | ||
kernelInfos = kernelInfoCollection; | ||
return true; | ||
|
||
case IDictionary<string, object> dotnetInteractiveDict: | ||
{ | ||
kernelInfo = new(); | ||
kernelInfos = new(); | ||
|
||
if (dotnetInteractiveDict.TryGetValue("defaultKernelName", out var nameObj) && | ||
nameObj is string name) | ||
{ | ||
kernelInfo.DefaultKernelName = name; | ||
kernelInfos.DefaultKernelName = name; | ||
} | ||
|
||
return true; | ||
|
@@ -364,7 +363,7 @@ internal static bool TryGetKernelInfoFromMetadata( | |
if (kernelspecDict.TryGetValue("language", out var languageObj) && | ||
languageObj is string defaultLanguage) | ||
{ | ||
kernelInfo = new KernelInfoCollection | ||
kernelInfos = new KernelInfoCollection | ||
{ | ||
DefaultKernelName = defaultLanguage | ||
}; | ||
|
@@ -375,7 +374,7 @@ internal static bool TryGetKernelInfoFromMetadata( | |
} | ||
|
||
// check if a KernelInfoCollection was directly serialized into the metadata | ||
kernelInfo = default; | ||
kernelInfos = default; | ||
return false; | ||
} | ||
|
||
|
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.
minor nit: This call uses the public instance overload while others below use the static overload. Could we standardize to the same call?