Skip to content

Commit

Permalink
properly tag the new files
Browse files Browse the repository at this point in the history
  • Loading branch information
shibbas authored and jonsequitur committed Oct 25, 2022
1 parent f9d7cd5 commit 4aed351
Show file tree
Hide file tree
Showing 52 changed files with 1,725 additions and 1,673 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,70 @@
using Microsoft.DotNet.Interactive.Jupyter.Http;
using Microsoft.DotNet.Interactive.Jupyter.ZMQ;

namespace Microsoft.DotNet.Interactive.Jupyter
namespace Microsoft.DotNet.Interactive.Jupyter;

public class ConnectJupyterKernelCommand : ConnectKernelCommand
{
public class ConnectJupyterKernelCommand : ConnectKernelCommand
public ConnectJupyterKernelCommand() : base("jupyter",
"Connects to a installed jupyter kernel")
{
public ConnectJupyterKernelCommand() : base("jupyter",
"Connects to a installed jupyter kernel")
{
AddOption(KernelType);
AddOption(TargetUrl);
AddOption(Token);
AddOption(UseBearerAuth);
}

public Option<string> KernelType { get; } =
new("--kernel-spec", "The kernel spec to connect to")
{
IsRequired = true
};

public Option<string> TargetUrl { get; } =
new("--url", "URl to connect to the jupyter server")
{
};
AddOption(KernelType);
AddOption(TargetUrl);
AddOption(Token);
AddOption(UseBearerAuth);
}

public Option<string> Token { get; } =
new("--token", "token to connect to the jupyter server")
{
};
public Option<string> KernelType { get; } =
new("--kernel-spec", "The kernel spec to connect to")
{
IsRequired = true
};

public Option<bool> UseBearerAuth { get; } =
new("--bearer", "auth type is bearer token")
{
};
public Option<string> TargetUrl { get; } =
new("--url", "URl to connect to the jupyter server")
{
};

public override async Task<Kernel> ConnectKernelAsync(
KernelInvocationContext context,
InvocationContext commandLineContext)
{
var kernelType = commandLineContext.ParseResult.GetValueForOption(KernelType);
var targetUrl = commandLineContext.ParseResult.GetValueForOption(TargetUrl);
var token = commandLineContext.ParseResult.GetValueForOption(Token);
var useBearerAuth = commandLineContext.ParseResult.GetValueForOption(UseBearerAuth);
public Option<string> Token { get; } =
new("--token", "token to connect to the jupyter server")
{
};

JupyterKernelConnector connector = null;
public Option<bool> UseBearerAuth { get; } =
new("--bearer", "auth type is bearer token")
{
};

CompositeDisposable disposables = new CompositeDisposable();
if (targetUrl is not null)
{
var connection = new JupyterHttpConnection(new Uri(targetUrl), token, useBearerAuth ? AuthType.Bearer : null);
connector = new JupyterKernelConnector(connection, kernelType);
disposables.Add(connection);
}
else
{
var connection = new LocalJupyterConnection();
connector = new JupyterKernelConnector(connection, kernelType);
disposables.Add(connection);
}
public override async Task<Kernel> ConnectKernelAsync(
KernelInvocationContext context,
InvocationContext commandLineContext)
{
var kernelType = commandLineContext.ParseResult.GetValueForOption(KernelType);
var targetUrl = commandLineContext.ParseResult.GetValueForOption(TargetUrl);
var token = commandLineContext.ParseResult.GetValueForOption(Token);
var useBearerAuth = commandLineContext.ParseResult.GetValueForOption(UseBearerAuth);

var localName = commandLineContext.ParseResult.GetValueForOption(KernelNameOption);
JupyterKernelConnector connector = null;

var kernel = await connector?.CreateKernelAsync(localName);
kernel?.RegisterForDisposal(disposables);
return kernel;
CompositeDisposable disposables = new CompositeDisposable();
if (targetUrl is not null)
{
var connection = new JupyterHttpConnection(new Uri(targetUrl), token, useBearerAuth ? AuthType.Bearer : null);
connector = new JupyterKernelConnector(connection, kernelType);
disposables.Add(connection);
}
else
{
var connection = new LocalJupyterConnection();
connector = new JupyterKernelConnector(connection, kernelType);
disposables.Add(connection);
}

var localName = commandLineContext.ParseResult.GetValueForOption(KernelNameOption);

var kernel = await connector?.CreateKernelAsync(localName);
kernel?.RegisterForDisposal(disposables);
return kernel;
}

}
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
using Microsoft.DotNet.Interactive.Commands;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Jupyter.Messaging;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.Jupyter.Connection
namespace Microsoft.DotNet.Interactive.Jupyter.Connection;

internal abstract class CommandToJupyterMessageHandlerBase<TCommand> : IKernelCommandToMessageHandler<TCommand> where TCommand: KernelCommand
{
internal abstract class CommandToJupyterMessageHandlerBase<TCommand> : IKernelCommandToMessageHandler<TCommand> where TCommand: KernelCommand
{
private readonly IMessageSender _sender;
private readonly IMessageReceiver _receiver;
private readonly IMessageSender _sender;
private readonly IMessageReceiver _receiver;

public CommandToJupyterMessageHandlerBase(IMessageSender sender, IMessageReceiver reciever)
{
_receiver = reciever;
_sender = sender;
}
public CommandToJupyterMessageHandlerBase(IMessageSender sender, IMessageReceiver reciever)
{
_receiver = reciever;
_sender = sender;
}

protected IMessageReceiver Receiver => _receiver;
protected IMessageReceiver Receiver => _receiver;

protected IMessageSender Sender => _sender;
protected IMessageSender Sender => _sender;

public abstract Task HandleCommandAsync(TCommand command, ICommandExecutionContext context, CancellationToken token);
}
public abstract Task HandleCommandAsync(TCommand command, ICommandExecutionContext context, CancellationToken token);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using Microsoft.DotNet.Interactive.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Microsoft.DotNet.Interactive.Jupyter.Connection
using Microsoft.DotNet.Interactive.Events;

namespace Microsoft.DotNet.Interactive.Jupyter.Connection;

internal interface ICommandExecutionContext
{
internal interface ICommandExecutionContext
{
void Publish(KernelEvent kernelEvent);
}
void Publish(KernelEvent kernelEvent);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using Microsoft.DotNet.Interactive.Jupyter.Messaging;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Jupyter.Messaging;
using System;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.Jupyter.Connection
namespace Microsoft.DotNet.Interactive.Jupyter.Connection;

public interface IJupyterConnection : IDisposable
{
public interface IJupyterConnection : IDisposable
{
Uri TargetUri { get; }
Uri TargetUri { get; }

Task<IJupyterKernelConnection> CreateKernelConnectionAsync(string kernelSpec);
}
Task<IJupyterKernelConnection> CreateKernelConnectionAsync(string kernelSpec);
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Microsoft.DotNet.Interactive.Jupyter.Messaging;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Jupyter.Messaging;
using System;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.Jupyter.Connection
namespace Microsoft.DotNet.Interactive.Jupyter.Connection;

public interface IJupyterKernelConnection : IDisposable
{
public interface IJupyterKernelConnection : IDisposable
{
Task StartAsync();
Task StartAsync();

IMessageSender Sender { get; }
IMessageSender Sender { get; }

IMessageReceiver Receiver { get; }
}
IMessageReceiver Receiver { get; }
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using Microsoft.DotNet.Interactive.Commands;
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.DotNet.Interactive.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.Jupyter.Connection
namespace Microsoft.DotNet.Interactive.Jupyter.Connection;

internal interface IKernelCommandToMessageHandler<TCommand> where TCommand: KernelCommand
{
internal interface IKernelCommandToMessageHandler<TCommand> where TCommand: KernelCommand
{
Task HandleCommandAsync(TCommand command, ICommandExecutionContext context, CancellationToken token);
}
Task HandleCommandAsync(TCommand command, ICommandExecutionContext context, CancellationToken token);
}
Loading

0 comments on commit 4aed351

Please sign in to comment.