Skip to content

Commit da74935

Browse files
authored
enable connecting to out-of-process kernels over stdio (#1591)
* enable connecting to out-of-process kernels over stdio * update sdk
1 parent e10c9e9 commit da74935

File tree

20 files changed

+198
-445
lines changed

20 files changed

+198
-445
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variables:
1919
- name: _DotNetArtifactsCategory
2020
value: .NETCore
2121
- name: DotNetSdkVersion
22-
value: '5.0.100'
22+
value: '5.0.400'
2323
- name: PocketLoggerLogPath
2424
value: $(Build.SourcesDirectory)/artifacts/log/$(_BuildConfig)
2525
- name: TryDotNetPackagesPath
@@ -385,67 +385,6 @@ stages:
385385
command: build
386386
Dockerfile: "$(Build.SourcesDirectory)/samples/my binder/Dockerfile"
387387

388-
- template: /eng/common/templates/jobs/jobs.yml
389-
parameters:
390-
enableMicrobuild: true
391-
jobs:
392-
- job: IntegrationTest
393-
dependsOn: Windows_NT
394-
condition: and(succeeded(), ne(variables['SkipTests'], 'true'))
395-
pool:
396-
${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
397-
name: NetCorePublic-Pool
398-
queue: BuildPool.Ubuntu.1604.amd64.Open
399-
${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
400-
name: NetCoreInternal-Pool
401-
queue: BuildPool.Ubuntu.1604.amd64
402-
variables:
403-
- name: DOTNET_INTERACTIVE_CLI_TELEMETRY_OPTOUT
404-
value: 1
405-
- name: DOTNET_INTERACTIVE_SKIP_FIRST_TIME_EXPERIENCE
406-
value: 1
407-
# specify tool version on public CI builds
408-
- ${{ if eq(variables['System.TeamProject'], 'public') }}:
409-
- name: ToolVersionArgs
410-
value: --version 1.0.0-ci
411-
# else
412-
- ${{ if ne(variables['System.TeamProject'], 'public') }}:
413-
- name: ToolVersionArgs
414-
value: ''
415-
steps:
416-
- checkout: self
417-
clean: true
418-
- task: UseDotNet@2
419-
displayName: Use .NET SDK 5.0
420-
inputs:
421-
packageType: sdk
422-
version: $(DotNetSdkVersion)
423-
installationPath: $(Agent.ToolsDirectory)/dotnet
424-
- task: DownloadBuildArtifacts@0
425-
displayName: Download built packages
426-
inputs:
427-
artifactName: packages
428-
downloadPath: $(Build.ArtifactStagingDirectory)
429-
- script: echo "<configuration><packageSources><clear /></packageSources></configuration>" > "$(Build.ArtifactStagingDirectory)/NuGet.config"
430-
displayName: Generate empty NuGet.config
431-
- script: dotnet tool install -g --configfile "$(Build.ArtifactStagingDirectory)/NuGet.config" $(ToolVersionArgs) --add-source "$(Build.ArtifactStagingDirectory)/packages/Shipping" Microsoft.dotnet-interactive
432-
displayName: Install global tool
433-
- script: dotnet interactive --version
434-
displayName: Write version
435-
- script: dotnet test
436-
"$(Build.SourcesDirectory)/src/dotnet-interactive.IntegrationTests/dotnet-interactive.IntegrationTests.csproj"
437-
--logger "trx;LogFileName=$(Build.ArtifactStagingDirectory)/TestResults/IntegrationTests.trx"
438-
displayName: Execute integration tests
439-
env:
440-
INTEGRATION_TEST_RUN: true
441-
- task: PublishTestResults@2
442-
displayName: Publish Test Results
443-
inputs:
444-
testResultsFormat: VSTest
445-
testResultsFiles: '**/*.trx'
446-
searchFolder: '$(Build.ArtifactStagingDirectory)/TestResults'
447-
condition: always()
448-
449388
#---------------------------------------------------------------------------------------------------------------------#
450389
# Post Build #
451390
#---------------------------------------------------------------------------------------------------------------------#

dotnet-interactive.sln

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.31603.294
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31709.452
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-interactive", "src\dotnet-interactive\dotnet-interactive.csproj", "{1A4A744F-FEF3-4361-A2E5-C5D496F7BFDC}"
77
EndProject
@@ -45,10 +45,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactiv
4545
EndProject
4646
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Interactive.PowerShell.Tests", "src\Microsoft.DotNet.Interactive.PowerShell.Tests\Microsoft.DotNet.Interactive.PowerShell.Tests.csproj", "{30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA}"
4747
EndProject
48-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-interactive.IntegrationTests", "src\dotnet-interactive.IntegrationTests\dotnet-interactive.IntegrationTests.csproj", "{8017943B-B591-49C8-B957-40141B427AD9}"
49-
EndProject
50-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "integration-tests", "integration-tests", "{979A5022-09CA-4258-B76D-CFDC31DA71E0}"
51-
EndProject
5248
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "interface-generator", "src\interface-generator\interface-generator.csproj", "{9A091E80-D5EB-4DEF-8E38-B24B128393DF}"
5349
EndProject
5450
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{4DD50BCA-133B-4594-8368-ED56939BAF6B}"
@@ -326,18 +322,6 @@ Global
326322
{30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA}.Release|x64.Build.0 = Release|Any CPU
327323
{30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA}.Release|x86.ActiveCfg = Release|Any CPU
328324
{30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA}.Release|x86.Build.0 = Release|Any CPU
329-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
330-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
331-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|x64.ActiveCfg = Debug|Any CPU
332-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|x64.Build.0 = Debug|Any CPU
333-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|x86.ActiveCfg = Debug|Any CPU
334-
{8017943B-B591-49C8-B957-40141B427AD9}.Debug|x86.Build.0 = Debug|Any CPU
335-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
336-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|Any CPU.Build.0 = Release|Any CPU
337-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|x64.ActiveCfg = Release|Any CPU
338-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|x64.Build.0 = Release|Any CPU
339-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|x86.ActiveCfg = Release|Any CPU
340-
{8017943B-B591-49C8-B957-40141B427AD9}.Release|x86.Build.0 = Release|Any CPU
341325
{9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
342326
{9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
343327
{9A091E80-D5EB-4DEF-8E38-B24B128393DF}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -482,7 +466,6 @@ Global
482466
{499F936C-AE39-477B-821A-FF48F9E1A0D0} = {11BA3480-4584-435C-BA9A-8C554DB60E9F}
483467
{CE412E28-8660-43CA-8E0B-293EAC624623} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
484468
{30DE6920-EA82-4E4F-BFCA-1FF179FAA2DA} = {11BA3480-4584-435C-BA9A-8C554DB60E9F}
485-
{8017943B-B591-49C8-B957-40141B427AD9} = {979A5022-09CA-4258-B76D-CFDC31DA71E0}
486469
{9A091E80-D5EB-4DEF-8E38-B24B128393DF} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
487470
{DE942DC3-B41B-45C5-9E01-3C4F042D3916} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}
488471
{5167FC61-2FBF-4E0D-877E-C2DD354FB955} = {B95A8485-8C53-4F56-B0CE-19C0726B5805}

global.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"sdk": {
3-
"version": "5.0.100",
3+
"version": "5.0.400",
44
"rollForward": "latestMinor"
55
},
66
"tools": {
7-
"dotnet": "5.0.100",
7+
"dotnet": "5.0.400",
88
"rollForward": "latestMinor"
99
},
1010
"msbuild-sdks": {
1111
"Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.21373.11"
1212
}
13-
}
13+
}

src/Microsoft.DotNet.Interactive.Tests/Utility/KernelExtensionTestHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static async Task<ExtensionPackage> CreateExtensionNupkg(
163163
"),
164164
("global.json", @"{
165165
""sdk"": {
166-
""version"": ""5.0.100"",
166+
""version"": ""5.0.400"",
167167
""rollForward"": ""latestMinor""
168168
}
169169
}
@@ -284,7 +284,7 @@ private static async Task CreateExtensionProjectAndBuild(
284284
"),
285285
("global.json", @"{
286286
""sdk"": {
287-
""version"": ""5.0.100"",
287+
""version"": ""5.0.400"",
288288
""rollForward"": ""latestMinor""
289289
}
290290
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.CommandLine;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Reactive.Linq;
10+
using System.Threading.Tasks;
11+
using Microsoft.DotNet.Interactive.Events;
12+
13+
namespace Microsoft.DotNet.Interactive.Connection
14+
{
15+
public class ConnectStdIO : ConnectKernelCommand<StdIOConnectionOptions>
16+
{
17+
public ConnectStdIO() : base("stdio",
18+
"Connects to a kernel using the stdio protocol")
19+
{
20+
AddOption(new Option<string[]>("--command", "The command to execute")
21+
{
22+
AllowMultipleArgumentsPerToken = true,
23+
IsRequired = true,
24+
});
25+
AddOption(new Option<DirectoryInfo>("--working-directory", () => new DirectoryInfo(Directory.GetCurrentDirectory()), "The working directory"));
26+
AddOption(new Option<bool>("--wait-for-kernel-ready-event", () => false, "Wait for a kernel ready event before continuing"));
27+
}
28+
29+
public override Task<Kernel> CreateKernelAsync(StdIOConnectionOptions options, KernelInvocationContext context)
30+
{
31+
return CreateStdioKernelAsync(options.KernelName, options.Command[0], string.Join(" ", options.Command.Skip(1)), options.WorkingDirectory, options.WaitForKernelReadyEvent);
32+
}
33+
34+
public static async Task<Kernel> CreateStdioKernelAsync(string kernelName, string command, string arguments, DirectoryInfo workingDirectory, bool waitForKernelReadyEvent = false)
35+
{
36+
var psi = new ProcessStartInfo
37+
{
38+
FileName = command,
39+
Arguments = arguments,
40+
WorkingDirectory = workingDirectory.FullName,
41+
RedirectStandardInput = true,
42+
RedirectStandardOutput = true,
43+
UseShellExecute = false,
44+
};
45+
46+
var process = new Process { StartInfo = psi };
47+
process.Start();
48+
49+
var receiver = new KernelCommandAndEventTextReceiver(process.StandardOutput);
50+
var sender = new KernelCommandAndEventTextStreamSender(process.StandardInput);
51+
52+
var kernel = new ProxyKernel(kernelName, receiver, sender);
53+
54+
kernel.RegisterForDisposal(() =>
55+
{
56+
process.Kill();
57+
process.Dispose();
58+
});
59+
60+
var _ = kernel.RunAsync();
61+
62+
if (waitForKernelReadyEvent)
63+
{
64+
TaskCompletionSource<bool> ready = new();
65+
var sub = kernel.KernelEvents.OfType<KernelReady>().Subscribe(_ =>
66+
{
67+
ready.SetResult(true);
68+
});
69+
70+
await ready.Task;
71+
sub.Dispose();
72+
}
73+
74+
return kernel;
75+
}
76+
}
77+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
#nullable enable
5+
6+
using System.IO;
7+
8+
namespace Microsoft.DotNet.Interactive.Connection
9+
{
10+
public class StdIOConnectionOptions : KernelConnectionOptions
11+
{
12+
public string[] Command { get; set; } = new string[0];
13+
public DirectoryInfo? WorkingDirectory { get; set; }
14+
public bool WaitForKernelReadyEvent { get; set; }
15+
}
16+
}

src/dotnet-interactive-vscode/common/stdioKernelTransport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class StdioKernelTransport implements KernelTransport {
114114
}
115115
catch (error) {
116116
this.diagnosticChannel.appendLine(`Failure setting up tunnel confinguration for Kernel process ${this.childProcess?.pid}`);
117-
this.diagnosticChannel.appendLine(`Error : ${error.message}`);
117+
this.diagnosticChannel.appendLine(`Error : ${(<any>error)?.message}`);
118118
return null;
119119
}
120120
}

src/dotnet-interactive.IntegrationTests/Directory.Build.props

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/dotnet-interactive.IntegrationTests/HttpApiTests.cs

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/dotnet-interactive.IntegrationTests/IntegrationFactAttribute.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)