Skip to content

Commit

Permalink
Support other file extensions (jonsequitur#72)
Browse files Browse the repository at this point in the history
* don't write serialized notebook to stdout

* update package versions

* enable directly running .ps1, .cs, .csx, .fs, .fsx files
  • Loading branch information
jonsequitur authored Sep 28, 2022
1 parent 5b4e59e commit 63ba668
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/dotnet-repl.Tests/Automation/NotebookRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,17 @@ public async Task When_an_ipynb_is_run_and_no_error_is_produced_then_the_exit_co
{
var result = await _parser.InvokeAsync($"--notebook \"{_directory}/succeed.ipynb\" --exit-after-run", console);

var output = _writer.ToString();
console.Error.ToString().Should().BeEmpty();
result.Should().Be(0);
output.Should().Contain("Success!");
}

[Fact]
public async Task When_an_ipynb_is_run_and_an_error_is_produced_from_a_cell_then_the_exit_code_is_2()
{
var result = await _parser.InvokeAsync($"--notebook \"{_directory}/fail.ipynb\" --exit-after-run", console);

var output = _writer.ToString();
console.Error.ToString().Should().BeEmpty();
result.Should().Be(2);
output.Should().Contain("Oops!");
}

[Fact]
Expand Down
8 changes: 2 additions & 6 deletions src/dotnet-repl/CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Command DescribeCommand()

foreach (var inputField in inputFields)
{
table.AddRow(inputField.Prompt, inputField.TypeHint, $"--input {inputField.Prompt}=\"parameter value\"");
table.AddRow(inputField.ValueName, inputField.TypeHint, $"--input {inputField.ValueName}=\"parameter value\"");
}

console.Write(table);
Expand Down Expand Up @@ -267,11 +267,7 @@ await repl.RunAsync(
case OutputFormat.ipynb:
{
var outputNotebook = resultNotebook.SerializeToJupyter();
if (options.OutputPath is null)
{
ansiConsole.Write(outputNotebook);
}
else
if (options.OutputPath is not null)
{
await File.WriteAllTextAsync(options.OutputPath.FullName, outputNotebook);
}
Expand Down
9 changes: 8 additions & 1 deletion src/dotnet-repl/DocumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static async Task<InteractiveDocument> LoadInteractiveDocumentAsync(
}

public static async Task<InteractiveDocument> LoadInteractiveDocumentAsync(
FileInfo file,
FileInfo file,
KernelInfoCollection kernelInfos)
{
var fileContents = await File.ReadAllTextAsync(file.FullName);
Expand All @@ -30,6 +30,13 @@ public static async Task<InteractiveDocument> LoadInteractiveDocumentAsync(
{
".ipynb" => Notebook.Parse(fileContents, kernelInfos),
".dib" => CodeSubmission.Parse(fileContents, kernelInfos),

".cs" => new InteractiveDocument { new InteractiveDocumentElement(fileContents, "csharp") },
".csx" => new InteractiveDocument { new InteractiveDocumentElement(fileContents, "csharp") },
".fs" => new InteractiveDocument { new InteractiveDocumentElement(fileContents, "fsharp") },
".fsx" => new InteractiveDocument { new InteractiveDocumentElement(fileContents, "fsharp") },
".ps1" => new InteractiveDocument { new InteractiveDocumentElement(fileContents, "pwsh") },

_ => throw new InvalidOperationException($"Unrecognized extension for a notebook: {file.Extension}"),
};
}
Expand Down
12 changes: 6 additions & 6 deletions src/dotnet-repl/dotnet-repl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22471.1" />
<PackageReference Include="microsoft.dotnet.interactive.csharp" Version="1.0.0-beta.22471.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Documents" Version="1.0.0-beta.22471.1" />
<PackageReference Include="microsoft.dotnet.interactive.fsharp" Version="1.0.0-beta.22471.1" />
<PackageReference Include="Microsoft.Dotnet.Interactive.Browser" Version="1.0.0-beta.22471.1" />
<PackageReference Include="microsoft.dotnet.interactive.powershell" Version="1.0.0-beta.22471.1" />
<PackageReference Include="microsoft.dotnet.interactive" Version="1.0.0-beta.22476.1" />
<PackageReference Include="microsoft.dotnet.interactive.csharp" Version="1.0.0-beta.22476.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Documents" Version="1.0.0-beta.22476.1" />
<PackageReference Include="microsoft.dotnet.interactive.fsharp" Version="1.0.0-beta.22476.1" />
<PackageReference Include="Microsoft.Dotnet.Interactive.Browser" Version="1.0.0-beta.22476.1" />
<PackageReference Include="microsoft.dotnet.interactive.powershell" Version="1.0.0-beta.22476.1" />
<PackageReference Include="radline" Version="0.6.0" />
<PackageReference Include="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" />
<PackageReference Include="system.reactive" Version="5.0.0" />
Expand Down

0 comments on commit 63ba668

Please sign in to comment.