Skip to content

Commit aefface

Browse files
authored
Merge pull request #29 from pjoiner/v0.1.10-Pre
V0.1.10 pre
2 parents 850b545 + 7d1aa8a commit aefface

23 files changed

+196
-105
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: .NET
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ '*' ]
66
pull_request:
77
branches: [ master ]
88

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ To import this library into a notbook use the `#r` magic command as follows.
2020
Click on the button to see an example notebook with a sample dataset.
2121

2222
**Note:** This library is in preview at the moment. More to come...
23+

notebooks/01_Introduction.ipynb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
"metadata": {
3434
"dotnet_interactive": {
3535
"language": "csharp"
36+
},
37+
"vscode": {
38+
"languageId": "dotnet-interactive.csharp"
3639
}
3740
},
3841
"outputs": [],
3942
"source": [
40-
"#r \"nuget:DwC-A_dotnet,0.6.0\"\n",
41-
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.9-Pre\""
43+
"#r \"nuget:DwC-A_dotnet,0.6.2\"\n",
44+
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.10-Pre\""
4245
]
4346
},
4447
{
@@ -57,6 +60,9 @@
5760
"metadata": {
5861
"dotnet_interactive": {
5962
"language": "csharp"
63+
},
64+
"vscode": {
65+
"languageId": "dotnet-interactive.csharp"
6066
}
6167
},
6268
"outputs": [],
@@ -86,6 +92,9 @@
8692
"metadata": {
8793
"dotnet_interactive": {
8894
"language": "csharp"
95+
},
96+
"vscode": {
97+
"languageId": "dotnet-interactive.csharp"
8998
}
9099
},
91100
"outputs": [],
@@ -99,6 +108,9 @@
99108
"metadata": {
100109
"dotnet_interactive": {
101110
"language": "csharp"
111+
},
112+
"vscode": {
113+
"languageId": "dotnet-interactive.csharp"
102114
}
103115
},
104116
"outputs": [],
@@ -112,6 +124,9 @@
112124
"metadata": {
113125
"dotnet_interactive": {
114126
"language": "csharp"
127+
},
128+
"vscode": {
129+
"languageId": "dotnet-interactive.csharp"
115130
}
116131
},
117132
"outputs": [],
@@ -134,6 +149,9 @@
134149
"metadata": {
135150
"dotnet_interactive": {
136151
"language": "csharp"
152+
},
153+
"vscode": {
154+
"languageId": "dotnet-interactive.csharp"
137155
}
138156
},
139157
"outputs": [],
@@ -158,6 +176,9 @@
158176
"metadata": {
159177
"dotnet_interactive": {
160178
"language": "csharp"
179+
},
180+
"vscode": {
181+
"languageId": "dotnet-interactive.csharp"
161182
}
162183
},
163184
"outputs": [],
@@ -187,6 +208,9 @@
187208
"metadata": {
188209
"dotnet_interactive": {
189210
"language": "csharp"
211+
},
212+
"vscode": {
213+
"languageId": "dotnet-interactive.csharp"
190214
}
191215
},
192216
"outputs": [],
@@ -209,6 +233,9 @@
209233
"metadata": {
210234
"dotnet_interactive": {
211235
"language": "csharp"
236+
},
237+
"vscode": {
238+
"languageId": "dotnet-interactive.csharp"
212239
}
213240
},
214241
"outputs": [],

notebooks/06_DataMapping.ipynb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
"metadata": {
1919
"dotnet_interactive": {
2020
"language": "csharp"
21+
},
22+
"vscode": {
23+
"languageId": "dotnet-interactive.csharp"
2124
}
2225
},
2326
"outputs": [],
2427
"source": [
25-
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.9-Pre\"\n",
28+
"#r \"nuget:DwC-A_dotnet.Interactive,0.1.10-Pre\"\n",
2629
"#r \"nuget:DwC-A_dotnet.Mapping,0.6.3\"\n",
2730
"#r \"nuget:Microsoft.ML\""
2831
]
@@ -52,6 +55,9 @@
5255
"metadata": {
5356
"dotnet_interactive": {
5457
"language": "csharp"
58+
},
59+
"vscode": {
60+
"languageId": "dotnet-interactive.csharp"
5561
}
5662
},
5763
"outputs": [],
@@ -85,6 +91,9 @@
8591
"metadata": {
8692
"dotnet_interactive": {
8793
"language": "csharp"
94+
},
95+
"vscode": {
96+
"languageId": "dotnet-interactive.csharp"
8897
}
8998
},
9099
"outputs": [],
@@ -108,6 +117,9 @@
108117
"metadata": {
109118
"dotnet_interactive": {
110119
"language": "csharp"
120+
},
121+
"vscode": {
122+
"languageId": "dotnet-interactive.csharp"
111123
}
112124
},
113125
"outputs": [],
@@ -136,6 +148,9 @@
136148
"metadata": {
137149
"dotnet_interactive": {
138150
"language": "csharp"
151+
},
152+
"vscode": {
153+
"languageId": "dotnet-interactive.csharp"
139154
}
140155
},
141156
"outputs": [],
@@ -186,6 +201,9 @@
186201
"metadata": {
187202
"dotnet_interactive": {
188203
"language": "csharp"
204+
},
205+
"vscode": {
206+
"languageId": "dotnet-interactive.csharp"
189207
}
190208
},
191209
"outputs": [],
@@ -199,6 +217,7 @@
199217
" m.Type = row[\"http://purl.org/dc/terms/type\"];\n",
200218
" m.Identifier = row[\"http://purl.org/dc/terms/identifier\"];\n",
201219
" m.Created = row.Convert<DateTime>(\"http://purl.org/dc/terms/created\");\n",
220+
" m.Creator = row[\"http://purl.org/dc/terms/creator\"];\n",
202221
"});\n",
203222
"\n",
204223
"archive.Extensions\n",
@@ -222,6 +241,9 @@
222241
"metadata": {
223242
"dotnet_interactive": {
224243
"language": "csharp"
244+
},
245+
"vscode": {
246+
"languageId": "dotnet-interactive.csharp"
225247
}
226248
},
227249
"outputs": [],

src/DwC-A_dotnet.Interactive/Commands/DwcaCodegenCommand.cs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
using Core::DwC_A;
44
using DwC_A.Config;
55
using DwC_A.Generator;
6+
using DwC_A.Interactive.Extensions;
67
using DwC_A.Interactive.Mapping;
78
using Microsoft.DotNet.Interactive;
89
using Microsoft.DotNet.Interactive.Events;
9-
using Microsoft.DotNet.Interactive.ValueSharing;
1010
using System;
1111
using System.CommandLine;
12-
using System.CommandLine.Invocation;
1312
using System.IO;
1413
using System.Threading.Tasks;
1514

@@ -20,47 +19,52 @@ internal class DwcaCodegenCommand : Command
2019
public DwcaCodegenCommand()
2120
: base("#!dwca-codegen", "Generate strongly typed class files for Darwin Core Archive")
2221
{
23-
AddArgument(new Argument<string>()
22+
var archivePathArg = new Argument<string>()
2423
{
2524
Name = "archivePath",
2625
Description = "Path to archive folder or zip file"
27-
});
26+
};
27+
AddArgument(archivePathArg);
2828

29-
AddOption(new Option<string>(
30-
aliases: new[] {"-c", "--configName"},
29+
var cfgOption = new Option<string>(
30+
aliases: new[] { "-c", "--configName" },
3131
description: "Name of configuration variable",
3232
getDefaultValue: () => ""
33-
));
33+
);
34+
AddOption(cfgOption);
3435

35-
Handler = CommandHandler.Create<KernelInvocationContext, string, string>((Func<KernelInvocationContext, string, string, Task>)(async (context, archivePath, configName) =>
36+
System.CommandLine.Handler.SetHandler(this,async (context) =>
3637
{
38+
var archivePath = context.ParseResult.GetValueForArgument(archivePathArg);
39+
var configName = context.ParseResult.GetValueForOption(cfgOption);
3740
var archive = new ArchiveReader(archivePath);
3841

39-
var csharpKernel = (ISupportGetValue)context.HandlingKernel.FindKernel("csharp");
40-
if (!csharpKernel.TryGetValue<IGeneratorConfiguration>(configName, out IGeneratorConfiguration config))
41-
{
42-
config = new GeneratorConfigurationBuilder().Build();
43-
}
44-
context.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
45-
context.Display(config, new[] { "text/html" });
42+
var csharpKernel = KernelInvocationContext.Current.HandlingKernel.FindKernelByName("csharp");
43+
var (success, value) = await csharpKernel.TryRequestValueAsync(configName);
44+
IGeneratorConfiguration config = success ?
45+
value.Value as IGeneratorConfiguration :
46+
null ??
47+
new GeneratorConfigurationBuilder().Build();
48+
KernelInvocationContext.Current.Display($"Opening archive {archive.FileName} using configuration", new[] { "text/html" });
49+
KernelInvocationContext.Current.Display(config, new[] { "text/html" });
4650

47-
await GenerateClass(context, archive.CoreFile, config);
48-
foreach(var extension in archive.Extensions.GetFileReaders())
51+
await GenerateClass(KernelInvocationContext.Current, archive.CoreFile, config);
52+
foreach (var extension in archive.Extensions.GetFileReaders())
4953
{
50-
await GenerateClass(context, extension, config);
54+
await GenerateClass(KernelInvocationContext.Current, extension, config);
5155
}
52-
}));
56+
});
5357
}
5458

5559
private static async Task GenerateClass(KernelInvocationContext context,
5660
IFileReader fileReader,
5761
IGeneratorConfiguration config)
5862
{
59-
var classGenerator = new ClassGenerator();
6063
var className = Path.GetFileNameWithoutExtension(fileReader.FileName);
61-
className = char.ToUpper(className[0]) + className.Substring(1);
64+
className = char.ToUpper(className[0]) + className[1..];
6265
context.Display($"Generating class {className}", new[] { "text/html" });
63-
var source = classGenerator.GenerateFile(fileReader.FileMetaData, config);
66+
var source = new ClassGenerator()
67+
.GenerateFile(fileReader.FileMetaData, config);
6468
var result = await context.HandlingKernel.SubmitCodeAsync(source);
6569
result.KernelEvents.Subscribe((ev) => { }, (ex) =>
6670
{

src/DwC-A_dotnet.Interactive/Commands/TermsCommand.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
using Microsoft.DotNet.Interactive;
22
using System;
33
using System.CommandLine;
4-
using System.CommandLine.Invocation;
54

65
namespace DwC_A.Interactive.Commands
76
{
87
internal class TermsCommand : Command
98
{
109
public TermsCommand() : base("#!terms", "Display Darwin Core standard terms")
1110
{
12-
Handler = CommandHandler.Create((KernelInvocationContext invocationContext) =>
11+
System.CommandLine.Handler.SetHandler(this, (invocationContext) =>
1312
{
1413
var defaultTerms = new DefaultTerms();
15-
invocationContext.Display(defaultTerms);
14+
KernelInvocationContext.Current.Display(defaultTerms);
1615
});
1716
}
1817
}
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
55
<RootNamespace>DwC_A.Interactive</RootNamespace>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Copyright>Copyright © Paul Joiner 2021</Copyright>
@@ -11,21 +11,22 @@
1111
<PackageTags>DwC-A darwin-core Biodiversity</PackageTags>
1212
<Authors>Paul Joiner</Authors>
1313
<Company>Paul Joiner</Company>
14-
<Version>0.1.9-Pre</Version>
14+
<Version>0.1.10-Pre</Version>
1515
<Description>.NET Interactive Extensions for Darwin Core Archive file reader</Description>
16-
<AssemblyVersion>0.1.9.0</AssemblyVersion>
17-
<FileVersion>0.1.9.0</FileVersion>
16+
<AssemblyVersion>0.1.10.0</AssemblyVersion>
17+
<FileVersion>0.1.10.0</FileVersion>
1818
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1919
<PackageReadmeFile>README.md</PackageReadmeFile>
20+
<NoWarn>NU5100</NoWarn>
2021
</PropertyGroup>
2122

2223
<ItemGroup>
23-
<PackageReference Include="DwC-A_dotnet" Version="0.6.0">
24+
<PackageReference Include="DwC-A_dotnet" Version="0.7.0">
2425
<Aliases>Core</Aliases>
2526
</PackageReference>
2627
<PackageReference Include="DwC-A_dotnet.Mapping" Version="0.6.3" />
27-
<PackageReference Include="System.CommandLine" Version="2.0.0-*" />
28-
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.21575.1" />
28+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
29+
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22553.7" />
2930
</ItemGroup>
3031

3132
<ItemGroup>
@@ -35,11 +36,8 @@
3536
</ItemGroup>
3637

3738
<ItemGroup>
38-
<None Include="$(OutputPath)/DwC-A_dotnet.Interactive.dll" Pack="true" PackagePath="interactive-extensions/dotnet" />
39-
<None Include="..\..\LICENSE">
40-
<Pack>True</Pack>
41-
<PackagePath></PackagePath>
42-
</None>
39+
<None Include="$(OutputPath)/net6.0/DwC-A_dotnet.Interactive.dll" Pack="true" PackagePath="interactive-extensions/dotnet" />
40+
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
4341
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
4442
</ItemGroup>
4543
</Project>

src/DwC-A_dotnet.Interactive/DwCKernelExtension.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using Core.DwC_A;
66
using Core.DwC_A.Meta;
77
using DwC_A.Interactive.Formatters;
8-
using System.CommandLine;
9-
using System.CommandLine.Invocation;
108
using System.Collections.Generic;
119
using DwC_A.Interactive.Commands;
1210
using DwC_A.Config;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.DotNet.Interactive;
2+
using Microsoft.DotNet.Interactive.Commands;
3+
using Microsoft.DotNet.Interactive.Events;
4+
using System.Linq;
5+
using System.Reactive.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace DwC_A.Interactive.Extensions
9+
{
10+
//Shamelessly copied from the dotnet.interactive test utilities.
11+
//See https://github.com/dotnet/interactive/blob/3c5637d513f0f3c406b449435b245e699f82a989/src/Microsoft.DotNet.Interactive.Tests/Utility/KernelExtensions.cs
12+
internal static class KernelExtensions
13+
{
14+
public static async Task<(bool success, ValueProduced valueProduced)> TryRequestValueAsync(this Kernel kernel, string valueName)
15+
{
16+
if (kernel.SupportsCommandType(typeof(RequestValue)))
17+
{
18+
var commandResult = await kernel.SendAsync(new RequestValue(valueName));
19+
20+
if (await commandResult.KernelEvents.OfType<ValueProduced>().FirstOrDefaultAsync() is { } valueProduced)
21+
{
22+
return (true, valueProduced);
23+
}
24+
}
25+
26+
return (false, default);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)