Skip to content
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

Add Preview info on #!connect jupyter command #2894

Merged
merged 5 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class ConnectJupyterKernelCommand : ConnectKernelCommand
private KeyValuePair<int, IEnumerable<CompletionItem>> _mruKernelSpecSuggestions;

public ConnectJupyterKernelCommand() : base("jupyter",
"Connects to a jupyter kernel")
"Connects to a jupyter kernel. This feature is in preview.")
{
AddOption(InitScript);
AddOption(KernelSpecName.AddCompletions(ctx => GetKernelSpecsCompletions(ctx)));
AddOption(InitScript);
}

public Option<string> KernelSpecName { get; } =
Expand Down Expand Up @@ -52,6 +52,10 @@ public override async Task<Kernel> ConnectKernelAsync(
KernelInvocationContext context,
InvocationContext commandLineContext)
{
context.DisplayAs(
"The `#!connect jupyter` feature is in preview. Please report any feedback or issues at https://github.com/dotnet/interactive/issues/new/choose.",
"text/markdown");

var kernelSpecName = commandLineContext.ParseResult.GetValueForOption(KernelSpecName);
var initScript = commandLineContext.ParseResult.GetValueForOption(InitScript);

Expand All @@ -60,7 +64,7 @@ public override async Task<Kernel> ConnectKernelAsync(
{
throw new InvalidOperationException("No supported connection options were specified");
}

JupyterKernelConnector connector = new JupyterKernelConnector(connection, kernelSpecName, initScript);

var localName = commandLineContext.ParseResult.GetValueForOption(KernelNameOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ public sealed class JupyterHttpKernelConnectionOptions : IJupyterKernelConnectio
private readonly IReadOnlyCollection<Option> _options;

public Option<string> TargetUrl { get; } =
new("--url", "URl to connect to the jupyter server")
new("--url", "URL to connect to a remote jupyter server")
{
};

public Option<string> Token { get; } =
new("--token", "token to connect to the jupyter server")
new("--token", "token to connect to a remote jupyter server")
{
};

private Option<bool> UseBearerAuth { get; } =
new("--bearer", "auth type is bearer token")
new("--bearer", "auth type is bearer token for remote jupyter server")
{
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using System.Linq;
using Microsoft.DotNet.Interactive.Formatting;
using System;

namespace Microsoft.DotNet.Interactive.Jupyter;

Expand Down Expand Up @@ -36,18 +37,26 @@ public Task<CommandLineResult> InstallKernel(DirectoryInfo sourceDirectory)

public async Task<IReadOnlyDictionary<string, KernelSpec>> ListKernels()
{
var kernelSpecsList = await ExecuteCommand("list", "--json");
if (kernelSpecsList.ExitCode == 0)
try
{
var results = JsonSerializer.Deserialize<KernelSpecListCommandResults>(string.Join(string.Empty, kernelSpecsList.Output));
return results.kernelspecs?.ToDictionary(r => r.Key, r =>
var kernelSpecsList = await ExecuteCommand("list", "--json");
if (kernelSpecsList.ExitCode == 0)
{
var spec = r.Value?.spec;
spec.Name ??= r.Key;
return spec;
});
var results = JsonSerializer.Deserialize<KernelSpecListCommandResults>(string.Join(string.Empty, kernelSpecsList.Output));
return results.kernelspecs?.ToDictionary(r => r.Key, r =>
{
var spec = r.Value?.spec;
spec.Name ??= r.Key;
return spec;
});
}
else
{
// fall back to custom lookup logic
return LookupInstalledKernels();
}
}
else
catch (Exception)
shibbas marked this conversation as resolved.
Show resolved Hide resolved
{
// fall back to custom lookup logic
return LookupInstalledKernels();
Expand Down